/* L'intendant — design system minimal, mobile-first, sans toolchain. */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-contrast: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgb(15 23 42 / 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-w: 15rem;
  --nav-w-collapsed: 4.25rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --surface: #1e293b; --text: #f1f5f9; --muted: #94a3b8;
    --border: #334155; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
a { color: var(--primary); text-decoration: none; }

/* ---- Shell applicatif : barre latérale + contenu ----
   Mobile d'abord : la barre est un tiroir hors écran, ouvert par le bouton ☰.
   À partir de 900 px elle devient permanente et peut se replier en rail. */

.app-shell { min-height: 100dvh; }

.skip-link {
  position: absolute; left: -9999px; z-index: 100;
}
.skip-link:focus {
  left: 0.5rem; top: 0.5rem; padding: 0.5rem 0.75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}

.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  width: var(--nav-w);
  display: flex; flex-direction: column; gap: 0.15rem;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 0.5rem
           calc(0.75rem + var(--safe-bottom)) 0.5rem;
  overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(-100%);
  transition: transform 0.2s ease, width 0.2s ease;
}
html.nav-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgb(0 0 0 / 0.3); }

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.25rem 0.35rem 0.75rem;
}
.brand {
  display: flex; align-items: center; gap: 0.55rem;
  font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden;
}
.brand-mark {
  flex: none; width: 1.85rem; height: 1.85rem; border-radius: 8px;
  background: var(--primary); color: var(--primary-contrast);
  display: grid; place-items: center; font-weight: 700;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.sidebar-foot {
  display: flex; flex-direction: column; gap: 0.15rem;
  border-top: 1px solid var(--border); padding-top: 0.5rem; margin-top: 0.5rem;
}
.sidebar-foot form { margin: 0; }

.navlink {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.6rem 0.65rem; border-radius: var(--radius);
  color: var(--text); white-space: nowrap; overflow: hidden;
}
.navlink:hover { background: var(--bg); }
.navlink.is-active { background: var(--primary); color: var(--primary-contrast); }
.navlink-icon {
  flex: none; width: 1.5rem; text-align: center; font-size: 1.05rem;
}
.navlink-button {
  width: 100%; border: none; background: none; font: inherit; text-align: left;
  cursor: pointer; color: var(--muted);
}

.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgb(15 23 42 / 0.5);
}
.scrim[hidden] { display: none; }
/* Tiroir ouvert : le fond ne défile pas sous le doigt */
body.nav-locked { overflow: hidden; }

.app-main { min-height: 100dvh; }

/* En-tête mobile : seul point d'entrée du tiroir */
.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: calc(0.5rem + env(safe-area-inset-top, 0px)) 1rem 0.5rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}

@media (min-width: 900px) {
  .sidebar { transform: none; box-shadow: none; }
  html.nav-open .sidebar { box-shadow: none; }
  .app-main { margin-left: var(--nav-w); }
  .topbar { display: none; }
  .scrim { display: none; }

  /* Replié : rail d'icônes, les libellés disparaissent */
  html.nav-collapsed .sidebar { width: var(--nav-w-collapsed); }
  html.nav-collapsed .app-main { margin-left: var(--nav-w-collapsed); }
  html.nav-collapsed .nav-text { display: none; }
  html.nav-collapsed .sidebar-head { justify-content: center; flex-wrap: wrap; }
  html.nav-collapsed .navlink { justify-content: center; padding-left: 0; padding-right: 0; }
  html.nav-collapsed .navlink-icon { width: auto; }
  html.nav-collapsed .nav-collapse span { display: inline-block; transform: rotate(180deg); }
}

/* Le bouton de repli n'a pas de sens quand la barre est un tiroir, et le
   burger n'en a pas quand elle est permanente. Sélecteurs à deux classes :
   .btn est déclaré plus bas et l'emporterait à poids égal. */
@media (max-width: 899.98px) {
  .sidebar .nav-collapse { display: none; }
}
@media (min-width: 900px) {
  .topbar .nav-burger { display: none; }
}

.container { max-width: 64rem; margin: 0 auto; padding: 1rem; }
.hero { text-align: center; padding: 3rem 1rem; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem;
}
.stack > * + * { margin-top: 0.75rem; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.inline { display: inline; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }
.success { color: var(--success); }
.right { text-align: right; }

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 0.9rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 1rem; cursor: pointer; touch-action: manipulation;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border: none; background: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-icon { padding: 0.5rem; min-width: 2.5rem; justify-content: center; }

label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.25rem; }
input, select, textarea {
  width: 100%; padding: 0.55rem 0.7rem; font-size: 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.field { margin-bottom: 0.9rem; }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; background: var(--border); color: var(--text);
}
.badge-source { background: transparent; border: 1px solid var(--border); color: var(--muted); }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }

/* Écran liste deux parties (§4.2) : colonne unique mobile, grid desktop */
.split { display: block; }
@media (min-width: 768px) {
  .split { display: grid; grid-template-columns: 3fr 2fr; gap: 1rem; align-items: start; }
  .bottom-sheet { position: static !important; box-shadow: none !important; }
  .searchbar-mobile { position: static !important; }
}
.searchbar-mobile {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 0.6rem 1rem calc(0.6rem + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottom-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-height: 70dvh; overflow-y: auto;
  background: var(--surface); border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgb(0 0 0 / 0.25);
  padding: 1rem 1rem calc(1rem + var(--safe-bottom));
}

/* Barre collante du caddie (§4.3) */
.cart-totalbar {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  background: var(--surface); border-top: 2px solid var(--primary);
  padding: 0.7rem 1rem calc(0.7rem + var(--safe-bottom));
  font-variant-numeric: tabular-nums;
}
.cart-total { font-size: 1.3rem; font-weight: 700; }

.offline-banner {
  background: var(--warning); color: #fff; text-align: center;
  padding: 0.3rem; font-size: 0.85rem;
}

/* Scanner */
.scanner-viewport { position: relative; width: 100%; aspect-ratio: 3/4; background: #000;
  border-radius: var(--radius); overflow: hidden; }
.scanner-viewport video { width: 100%; height: 100%; object-fit: cover; }
.scanner-reticle {
  position: absolute; inset: 20% 10%; border: 2px solid rgb(255 255 255 / 0.7);
  border-radius: 8px; pointer-events: none;
}

[x-cloak] { display: none !important; }

/* Graphes SVG serveur */
.chart svg { max-width: 100%; height: auto; }
