:root {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe8dc;
  --ink: #241f2e;
  --muted: #7a7184;
  --line: #e2d9c9;
  --brand: #2b2340;
  --accent: #c2553a;
  --accent-ink: #fff;
  --ok: #3f7d4e;
  --warn: #b7791f;
  --danger: #b23a3a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(36, 31, 46, .06), 0 4px 14px rgba(36, 31, 46, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17141d; --surface: #211d29; --surface-2: #2b2635; --ink: #efe9f4;
    --muted: #a69db0; --line: #383143; --brand: #110e16; --accent: #e07457;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(68px + var(--safe-b));
  overscroll-behavior-y: none;
}
h1, h2, h3 { font-family: "Iowan Old Style", "Palatino", Georgia, serif; font-weight: 600; margin: 0 0 .6rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
a { color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--brand); color: #f6f2ea;
}
.brand { font-family: "Iowan Old Style", Georgia, serif; font-size: 1.15rem; letter-spacing: .02em; }
.sync {
  border: 0; border-radius: 999px; padding: 5px 11px; font-size: .8rem; font-weight: 600;
  background: rgba(255,255,255,.14); color: #fff; cursor: pointer;
}
.sync.offline { background: var(--warn); }
.sync.pending { background: var(--accent); }

main { max-width: 980px; margin: 0 auto; padding: 14px 16px 24px; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 9px; font-size: .7rem; text-decoration: none; color: var(--muted);
}
.tabbar .ico { font-size: 1.15rem; line-height: 1; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-size: .88rem; }
.right { text-align: right; }
.hidden { display: none !important; }

