:root {
  --bg: #f4f6fb; --panel: #ffffff; --panel-2: #f8f9fc; --line: #e3e7ef; --text: #1b2333; --muted: #6b7489;
  --brand: #2f4bd8; --brand-2: #1f36a8; --brand-soft: #e8ecff;
  --ok: #138a52; --ok-soft: #e3f6ec; --warn: #b26b00; --warn-soft: #fff3dc; --bad: #c62f3a; --bad-soft: #fde8ea;
  --info: #0b6fa4; --info-soft: #e1f2fb;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --side: 236px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1420; --panel: #171e2d; --panel-2: #1c2436; --line: #2a3448; --text: #e6e9f2; --muted: #95a0b8;
  --brand: #6e86ff; --brand-2: #8fa0ff; --brand-soft: #222c4f;
  --ok: #3fcf8e; --ok-soft: #12352a; --warn: #f2b14a; --warn-soft: #3a2d12; --bad: #ff6b76; --bad-soft: #3d1a1f;
  --info: #5bc0f0; --info-soft: #11303f;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
img { max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--side); background: var(--panel); border-right: 1px solid var(--line); position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 40; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 17px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), #7b5cff); color: #fff; display: grid; place-items: center; font-weight: 800; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.nav { padding: 6px 10px; overflow-y: auto; flex: 1; }
.nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.nav .count.info { background: var(--brand); }
.side-foot { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.main { margin-left: var(--side); flex: 1; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; align-items: center; gap: 12px; }
.topbar .title { font-weight: 650; font-size: 16px; }
.content { padding: 22px 24px 60px; max-width: 1500px; }
.menu-btn { display: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 14px; }
  .content { padding: 16px 14px 70px; }
}

