:root {
  --bg: #f7f5f3;
  --card: #ffffff;
  --fg: #1d1916;
  --fg-2: #52483f;
  --muted: #8a7f76;
  --border: #e8e2dc;
  --input: #ddd5cd;
  --primary: #9e4257;
  --primary-10: rgba(158, 66, 87, .1);
  --side: #1d1916;
  --side-fg: #cfc6bd;
  --success: #2f7a52; --success-10: rgba(47, 122, 82, .11);
  --warning: #b26b00; --warning-10: rgba(178, 107, 0, .12);
  --info: #2a62a8; --info-10: rgba(42, 98, 168, .1);
  --danger: #c0352b; --danger-10: rgba(192, 53, 43, .1);
  --violet: #6a4bb0; --violet-10: rgba(106, 75, 176, .1);
  --gray-10: rgba(29, 25, 22, .07);
  --radius: 12px;
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 400 14.5px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }
.brand-word { font: italic 500 26px/1 'Newsreader', Georgia, serif; letter-spacing: -.02em; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--side); }
.login-card { width: 100%; max-width: 360px; background: var(--card); border-radius: 18px; padding: 28px; display: grid; gap: 14px; }
.login-card p { margin: -6px 0 6px; color: var(--muted); }
.err { color: var(--danger); font-weight: 600; min-height: 1em; }

