/* DHD Livraison Express Plus — interface écran.

   Chargée après style.css : redéfinit les jetons de couleur et habille la
   coque (menu latéral, barre du haut, contenu). Tout est sous
   @media screen : les papiers imprimés restent régis par style.css et
   fiche-print.css, sans aucun changement. */

:root {
  --navy: #0f1f3d;
  --navy-2: #182b52;
  --navy-text: #c7d0e0;
  --orange: #f58220;
  --orange-dark: #d96e12;
  --orange-soft: #fff3e8;
  --ink: #111827;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f4f6fa;
  --card: #ffffff;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --success: #067647;
  --success-soft: #ecfdf3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.07);
  --shadow-lg: 0 16px 40px rgba(15, 31, 61, 0.22);
  --sidebar-w: 264px;
  --topbar-h: 64px;
}

@media screen {
  /* Peint avant tout script : le passage d'une page à l'autre ne montre
     plus le blanc du navigateur. */
  html {
    background: var(--bg);
  }

  body {
    background: var(--bg);
    color: var(--ink);
  }

  /* Rien ne s'affiche avant la vérification de la session. */
  .auth-pending .shell {
    visibility: hidden;
  }

  /* ——— Coque ——— */

  .shell-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    padding: 1rem 0.75rem;
    background: var(--navy);
    color: var(--navy-text);
    overflow-y: auto;
  }

  .shell-main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin-left: var(--sidebar-w);
  }

  .shell-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: var(--topbar-h);
    padding: 0 1.75rem;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: saturate(1.4) blur(8px);
  }

  .shell-title {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .shell-content {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.75rem;
  }

  .shell-overlay {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(15, 31, 61, 0.45);
  }

  .shell-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
  }

  /* ——— Menu latéral ——— */

  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.35rem 0.6rem 1.1rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
  }

  .sidebar-brand:hover {
    text-decoration: none;
  }

  .sidebar-mark {
    width: 40px;
    height: 40px;
    padding: 4px;
    border-radius: 10px;
    background: #fff;
  }

  .sidebar-name {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.25;
  }

  .sidebar-nav {
    flex: 1;
  }

  .nav-section {
    margin-top: 0.9rem;
  }

  .nav-title {
    margin: 0 0 0.35rem;
    padding: 0 0.75rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #7d8aa5;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    margin: 0.1rem 0;
    padding: 0.62rem 0.75rem;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--navy-text);
    font: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
  }

  .nav-item:hover {
    background: var(--navy-2);
    color: #fff;
    text-decoration: none;
  }

  .nav-badge {
    margin-left: auto;
    min-width: 1.35rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--orange);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
  }

  .nav-item.is-current .nav-badge {
    background: #fff;
    color: var(--orange-dark);
  }

  .nav-item.is-current {
    background: var(--orange);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(245, 130, 32, 0.35);
  }

  .nav-item:focus-visible {
    outline: 2px solid var(--orange);
    outline-offset: 2px;
  }

  .nav-icon {
    flex: 0 0 auto;
    width: 1.15rem;
    height: 1.15rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .sidebar-foot {
    padding-top: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  .nav-logout:hover {
    background: rgba(217, 45, 32, 0.18);
    color: #ffd3cf;
  }

  .sidebar-phone {
    display: block;
    padding: 0.5rem 0.75rem 0;
    font-size: 0.8rem;
    color: #7d8aa5;
  }

  /* ——— Utilisateur connecté ——— */

  .shell-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }

  .user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 999px;
    background: var(--navy);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
  }

  .user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
  }

  .user-name {
    font-size: 0.88rem;
    font-weight: 600;
  }

  .role-badge,
  .status-badge {
    display: inline-block;
    width: fit-content;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
  }

  .role-admin {
    background: #e8edf8;
    color: var(--navy);
  }

  .role-agent {
    background: var(--orange-soft);
    color: var(--orange-dark);
  }

  .status-badge.is-active {
    background: var(--success-soft);
    color: var(--success);
  }

  .status-badge.is-inactive {
    background: #f2f4f7;
    color: var(--muted);
  }

  /* Plusieurs pastilles dans une même cellule restent côte à côte. */
  .badge-group {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.3rem;
  }

  /* ——— Cartes, formulaires, boutons ——— */

  .panel {
    border-color: var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.35rem 1.5rem 1.5rem;
  }

  .panel-head {
    border-bottom: 1px solid var(--line);
    position: relative;
  }

  .panel-head::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 3rem;
    height: 3px;
    border-radius: 3px;
    background: var(--orange);
  }

  .field input,
  .field select,
  .field textarea {
    width: 100%;
    padding: 0.62rem 0.8rem;
    border: 1px solid #d0d5dd;
    border-radius: 9px;
    font: inherit;
    font-size: 0.95rem;
    color: var(--ink);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
  }

  .field textarea {
    resize: vertical;
    line-height: 1.5;
  }

  .field input:focus,
  .field select:focus,
  .field textarea:focus {
    outline: none;
    border-color: var(--orange);
    box-shadow: 0 0 0 4px rgba(245, 130, 32, 0.16);
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border-radius: 9px;
    text-decoration: none;
  }

  .btn:hover {
    text-decoration: none;
  }

  .btn-primary {
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  }

  .btn-primary:disabled {
    opacity: 0.6;
    cursor: wait;
  }

  .btn-danger {
    background: var(--danger);
    color: #fff;
  }

  .btn-danger:hover {
    background: #b42318;
  }

  .btn-sm {
    padding: 0.45rem 0.85rem;
    font-size: 0.85rem;
  }

  .btn-block {
    width: 100%;
  }

  .btn-link {
    padding: 0;
    border: none;
    background: none;
    color: var(--orange-dark);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
  }

  .btn-link:hover {
    text-decoration: underline;
  }

  .form-error {
    margin: 0 0 1rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid #fecdca;
    border-radius: 9px;
    background: var(--danger-soft);
    color: #b42318;
    font-size: 0.88rem;
    font-weight: 600;
  }

  /* ——— Listes ——— */

  .list-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 1rem;
    margin: -0.35rem 0 1rem;
  }

  .field-inline {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
  }

  .field-inline select {
    width: auto;
    min-width: 11rem;
    padding: 0.5rem 0.7rem;
  }

  .data-table thead th {
    background: #f9fafb;
    color: var(--muted);
  }

  .data-table tbody tr:hover {
    background: #fcfcfd;
  }

  .cell-author {
    color: var(--muted);
  }

  /* ——— Tableau de bord ——— */

  .stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
  }

  .stat-card {
    padding: 1.1rem 1.25rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
  }

  .stat-label {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
  }

  .stat-value {
    margin: 0.35rem 0 0;
    font-size: 1.9rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--navy);
  }

  .stat-card.is-accent {
    border-color: transparent;
    background: linear-gradient(135deg, var(--orange), #f9a14a);
  }

  .stat-card.is-accent .stat-label,
  .stat-card.is-accent .stat-value {
    color: #fff;
  }

  /* ——— Paramètres ——— */

  .settings-group {
    margin: 0 0 1.25rem;
    padding: 1rem 1.1rem 0.25rem;
    border: 1px solid var(--line);
    border-radius: 10px;
  }

  .settings-group legend {
    padding: 0 0.4rem;
    font-weight: 700;
    color: var(--navy);
  }

  .settings-field-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .field-warn {
    margin: 0.35rem 0 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--orange-dark);
  }

  .sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 0 -1.75rem;
    padding: 0.85rem 1.75rem;
    background: rgba(244, 246, 250, 0.95);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(6px);
  }

  /* ——— Messages ——— */

  .toast-host {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .toast {
    max-width: 22rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    background: var(--navy);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
  }

  .toast-success {
    background: var(--success);
  }

  .toast-error {
    background: var(--danger);
  }

  /* ——— Connexion ——— */

  .auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    background:
      radial-gradient(ellipse 70% 60% at 100% 0%, rgba(245, 130, 32, 0.25), transparent 60%),
      linear-gradient(160deg, var(--navy) 0%, #0a1630 100%);
  }

  .auth-card {
    width: 100%;
    max-width: 26rem;
    padding: 2rem;
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-lg);
  }

  .auth-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
  }

  .auth-mark {
    width: 52px;
    height: 52px;
  }

  .auth-company {
    margin: 0;
    font-weight: 800;
    color: var(--navy);
  }

  .auth-sub {
    margin: 0.1rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
  }

  .auth-form h1 {
    margin: 0 0 1rem;
    font-size: 1.35rem;
  }

  .auth-help {
    margin: 0.9rem 0 0;
    font-size: 0.82rem;
    color: var(--muted);
  }

  .auth-form .auth-help:first-of-type {
    margin: -0.4rem 0 1rem;
  }

  .password-field {
    position: relative;
    display: flex;
  }

  .password-field input {
    padding-right: 5.2rem;
  }

  .password-toggle {
    position: absolute;
    top: 50%;
    right: 0.4rem;
    transform: translateY(-50%);
    padding: 0.3rem 0.55rem;
    border: none;
    border-radius: 6px;
    background: #f2f4f7;
    color: var(--muted);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
  }

  /* ——— Tablette : menu en tiroir ——— */

  @media (max-width: 1023px) {
    .shell-sidebar {
      transform: translateX(-100%);
      transition: transform 0.22s ease;
      box-shadow: var(--shadow-lg);
    }

    body.nav-open .shell-sidebar {
      transform: none;
    }

    .shell-main {
      margin-left: 0;
    }

    .shell-menu-btn {
      display: inline-flex;
    }

    .shell-topbar {
      padding: 0 1rem;
    }

    .shell-content {
      padding: 1.25rem 1rem;
    }

    .sticky-actions {
      margin: 0 -1rem;
      padding: 0.75rem 1rem;
    }
  }

  /* ——— Téléphone : tableaux en cartes ——— */

  @media (max-width: 720px) {
    .user-meta {
      display: none;
    }

    .panel {
      padding: 1rem;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
      display: block;
      width: 100%;
      min-width: 0;
    }

    .data-table thead,
    .data-table colgroup {
      display: none;
    }

    .data-table tr {
      margin-bottom: 0.75rem;
      padding: 0.5rem 0.75rem;
      border: 1px solid var(--line);
      border-radius: 10px;
      background: #fff;
    }

    .data-table td {
      display: flex;
      justify-content: space-between;
      gap: 1rem;
      padding: 0.4rem 0;
      border-bottom: 1px dashed var(--line);
      white-space: normal;
      text-align: right;
    }

    .data-table td:last-child {
      border-bottom: none;
    }

    .data-table td::before {
      content: attr(data-label);
      flex: 0 0 auto;
      font-size: 0.72rem;
      font-weight: 700;
      text-transform: uppercase;
      color: var(--muted);
      text-align: left;
    }

    .data-table .actions-cell {
      justify-content: flex-end;
    }

    .data-table .actions-cell::before {
      content: none;
    }

    .stat-value {
      font-size: 1.5rem;
    }
  }
}

