:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e2e4e9;
  --text: #1c1f26;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-contrast: #ffffff;
  --accent-soft: #eef0ff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --danger: #c0262d;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #232730;
    --border: #2e333d;
    --text: #e8eaef;
    --muted: #9aa1ad;
    --accent: #8b85ff;
    --accent-contrast: #12131a;
    --accent-soft: #25254a;
    --ok: #4ade80;
    --ok-soft: #173024;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --danger: #f87171;
    --danger-soft: #3d1c1e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* L'attribut hidden doit toujours masquer, même sur un élément stylé en flex/grid. */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Barre latérale */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--accent); padding: 0 6px; }
.brand span { color: var(--text); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  color: var(--text);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
}
nav a:hover { background: var(--surface-2); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sync-box { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.sync-box small { font-size: 12px; padding: 0 2px; }

main { padding: 28px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions.right { justify-content: flex-end; }
.spacer { flex: 1; }

/* Boutons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 8px 14px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); filter: none; }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); filter: none; }
.btn-block { width: 100%; }
.icon-btn {
  width: 30px; height: 30px; padding: 0;
  border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: 600 16px/1 system-ui; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.plus { color: var(--ok); }
.icon-btn.minus { color: var(--danger); }

/* Cartes & statistiques */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: 15px; font-weight: 600; }
.stat.warn .stat-value { color: var(--warn); }
.stat.danger .stat-value { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

.banner { background: var(--accent-soft); border: 1px solid var(--border); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }

/* Tableaux */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .right { text-align: right; }
.table.products td:first-child { width: 44px; padding-right: 0; }
.thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--surface-2); display: block; }
.prod-name { font-weight: 500; }
.prod-name a { color: inherit; text-decoration: none; }
.prod-name a:hover { text-decoration: underline; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.stock-num { font-size: 15px; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 30px; margin: 0; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.pos { color: var(--ok); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }

/* Formulaires */
input, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { flex: 1; min-width: 220px; }
label.inline { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.form { max-width: 640px; display: flex; flex-direction: column; gap: 14px; }
.form h2 { margin-top: 8px; margin-bottom: 0; }
.form p { margin: 0; }
form label:not(.inline):not(.drop):not(.seg label) { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.quick { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; padding: 12px 14px; }
.quick #quickCode { flex: 1; min-width: 200px; }
.quick .qty { width: 80px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 5px 12px; border-radius: 6px; font-weight: 600; font-size: 13px; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg.wide { display: flex; }
.seg.wide label { flex: 1; text-align: center; }

.msg { padding: 10px 12px; border-radius: 8px; background: var(--ok-soft); color: var(--ok); margin: 0; }
.msg.error { background: var(--danger-soft); color: var(--danger); }

/* Dialogues */
dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  width: min(460px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 12, 20, .45); }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font-size: 17px; }
dialog p { margin: 0; }
.preview { font-size: 15px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font-variant-numeric: tabular-nums; }

/* Notifications */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 40px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; animation: pop .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 800px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 12px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sync-box { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  main { padding: 20px 16px 60px; }
  .row { grid-template-columns: 1fr; }
}

/* Commandes boutiques */
.import { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.import .msg { margin: 0; }
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 26px 16px; text-align: center; cursor: pointer; background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-name { font-weight: 600; color: var(--accent); }
.file-name:empty { display: none; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover td { background: var(--surface-2); }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-weight: 500; }
.back:hover { text-decoration: underline; }
#odMeta { margin: 4px 0 0; }
#odBanner .banner { margin-bottom: 16px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
tr.row-danger td { background: var(--danger-soft); }
tr.row-warn td { background: var(--warn-soft); }
tr.row-muted td { color: var(--muted); }
.line-qty { width: 84px; text-align: right; padding: 5px 8px; }
.line-product { max-width: 280px; padding: 5px 8px; }
.line-error { display: block; color: var(--danger); font-size: 12px; margin-top: 2px; }
.od-add { margin-top: 12px; }
.od-add #odAddProduct { flex: 1; min-width: 240px; }
.icon-btn.remove { width: 24px; height: 24px; font-size: 12px; color: var(--danger); margin-left: 6px; vertical-align: middle; }
.tracking #odTrackingInput { flex: 1; min-width: 220px; max-width: 340px; font-family: ui-monospace, Consolas, monospace; letter-spacing: .03em; }
.tracking-link { display: inline-flex; align-items: center; gap: 8px; }
.tracking-link:empty { display: none; }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* Expédition (suivi + colis) */
.shipping { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.shipping h2 { margin: 0; }
.ship-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ship-label { width: 90px; }
.packages { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 16px; }
.pkg-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.pkg-list:empty { display: none; }
.pkg { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border-radius: 8px; padding: 6px 8px; }
.pkg-num { font-weight: 600; font-size: 13px; min-width: 58px; }
.pkg input { width: 80px; text-align: right; padding: 5px 8px; }
.pkg .unit { color: var(--muted); font-size: 13px; }
.pkg .icon-btn.remove { margin-left: auto; }
.pkg-summary { font-weight: 600; color: var(--accent); }
.qty { width: 80px; }
.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name small { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }

/* Page de connexion */
body.login-page { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-box { width: min(380px, 100%); display: flex; flex-direction: column; gap: 20px; }
.login-box .brand { justify-content: center; font-size: 20px; }
.login-box .form { max-width: none; }
.login-box .btn { width: 100%; padding: 10px; }
.center { text-align: center; }
code { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: 12px; }

/* Utilisateur connecté */
.user-box { display: flex; align-items: center; justify-content: space-between; gap: 6px; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px; }
.user-box span { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.user-box .btn { padding: 4px 8px; font-size: 12px; }
.account { margin-top: 16px; }

/* Seuil d'alerte modifiable dans le tableau des produits */
.threshold-input { width: 64px; text-align: right; padding: 4px 6px; font-variant-numeric: tabular-nums; background: transparent; border-color: transparent; }
.threshold-input:hover { border-color: var(--border); background: var(--surface); }
.threshold-input:focus { background: var(--surface); }
.threshold-input.saved { border-color: var(--ok); background: var(--ok-soft); transition: background .3s; }