/* ---------- Components ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-b { padding: 16px; }
.page-h { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-h .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { padding: 7px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn.on { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); position: relative; }

input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
textarea { resize: vertical; min-height: 64px; }
input[type=checkbox] { width: auto; }
label.f { display: block; }
label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label.f > span b { color: var(--bad); }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .spanall { grid-column: 1 / -1; }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2, .span3 { grid-column: auto; } }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search input { padding-left: 32px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .search { flex: 1; min-width: 200px; }
.toolbar select, .toolbar input[type=date], .toolbar input[type=month] { width: auto; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th, .t td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.t th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; background: var(--panel-2); position: sticky; top: 0; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: var(--panel-2); }
.t tr.click { cursor: pointer; }
.t td.num, .t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.t tfoot td { font-weight: 700; background: var(--panel-2); }
.thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: var(--panel-2); border: 1px solid var(--line); flex: none; display: block; }
.thumb.lg { width: 96px; height: 96px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.link { cursor: pointer; }
.kpi.link:hover { border-color: var(--brand); }
.kpi .v.bad { color: var(--bad); } .kpi .v.warn { color: var(--warn); } .kpi .v.ok { color: var(--ok); }

/* Stock grid */
.stock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.sitem { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; cursor: pointer; transition: border-color .15s, transform .15s; }
.sitem:hover { border-color: var(--brand); transform: translateY(-1px); }
.sitem .ph { aspect-ratio: 4/3; background: var(--panel-2); position: relative; }
.sitem .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sitem .ph .badge { position: absolute; top: 8px; left: 8px; }
.sitem .bd { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sitem .nm { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sitem .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.sitem .qty { display: flex; align-items: baseline; justify-content: space-between; margin-top: auto; padding-top: 6px; }
.sitem .qty b { font-size: 20px; font-variant-numeric: tabular-nums; }
.sitem.out .qty b { color: var(--bad); } .sitem.low .qty b { color: var(--warn); }
.ph-empty { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); }
.ph-empty svg { width: 36px; height: 36px; opacity: .4; }

/* Consume */
.consume { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .consume { grid-template-columns: 1fr; } }
.pick-list { max-height: 560px; overflow-y: auto; }
.pick { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick:hover { background: var(--panel-2); }
.pick.disabled { opacity: .5; cursor: not-allowed; }
.pick .info { flex: 1; min-width: 0; }
.pick .info .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-line { display: grid; grid-template-columns: 42px minmax(0,1fr) 78px 92px 84px 28px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.cart-line input { padding: 6px 8px; }
@media (max-width: 560px) { .cart-line { grid-template-columns: 42px minmax(0,1fr) 70px 28px; } .cart-line .cl-price, .cart-line .cl-total { display: none; } }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); padding-top: 8px; }
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 20; max-height: 260px; overflow-y: auto; }
.ac-list div { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.ac-list div:hover { background: var(--panel-2); }

/* Delivery cards */
.dcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.dcard { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.dcard.urgent { border-left: 4px solid var(--bad); }
.dcard .addr { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.dcard .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10,14,25,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 14px; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.3); border: 1px solid var(--line); }
.modal.lg { max-width: 880px; } .modal.xl { max-width: 1100px; }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-h h2 { flex: 1; }
.modal-b { padding: 18px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* Toast */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--panel); padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 360px; animation: tin .2s; }
.toast.bad { background: var(--bad); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* Timeline */
.tl { list-style: none; padding: 0; margin: 0; }
.tl li { position: relative; padding: 0 0 12px 20px; border-left: 2px solid var(--line); margin-left: 6px; }
.tl li::before { content: ''; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.tl li:last-child { border-color: transparent; }

/* Chart */
.chart { width: 100%; height: 170px; }
.chart rect.b { fill: var(--brand); }
.chart rect.b:hover { fill: var(--brand-2); }
.chart text { fill: var(--muted); font-size: 10px; }
.chart line { stroke: var(--line); }

.photo-drop { border: 2px dashed var(--line); border-radius: 10px; aspect-ratio: 1; display: grid; place-items: center; text-align: center; cursor: pointer; overflow: hidden; background: var(--panel-2); position: relative; }
.photo-drop img { width: 100%; height: 100%; object-fit: cover; }
.photo-drop.drag { border-color: var(--brand); }
.photo-drop .hint { padding: 12px; color: var(--muted); font-size: 12.5px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1000px 500px at 10% -10%, var(--brand-soft), transparent), var(--bg); }
.login { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 18px; font-size: 22px; }
.login .brand .logo { width: 44px; height: 44px; font-size: 20px; }
.err { background: var(--bad-soft); color: var(--bad); padding: 8px 10px; border-radius: 8px; font-size: 13px; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); display: flex; gap: 8px; align-items: center; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* ---------- Print ---------- */
#print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; inset: 0; padding: 18px; color: #000; background: #fff; font-size: 12px; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border: 1px solid #999; padding: 5px 7px; text-align: left; }
  #print-area .num { text-align: right; }
  #print-area h1 { font-size: 20px; } #print-area h2 { font-size: 15px; margin: 14px 0 6px; }
  .modal-bg, #toasts { display: none !important; }
}
a[role=button] { cursor: pointer; }

/* Call buttons (open the phone dialer on mobile) */
.btn.call { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.call:hover { filter: brightness(1.08); background: var(--ok); }
.btn.call.big { width: 100%; padding: 12px 14px; font-size: 16px; font-weight: 700; border-radius: 10px; }
.btn.call.big svg { width: 20px; height: 20px; }
.call-row { display: flex; gap: 8px; }
.call-row .btn.call.big + .btn.call.big { flex: 0 0 40%; background: var(--panel); color: var(--ok); border-color: var(--ok); }
.area-badge { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

/* Live map */
.map-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
#map { height: min(72vh, 680px); width: 100%; }
#mp-list { max-height: min(72vh, 680px); overflow-y: auto; }
@media (max-width: 1000px) { .map-wrap { grid-template-columns: 1fr; } #map { height: 55vh; } #mp-list { max-height: none; } }
.drv-pin { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.drv-pin.on { background: #138a52; } .drv-pin.stale { background: #8a93a6; }
button.badge { font: inherit; font-size: 11.5px; font-weight: 600; }
