:root {
  color-scheme: light;
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --ink: #1C1917;
  --muted: #57534E;
  --line: #E7E2DA;
  --soft: #F5F0E8;
  --accent: #C2410C;
  --accent-ink: #9A3412;
  --accent-soft: #FDEBDD;
  --green: #15803D;
  --green-soft: #DCFCE7;
  --red: #B91C1C;
  --red-soft: #FEE2E2;
  --blue: #1D4ED8;
  --blue-soft: #DBEAFE;
  --radius: 16px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Cairo', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
a { color: #B4350B; }
a:hover { color: #8A2808; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grow { flex: 1; min-width: 0; }

/* controls */
.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  min-height: 42px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--red); border-color: #F3C9C9; }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; }
input, select, textarea {
  font: inherit; font-size: 15px; font-weight: 400;
  min-height: 44px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 3px solid #FDBA8C; outline-offset: 1px; }
.inline-num { width: 120px; min-height: 36px; padding: 4px 10px; }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 420px; padding: 28px; display: flex; flex-direction: column; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 44px; height: 44px; border-radius: 14px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 20px; flex-shrink: 0; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--soft); border-radius: 12px; padding: 4px; }
.seg button { font: inherit; font-weight: 600; border: 0; background: transparent; min-height: 40px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* shell */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tabs { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; }
.tabs button {
  font: inherit; font-weight: 600; font-size: 14px; border: 0; background: transparent; color: var(--muted);
  padding: 12px 14px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.tabs button.on { color: var(--accent-ink); border-bottom-color: var(--accent); }
.count[hidden] { display: none; }
.count { background: var(--accent); color: #fff; border-radius: 999px; min-width: 22px; height: 22px; padding: 0 6px; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }

/* chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 14px; font-weight: 600; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 999px; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.tag { display: inline-flex; align-items: center; gap: 6px; background: var(--soft); border: 1px solid var(--line); padding: 4px 6px 4px 12px; border-radius: 999px; font-size: 14px; }
.tag button { border: 0; background: transparent; cursor: pointer; color: var(--red); font-size: 16px; width: 26px; height: 26px; border-radius: 999px; }
.tag button:hover { background: var(--red-soft); }

/* badges */
.badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.b-pending { background: var(--accent-soft); color: var(--accent-ink); }
.b-accepted, .b-preparing { background: var(--blue-soft); color: var(--blue); }
.b-ready, .b-picked_up { background: #FEF3C7; color: #92400E; }
.b-delivered, .b-on { background: var(--green-soft); color: var(--green); }
.b-cancelled, .b-rejected, .b-off { background: var(--red-soft); color: var(--red); }
.b-neutral { background: var(--soft); color: var(--muted); }

/* orders */
.order { display: flex; flex-direction: column; gap: 12px; }
.order.s-pending { border-color: #F5B78E; box-shadow: 0 0 0 3px var(--accent-soft); }
.kv { margin: 0; display: grid; gap: 6px; }
.kv div { display: flex; gap: 8px; }
.kv dt { color: var(--muted); min-width: 84px; font-size: 13px; }
.kv dd { margin: 0; font-weight: 500; }
.items { list-style: none; margin: 0; padding: 10px 12px; background: var(--soft); border-radius: 12px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.items li { display: flex; justify-content: space-between; gap: 8px; }
.note { margin: 0; padding: 8px 12px; border-radius: 10px; background: #FEF9C3; font-size: 14px; }
.totals { border-top: 1px dashed var(--line); padding-top: 10px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { background: var(--soft); font-weight: 600; color: var(--muted); font-size: 13px; }
tr:last-child td { border-bottom: 0; }

/* toasts */
#toasts { position: fixed; bottom: 16px; left: 16px; right: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 480px; }
.toast.err { background: var(--red); }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .wrap { padding: 16px 12px 60px; }
}

/* ===== stat tiles ===== */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.tile-k { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile-v { font-size: 24px; font-weight: 700; line-height: 1.25; }
.tile-s { font-size: 13px; color: var(--muted); }
.grid2 { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.owe { color: var(--accent-ink); }

/* daily bars: single series, accent color, hover title shows the value */
.bars { display: flex; align-items: flex-end; gap: 6px; overflow-x: auto; padding-top: 18px; min-height: 190px; }
.bar-col { flex: 1 0 44px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar { width: 100%; max-width: 36px; background: var(--accent); border-radius: 4px 4px 0 0; }
.bar-col:hover .bar { background: var(--accent-ink); }
.bar-val { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bar-lbl { font-size: 11px; color: var(--muted); white-space: nowrap; border-top: 1px solid var(--line); padding-top: 4px; width: 100%; text-align: center; }

/* settlement inline form */
.settle { display: flex; gap: 6px; align-items: center; }
.settle input { width: 110px; min-height: 36px; padding: 4px 10px; }
.settle select { width: auto; min-height: 36px; padding: 4px 8px; }

/* restaurant open/closed switch */
.switch { font: inherit; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px 0 6px; border-radius: 999px; border: 1px solid #F3C9C9; background: var(--red-soft); color: var(--red); cursor: pointer; }
.switch .knob { width: 28px; height: 28px; border-radius: 999px; background: var(--red); }
.switch.on { background: var(--green-soft); border-color: #BBE5C8; color: var(--green); }
.switch.on .knob { background: var(--green); }

.btn.block { width: 100%; }
.btn.lg { min-height: 54px; font-size: 16px; border-radius: 14px; }
.btn.grow { flex: 1; }
.icon-btn { width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: inline-flex; align-items: center; justify-content: center; color: var(--ink); text-decoration: none; }
.icon-btn.wa { background: var(--green); border-color: var(--green); color: #fff; }
.ok-text { color: var(--green); font-weight: 600; }

/* ===== driver page (mobile first) ===== */
.drv { max-width: 560px; margin: 0 auto; min-height: 100vh; }
.drv-top { background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 12px; }
.drv .tabs { background: var(--surface); border-bottom: 1px solid var(--line); }
.drv-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.online-btn { font: inherit; font-size: 16px; font-weight: 700; min-height: 56px; border-radius: 16px; border: 2px dashed var(--line); background: var(--soft); color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; }
.online-btn .dot { width: 12px; height: 12px; border-radius: 999px; background: #A8A29E; }
.online-btn.on { border: 2px solid var(--green); background: var(--green-soft); color: var(--green); }
.online-btn.on .dot { background: var(--green); box-shadow: 0 0 0 4px #BBF7D0; }
.drv-card { display: flex; flex-direction: column; gap: 12px; }
.drv-card.hot { border-color: #F5B78E; box-shadow: 0 0 0 3px var(--accent-soft); }
.leg { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 12px; background: var(--soft); border-inline-start: 0; }
.leg.cur { background: var(--accent-soft); }
.leg.done { opacity: .6; }
.leg-k { font-size: 12px; font-weight: 700; color: var(--muted); }
.leg.cur .leg-k { color: var(--accent-ink); }
.collect { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--ink); color: #fff; }
.collect strong { font-size: 18px; }
.collect .muted-inv { font-weight: 400; opacity: .7; font-size: 14px; }


/* ---------- dark appearance (auto by system, or forced with data-theme) ---------- */
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) { color-scheme: dark;
  --bg: #12100E; --surface: #1C1916; --ink: #F5F0E8; --ink-2: #D6D0C8; --muted: #A8A29E;
  --line: #34302B; --soft: #25211D; --stripe-a: #2A2520; --stripe-b: #302A24;
  --accent: #C2410C; --accent-ink: #EA580C; --accent-soft: #3A2214;
  --green: #4ADE80; --green-soft: #12301E; --red: #F87171; --red-soft: #3B1717;
  --blue: #93C5FD; --blue-soft: #1E2A44; }
:root:not([data-theme="light"]) a:not([class]), :root:not([data-theme="light"]) .btn.ghost { color: #FB923C; }
:root:not([data-theme="light"]) a:not([class]):hover { color: #FDBA74; }
:root:not([data-theme="light"]) .chip.on, :root:not([data-theme="light"]) .btn.dark { background: var(--accent); border-color: var(--accent); color: #fff; }
:root:not([data-theme="light"]) .toast, :root:not([data-theme="light"]) .avatar, :root:not([data-theme="light"]) .collect, :root:not([data-theme="light"]) .banner { background: #2E2925; color: #fff; }
:root:not([data-theme="light"]) .toast.err { background: #991B1B; }
:root:not([data-theme="light"]) .wa, :root:not([data-theme="light"]) .icon-btn.wa, :root:not([data-theme="light"]) .steps .done .dotc, :root:not([data-theme="light"]) .steps .done .bar, :root:not([data-theme="light"]) .switch.on .knob, :root:not([data-theme="light"]) .online-btn.on .dot { background: #16A34A; border-color: #16A34A; }
:root:not([data-theme="light"]) .switch .knob { background: #DC2626; }
:root:not([data-theme="light"]) .btn.danger, :root:not([data-theme="light"]) .switch { border-color: #5B2121; }
:root:not([data-theme="light"]) .switch.on { border-color: #1F5130; }
:root:not([data-theme="light"]) .warn, :root:not([data-theme="light"]) .st-accepted, :root:not([data-theme="light"]) .st-preparing, :root:not([data-theme="light"]) .st-ready, :root:not([data-theme="light"]) .st-picked_up, :root:not([data-theme="light"]) .b-ready, :root:not([data-theme="light"]) .b-picked_up { background: #3A2E0E; color: #FCD34D; }
:root:not([data-theme="light"]) .note { background: #3A320E; color: #FDE68A; }
:root:not([data-theme="light"]) .order.s-pending, :root:not([data-theme="light"]) .drv-card.hot { border-color: #9A3412; }
:root:not([data-theme="light"]) .online-btn.on .dot { box-shadow: 0 0 0 4px #14532D; }
:root:not([data-theme="light"]) .stats, :root:not([data-theme="light"]) .item, :root:not([data-theme="light"]) .line { border-color: var(--line); }
:root:not([data-theme="light"]) .sum .t { border-top-color: #4A443D; }
:root:not([data-theme="light"]) .map { background-color: #25211D; background-image: linear-gradient(#34302B 1px, transparent 1px), linear-gradient(90deg, #34302B 1px, transparent 1px); }
:root:not([data-theme="light"]) .steps .cur .dotc, :root:not([data-theme="light"]) .steps .todo .dotc { background: var(--surface); }
:root:not([data-theme="light"]) .steps .todo .dotc { border-color: #4A443D; }
:root:not([data-theme="light"]) .steps .bar { background: #3A3530; }
:root:not([data-theme="light"]) .offer { border-color: #7C3A12; }
:root:not([data-theme="light"]) .offer.loyal { background: #2A1E14; }
:root:not([data-theme="light"]) .stamps i { background: var(--surface); border-color: #7C3A12; }
:root:not([data-theme="light"]) .seg button.on { box-shadow: none; }
:root:not([data-theme="light"]) img.logo { box-shadow: none; }
}
:root[data-theme="dark"] { color-scheme: dark;
  --bg: #12100E; --surface: #1C1916; --ink: #F5F0E8; --ink-2: #D6D0C8; --muted: #A8A29E;
  --line: #34302B; --soft: #25211D; --stripe-a: #2A2520; --stripe-b: #302A24;
  --accent: #C2410C; --accent-ink: #EA580C; --accent-soft: #3A2214;
  --green: #4ADE80; --green-soft: #12301E; --red: #F87171; --red-soft: #3B1717;
  --blue: #93C5FD; --blue-soft: #1E2A44; }
:root[data-theme="dark"] a:not([class]), :root[data-theme="dark"] .btn.ghost { color: #FB923C; }
:root[data-theme="dark"] a:not([class]):hover { color: #FDBA74; }
:root[data-theme="dark"] .chip.on, :root[data-theme="dark"] .btn.dark { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .toast, :root[data-theme="dark"] .avatar, :root[data-theme="dark"] .collect, :root[data-theme="dark"] .banner { background: #2E2925; color: #fff; }
:root[data-theme="dark"] .toast.err { background: #991B1B; }
:root[data-theme="dark"] .wa, :root[data-theme="dark"] .icon-btn.wa, :root[data-theme="dark"] .steps .done .dotc, :root[data-theme="dark"] .steps .done .bar, :root[data-theme="dark"] .switch.on .knob, :root[data-theme="dark"] .online-btn.on .dot { background: #16A34A; border-color: #16A34A; }
:root[data-theme="dark"] .switch .knob { background: #DC2626; }
:root[data-theme="dark"] .btn.danger, :root[data-theme="dark"] .switch { border-color: #5B2121; }
:root[data-theme="dark"] .switch.on { border-color: #1F5130; }
:root[data-theme="dark"] .warn, :root[data-theme="dark"] .st-accepted, :root[data-theme="dark"] .st-preparing, :root[data-theme="dark"] .st-ready, :root[data-theme="dark"] .st-picked_up, :root[data-theme="dark"] .b-ready, :root[data-theme="dark"] .b-picked_up { background: #3A2E0E; color: #FCD34D; }
:root[data-theme="dark"] .note { background: #3A320E; color: #FDE68A; }
:root[data-theme="dark"] .order.s-pending, :root[data-theme="dark"] .drv-card.hot { border-color: #9A3412; }
:root[data-theme="dark"] .online-btn.on .dot { box-shadow: 0 0 0 4px #14532D; }
:root[data-theme="dark"] .stats, :root[data-theme="dark"] .item, :root[data-theme="dark"] .line { border-color: var(--line); }
:root[data-theme="dark"] .sum .t { border-top-color: #4A443D; }
:root[data-theme="dark"] .map { background-color: #25211D; background-image: linear-gradient(#34302B 1px, transparent 1px), linear-gradient(90deg, #34302B 1px, transparent 1px); }
:root[data-theme="dark"] .steps .cur .dotc, :root[data-theme="dark"] .steps .todo .dotc { background: var(--surface); }
:root[data-theme="dark"] .steps .todo .dotc { border-color: #4A443D; }
:root[data-theme="dark"] .steps .bar { background: #3A3530; }
:root[data-theme="dark"] .offer { border-color: #7C3A12; }
:root[data-theme="dark"] .offer.loyal { background: #2A1E14; }
:root[data-theme="dark"] .stamps i { background: var(--surface); border-color: #7C3A12; }
:root[data-theme="dark"] .seg button.on { box-shadow: none; }
:root[data-theme="dark"] img.logo { box-shadow: none; }
#pushNote:empty { display: none; }

/* Talla Plus */
.plus-stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-top: 12px; }
.plus-stats > div { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.plus-stats span { color: var(--muted); font-size: 13px; }
.plus-stats b { font-size: 20px; }

/* Turnstile anti-bot widget (hidden unless a check is needed) */
.cf-box { display: flex; justify-content: center; }
.cf-box:empty { display: none; }
