/* ============================================================
   BTP FINCOOP 1.6.1 — TABLETTE, TÉLÉPHONE ET NAVIGATION REPLIABLE
   Structure claire, palette bleue.
   ============================================================ */

/* ============================================================
   1. VARIABLES & STRUCTURE GÉNÉRALE
   ============================================================ */
:root { --sidebar-width: 245px; }

.app-shell { align-items: flex-start; }

.sidebar {
  position: sticky;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.sidebar .brand { flex-shrink: 0; }
.brand-mark, .nav-icon { flex-shrink: 0; }

.nav-initials {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .02em;
}

.nav-icon {
  width: 20px;
  text-align: center;
}

.side-link {
  align-items: center;
  min-height: 44px;
}

.side-nav-project {
  max-height: none;
  overflow: visible;
}

.sidebar-footer {
  padding-top: 18px;
  margin-top: 24px;
}

.main-area { width: 0; }
.content { max-width: 1760px; }


/* ============================================================
   2. TOPBAR & EN-TÊTE
   ============================================================ */
.topbar {
  min-height: 78px;
  height: auto;
  padding-block: 12px;
  gap: 16px;
}

.topbar-heading {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.topbar-heading > div { min-width: 0; }

.topbar-title,
.user-info,
.page-heading h1 { overflow-wrap: anywhere; }


/* ============================================================
   3. BOUTONS TOGGLE / CLOSE / BACKDROP (SIDEBAR)
   ============================================================ */
.sidebar-toggle,
.sidebar-close {
  display: none;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--navy);
  cursor: pointer;
}

.navigation-ready .sidebar-toggle { display: grid; }

.sidebar-backdrop[hidden] { display: none; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #11243a80;
  border: 0;
  padding: 0;
}

.sidebar-toggle:hover {
  background: #eff6ff;         /* Bleu clair (anciennement #e8f5f6) */
  border-color: #2563eb;       /* Bleu (anciennement #087f8c) */
}


/* ============================================================
   4. ACCESSIBILITÉ (FOCUS)
   ============================================================ */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--navy);
  outline-offset: 3px;
}

.sidebar :focus-visible {
  outline-color: #ffffff;
  outline-offset: -2px;
}


/* ============================================================
   5. BOUTONS & MENUS
   ============================================================ */
.button,
.button-small,
.notification-menu > summary { min-height: 44px; }

.notification-menu > summary { width: 44px; }

.user-menu { flex-shrink: 0; }
.user-menu form { margin: 0; }

.breadcrumb,
.toolbar-actions,
.form-actions,
.gantt-actions { flex-wrap: wrap; }


/* ============================================================
   6. GRILLES & CONTENEURS (MIN-WIDTH)
   ============================================================ */
.page-heading > *,
.two-column > *,
.stats-grid > *,
.report-charts-grid > * { min-width: 0; }

.table-wrap,
.boq-wrap {
  max-width: 100%;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.table-wrap th,
.boq-wrap th { position: relative; }


/* ============================================================
   7. FORMULAIRES
   ============================================================ */
.field input,
.field select,
.field textarea { min-height: 44px; }

.field input[type=checkbox],
.field input[type=radio] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  accent-color: var(--accent-hover);
}

.field input[type=file] { max-width: 100%; }
.field input[type=checkbox] + label { padding-block: 10px; }


/* ============================================================
   8. MÉDIAS & TEXTES LONGS
   ============================================================ */
img, video { max-width: 100%; }

.notification-dropdown {
  max-height: min(70vh, 560px);
  overflow-y: auto;
}

.description-block,
.notification-item,
.document-main,
.purchase-note { overflow-wrap: anywhere; }


/* ============================================================
   9. MEDIA QUERIES
   ============================================================ */

/* --- Grands écrans (≥1200px) : Sidebar repliée --- */
@media (min-width: 1200px) {
  .sidebar-collapsed .sidebar {
    width: 80px;
    padding-inline: 12px;
  }
  .sidebar-collapsed .brand { padding-inline: 8px; }

  .sidebar-collapsed .brand-text,
  .sidebar-collapsed .nav-label,
  .sidebar-collapsed .sidebar-label,
  .sidebar-collapsed .sidebar-project-name,
  .sidebar-collapsed .sidebar-footer { display: none; }

  .sidebar-collapsed .side-link {
    justify-content: center;
    padding-inline: 0;
  }
  .sidebar-collapsed .sidebar-project { margin-top: 18px; }
  .sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
}