label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 11px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { margin-bottom: 10px; }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px;
  padding: 11px 16px; min-height: 44px; cursor: pointer;
  background: var(--surface-2); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.dark { background: var(--brand); color: #fff; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.small { min-height: 34px; padding: 6px 11px; font-size: .85rem; border-radius: 9px; }
button:disabled { opacity: .45; cursor: default; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.chip { flex: 0 0 auto; padding: 7px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .85rem; font-weight: 600; min-height: 0; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ----- Caisse ----- */
.pos { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .pos { grid-template-columns: 1fr 340px; align-items: start; } .cart { position: sticky; top: 70px; } }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.tile {
  position: relative; display: flex; flex-direction: column; justify-content: space-between;
  min-height: 112px; padding: 11px; border-radius: var(--radius); text-align: left;
  background: var(--tile, var(--surface-2)); color: #fff; box-shadow: var(--shadow); align-items: stretch;
  user-select: none; -webkit-user-select: none; transition: transform .08s;
}
.tile:active { transform: scale(.96); }
.tile .t-name { font-weight: 700; font-size: .95rem; line-height: 1.2; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.tile .t-foot { display: flex; width: 100%; justify-content: space-between; align-items: end; font-size: .85rem; }
.tile .t-price { font-weight: 700; font-size: 1.05rem; }
.tile .t-stock { background: rgba(0,0,0,.25); border-radius: 999px; padding: 1px 8px; font-size: .75rem; }
.tile .t-stock.low { background: var(--warn); }
.tile .t-stock.out { background: var(--danger); }
.tile .t-badge { position: absolute; top: -6px; right: -6px; background: var(--ink); color: var(--bg); border-radius: 999px; min-width: 26px; height: 26px; display: grid; place-items: center; font-weight: 700; font-size: .85rem; border: 2px solid var(--bg); }

.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.cart-line:last-child { border-bottom: 0; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { min-height: 32px; width: 32px; padding: 0; border-radius: 8px; }
.price-edit { width: 84px; min-height: 32px; padding: 4px 7px; text-align: right; }
.total { font-size: 1.6rem; font-weight: 700; font-family: "Iowan Old Style", Georgia, serif; }
.pay { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.pay button { min-height: 56px; flex-direction: column; gap: 0; font-size: .95rem; }
.pay button small { font-weight: 400; font-size: .7rem; opacity: .85; }

/* ----- Tableaux ----- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: .75rem; font-weight: 600; background: var(--surface-2); }
.pill.low { background: #f6e3c4; color: #7a4b05; }
.pill.out { background: #f3d0d0; color: #7d1d1d; }
.pill.pending { background: #f6dcd3; color: #8a3418; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.neg { color: var(--danger); } .pos-v { color: var(--ok); }

.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 90px 1fr 70px; gap: 8px; align-items: center; font-size: .85rem; }
.bar .track { display: block; height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--accent); border-radius: 6px; }

.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item.archived { opacity: .5; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; vertical-align: middle; margin-right: 6px; }

.login { max-width: 360px; margin: 10vh auto 0; }

.toast {
  position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%) translateY(-12px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, 94vw); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(20, 16, 26, .55); }
dialog form { padding: 18px; max-height: 85vh; overflow-y: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.lines .line { display: grid; grid-template-columns: 1fr 90px 38px; gap: 8px; align-items: end; margin-bottom: 8px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

/* Barre d'encaissement rapide (mobile) */
.cartbar { display: none; }
@media (max-width: 819px) {
  .cartbar {
    position: fixed; left: 10px; right: 10px; bottom: calc(66px + var(--safe-b)); z-index: 9;
    display: flex; justify-content: space-between; align-items: center;
    background: var(--accent); color: #fff; border-radius: 14px; padding: 12px 16px; font-weight: 700;
    box-shadow: 0 6px 20px rgba(0,0,0,.25);
  }
  body.has-cart main { padding-bottom: 80px; }
}

/* Champ avec bouton scanner */
.input-scan { display: flex; gap: 8px; }
.input-scan input { flex: 1; }
.input-scan button { flex: 0 0 52px; padding: 0; font-size: 1.2rem; }

/* Scanner plein écran */
dialog.scanner {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border-radius: 0;
  background: #000; color: #fff; display: none; flex-direction: column;
  padding: var(--safe-t) 0 var(--safe-b);
}
dialog.scanner[open] { display: flex; }
dialog.scanner::backdrop { background: #000; }
.sc-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; gap: 10px; }
.sc-top button { background: rgba(255,255,255,.18); color: #fff; }
.sc-view { position: relative; flex: 1; overflow: hidden; display: grid; place-items: center; }
.sc-view video { width: 100%; height: 100%; object-fit: cover; }
.sc-frame {
  position: absolute; left: 8%; right: 8%; top: 32%; bottom: 32%;
  border: 3px solid rgba(255,255,255,.85); border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.45);
}
.sc-frame::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: var(--accent); opacity: .9; }
.flash-ok .sc-frame { border-color: #5fd17a; }
.flash-ko .sc-frame { border-color: #ff6b6b; }
.sc-msg { padding: 12px 16px; text-align: center; font-weight: 600; min-height: 48px; }
.sc-msg.ok { color: #7be495; }
.sc-msg.ko { color: #ff8a8a; }
.sc-manual { display: flex; gap: 8px; padding: 0 16px 14px; }
.sc-manual input { background: #1c1c1c; color: #fff; border-color: #333; }
.scan-warn { color: var(--danger); font-size: .85rem; font-weight: 600; margin-top: 4px; }

/* Photos des produits (prototype 1.2.0) */
.tile.has-photo { background: linear-gradient(180deg, rgba(0,0,0,.05) 25%, rgba(0,0,0,.72)), var(--photo) center / cover no-repeat, var(--tile, var(--surface-2)); }
.thumb { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; vertical-align: middle; margin-right: 8px; background: var(--surface-2); }
.photo-edit { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.photo-preview { width: 104px; height: 104px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.photo-actions { display: flex; flex-direction: column; gap: 6px; }

/* Bandeau permanent de la version de test (DEVELOPMENT PLAN task 1.8) */
.test-banner { background: #b7791f; color: #fff; text-align: center; font-size: .8rem; font-weight: 600; padding: calc(4px + var(--safe-t)) 12px 4px; }
.test-banner + .topbar { padding-top: 10px; }
