:root {
  --bg: #f4f6f5; --card: #fff; --text: #14201e; --muted: #5d6b68; --line: #e1e6e4;
  --accent: #2563eb; --accent2: #0ea5e9; --accent-text: #1d4ed8; --accent-ink: #fff; --danger: #b42318; --soft: #e5edff;
  --s-pending: #7a8683; --s-info: #2563eb; --s-transit: #0f766e; --s-out: #d97706;
  --s-pickup: #7c3aed; --s-delivered: #15803d; --s-problem: #b42318; --s-returned: #9f1239;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --card: #18211f; --text: #e8efed; --muted: #9aa8a4; --line: #2a3633;
    --accent: #60a5fa; --accent2: #22d3ee; --accent-text: #60a5fa; --accent-ink: #06142e; --danger: #f97066; --soft: #14233f;
    --s-pending: #9aa8a4; --s-info: #60a5fa; --s-transit: #2dd4bf; --s-out: #fbbf24;
    --s-pickup: #a78bfa; --s-delivered: #4ade80; --s-problem: #f97066; --s-returned: #fb7185;
  }
}
:root[data-theme="orange"] { --accent: #ea580c; --accent2: #dc2626; --accent-text: #c2410c; --accent-ink: #fff; --soft: #ffedd5; }
:root[data-theme="violet"] { --accent: #7c3aed; --accent2: #d946ef; --accent-text: #6d28d9; --accent-ink: #fff; --soft: #f0e8ff; }
:root[data-theme="rose"] { --accent: #db2777; --accent2: #f97316; --accent-text: #be185d; --accent-ink: #fff; --soft: #ffe4f0; }
:root[data-theme="rouge"] { --accent: #dc2626; --accent2: #f97316; --accent-text: #b91c1c; --accent-ink: #fff; --soft: #ffe4e4; }
:root[data-theme="vert"] { --accent: #0f766e; --accent2: #16a34a; --accent-text: #0f766e; --accent-ink: #fff; --soft: #e1f3ef; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="orange"] { --accent: #fb923c; --accent2: #fbbf24; --accent-text: #fb923c; --accent-ink: #2b1200; --soft: #3a2111; }
  :root[data-theme="violet"] { --accent: #a78bfa; --accent2: #e879f9; --accent-text: #a78bfa; --accent-ink: #1a0a38; --soft: #26193f; }
  :root[data-theme="rose"] { --accent: #f472b6; --accent2: #fb923c; --accent-text: #f472b6; --accent-ink: #2e0a1c; --soft: #3a1428; }
  :root[data-theme="rouge"] { --accent: #f87171; --accent2: #fb923c; --accent-text: #f87171; --accent-ink: #2e0808; --soft: #3b1515; }
  :root[data-theme="vert"] { --accent: #2dd4bf; --accent2: #4ade80; --accent-text: #2dd4bf; --accent-ink: #06231f; --soft: #16302c; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-text); }

/* Connexion */
#auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  padding: 28px 24px; display: grid; gap: 14px; text-align: center;
}
.auth-card img { margin: 0 auto; border-radius: 18px; }
.auth-card p { color: var(--muted); font-size: 14px; }
.auth-card label { text-align: left; }

/* Structure */
#app { max-width: 760px; margin: 0 auto; padding: 0 16px 110px; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 18px 0 10px; }
.top h1 { font-size: 26px; letter-spacing: -0.02em; }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg, .fab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.filters { display: flex; gap: 4px; background: var(--line); padding: 4px; border-radius: 12px; margin: 6px 0 14px; }
.filters button {
  flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 14px;
}
.filters button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.filters span { font-weight: 500; opacity: .7; }

.tools { display: flex; gap: 8px; margin-bottom: 12px; }
.tools input { flex: 1; background: var(--card); }
.tools select { width: auto; max-width: 46%; background: var(--card); }
.item .side b.dim { color: var(--muted); }
.timeline li.more { display: none; }
.timeline.all li.more { display: block; }
.link-btn { border: 0; background: transparent; color: var(--accent-text); font-weight: 600; cursor: pointer; padding: 4px 0; }
#map { height: 260px; border-radius: 16px; margin-top: 14px; border: 1px solid var(--line); overflow: hidden; z-index: 0; }
.map-note { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.themes { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-pick { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 2px solid var(--line); border-radius: 999px; background: var(--card); cursor: pointer; font-weight: 600; }
.theme-pick .swatch { width: 26px; height: 26px; border-radius: 50%; display: block; }
.theme-pick.on { border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 90px; gap: 10px; }
.imp-row { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); font-weight: 400; }
.imp-row input { width: auto; margin-top: 4px; }
.imp-row b { display: block; overflow-wrap: anywhere; }
.imp-row span { color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; }

/* Liste */
.list { display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: 6px 1fr auto; gap: 14px; align-items: stretch; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px 14px 0;
  cursor: pointer; overflow: hidden;
}
.item:hover { border-color: var(--accent); }
.item .bar { border-radius: 0 4px 4px 0; background: var(--c); }
.item .main { min-width: 0; display: grid; gap: 2px; }
.item .desc { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .lab { color: var(--c); font-weight: 600; font-size: 14.5px; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .side { text-align: right; font-size: 13px; color: var(--muted); display: grid; align-content: center; gap: 2px; white-space: nowrap; }
.item .side b { font-size: 20px; color: var(--text); line-height: 1.1; }
.warn { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 56px 16px; border: 1px dashed var(--line); border-radius: 16px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

.fab {
  position: fixed; right: max(20px, calc(50vw - 360px)); bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px; padding: 14px 20px; border: 0; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--accent-ink); font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

/* Dialogues */
dialog {
  border: 1px solid var(--line); border-radius: 20px; background: var(--card); color: var(--text);
  width: min(460px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 22px; overflow: auto;
}
dialog.wide { width: min(640px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(8, 14, 13, .55); }
dialog h2 { font-size: 21px; letter-spacing: -0.01em; }
dialog h3 { font-size: 15px; margin: 22px 0 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
form { display: grid; gap: 14px; }
label { display: grid; gap: 5px; font-size: 14px; font-weight: 600; }
label em { font-weight: 400; color: var(--muted); font-style: normal; }
label small { font-weight: 400; color: var(--muted); min-height: 1.2em; }
input, select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); font-weight: 400;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.error { color: var(--danger); font-size: 14px; }
.btn {
  padding: 11px 16px; border-radius: 11px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--text); display: inline-flex; align-items: center; justify-content: center;
}
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 7px 11px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
#manualFields { display: grid; gap: 14px; }

/* Détail */
.d-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.d-head h2 { overflow-wrap: anywhere; }
.d-sub { color: var(--muted); font-size: 14px; margin-top: 4px; overflow-wrap: anywhere; }
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); margin-top: 12px; }
.d-eta { margin-top: 8px; font-weight: 600; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 4px; }
.note { background: var(--soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }
.note.bad { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.timeline { list-style: none; margin: 16px 0 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(--line); }
.timeline li:first-child::before { background: var(--c); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 22%, transparent); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 20px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .t-lab { font-weight: 600; overflow-wrap: anywhere; }
.timeline li:first-child .t-lab { color: var(--c); }
.timeline .t-meta { color: var(--muted); font-size: 13.5px; }
.close-x { border: 0; background: transparent; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }

/* Réglages */
.set-row { display: grid; gap: 6px; margin-bottom: 12px; }
.set-row p, .hint { font-size: 13.5px; color: var(--muted); font-weight: 400; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--accent-text); }
.pill.off { background: var(--line); color: var(--muted); }
code.copy { display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
  font-size: 12.5px; overflow-wrap: anywhere; cursor: pointer; }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  max-width: calc(100vw - 32px); z-index: 99; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
@media (max-width: 480px) {
  .fab span { display: none; }
  .fab { padding: 16px; }
  .top h1 { font-size: 23px; }
}
