:root {
  --bg: #f5f6fa; --panel: #ffffff; --ink: #1d2433; --muted: #6b7385; --line: #e5e8ef;
  --brand: #4f46e5; --brand-soft: #eef0ff; --ok: #12a150; --ok-soft: #e6f6ec;
  --warn: #c77700; --warn-soft: #fff4e0; --bad: #d92d20; --bad-soft: #fdecea;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --panel: #171b24; --ink: #e8ebf2; --muted: #9aa2b4; --line: #262c39;
    --brand: #8b85ff; --brand-soft: #23264a; --ok: #3ccf7f; --ok-soft: #133022;
    --warn: #ffb547; --warn-soft: #3a2a10; --bad: #ff6b5e; --bad-soft: #3b1714;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--brand); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1em; margin: 6px 0 0; }

/* Layout */
#app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; padding: 0 8px; }
.brand.big { font-size: 24px; justify-content: center; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--brand-soft); display: grid; place-items: center; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink); font-weight: 500; }
nav a:hover { background: var(--bg); }
nav a.active { background: var(--brand-soft); color: var(--brand); }
nav .count { margin-left: auto; font-size: 12px; background: var(--bg); color: var(--muted); padding: 1px 8px; border-radius: 99px; }
nav .count:empty { display: none; }
nav .count.alert { background: var(--bad); color: #fff; }
.me { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-top: 1px solid var(--line); }
main { padding: 28px 32px 60px; min-width: 0; }

.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head h1 { font-size: 22px; margin: 0; margin-right: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 24px; }
.stat.bad b { color: var(--bad); } .stat.warn b { color: var(--warn); } .stat.ok b { color: var(--ok); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; }
.tabs button.on { background: var(--brand-soft); color: var(--brand); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.search { max-width: 320px; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; }

/* Liste de colis */
.list { display: flex; flex-direction: column; gap: 10px; }
.row { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: grid; grid-template-columns: auto 72px 1fr auto auto; gap: 14px; align-items: center; padding: 12px 14px; }
.row.sel { outline: 2px solid var(--brand); }
.row .thumb { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; background: var(--bg); display: grid; place-items: center; font-size: 26px; cursor: zoom-in; }
.row .title { font-weight: 600; word-break: break-word; }
.row .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.row .actions { display: flex; gap: 6px; align-items: center; }
.row .nocheck { width: 0; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; font-weight: 600; }
.chip.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.dots { width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); }
.dots:hover { background: var(--bg); border-color: var(--line); color: var(--ink); }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

.dropdown { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(16,24,40,.18); padding: 6px; min-width: 220px; }
.dropdown button { display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; }
.dropdown button:hover { background: var(--bg); }
.dropdown button.danger { color: var(--bad); }
.dropdown hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* Barre de sélection */
.selbar { position: sticky; bottom: 16px; margin-top: 16px; background: var(--ink); color: var(--panel); border-radius: 14px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); }
.selbar .btn { background: var(--panel); color: var(--ink); border-color: transparent; }
.selbar span { margin-right: auto; font-weight: 600; }