/* ——— Filtres des listes et actions bloquées ——— */

@media screen {
  .col-author {
    width: 9.5rem;
  }

  .filter-select {
    min-width: 11rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid #d0d5dd;
    border-radius: 9px;
    background: #fff;
    font: inherit;
    font-size: 0.9rem;
    color: var(--ink);
  }

  .filter-select:focus {
    outline: none;
    border-color: var(--orange);
    box-shadow: 0 0 0 4px rgba(245, 130, 32, 0.16);
  }

  .icon-btn[aria-disabled="true"] {
    opacity: 0.35;
    cursor: not-allowed;
  }
}

/* ——— Ajustements responsive ——— */

@media screen and (max-width: 1023px) {
  /* L'ombre du menu replié débordait sur le bord gauche de la page. */
  .shell-sidebar {
    box-shadow: none;
  }

  body.nav-open .shell-sidebar {
    box-shadow: var(--shadow-lg);
  }
}

@media screen {
  /* 7 colonnes seulement : pas besoin de la largeur minimale de l'historique. */
  #users-table {
    min-width: 40rem;
  }
}

@media screen and (max-width: 720px) {
  #history-table td:nth-child(7) {
    padding-left: 0;
  }

  #users-table {
    min-width: 0;
  }
}

/* ——— Fiche client : carte d'identité jointe à l'inscription ——— */

@media screen {
  .id-photo-view {
    display: inline-block;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
    padding: 0.5rem;
    cursor: zoom-in;
  }

  .id-photo-view img {
    display: block;
    max-width: min(100%, 34rem);
    max-height: 22rem;
    border-radius: 8px;
  }
}

/* ——— Bouton du menu visible sur tous les écrans ——— */

@media screen {
  .shell-menu-btn {
    display: inline-flex;
  }

  .shell-menu-btn:hover {
    background: #f2f4f7;
  }
}

@media screen and (min-width: 1024px) {
  .shell-sidebar {
    transition: transform 0.22s ease;
  }

  .shell-main {
    transition: margin-left 0.22s ease;
  }

  body.nav-collapsed .shell-sidebar {
    transform: translateX(-100%);
  }

  body.nav-collapsed .shell-main {
    margin-left: 0;
  }
}
