:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --border: #dfe3dc;
  --text: #223022;
  --text-muted: #6b756a;
  --primary: #2e7d32;
  --primary-dark: #205825;
  --danger: #c62828;
  --warning: #ed6c02;
  --info: #1565c0;
  --radius: 6px;
}

* { box-sizing: border-box; }

/* L'attribut HTML "hidden" (basculé en JS) a la même spécificité qu'une
   règle de classe comme ".login-screen { display: flex }" plus bas : sans ce
   !important, le "display: flex" gagnerait et l'élément resterait visible
   même marqué hidden. Cette règle garantit que hidden l'emporte toujours. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
}

.login-form h1 { margin: 0 0 4px; font-size: 1.4rem; }
.login-sub { margin: 0 0 20px; color: var(--text-muted); }
.login-form label { display: block; margin-top: 14px; font-weight: 600; font-size: 0.9rem; }
.login-form input { width: 100%; padding: 8px; margin-top: 4px; border: 1px solid var(--border); border-radius: var(--radius); }
.login-form button {
  margin-top: 20px; width: 100%; padding: 10px; border: none; border-radius: var(--radius);
  background: var(--primary); color: #fff; font-weight: 600; cursor: pointer;
}
.login-form button:hover { background: var(--primary-dark); }
.error-msg { color: var(--danger); font-size: 0.9rem; margin-top: 12px; }

/* ---------- App shell ---------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 0 16px; height: 56px; flex-shrink: 0;
}
.topnav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topnav a {
  padding: 8px 10px; border-radius: var(--radius); text-decoration: none; color: var(--text);
  font-size: 0.9rem; white-space: nowrap;
}
.topnav a:hover { background: var(--bg); }
.topnav a.active { background: var(--primary); color: #fff; }

.topbar-right { display: flex; align-items: center; gap: 16px; position: relative; }
.notif-btn { position: relative; background: none; border: none; font-size: 1.2rem; cursor: pointer; }
.notif-count {
  position: absolute; top: -4px; right: -8px; background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 0.65rem; padding: 1px 5px; font-weight: 700;
}
.notif-panel {
  position: absolute; top: 44px; right: 60px; width: 340px; max-height: 420px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 20;
}
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 0.85rem; cursor: pointer; }
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: #eef6ee; font-weight: 600; }
.notif-item .notif-titre { margin: 0 0 2px; }
.notif-item .notif-date { color: var(--text-muted); font-size: 0.75rem; font-weight: 400; }
.notif-empty { padding: 20px; text-align: center; color: var(--text-muted); }

.settings-menu { position: relative; }
.settings-panel {
  position: absolute; top: 36px; right: 0; width: 160px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 20; padding: 4px 0;
}
.settings-panel a { display: block; padding: 8px 14px; color: var(--text); text-decoration: none; font-size: 0.85rem; }
.settings-panel a:hover { background: var(--bg); }

.user-menu { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; white-space: nowrap; }
.link-btn { background: none; border: none; color: var(--info); cursor: pointer; padding: 0; font-size: 0.85rem; }
.link-btn:hover { text-decoration: underline; }

.view { flex: 1; padding: 20px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- Generic building blocks ---------- */

h2 { margin-top: 0; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }

/* Tableau de bord façon kanban : une colonne par état, une tuile par commande */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; align-items: start; }

.kanban-col { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: outline-color 0.1s; }
.kanban-col.drag-over { outline: 2px dashed var(--primary); outline-offset: -2px; }

.stat-card-header {
  display: block; padding: 14px; text-decoration: none; color: inherit;
  border-bottom: 1px solid var(--border);
}
.stat-card-header:hover { background: var(--bg); }
.stat-card-header .stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-card-header .stat-label { font-size: 0.8rem; color: var(--text-muted); }
.stat-card-header.has-alerte { border-left: 4px solid var(--warning); }

