:root {
  --paper: #f3f4f1;
  --surface: #ffffff;
  --ink: #17201c;
  --muted: #6b7570;
  --line: #e2e4df;
  --accent: #8e2d54;      /* lie-de-vin — signature boutique */
  --accent-ink: #ffffff;
  --accent-soft: #f7e9ef;
  --ok: #1f7a54;
  --warn: #b4531a;
  --danger: #b02a37;
  --shadow: 0 1px 2px rgba(23,32,28,.06), 0 8px 24px rgba(23,32,28,.06);
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 620; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.num { text-align: right; }
.brand-mark { color: var(--accent); font-size: 1.05em; }

/* ---------- Boutons ---------- */
.btn {
  font: inherit; font-weight: 560; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: .55rem .9rem; border-radius: 10px; transition: .12s ease;
}
.btn:hover { border-color: #cfd2cb; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #7c2649; border-color: #7c2649; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: rgba(23,32,28,.04); }
.btn-block { width: 100%; padding: .7rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 2rem 1.75rem;
}
.brand { text-align: center; margin-bottom: 1.5rem; }
.brand h1 { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; margin-top: .3rem; }
.brand .brand-mark { font-size: 1.6rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .3rem; }
input[type=text], input[type=password], input[type=number], input[type=search] {
  width: 100%; font: inherit; padding: .6rem .7rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fbfbfa; color: var(--ink);
}
input:focus { border-color: var(--accent); background: #fff; outline: none; }
.err { color: var(--danger); font-size: .86rem; margin: .6rem 0 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem; justify-content: space-between;
  padding: .6rem 1.1rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: .5rem; font-family: var(--serif); font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }
.tabs { display: flex; gap: .25rem; }
.tab {
  font: inherit; font-weight: 550; border: 0; background: transparent; color: var(--muted);
  padding: .5rem .85rem; border-radius: 9px; cursor: pointer;
}
.tab:hover { color: var(--ink); background: rgba(23,32,28,.04); }
.tab.is-active { color: var(--accent); background: var(--accent-soft); }

main { padding: 1.1rem; max-width: 1200px; margin: 0 auto; }
.view { display: none; }
.view.is-active { display: block; }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1.1rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.panel-head h2 { font-size: 1.05rem; }
.search { max-width: 260px; }

/* ---------- Caisse ---------- */
.split { display: grid; grid-template-columns: 1fr 340px; gap: 1.1rem; align-items: start; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.pcard {
  text-align: left; border: 1px solid var(--line); background: #fbfbfa; border-radius: 11px;
  padding: .7rem .75rem; cursor: pointer; transition: .12s ease; display: flex; flex-direction: column; gap: .15rem;
}
.pcard:hover { border-color: var(--accent); background: #fff; }
.pcard:disabled { opacity: .5; cursor: not-allowed; }
.pcard .pname { font-weight: 580; line-height: 1.2; }
.pcard .pvar { font-size: .8rem; color: var(--muted); }
.pcard .prow { display: flex; justify-content: space-between; align-items: baseline; margin-top: .3rem; }
.pcard .pprice { font-weight: 620; }
.pcard .pstock { font-size: .76rem; color: var(--muted); }
.pcard .pstock.low { color: var(--warn); }
.pcard .pstock.out { color: var(--danger); }

.cart { position: sticky; top: 68px; display: flex; flex-direction: column; }
.cart-lines { display: flex; flex-direction: column; gap: .4rem; min-height: 60px; }
.cart-lines .empty { color: var(--muted); font-size: .9rem; text-align: center; padding: 1rem 0; }
.cline { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center;
  padding: .4rem 0; border-bottom: 1px dashed var(--line); }
.cline .cname { font-size: .9rem; }
.cline .cname small { color: var(--muted); display: block; }
.stepper { display: inline-flex; align-items: center; gap: .35rem; }
.stepper button { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-weight: 700; line-height: 1; }
.stepper span { min-width: 1.4ch; text-align: center; font-variant-numeric: tabular-nums; }
.cline .cprice { font-weight: 580; font-variant-numeric: tabular-nums; min-width: 66px; text-align: right; }
.cart-total { display: flex; justify-content: space-between; align-items: baseline;
  margin: .8rem 0; padding-top: .7rem; border-top: 1px solid var(--line); }
.cart-total strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.cart-actions { display: grid; grid-template-columns: auto 1fr; gap: .5rem; }

/* ---------- Stock ---------- */
.add-form { border: 1px dashed var(--line); border-radius: 11px; padding: 1rem; margin-bottom: 1rem; background: #fbfbfa; }
.add-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.add-grid label { display: flex; flex-direction: column; font-size: .82rem; color: var(--muted); gap: .3rem; }
.add-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .9rem; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-weight: 560; color: var(--muted); font-size: .8rem;
  padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:hover td { background: #fbfbfa; }
.table .num { font-variant-numeric: tabular-nums; }
.chip { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem;
  background: rgba(23,32,28,.06); color: var(--muted); }
.stock-badge { font-variant-numeric: tabular-nums; font-weight: 580; }
.stock-badge.low { color: var(--warn); }
.stock-badge.out { color: var(--danger); }
.row-actions { display: inline-flex; gap: .3rem; justify-content: flex-end; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: .3rem .5rem;
  cursor: pointer; font-size: .82rem; color: var(--muted); }
.icon-btn:hover { color: var(--ink); border-color: #cfd2cb; }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- CA ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.1rem; margin-bottom: 1.1rem; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .25rem; }
.stat-card.accent { background: linear-gradient(135deg, var(--accent), #6f2340); border-color: transparent; color: #fff; }
.stat-card.accent .stat-label, .stat-card.accent .muted { color: rgba(255,255,255,.8); }
.stat-label { font-size: .82rem; color: var(--muted); }
.stat-big { font-size: 2rem; font-weight: 640; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.sales-list { display: flex; flex-direction: column; gap: .5rem; }
.sale-item { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
.sale-item .sale-head { display: flex; justify-content: space-between; font-weight: 580; }
.sale-item .sale-body { font-size: .85rem; color: var(--muted); margin-top: .2rem; }
.empty { color: var(--muted); }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 50; font-weight: 540; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .split { grid-template-columns: 1fr; }
  .cart { position: static; }
  .topbar { flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
