:root {
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, white);
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #1c1f1e;
  --muted: #6b716f;
  --line: #e3e5e0;
  --ok: #15803d;   --ok-soft: #e6f4ea;
  --warn: #b45309; --warn-soft: #fdf1e1;
  --bad: #b91c1c;  --bad-soft: #fde8e8;
  --info: #1d4ed8; --info-soft: #e7eefe;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --nav-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; font-size: 15px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.stack-s > * + * { margin-top: 6px; }
.hide { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- mise en page */
.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand img { width: 34px; height: 34px; object-fit: contain; border-radius: 8px; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.brand b { display: block; font-size: 15px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.topbar select { max-width: 150px; min-height: 38px; padding: 6px 8px; font-size: 14px; }
@media (min-width: 700px) { .topbar select { max-width: 240px; } }
main { padding: 16px; padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; position: relative; }
.bottomnav a.on { color: var(--brand); }
.bottomnav a.on::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--brand); }
.bottomnav .icon { width: 22px; height: 22px; }
.dot { position: absolute; top: 8px; right: calc(50% - 20px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 10px; display: grid; place-items: center; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 230px 1fr; grid-template-rows: auto 1fr; }
  .bottomnav { position: sticky; top: 0; height: 100vh; grid-template-columns: 1fr; grid-auto-rows: 52px; align-content: start; border-top: 0; border-right: 1px solid var(--line); padding: 76px 10px 10px; grid-row: 1 / span 2; }
  .bottomnav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; border-radius: 10px; font-size: 14px; }
  .bottomnav a.on { background: var(--brand-soft); }
  .bottomnav a.on::before { display: none; }
  .bottomnav .dot { position: static; margin-left: auto; }
  .topbar { grid-column: 2; }
  main { grid-column: 2; padding: 24px; padding-bottom: 40px; }
}

/* ---------- éléments */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card.flat { box-shadow: none; }
.card h2 { margin-bottom: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink);
  -webkit-tap-highlight-color: transparent; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, white); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 16px; }
.iconbtn { width: 42px; height: 42px; border-radius: 11px; display: inline-grid; place-items: center; border: 1px solid var(--line); background: var(--card); cursor: pointer; color: var(--ink); text-decoration: none; flex: none; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns > .btn { flex: 1 1 auto; }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid #cfd3cd; background: #fff; outline: none;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr 1fr; } }

.seg { display: flex; background: #eceee9; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: #eceee9; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; cursor: pointer; background: none; width: 100%; text-align: left; border-left: 0; border-right: 0; border-bottom: 0; }
.item:first-child { border-top: 0; }
.item:active { background: #fafaf8; }
.item .t { font-weight: 600; }
.item .s { font-size: 13px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 20px; font-weight: 750; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .h { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hero { grid-column: span 2; background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.kpi.hero .l, .kpi.hero .h { color: color-mix(in srgb, var(--brand-ink) 80%, transparent); }
.kpi.hero .v { font-size: 28px; }
.alert { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-weight: 600; text-decoration: none; font-size: 14px; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--info-soft); color: var(--info); }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding-top: 8px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .b i { display: block; width: 100%; max-width: 38px; background: var(--brand); border-radius: 6px 6px 2px 2px; min-height: 2px; opacity: .85; }
.bars .b.today i { opacity: 1; }
.bars .b span { font-size: 11px; color: var(--muted); }

/* ---------- caisse */
.pos { display: grid; gap: 14px; }
@media (max-width: 899px) { .pos .cart-side { display: none; } }
@media (min-width: 900px) { .pos { grid-template-columns: 1fr 380px; align-items: start; } .pos .cart-side { position: sticky; top: 80px; } .cartbar { display: none !important; } }
.prods { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.prod { background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 12px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-height: 104px; position: relative; }
.prod:active { transform: scale(.98); }
.prod .n { font-weight: 650; font-size: 14px; line-height: 1.25; padding-right: 22px; }
.prod .p { font-weight: 750; margin-top: auto; }
.prod .q { font-size: 12px; color: var(--muted); }
.prod.out { opacity: .45; cursor: not-allowed; }
.prod .incart { position: absolute; top: 8px; right: 8px; background: var(--brand); color: var(--brand-ink); border-radius: 999px; min-width: 24px; height: 24px; display: grid; place-items: center; font-size: 12px; font-weight: 700; padding: 0 6px; }
.cartbar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 10px + env(safe-area-inset-bottom)); z-index: 25; }
.cartbar .btn { width: 100%; min-height: 54px; justify-content: space-between; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.line { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.line:first-child { border-top: 0; }
.qty { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.qty button { width: 34px; height: 34px; border: 0; background: #f4f5f2; font-size: 18px; font-weight: 700; cursor: pointer; }
.qty span { min-width: 32px; text-align: center; font-weight: 700; }
.totals { border-top: 1px dashed #cfd3cd; padding-top: 10px; }
.totals .row { justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 20px; font-weight: 800; }

/* ---------- détail commande / livraison */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; word-break: break-word; }
.deliv { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.deliv.done { opacity: .75; box-shadow: none; }
.deliv .amount { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.deliv .addr { font-size: 15px; font-weight: 600; }
.sum { background: var(--ink); color: #fff; border-radius: var(--radius); padding: 16px; }
.sum .big { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sum .muted { color: #b9bfbc; }
.sum .grid3 > div { background: rgba(255,255,255,.08); border-radius: 10px; padding: 8px 10px; }
.sum .grid3 b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- fenêtres */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(20,22,21,.45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); animation: up .18s ease-out; }
.sheet .head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; position: sticky; top: -16px; background: var(--bg); padding: 14px 0 8px; margin-top: -14px; z-index: 2; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top)); z-index: 90; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: down .2s; text-align: center; }
@keyframes down { from { transform: translateY(-12px); opacity: 0; } }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- connexion */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 400px; padding: 22px; }
.auth .logo { width: 72px; height: 72px; object-fit: contain; margin: 0 auto 10px; display: block; }
.auth .mark { width: 60px; height: 60px; border-radius: 16px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 26px; font-weight: 800; margin: 0 auto 12px; }

/* ---------- reçu (aperçu écran + impression) */
.receipt-preview { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; max-height: 50vh; overflow: auto; display: flex; justify-content: center; }
.receipt-preview img { width: 100%; max-width: 300px; height: auto; display: block; }
#print-root { display: none; }
.ticket { font-family: "Courier New", ui-monospace, monospace; color: #000; font-size: 12px; line-height: 1.35; }
.ticket .c { text-align: center; }
.ticket .b { font-weight: 700; }
.ticket .big { font-size: 16px; font-weight: 700; }
.ticket hr { border: 0; border-top: 1px dashed #000; margin: 5px 0; }
.ticket .r { display: flex; justify-content: space-between; gap: 6px; }
.ticket img { max-width: 60%; max-height: 70px; display: block; margin: 0 auto 4px; filter: grayscale(1) contrast(1.3); }
@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  html, body { background: #fff; }
}