.kanban-tiles {
  max-height: 320px; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px;
}
.order-tile {
  display: block; padding: 8px 10px 8px 8px; border: 1px solid var(--border); border-left: 3px solid transparent;
  border-radius: 4px; background: var(--bg); text-decoration: none; color: inherit;
}
.order-tile:hover { border-color: var(--primary); }
/* Vert + liseré = peut être glissée directement vers l'étape suivante.
   Grisée = pas de passage direct ici (droit insuffisant, ou plusieurs
   actions possibles depuis cet état) — reste cliquable pour aller à la fiche. */
.order-tile[draggable="true"] {
  cursor: grab; border-left-color: var(--primary); background: #f2f9f2;
}
.order-tile[draggable="true"]:active { cursor: grabbing; }
.order-tile[draggable="false"] { opacity: 0.7; }
.order-tile-numero { font-size: 0.72rem; font-weight: 700; color: var(--text-muted); }
.order-tile-titre { margin: 2px 0; font-size: 0.82rem; font-weight: 600; line-height: 1.25; }
.order-tile-client { font-size: 0.72rem; color: var(--text-muted); }
.kanban-empty { padding: 6px 4px; color: var(--text-muted); font-size: 0.78rem; text-align: center; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
th { background: var(--bg); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg); }
tr.alerte-row { background: #fff6ea; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; color: #fff; }
.badge-CMD_ENTRANTE, .badge-ADMIN_A_SAISIR { background: var(--info); }
.badge-ATTENTE_RETOUR_CLIENT { background: #7b1fa2; }
.badge-EN_PREPARATION, .badge-ADMIN_ATTENTE_LIVRAISON { background: var(--warning); }
.badge-EN_ATTENTE_DEPART { background: #ef6c00; }
.badge-EN_TRANSIT { background: #0277bd; }
.badge-ARCHIVEE, .badge-ADMIN_ARCHIVEE { background: var(--primary); }
.badge-ANNULEE { background: var(--text-muted); }
.badge-ADMIN_A_FACTURER { background: #6a1b9a; }
.badge-ADMIN_GESTION_AVARIE { background: var(--danger); }
.badge-PRET_A_DEPOSER { background: var(--warning); }
.badge-DEPOSE { background: #0277bd; }
.badge-ENCAISSE { background: var(--primary); }

.badge-alerte { background: var(--warning); color: #fff; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; margin-left: 6px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: end; }
.filters label { font-size: 0.8rem; color: var(--text-muted); display: block; }
.filters input, .filters select { padding: 6px; border: 1px solid var(--border); border-radius: var(--radius); margin-top: 2px; }

.btn {
  padding: 7px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel);
  cursor: pointer; font-size: 0.85rem; margin: 3px 6px 3px 0;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }

.form-row { margin-bottom: 10px; }
.form-row label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 3px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 7px; border: 1px solid var(--border); border-radius: var(--radius); font-family: inherit;
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box { background: var(--panel); border-radius: var(--radius); padding: 20px; width: 320px; box-shadow: 0 8px 30px rgba(0,0,0,0.25); }
.modal-box h3 { margin: 0 0 14px; font-size: 1rem; }
.modal-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end; }

.breadcrumb { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 10px; }
.breadcrumb a { color: var(--info); text-decoration: none; }

.section-title { font-size: 1rem; font-weight: 700; margin: 18px 0 8px; }

.hist-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.hist-item:last-child { border-bottom: none; }
.hist-meta { color: var(--text-muted); font-size: 0.78rem; }

.droits-table th, .droits-table td { text-align: center; }
.droits-table td:first-child, .droits-table th:first-child { text-align: left; }

.email-meta { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 4px; }
.email-sujet { font-weight: 600; margin-bottom: 6px; }
.email-corps { font-size: 0.85rem; white-space: pre-wrap; word-break: break-word; }
.badge-email-in { background: var(--info); }
.badge-email-out { background: var(--primary); }

.muted { color: var(--text-muted); }
.empty-state { padding: 30px; text-align: center; color: var(--text-muted); }
