:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --text: #1c2326;
  --muted: #66707a;
  --border: #e4e0d8;
  --brand: #1f4e5f;
  --brand-ink: #ffffff;
  --accent: #f2b544;
  --danger: #c2412d;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(20 30 40 / 6%), 0 4px 16px rgb(20 30 40 / 6%);

  --s-pending: #7a8590;
  --s-in_transit: #2f6fdb;
  --s-out_for_delivery: #d98a00;
  --s-pickup: #8a4fd1;
  --s-delivered: #1f9d5b;
  --s-exception: #d1432f;
  --s-unknown: #9aa3ab;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171a;
    --surface: #1a2125;
    --surface-2: #1f272c;
    --text: #e8ecee;
    --muted: #97a3ab;
    --border: #2b353b;
    --brand: #5fa8bf;
    --brand-ink: #0d1a1f;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    --s-in_transit: #6ea0ff;
    --s-out_for_delivery: #f2b544;
    --s-pickup: #b58cf0;
    --s-delivered: #4cc98a;
    --s-exception: #ff7a66;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 20px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; letter-spacing: .02em; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* Barre du haut */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 10px; padding: 9px 16px; border: 1px solid transparent;
  font-weight: 600; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Bandeau démo */
.banner {
  margin-top: 20px; padding: 12px 16px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  font-size: 14px;
}
.banner code { background: var(--surface); padding: 1px 6px; border-radius: 6px; border: 1px solid var(--border); }

/* Formulaire d'ajout */
.add-card {
  margin-top: 20px; display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 180px; }
.field.grow { flex: 1 1 240px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
input, select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; outline: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
#number { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; text-transform: uppercase; }
#number::placeholder { text-transform: none; }
.form-error { color: var(--danger); margin: 8px 4px 0; font-size: 14px; }

/* Onglets & recherche */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 28px 0 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.tab { background: none; border: 0; padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--brand); color: var(--brand-ink); }
.count { opacity: .75; font-weight: 500; margin-left: 2px; }
.count:empty { display: none; }
#search { min-width: 220px; background: var(--surface); }

/* Liste */
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; padding-bottom: 60px; }
.card {
  text-align: left; color: inherit; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
  transition: transform .12s, border-color .12s;
  border-top: 4px solid var(--status-color, var(--border));
}
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--status-color) 50%, var(--border)); border-top-color: var(--status-color); }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card-title { font-weight: 700; font-size: 16px; margin: 0; overflow-wrap: anywhere; }
.card-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.card-event { font-size: 14px; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12.5px; gap: 8px; }
.card-error { color: var(--danger); font-size: 13px; margin: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  color: var(--status-color); background: color-mix(in srgb, var(--status-color) 14%, transparent);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* Barre de progression */
.progress { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.progress span { height: 5px; border-radius: 3px; background: var(--border); }
.progress span.on { background: var(--status-color); }
.progress-labels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.progress-labels span.on { color: var(--text); font-weight: 600; }

/* Vide */
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 20px; border: 2px dashed var(--border); border-radius: var(--radius); }
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* Squelette pendant l'ajout */
.skeleton { min-height: 150px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Panneau de détail */
.overlay { position: fixed; inset: 0; background: rgb(10 15 20 / 40%); z-index: 10; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(480px, 100%);
  background: var(--surface); z-index: 11; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s ease; box-shadow: -8px 0 30px rgb(0 0 0 / 15%);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 20px 20px 12px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0 0 2px; font-size: 20px; overflow-wrap: anywhere; }
.copy { background: none; border: 0; padding: 0; color: var(--muted); font-size: 13px; }
.copy:hover { color: var(--text); text-decoration: underline; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px; }
.drawer-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.drawer-foot .btn { padding: 8px 12px; font-size: 14px; }
.drawer-foot .btn-danger { margin-left: auto; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 22px; }
.summary div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.summary dt { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.summary dd { margin: 2px 0 0; font-weight: 600; }
.note { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 0 0 18px; }
.note.err { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--border); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.timeline li::after { content: ""; position: absolute; left: 10px; top: 20px; bottom: -2px; width: 2px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline li:first-child::before { background: var(--status-color); box-shadow: 0 0 0 4px color-mix(in srgb, var(--status-color) 25%, transparent); }
.t-label { margin: 0; font-weight: 500; }
.timeline li:first-child .t-label { font-weight: 700; }
.t-meta { font-size: 12.5px; color: var(--muted); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
}

@media (max-width: 640px) {
  .field { min-width: 100%; }
  .add-card .btn { width: 100%; justify-content: center; }
  #search { width: 100%; }
  .brand h1 { font-size: 18px; }
  #refresh-all span { display: none; }
}

/* Couleur selon le statut (pas de style dans le HTML : la CSP l'interdit) */
[data-status="pending"] { --status-color: var(--s-pending); }
[data-status="in_transit"] { --status-color: var(--s-in_transit); }
[data-status="out_for_delivery"] { --status-color: var(--s-out_for_delivery); }
[data-status="pickup"] { --status-color: var(--s-pickup); }
[data-status="delivered"] { --status-color: var(--s-delivered); }
[data-status="exception"] { --status-color: var(--s-exception); }
[data-status="unknown"] { --status-color: var(--s-unknown); }
.mt { margin-top: 14px; }
.h-hist { font-size: 15px; margin: 0 0 12px; }
.top-actions { display: flex; gap: 8px; }

/* Page de connexion */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.gate-card { flex-direction: column; align-items: stretch; width: min(360px, 100%); margin: 0; gap: 16px; }
.gate-card .field { min-width: 0; }
.gate-card .btn { justify-content: center; }
.gate-card .form-error { margin: 0; min-height: 1.2em; }
