/* ============================================================
   Caisse Patro — design tactile, tablette d'abord.
   ============================================================ */
:root{
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, ui-sans-serif, system-ui, sans-serif;
  --cream: #F4F7F5; --cream-deep: #E9F0EC; --surface: #FFFFFF; --surface-rgb: 255,255,255;
  --green: #0F6B45; --green-dark: #084C35; --green-bright: #17835A; --green-soft: #E1F0E7;
  --gold: #F7C600; --gold-dark: #7A6200; --gold-soft: #FFF4B8;
  --red: #C23B2E; --red-soft: #FBE2DF;
  --blue: #2464B4; --blue-soft: #E1EDFB;
  --ink: #12372A; --muted: #607068; --line: #DCE5DF; --heading: var(--green-dark);
  --radius-lg: 18px; --radius-md: 14px; --radius-sm: 10px;
  --shadow: 0 10px 26px -12px rgba(8,76,53,.16); --shadow-sm: 0 2px 8px -3px rgba(8,76,53,.10);
  color-scheme: light;
}
@media (prefers-color-scheme: dark){ :root:not([data-theme="light"]){ color-scheme: dark;
  --cream:#0B0E13; --cream-deep:#05070A; --surface:#151A22; --surface-rgb:21,26,34;
  --green:#35C77E; --green-bright:#4CDB92; --green-dark:#7FE8AC; --green-soft:#10301F;
  --gold:#F7C600; --gold-dark:#FFDD57; --gold-soft:#2E2408;
  --red:#F1685C; --red-soft:#301613; --blue:#6FA9F7; --blue-soft:#10203A;
  --ink:#E6EAEF; --muted:#8D96A3; --line:#262C36; --heading:#F3F5F7; } }
:root[data-theme="dark"]{ color-scheme: dark;
  --cream:#0B0E13; --cream-deep:#05070A; --surface:#151A22; --surface-rgb:21,26,34;
  --green:#35C77E; --green-bright:#4CDB92; --green-dark:#7FE8AC; --green-soft:#10301F;
  --gold:#F7C600; --gold-dark:#FFDD57; --gold-soft:#2E2408;
  --red:#F1685C; --red-soft:#301613; --blue:#6FA9F7; --blue-soft:#10203A;
  --ink:#E6EAEF; --muted:#8D96A3; --line:#262C36; --heading:#F3F5F7; }

*{ box-sizing: border-box; }
html{ min-width: 320px; overflow-x: hidden; }
body{ margin:0; min-width:320px; font-family: var(--font); background: var(--cream); color: var(--ink); font-size:16px; line-height:1.45; }
a{ color: var(--green); }
h1{ font-size: clamp(1.3rem,3.5vw,1.7rem); color: var(--heading); margin:0 0 10px; font-weight:800; }
button, .button, .btn-primary{ display:inline-flex; align-items:center; justify-content:center; min-height:44px; border:0; border-radius:10px; padding:8px 16px; font:inherit; font-weight:700; cursor:pointer; background:var(--green); color:#fff; text-decoration:none; touch-action:manipulation; }
button:hover, .button:hover{ background: var(--green-dark); }
.button.alt{ background: var(--surface); color: var(--green); border:1.5px solid var(--green); }
.button.danger{ background: var(--surface); color: var(--red); border:1.5px solid var(--red); }
input, select, textarea{ display:block; width:100%; min-height:48px; padding:11px 13px; border:1.5px solid var(--line); border-radius:var(--radius-sm); background:var(--surface); color:var(--ink); font:inherit; font-size:16px; }
label{ display:block; font-weight:700; margin:12px 0 6px; font-size:.92rem; }
.card{ background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-lg); padding:18px; margin:10px 0; box-shadow: var(--shadow-sm); }
.error{ background:var(--red-soft); color:var(--red); padding:12px 15px; border-radius:var(--radius-sm); font-weight:650; margin:10px 0; }
.success{ background:var(--green-soft); color:var(--green-dark); padding:12px 15px; border-radius:var(--radius-sm); font-weight:650; margin:10px 0; }

/* Topbar */
.topbar{ display:flex; align-items:center; gap:14px; padding:8px 14px; background:var(--surface); border-bottom:1px solid var(--line); flex-wrap:wrap; }
.brand{ font-weight:900; color:var(--heading); text-decoration:none; font-size:1.05rem; }
.topnav{ display:flex; gap:4px; flex-wrap:wrap; flex:1; }
.nav-link{ color:var(--ink); text-decoration:none; font-weight:700; font-size:.88rem; padding:8px 10px; border-radius:8px; min-height:38px; display:flex; align-items:center; }
.nav-link.active, .nav-link:hover{ background: var(--green-soft); color: var(--green-dark); }
.who{ font-size:.85rem; color:var(--muted); font-weight:700; }
.logout{ font-size:.85rem; color:var(--red); text-decoration:none; font-weight:700; }
.net-badge{ font-size:.78rem; font-weight:800; padding:4px 10px; border-radius:99px; background:var(--green-soft); color:var(--green-dark); }
.net-badge.offline{ background:var(--gold-soft); color:var(--gold-dark); }

.page-main{ max-width:960px; margin:0 auto; padding:18px 16px 40px; }

/* Login */
.login-wrap{ min-height:100dvh; display:flex; align-items:center; justify-content:center; padding:16px; }
.login-card{ width:100%; max-width:380px; background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-lg); padding:28px; box-shadow:var(--shadow); border-top:4px solid var(--gold); }
.login-card h1{ text-align:center; }
.link-row{ text-align:center; margin-top:14px; }
.link-row a{ font-weight:700; font-size:.9rem; }

/* Connexion rapide par code PIN */
.pin-card{ max-width:420px; }
.pin-staff-grid{ display:grid; grid-template-columns:repeat(2,1fr); gap:8px; margin:12px 0; }
.pin-staff-btn{ min-height:56px; background:var(--surface); color:var(--ink); border:1.5px solid var(--line); font-weight:750; }
.pin-staff-btn:hover{ background:var(--green-soft); border-color:var(--green-soft); color:var(--green-dark); }
#pin-selected-name{ text-align:center; font-weight:800; color:var(--heading); font-size:1.05rem; margin:0 0 10px; }
.pin-dots{ display:flex; justify-content:center; gap:14px; margin:18px 0; }
.pin-dots span{ width:16px; height:16px; border-radius:50%; border:2px solid var(--line); background:var(--surface); }
.pin-dots span.filled{ background:var(--green); border-color:var(--green); }
.pin-pad{ display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.pin-key{ min-height:64px; font-size:1.4rem; background:var(--surface); color:var(--ink); border:1.5px solid var(--line); }
.pin-key:active{ background:var(--green-soft); }
.pin-key-alt{ font-size:.85rem; color:var(--red); }

/* ==================== POS ==================== */
.pos-body{ overflow:hidden; height:100dvh; }
.pos-main{ display:flex; flex-direction:column; height: calc(100dvh - 58px); }
.pos-layout{ display:flex; flex:1; min-height:0; }
.pos-catalog{ flex:1; min-width:0; display:flex; flex-direction:column; padding:10px 12px; overflow:hidden; }
.pos-categories{ display:flex; gap:6px; overflow-x:auto; padding-bottom:8px; flex:0 0 auto; }
.pos-cat-btn{ flex:0 0 auto; min-height:42px; padding:8px 16px; border-radius:99px; background:var(--surface); border:1.5px solid var(--line); color:var(--ink); font-weight:750; }
.pos-cat-btn.active{ background:var(--green); color:#fff; border-color:var(--green); }
.pos-grid{ flex:1; overflow-y:auto; display:grid; grid-template-columns:repeat(auto-fill,minmax(120px,1fr)); gap:10px; padding:4px 2px 20px; align-content:start; }
.pos-product{ display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px; min-height:110px; padding:10px; border-radius:var(--radius-md); background:var(--surface); border:1.5px solid var(--line); box-shadow:var(--shadow-sm); color:var(--ink); font-weight:800; text-align:center; cursor:pointer; }
.pos-product:active{ transform:scale(.96); background:var(--green-soft); }
.pos-product img{ width:48px; height:48px; object-fit:cover; border-radius:10px; }
.pos-product .px{ color: var(--green-dark); font-size:.85rem; font-weight:800; }
.pos-product[disabled]{ opacity:.4; }
.pos-ticket{ flex:0 0 340px; max-width:44vw; display:flex; flex-direction:column; border-left:1px solid var(--line); background:var(--surface); }
.ticket-head{ padding:12px 14px; border-bottom:1px solid var(--line); font-weight:800; display:flex; justify-content:space-between; align-items:center; }
.ticket-lines{ flex:1; overflow-y:auto; padding:6px 10px; }
.ticket-line{ display:flex; align-items:center; gap:8px; padding:10px 4px; border-bottom:1px solid var(--line); }
.ticket-line .tl-name{ flex:1; min-width:0; font-weight:700; font-size:.92rem; overflow-wrap:anywhere; }
.ticket-line .tl-qty{ display:flex; align-items:center; gap:4px; }
.tl-qty button{ min-width:32px; min-height:32px; padding:0; font-size:1.1rem; background:var(--cream-deep); color:var(--ink); }
.ticket-line .tl-total{ width:64px; text-align:right; font-weight:800; font-size:.9rem; }
.ticket-line .tl-del{ min-width:32px; min-height:32px; padding:0; background:var(--red-soft); color:var(--red); }
.ticket-empty{ text-align:center; color:var(--muted); padding:40px 12px; }
.ticket-footer{ padding:12px 14px; border-top:1px solid var(--line); }
.ticket-total{ display:flex; justify-content:space-between; align-items:center; font-size:1.5rem; font-weight:900; color:var(--heading); margin-bottom:10px; }
.ticket-actions{ display:flex; gap:8px; }
.ticket-actions .button{ flex:1; }
.btn-pay{ width:100%; min-height:56px; font-size:1.1rem; background:var(--green); }
.btn-clear{ background:var(--surface); color:var(--red); border:1.5px solid var(--red); }

/* Paiement modal */
.pay-overlay{ position:fixed; inset:0; background:rgba(5,7,10,.6); display:none; align-items:center; justify-content:center; z-index:200; padding:16px; }
.pay-overlay.open{ display:flex; }
.pay-box{ background:var(--surface); border-radius:var(--radius-lg); padding:24px; width:100%; max-width:420px; box-shadow:var(--shadow); }
.pay-total{ text-align:center; font-size:2rem; font-weight:900; color:var(--heading); margin-bottom:18px; }
.pay-methods{ display:flex; gap:10px; margin-bottom:14px; }
.pay-methods button{ flex:1; min-height:64px; font-size:1.05rem; background:var(--surface); color:var(--ink); border:2px solid var(--line); }
.pay-methods button.selected{ border-color:var(--green); background:var(--green-soft); color:var(--green-dark); }
.pay-cash-row{ display:flex; gap:8px; margin:10px 0; }
.pay-quick{ flex:1; min-height:44px; background:var(--cream-deep); color:var(--ink); }
.pay-change{ text-align:center; font-size:1.3rem; font-weight:800; margin:10px 0; color:var(--green-dark); }
.pay-confirm{ width:100%; min-height:56px; font-size:1.1rem; margin-top:8px; }

@media (max-width: 900px){
  .pos-layout{ flex-direction:column; }
  .pos-ticket{ flex:0 0 42vh; max-width:none; border-left:0; border-top:1px solid var(--line); }
}
@media (max-width: 480px){
  .pos-grid{ grid-template-columns:repeat(auto-fill,minmax(100px,1fr)); }
  .pos-product{ min-height:92px; }
}

/* Tables & admin */
table.list{ width:100%; border-collapse:collapse; }
table.list th{ text-align:left; padding:9px 10px; font-size:.78rem; text-transform:uppercase; color:var(--muted); border-bottom:2px solid var(--line); }
table.list td{ padding:10px; border-bottom:1px solid var(--line); }
.grid-stats{ display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:10px; margin:14px 0; }
.stat{ background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md); padding:14px; box-shadow:var(--shadow-sm); }
.stat span{ display:block; font-size:.78rem; color:var(--muted); font-weight:700; }
.stat b{ display:block; font-size:1.3rem; color:var(--heading); margin-top:4px; }
.error-page{ max-width:420px; margin:60px auto; text-align:center; }
.error-code{ font-size:3rem; font-weight:900; color:var(--gold-dark); }
.badge{ display:inline-block; padding:3px 9px; border-radius:99px; font-size:.75rem; font-weight:800; background:var(--cream-deep); color:var(--muted); }
.badge.ok{ background:var(--green-soft); color:var(--green-dark); }
.badge.warn{ background:var(--gold-soft); color:var(--gold-dark); }
.badge.danger{ background:var(--red-soft); color:var(--red); }
.muted{ color:var(--muted); }
.chart-dot{ display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:5px; vertical-align:middle; }
.chart-card{ overflow-x:auto; }