/* --- Tablettes (≤1199px) : Navigation en overlay --- */
@media (max-width: 1199px) {
  .navigation-ready .app-shell { display: block; }
  .main-area { width: 100%; }

  .navigation-ready .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 110;
    width: min(320px, 88vw);
    padding: 24px 16px;
    transform: translateX(-100%);
    visibility: hidden;
    box-shadow: 16px 0 48px #11243a30;
  }

  .navigation-ready .sidebar-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }

  .sidebar-open { overflow: hidden; }

  .navigation-ready .sidebar-close {
    display: grid;
    position: absolute;
    top: 14px;
    right: 12px;
    background: #ffffff12;
    border-color: #ffffff30;
    color: #fff;
    font-size: 26px;
  }

  .sidebar .brand { padding: 0 42px 28px 8px; }
  .sidebar .brand strong { font-size: 14px; }

  .sidebar .sidebar-label,
  .sidebar .sidebar-footer { display: flex; }

  .sidebar .sidebar-project-name { display: block; }
  .sidebar .side-nav { display: grid; overflow: visible; }

  .sidebar .side-link {
    white-space: normal;
    padding: 12px;
    font-size: 15px;
  }

  .sidebar-project { margin-top: 22px; padding-top: 18px; }

  .topbar { padding: 12px 24px; }
  .content { padding: 24px 24px 40px; }

  .page-heading { align-items: flex-start; flex-wrap: wrap; }
  .page-heading > div:first-child { flex: 1 1 300px; }
  .page-heading .gantt-actions { flex: 1 1 auto; justify-content: flex-start; }

  .stats-grid,
  .stock-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .two-column { grid-template-columns: minmax(0, 1fr); }
  .module-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .module-links .planning-link-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .document-row { grid-template-columns: 44px minmax(0, 1fr); }
  .document-actions {
    grid-column: 2;
    justify-content: flex-start;
    max-width: none;
  }

  .courrier-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .courrier-filters > .field:first-child { grid-column: 1 / -1; }

  .report-charts-grid { grid-template-columns: minmax(0, 1fr); }

  .frappe-task-list { flex-basis: 240px; }
  .frappe-host .gantt-container { min-width: 0; }
  .frappe-view-actions button { min-height: 44px; padding-inline: 14px; }

  .plan-toolbar,
  .wbs-head,
  .depot-setup { flex-wrap: wrap; }

  .toolbar-actions { gap: 8px; }

  td { font-size: 13px; padding-block: 16px; }
  th { font-size: 11px; }

  .field label { font-size: 14px; }
  .field input,
  .field select,
  .field textarea,
  .table-wrap input,
  .table-wrap select,
  .table-wrap textarea { font-size: 17px; min-height: 44px; }

  .text-button,
  .add-boq { min-height: 44px; display: inline-flex; align-items: center; }

  .document-history > summary,
  .courrier-audit > summary { min-height: 44px; padding-block: 12px; }
}


/* --- Mobile (≤740px) --- */
@media (max-width: 740px) {
  .topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar-heading { flex: 1 1 180px; gap: 10px; }
  .user-menu { margin-left: auto; gap: 8px; }
  .topbar-title { font-size: 15px; }

  .user-info { display: block; max-width: 140px; }
  .user-info strong { display: none; }
  .user-info small { font-size: 12px; }
  .user-menu .avatar { display: none; }

  .content { padding: 20px 14px 32px; }
  .page-heading > div:first-child { flex-basis: auto; }

  .module-links,
  .alert-settings-grid,
  .form-grid { grid-template-columns: minmax(0, 1fr); }

  .form-actions { justify-content: flex-start; }
  .form-actions .button { flex: 1 1 140px; }

  .stat-card strong {
    font-size: clamp(18px, 4vw, 23px);
    overflow-wrap: anywhere;
  }

  .notification-dropdown {
    position: fixed;
    top: 125px;
    right: 12px;
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 145px);
  }

  .member-list-panel {
    position: fixed;
    top: 140px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100dvh - 160px);
    overflow: auto;
    z-index: 60;
  }

  .frappe-task-list { flex-basis: 145px; }
  .frappe-task-row strong { font-size: 12px; }
  .frappe-toolbar { padding: 12px; }
  .frappe-task-head { padding-inline: 8px; }

  .document-history-row { flex-wrap: wrap; }

  .execution-actions form { min-width: 0; width: 100%; }
  .execution-actions input { min-width: 0; width: 100%; }

  .notification-center-row { flex-wrap: wrap; }
  .notification-center-row > .button { margin-left: 20px; }

  .breadcrumb { line-height: 1.8; }
}


/* --- Très petits écrans (≤470px) --- */
@media (max-width: 470px) {
  .courrier-filters { grid-template-columns: minmax(0, 1fr); }
  .courrier-filters > .field:first-child { grid-column: auto; }

  .gantt-actions .button { flex: 1 1 140px; }

  .member-list-row { grid-template-columns: 28px minmax(0, 1fr); }
  .member-role {
    grid-column: 2;
    justify-self: start;
    max-width: 100%;
  }
}


/* --- Mouvement réduit --- */
@media (prefers-reduced-motion: no-preference) {
  .sidebar {
    transition: width .18s ease, transform .18s ease;
  }
}


/* --- Impression --- */
@media print {
  .sidebar,
  .sidebar-toggle,
  .sidebar-backdrop,
  .user-menu { display: none !important; }

  .main-area { width: 100%; }
  .app-shell { display: block; }
  .content { max-width: none; padding: 0; }
  .table-wrap { overflow: visible; }
}