/* Lots */
.section-title { font-size: 16px; margin: 30px 0 12px; display: flex; align-items: center; gap: 10px; }
.lots { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.lot { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.lot.sel { outline: 2px solid var(--brand); }
.lot img { width: 100%; aspect-ratio: 4/3; object-fit: contain; background: var(--bg); }
.lot .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.lot ol { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13px; }
.lot .top { display: flex; align-items: center; gap: 8px; }
.lot .top b { margin-right: auto; }

/* Tableau suivi */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--bg); }
.table tr:last-child td { border-bottom: 0; }
.table tr.done td { opacity: .55; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.eta { font-weight: 700; }
.paste { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; box-shadow: var(--shadow); }
.paste textarea { min-height: 110px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.paste .foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15,18,24,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 18px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card.wide { width: min(900px, 100%); }
.modal-card h2 { margin: 0 0 16px; font-size: 18px; }
.modal-card form { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.svc { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.preview { max-width: 100%; max-height: 70vh; border-radius: 12px; display: block; margin: 0 auto; }
.photo-prev { width: 90px; height: 90px; object-fit: cover; border-radius: 10px; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { background: var(--panel); padding: 30px; border-radius: 20px; width: min(380px, 100%); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; border: 1px solid var(--line); }
.auth-card p { margin: 0; text-align: center; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 10px 18px; border-radius: 12px; z-index: 70; font-weight: 500; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }

/* Mobile */
@media (max-width: 820px) {
  html, body { -webkit-text-size-adjust: 100%; }
  #app { grid-template-columns: 1fr; }
  /* Barre d'onglets en bas de l'écran */
  .side { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; align-items: stretch; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 0; z-index: 40; border-right: 0; border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(16,24,40,.08); }
  .side .brand { display: none; }
  nav { flex-direction: row; flex: 1; gap: 0; min-width: 0; }
  nav a { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 10.5px; line-height: 1.15; text-align: center; border-radius: 10px; position: relative; white-space: normal; }
  nav a > span { font-size: 20px; line-height: 1; }
  nav .count { position: absolute; top: 2px; left: 50%; margin-left: 6px; font-size: 10px; padding: 0 5px; min-width: 16px; line-height: 16px; background: var(--brand); color: #fff; }
  .me { border: 0; padding: 0; display: flex; align-items: center; }
  .me div { display: none; }
  .me .btn { padding: 6px 6px; font-size: 0; min-width: 44px; justify-content: center; }
  .me .btn::before { content: '🚪'; font-size: 20px; }
  main { padding: 14px 12px calc(84px + env(safe-area-inset-bottom)); }
  .head { margin-bottom: 12px; gap: 8px; }
  .head h1 { font-size: 20px; }
  .head .btn { flex: 1 1 auto; justify-content: center; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 20px; }
  .toolbar { gap: 8px; }
  .tabs { width: 100%; overflow-x: auto; }
  .tabs button { flex: 1; white-space: nowrap; padding: 9px 10px; }
  input, select, textarea { font-size: 16px; } /* évite le zoom automatique sur iPhone */
  input[type=checkbox] { width: 22px; height: 22px; }
  .btn { padding: 11px 14px; }
  .btn.sm { padding: 8px 12px; }
  .dots { width: 44px; height: 44px; }
  /* Lignes de colis */
  .row { grid-template-columns: auto 56px minmax(0, 1fr) auto; gap: 10px; padding: 10px; }
  .row .thumb { width: 56px; height: 56px; }
  .row .actions { display: none; }
  .row .title { font-size: 14px; }
  .chip { font-size: 11.5px; }
  .grid2, .svc { grid-template-columns: 1fr; }
  .search { max-width: none; flex: 1 1 100%; }
  .lots { grid-template-columns: 1fr; }
  .selbar { bottom: calc(76px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .selbar span { flex: 1 1 100%; }
  .selbar .btn { flex: 1; justify-content: center; }
  /* Tableaux → cartes */
  .table-wrap { overflow: visible; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table { border: 0; background: none; box-shadow: none; overflow: visible; }
  .table thead { display: none; }
  .table tr { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; padding: 8px 12px; position: relative; }
  .table td { border: 0; padding: 6px 0; display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; text-align: right; min-height: 0; word-break: break-word; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: 0 0 38%; padding-top: 2px; }
  .table td[data-label=""]::before { display: none; }
  .table td:empty { display: none; }
  .table td > * { max-width: 100%; }
  .table td:not([data-label=""]) { display: grid; grid-template-columns: minmax(96px, 36%) minmax(0, 1fr); column-gap: 12px; row-gap: 2px; justify-items: end; }
  .table td:not([data-label=""])::before { grid-column: 1; grid-row: 1 / span 9; justify-self: start; font-family: Inter, system-ui, sans-serif; }
  .table td:not([data-label=""]) > * { grid-column: 2; }
  .table td:first-child { font-size: 15px; }
  .table td .check { justify-content: flex-end; }
  .table td:last-child { justify-content: flex-end; }
  /* Fenêtres : panneau qui monte du bas */
  .modal { place-items: end center; padding: 0; }
  .modal-card, .modal-card.wide { width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .modal-foot { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); background: var(--panel); padding: 10px 0 4px; margin-bottom: -4px; }
  .modal-foot .btn { flex: 1; justify-content: center; }
  .preview { max-height: 75vh; }
  /* Menu ⋮ : liste en bas de l'écran */
  .dropdown { left: 8px !important; right: 8px !important; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom)); min-width: 0; border-radius: 16px; padding: 8px; z-index: 60; }
  .dropdown button { padding: 14px 14px; font-size: 15px; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); text-align: center; }
  .auth-card { padding: 24px 18px; }
}
@media (max-width: 380px) {
  nav a { font-size: 9.5px; }
  .stats { grid-template-columns: 1fr 1fr; }
}