/* Structure */
.app { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-fg); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 16px 12px; }
.side-brand { display: flex; align-items: baseline; gap: 8px; padding: 6px 10px 22px; color: #fff; }
.side-sub { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #8f857c; }
.side-nav, .side-foot { display: grid; gap: 2px; }
.side-foot { margin-top: auto; border-top: 1px solid #3a332e; padding-top: 10px; }
.side a, .side button { display: flex; align-items: center; gap: 11px; height: 40px; padding: 0 12px; border-radius: 9px; background: none; border: 0; font-weight: 500; color: var(--side-fg); text-align: left; width: 100%; }
.side a:hover, .side button:hover { background: #2c2622; color: #fff; }
.side a.on { background: #fff; color: var(--fg); }
.side .pill { margin-left: auto; }
.pill { font-style: normal; font-size: 11.5px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; background: var(--primary); color: #fff; display: inline-grid; place-items: center; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 64px; display: flex; align-items: center; gap: 12px; padding: 0 28px; border-bottom: 1px solid var(--border); background: var(--card); position: sticky; top: 0; z-index: 20; }
.top h1 { margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-back { border: 0; background: none; width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; margin-left: -8px; }
.top-back:hover { background: var(--gray-10); }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.content { padding: 24px 28px 60px; max-width: 1240px; width: 100%; }
.tabs { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .top { padding: 0 16px; height: 58px; }
  .content { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  .tabs {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(62px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--border);
  }
  .tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); position: relative; }
  .tabs svg { width: 22px; height: 22px; }
  .tabs a.on { color: var(--primary); }
  .tabs .pill { position: absolute; top: 5px; left: calc(50% + 6px); height: 18px; min-width: 18px; font-size: 10.5px; }
}

/* Boutons */
.b { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--input); background: var(--card); font-weight: 600; font-size: 14px; white-space: nowrap; }
.b:hover { background: #faf8f6; border-color: #c9bfb5; }
.b[disabled] { opacity: .5; pointer-events: none; }
.b-primary { background: var(--fg); border-color: var(--fg); color: #fff; }
.b-primary:hover { background: #000; }
.b-success { background: var(--success); border-color: var(--success); color: #fff; }
.b-success:hover { background: #276845; }
.b-danger { color: var(--danger); }
.b-block { width: 100%; height: 44px; }
.b-lg { height: 48px; font-size: 15px; padding: 0 18px; }
.b-sm { height: 32px; padding: 0 10px; font-size: 13px; }

/* Cartes */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 0; }
.card-h h2 { margin: 0; font-size: 15px; font-weight: 700; }
.card-b { padding: 16px 18px 18px; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: start; }
.kpi .lbl { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 26px; font-weight: 700; letter-spacing: -.01em; grid-column: 1; }
.kpi .sub { font-size: 12.5px; color: var(--muted); grid-column: 1 / -1; }
.kpi .ico { grid-row: 1 / 3; grid-column: 2; width: 38px; height: 38px; border-radius: 10px; background: var(--primary-10); color: var(--primary); display: grid; place-items: center; }
.kpi a.val:hover { text-decoration: underline; }
.two-col { display: grid; gap: 18px; grid-template-columns: 1.6fr 1fr; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

/* Graphique */
.chart { position: relative; height: 210px; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart .bar { fill: var(--primary); }
.chart .bar:hover, .chart .bar.hl { fill: #7f3245; }
.chart .grid line { stroke: var(--border); }
.chart text { fill: var(--muted); font-size: 11px; }
.tip { position: absolute; pointer-events: none; background: var(--fg); color: #fff; font-size: 12.5px; padding: 6px 9px; border-radius: 7px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; }
.tip.on { opacity: 1; }

/* Listes */
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); font-size: 14px; }
.list-row:first-child { border-top: 0; }
.muted { color: var(--muted); }

/* Badges de statut */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.st::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-nouvelle { background: var(--info-10); color: var(--info); }
.st-injoignable { background: var(--warning-10); color: var(--warning); }
.st-confirmee { background: var(--violet-10); color: var(--violet); }
.st-expediee { background: var(--primary-10); color: var(--primary); }
.st-livree { background: var(--success-10); color: var(--success); }
.st-retour { background: var(--danger-10); color: var(--danger); }
.st-annulee { background: var(--gray-10); color: var(--muted); }
.flag { font-size: 11.5px; font-weight: 700; color: var(--warning); background: var(--warning-10); padding: 2px 8px; border-radius: 999px; }

/* Commandes */
.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; margin-bottom: 12px; }
.seg::-webkit-scrollbar { display: none; }
.seg button { border: 1px solid var(--input); background: var(--card); height: 34px; padding: 0 12px; border-radius: 999px; font-weight: 600; font-size: 13px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.seg button.on { background: var(--fg); color: #fff; border-color: var(--fg); }
.seg button em { font-style: normal; font-size: 11.5px; opacity: .7; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg { position: absolute; left: 11px; top: 10px; color: var(--muted); }
.search input { width: 100%; height: 38px; border: 1px solid var(--input); border-radius: 9px; padding: 0 12px 0 36px; background: var(--card); outline: none; }
.search input:focus { border-color: var(--fg); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover { background: #fbfaf8; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.o-name { font-weight: 600; }
.o-sub { font-size: 12.5px; color: var(--muted); }
.ocards { display: none; }
@media (max-width: 760px) {
  .table-wrap { display: none; }
  .ocards { display: grid; gap: 10px; }
}
.ocard { display: grid; gap: 6px; padding: 14px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); position: relative; }
.ocard .r1 { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ocard .r2 { font-size: 13px; color: var(--fg-2); }
.ocard .r3 { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.ocard .r3 b { color: var(--fg); font-size: 14.5px; }
.ocard input[type='checkbox'] { position: absolute; right: 12px; bottom: 12px; }
.bulk { position: sticky; bottom: 12px; z-index: 15; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--fg); color: #fff; padding: 10px 12px; border-radius: 12px; margin-top: 12px; }
@media (max-width: 900px) { .bulk { bottom: calc(72px + env(safe-area-inset-bottom)); } }
.bulk select { height: 34px; border-radius: 8px; border: 0; padding: 0 8px; color: var(--fg); }
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 14px; align-items: center; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* Détail commande */
.detail { display: grid; gap: 16px; grid-template-columns: 1.5fr 1fr; align-items: start; }
@media (max-width: 1000px) { .detail { grid-template-columns: 1fr; } }
.cust-name { font-size: 20px; font-weight: 700; margin: 0; }
.cust-phone { font-size: 22px; font-weight: 700; letter-spacing: .02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.call-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.actions-big { display: grid; gap: 8px; }
.actions-big .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.items .it { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.items .it:first-child { border-top: 0; }
.items .tot { font-weight: 700; font-size: 16px; }
.timeline { display: grid; gap: 10px; font-size: 13.5px; }
.timeline div { display: grid; grid-template-columns: 110px 1fr; gap: 10px; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--warning-10); color: #7a4a00; font-size: 13.5px; font-weight: 500; }

/* Formulaires */
.fld { display: grid; gap: 5px; }
.fld > span { font-size: 13px; font-weight: 600; color: var(--fg-2); }
.fld small { color: var(--muted); font-size: 12.5px; }
.fld input, .fld select, .fld textarea, .in { height: 38px; border: 1px solid var(--input); border-radius: 9px; padding: 0 11px; background: #fff; outline: none; width: 100%; }
.fld textarea { height: auto; min-height: 80px; padding: 9px 11px; resize: vertical; }
.fld input:focus, .fld select:focus, .fld textarea:focus, .in:focus { border-color: var(--fg); box-shadow: 0 0 0 3px rgba(29, 25, 22, .07); }
.form-grid { display: grid; gap: 14px; }
.form-grid.c2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .form-grid.c2 { grid-template-columns: 1fr; } }
.switch { position: relative; display: inline-block; vertical-align: middle; width: 38px; height: 22px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; background: #d6cdc4; border-radius: 11px; transition: .15s; }
.switch i::after { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + i { background: var(--success); }
.switch input:checked + i::after { transform: translateX(16px); }

/* Produits */
.prod-row td { padding: 10px 8px; }
.prod-img { width: 46px; height: 46px; border-radius: 8px; border: 1px solid var(--border); object-fit: contain; background: #fff; padding: 3px; }
.prod-row .in { height: 34px; width: 96px; text-align: right; padding: 0 8px; }
.prod-row .in.stock { width: 64px; }
.prod-cards { display: none; }
@media (max-width: 860px) { .prod-table { display: none; } .prod-cards { display: grid; gap: 10px; } }
.pcard { padding: 12px; display: grid; grid-template-columns: 54px 1fr; gap: 10px 12px; }
.pcard .prod-img { width: 54px; height: 54px; }
.pcard .f { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 80px; gap: 8px; align-items: end; }
.pcard .f .in { width: 100%; text-align: left; }
.pcard .t { display: flex; gap: 14px; align-items: center; font-size: 13px; grid-column: 1 / -1; }
.pcard .t label { display: inline-flex; gap: 6px; align-items: center; }

/* Fenêtre */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(20, 16, 13, .45); display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--card); border-radius: 16px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); overflow: auto; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); }
.modal-h h3 { margin: 0; font-size: 16px; }
.modal-b { padding: 18px; }
.modal-f { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: var(--card); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; background: var(--fg); color: #fff; padding: 11px 16px; border-radius: 10px; font-weight: 600; z-index: 90; transition: all .2s; pointer-events: none; max-width: calc(100% - 32px); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); }
@media (max-width: 900px) { .toast { bottom: calc(76px + env(safe-area-inset-bottom)); } }
