:root {
  --bg: #f6f3ef;
  --card: #ffffff;
  --ink: #221c18;
  --muted: #76695f;
  --line: #e6ddd3;
  --char: #1f1a17;
  --ember: #e8590c;
  --ember-dark: #c44a08;
  --warn-bg: #fff3bf; --warn: #7a5a00;
  --danger-bg: #ffe3e3; --danger: #c92a2a;
  --ok: #2f9e44;
  --radius: 12px;
  --font-body: "Inter", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-body); font-size: 15px; color: var(--ink); background: var(--bg); line-height: 1.5; }
[hidden] { display: none !important; }
.wrap { width: min(1180px, 100% - 32px); margin-inline: auto; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid rgba(232, 89, 12, .45); outline-offset: 2px; }
input, select, textarea, button { font: inherit; color: inherit; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; text-decoration: none;
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn.primary { background: var(--ember); color: #fff; }
.btn.primary:hover { background: var(--ember-dark); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: #fff; border-color: #cfc2b5; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #a61e1e; }
.btn.small { padding: 6px 12px; font-size: .88rem; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; font-weight: 700; line-height: 1;
}
.icon-btn:hover:not(:disabled) { border-color: var(--ember); color: var(--ember); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.link-btn { background: none; border: 0; padding: 4px 6px; cursor: pointer; font-weight: 600; color: var(--ember-dark); border-radius: 6px; }
.link-btn:hover { background: #fff0e6; }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: var(--danger-bg); }

/* Champs */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ember); box-shadow: 0 0 0 3px rgba(232, 89, 12, .15); }
input.saving { border-color: #fab005; }
input.saved { border-color: var(--ok); }
input.error { border-color: var(--danger); background: var(--danger-bg); }
label { display: grid; gap: 5px; font-weight: 600; font-size: .9rem; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
label.check input { width: 18px; height: 18px; accent-color: var(--ember); margin: 0; }
.form-error { color: var(--danger); background: var(--danger-bg); padding: 8px 12px; border-radius: 8px; margin: 0; font-weight: 600; font-size: .9rem; }
.danger-text { color: var(--danger); }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 120%, #7a2e0b, var(--char) 65%); }
.login-card { width: min(380px, 100%); background: var(--card); border-radius: 18px; padding: 32px 28px; display: grid; gap: 14px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.5); }
.login-card img { margin: 0 auto; }
.login-card h1 { font-family: var(--font-display); text-align: center; margin: 0; font-size: 1.7rem; }
.login-card > .muted { text-align: center; margin: -10px 0 4px; }
.back { text-align: center; color: var(--muted); font-size: .9rem; }

/* Barre du haut */
.topbar { background: var(--char); color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.2rem; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.25); }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.1); }

/* Résumé */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 24px 0 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--muted); font-weight: 500; }
.stat span { display: block; font-family: var(--font-display); font-size: 1.8rem; color: var(--ink); line-height: 1.1; }
.stat.warn span { color: #b08800; }
.stat.danger span { color: var(--danger); }

/* Onglets */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { background: none; border: 0; padding: 10px 16px; font-weight: 600; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ember); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"], .toolbar input[name="name"] { flex: 1 1 240px; width: auto; }
.toolbar select { width: auto; flex: 0 1 220px; }
.hint { margin: 0 0 12px; font-size: .9rem; }

/* Tableau produits */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.products { width: 100%; border-collapse: collapse; }
.products th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 14px; background: #faf7f3; border-bottom: 1px solid var(--line); }
.products td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.products tr:last-child td { border-bottom: 0; }
.products tr.is-hidden td:first-child { opacity: .55; }
.products tr.is-out { background: #fff8f8; }
.products tr.is-low { background: #fffcf0; }
th.num { text-align: right; }
.p-name { font-weight: 700; }
.p-desc { color: var(--muted); font-size: .85rem; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; }
.p-badge.out { background: var(--danger-bg); color: var(--danger); }
.p-badge.low { background: var(--warn-bg); color: var(--warn); }
.price-input { width: 96px !important; text-align: right; margin-left: auto; display: block; }
.stock-ctl { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.stock-ctl input { width: 64px !important; text-align: center; padding: 6px 4px !important; }
.unlimited { color: var(--muted); font-size: .88rem; display: block; text-align: right; }
.unlimited button { margin-left: 2px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.empty { text-align: center; color: var(--muted); padding: 32px; margin: 0; }

/* Interrupteur visible */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: #d5ccc2; border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 3px solid rgba(232, 89, 12, .45); outline-offset: 2px; }

/* Catégories */
.cat-list { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.cat-list li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.cat-list li:last-child { border-bottom: 0; }
.cat-order { display: flex; gap: 4px; }
.cat-name { flex: 1; font-weight: 700; }
.cat-name input { max-width: 320px; }
.cat-count { color: var(--muted); font-size: .88rem; white-space: nowrap; }

/* Fenêtres */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, 100% - 24px); box-shadow: 0 30px 80px -20px rgba(0,0,0,.45); color: var(--ink); }
dialog::backdrop { background: rgba(31, 26, 23, .55); }
.dialog-body { padding: 24px; display: grid; gap: 14px; }
.dialog-body h2 { margin: 0 0 4px; font-family: var(--font-display); font-size: 1.4rem; }
.dialog-body p { margin: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
#delcat-form label.check select { width: auto; flex: 1; }

/* Notifications */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: min(420px, 100% - 32px); }
.toast { background: var(--char); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 500; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* Mobile : le tableau devient une liste de fiches */
@media (max-width: 820px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .products thead { display: none; }
  .products, .products tbody, .products tr, .products td { display: block; width: 100%; }
  .products tr { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; padding: 14px; border-bottom: 1px solid var(--line); }
  .products tr:last-child { border-bottom: 0; }
  .products td { padding: 0; border: 0; }
  .products td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
  .products td.c-name { grid-column: 1 / -1; }
  .products td.c-cat { grid-column: 1 / -1; color: var(--muted); font-size: .9rem; }
  .products td.c-cat::before { display: none !important; }
  .products td.c-actions { grid-column: 1 / -1; }
  .price-input { margin-left: 0; }
  .stock-ctl, .row-actions { justify-content: flex-start; }
  .unlimited { text-align: left; }
  .p-desc { max-width: none; white-space: normal; }
  .toolbar select, .toolbar .btn { flex: 1 1 auto; }
}
@media (max-width: 520px) {
  .row { grid-template-columns: 1fr; }
  .cat-list li { flex-wrap: wrap; }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1; }
}
