/* Tawsil — esthétique « bordereau » : papier froid, encre bleu nuit, tampons de statut. */
:root {
  --paper: #F1F3F6; --card: #fff; --ink: #14213D; --muted: #596479; --line: #D9DEE7; --field: #C5CCD8;
  --brand: #1F3BD1; --brand-soft: #E8ECFF; --good: #12805C; --bad: #C23A32; --warn: #8A5200;
  --r-card: 14px; --r-ctl: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Noto Naskh Arabic", "Helvetica Neue", Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 1rem/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid rgba(31, 59, 209, .55); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.i { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i.xl { width: 52px; height: 52px; stroke-width: 1.5; }
[dir="rtl"] .flip { transform: scaleX(-1); }
.muted { color: var(--muted); font-size: .9rem; }
.pad { padding-inline: 4px; margin-bottom: 12px; }
.pre { white-space: pre-wrap; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

#shell { width: min(100%, 640px); margin-inline: auto; }
main { padding: 16px 16px 120px; outline: none; }
body[data-route="new"] main, body[data-route="edit"] main { padding-bottom: 200px; }
body[data-route="order"] main { padding-bottom: 110px; }

/* En-têtes */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.top h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; line-height: 1.15; overflow-wrap: anywhere; }
.top.bar { justify-content: flex-start; }
.top.bar h1 { flex: 1; font-size: 1.2rem; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; border-radius: 50%; color: var(--ink); text-decoration: none; }
.icon-btn:active { background: #E3E7EE; }

/* Boutons */
.btn { min-height: 44px; padding: 0 16px; border-radius: var(--r-ctl); border: 1px solid var(--field); background: #fff; color: var(--ink); font-weight: 650; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; text-align: center; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-o { color: var(--bad); border-color: #E3B3AF; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: .9rem; }
.btn-lg { min-height: 52px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.grow { flex: 1; }
.link-btn { background: none; border: 0; padding: 10px 4px; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; color: var(--brand); font-weight: 650; }
.link-btn.danger { color: var(--bad); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.stack { display: grid; gap: 8px; }
.top-add { flex: none; }

/* Cartes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px; margin-bottom: 12px; }
.card h2, .slip-sec h2 { font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 10px; letter-spacing: .01em; }
.banner { display: flex; gap: 12px; background: var(--brand-soft); border-radius: var(--r-card); padding: 14px; margin-bottom: 12px; color: var(--ink); }
.banner p { font-size: .9rem; color: var(--muted); margin-top: 2px; }
.strip { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin-bottom: 12px; }
.strip > div { background: var(--ink); color: #fff; border-radius: var(--r-card); padding: 12px 14px; display: grid; gap: 2px; }
.strip span { font-size: .8rem; opacity: .75; }
.strip strong { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.strip small { font-size: .78rem; opacity: .7; }

/* Recherche et filtres */
.search { position: relative; margin-bottom: 10px; }
.search .i { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { width: 100%; min-height: 48px; padding-inline: 44px 14px; border: 1px solid var(--field); border-radius: 12px; background: #fff; font-size: 1rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 12px; margin-inline: -16px; scrollbar-width: none; transition: opacity .15s; }
.chips::-webkit-scrollbar { display: none; }
.chips.dim { opacity: .4; }
.chip { flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--field); background: #fff; font-weight: 600; font-size: .9rem; display: inline-flex; align-items: center; }
.chip b { margin-inline-start: 7px; font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.on b { color: #C8D0E4; }

/* Tampons de statut */
.stamp { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 6px; border: 1.5px solid currentColor; font-weight: 700; font-size: .8rem; line-height: 1.3; white-space: nowrap; flex: none; }
.stamp.mini { font-size: .72rem; padding: 1px 8px; }
.s-new { color: #1F3BD1; background: #E8ECFF; }
.s-noanswer { color: #8A5200; background: #FFF1D6; }
.s-confirmed { color: #0A6580; background: #DDF1F7; }
.s-shipped { color: #5B3FC4; background: #ECE8FB; }
.s-delivered { color: #0C6A4B; background: #DFF3EA; }
.s-returned { color: #A12D26; background: #FBE4E2; }
.s-cancelled { color: #4D576A; background: #E7EAF0; }
.stamp.big { font-size: 1.3rem; padding: 6px 18px; border-width: 3px; border-radius: 8px; letter-spacing: .03em; transform: rotate(-4deg); background: transparent; box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 3.5px currentColor; }
.stamp-in { animation: stampIn .28s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes stampIn { from { transform: rotate(-12deg) scale(1.7); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }

/* Liste de commandes */
.order { background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: 14px; margin-bottom: 10px; display: grid; gap: 6px; cursor: pointer; }
.order:active { background: #F8F9FB; }
.order-head, .order-main, .order-sub { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.order-num { font-weight: 700; font-size: .85rem; color: var(--brand); font-variant-numeric: tabular-nums; }
.order-when { font-size: .8rem; color: var(--muted); }
.order-main h3 { font-size: 1.05rem; font-weight: 700; overflow-wrap: anywhere; }
.order-where { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: .9rem; }
.order-where .i { width: 1em; height: 1em; }
.order-cod { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.order-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding-top: 10px; border-top: 1px dashed var(--line); }
.order-actions .btn { margin-inline-start: auto; }
.act { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--field); display: inline-flex; align-items: center; justify-content: center; color: var(--ink); text-decoration: none; background: #fff; }
.act:active { background: #E3E7EE; }
.empty { text-align: center; padding: 40px 16px; display: grid; justify-items: center; gap: 12px; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 1.2rem; }
.empty.small { padding: 24px 16px; }

/* Bordereau (fiche commande) */
.slip { background: #fff; border-radius: 16px; margin-bottom: 12px; overflow: hidden; box-shadow: 0 1px 0 var(--line), 0 14px 28px -22px rgba(20, 33, 61, .55); }
.slip-stamp { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 18px 6px; }
.slip-stamp time { font-size: .85rem; color: var(--muted); }
.slip-sec { padding: 16px 18px; }
.big-line { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }
.phone-line { font-size: 1.05rem; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tear { border-top: 2px dashed var(--line); margin-inline: 18px; position: relative; height: 0; }
.tear::before, .tear::after { content: ""; position: absolute; top: -11px; width: 20px; height: 20px; border-radius: 50%; background: var(--paper); box-shadow: inset 0 0 0 1px var(--line); }
.tear::before { inset-inline-start: -28px; }
.tear::after { inset-inline-end: -28px; }
.lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lines li { display: flex; gap: 10px; justify-content: space-between; align-items: baseline; }
.lines .q { flex: none; min-width: 2.2em; color: var(--muted); font-variant-numeric: tabular-nums; }
.lines .n { flex: 1; overflow-wrap: anywhere; }
.lines .p, .lines.sub li span:last-child { font-variant-numeric: tabular-nums; text-align: end; }
.lines.sub { margin-top: 10px; color: var(--muted); font-size: .92rem; }
.cod { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 12px; border-top: 2px solid var(--ink); }
.cod span { font-weight: 650; }
.cod strong { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.cod.neg strong { color: var(--bad); }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.timeline time { font-size: .85rem; color: var(--muted); }
.foot-links { justify-content: space-between; }
.print-only { display: none; }

/* Barres d'action fixes */
.actionbar, .formbar, #nav { position: fixed; bottom: 0; inset-inline: 0; margin-inline: auto; width: min(100%, 640px); background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.actionbar { display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.formbar { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.sums { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sums div { display: grid; }
.sums span { font-size: .78rem; color: var(--muted); }
.sums strong { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.sums strong.neg { color: var(--bad); }
#nav { display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; padding-top: 6px; }
#nav[hidden] { display: none; }
#nav a { padding-inline: 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 54px; color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600; }
#nav a[aria-current="page"] { color: var(--brand); }
#nav a .i { width: 1.5em; height: 1.5em; }
#nav a.nav-add { width: 56px; height: 56px; min-height: 0; margin: -22px auto 4px; border-radius: 50%; background: var(--brand); color: #fff; box-shadow: 0 6px 16px -4px rgba(31, 59, 209, .6), 0 0 0 5px var(--paper); }
#nav a.nav-add .i { width: 1.7em; height: 1.7em; }

/* Formulaires */
.fld { display: grid; gap: 6px; margin-bottom: 12px; }
.fld > span { font-size: .85rem; font-weight: 650; color: var(--muted); }
input, select, textarea { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--field); border-radius: var(--r-ctl); background: #fff; font-size: 1rem; }
textarea { padding: 10px 12px; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: 3px solid rgba(31, 59, 209, .3); outline-offset: 0; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); background: #FFF8F7; }
input[type="tel"], input[dir="ltr"] { text-align: start; }
.inline { display: flex; gap: 6px; align-items: center; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.three { display: grid; grid-template-columns: .7fr 1fr 1fr; gap: 10px; align-items: end; }
.item { padding-bottom: 8px; margin-bottom: 12px; border-bottom: 1px dashed var(--line); }
.item .hint:empty { display: none; }
small.err { color: var(--bad); font-size: .82rem; font-weight: 600; }
small.err:empty { display: none; }
.hint { font-size: .85rem; color: var(--muted); }
.hint.err, .hint.ok, .hint.warn { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; margin-top: 8px; font-weight: 600; }
.hint.err { background: #FBE4E2; color: #A12D26; }
.hint.ok { background: #DFF3EA; color: #0C6A4B; }
.hint.warn { background: #FFF1D6; color: #7A4A00; }
.hint .i { width: 1.1em; height: 1.1em; margin-top: 2px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; margin-bottom: 10px; font-weight: 600; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); flex: none; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #E3E7EE; border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 12px; }
.seg label { position: relative; display: block; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 42px; border-radius: 9px; font-weight: 650; text-align: center; padding: 0 8px; }
.seg input:checked + span { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(20, 33, 61, .18); }
.seg input:focus-visible + span { outline: 3px solid rgba(31, 59, 209, .55); }

/* Produits, bilan, tarifs, réglages */
.plist { display: grid; gap: 10px; }
.prod { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-align: start; width: 100%; background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: 14px; }
.prod .pn { font-weight: 700; overflow-wrap: anywhere; }
.prod .pm { text-align: end; font-weight: 700; font-variant-numeric: tabular-nums; }
.prod .pg { font-size: .85rem; color: var(--good); }
.prod .pg.neg { color: var(--bad); }
.prod .badge { justify-self: end; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700; background: #E3E7EE; color: #3C465A; white-space: nowrap; }
.badge.warn { background: #FFF1D6; color: #7A4A00; }
.badge.bad { background: #FBE4E2; color: #A12D26; }
.badge.good { background: #DFF3EA; color: #0C6A4B; }
.stock-box { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--line); }
.stock-box p { margin-bottom: 10px; }
.hero-kpi { background: var(--ink); color: #fff; border-radius: 16px; padding: 18px; margin-bottom: 10px; display: grid; gap: 4px; }
.hero-kpi span { font-size: .85rem; opacity: .78; }
.hero-kpi strong { font-size: 2.1rem; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.hero-kpi.neg strong { color: #FFB4AE; }
.hero-kpi small { opacity: .75; font-size: .85rem; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpis > div { background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: 12px 14px; display: grid; gap: 2px; }
.kpis span { font-size: .8rem; color: var(--muted); }
.kpis strong { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpis strong.neg, .rk-p.neg { color: var(--bad); }
.chart { width: 100%; height: auto; direction: ltr; display: block; }
.bar-pos { fill: var(--brand); } .bar-neg { fill: var(--bad); }
.axis { stroke: var(--field); stroke-width: 1; }
.ax-t { font-size: 10px; fill: var(--muted); }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.rank li { display: grid; grid-template-columns: 1fr auto auto; gap: 2px 10px; align-items: center; }
.rk-n { font-weight: 650; overflow-wrap: anywhere; }
.rk-c { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.rk-p { grid-column: 1 / -1; font-size: .88rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.lock-card, .pro-card { flex-wrap: wrap; }
.lock-card .btn, .pro-card .btn { width: 100%; }
.lock-card { display: flex; align-items: center; gap: 12px; background: var(--brand-soft); border-color: #CBD3FA; }
.lock-card h2 { color: var(--ink); margin-bottom: 2px; }
.lock-card p { font-size: .88rem; color: var(--muted); }
.lock-card > div { flex: 1; min-width: 0; }
.pro-card { display: flex; align-items: center; gap: 12px; }
.pro-card > div { flex: 1; }
.pro-card h2 { color: var(--ink); font-size: 1rem; margin-bottom: 2px; }
.pro-card p { font-size: .88rem; color: var(--muted); }
.pro-card.on { background: #DFF3EA; border-color: #B4DFCC; color: #0C6A4B; }
.trows { background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: 4px 14px; }
.trow { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.trow:last-child { border-bottom: 0; }
.trow input { min-height: 42px; padding: 0 8px; text-align: center; }
.tn { font-weight: 650; font-size: .92rem; }
.perks { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.perks li { display: flex; gap: 8px; align-items: center; }
.perks .i { color: var(--good); }
.price { margin: 14px 0; } .price strong { font-size: 1.6rem; font-weight: 800; } .price span { color: var(--muted); }

/* Feuilles, dialogues, toasts */
dialog { border: 0; padding: 0; color: var(--ink); background: #fff; max-width: none; }
dialog::backdrop { background: rgba(20, 33, 61, .5); }
#sheet { width: min(100%, 640px); margin: auto auto 0; border-radius: 20px 20px 0 0; max-height: 90dvh; }
#confirm { width: min(92%, 400px); border-radius: 16px; margin: auto; }
.sheet-body { padding: 22px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 90dvh; overflow: auto; }
.sheet-body h2 { font-size: 1.2rem; margin-bottom: 8px; }
.sheet-body > p { margin-bottom: 10px; color: var(--muted); }
.confirm .row-btns .btn { flex: 1; }
.status-list { display: grid; gap: 8px; margin-top: 10px; }
.status-opt { display: grid; gap: 4px; justify-items: start; text-align: start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; text-decoration: none; color: var(--ink); }
.status-opt.cur { border-color: var(--ink); background: #F6F7F9; }
.status-opt span:not(.stamp) { font-size: .85rem; color: var(--muted); }
.wa-prev { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
#toast { position: fixed; inset-inline: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); margin-inline: auto; width: fit-content; max-width: min(92%, 520px); background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; display: flex; gap: 14px; align-items: center; z-index: 30; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5); opacity: 0; transform: translateY(8px); transition: opacity .18s, transform .18s; }
#toast.show { opacity: 1; transform: none; }
#toast[hidden] { display: none; }
.toast-btn { background: none; border: 0; color: #A9B8FF; font-weight: 800; padding: 6px 4px; min-height: 36px; }
body[data-route="order"] #toast { bottom: calc(100px + env(safe-area-inset-bottom)); }
body[data-route="new"] #toast, body[data-route="edit"] #toast { bottom: calc(150px + env(safe-area-inset-bottom)); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print {
  #nav, .top, .actionbar, .card, .foot-links, .no-print, #toast, dialog { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .slip { box-shadow: none; border: 1px solid #999; }
  .tear::before, .tear::after { display: none; }
  .print-only { display: block !important; }
  .print-shop { font-size: 1.4rem; font-weight: 800; margin-bottom: 8px; }
  .stamp-in { animation: none; }
}

.sheet-body > p.price { color: var(--ink); }
#proForm { margin-top: 18px; }
.pro-card > div { min-width: 0; }
