/* NSofts SFA design system. Tokens first; components below use only tokens so dark mode is free. */
:root {
  --bg: #f4f7fa; --surface: #ffffff; --surface-2: #f8fafc; --line: #e3e9f0; --line-strong: #cfd8e3;
  --ink: #0f1b2d; --ink-2: #44546a; --ink-3: #7a8aa0;
  --brand: #0e7490; --brand-ink: #ffffff; --brand-soft: #e0f2f7; --brand-deep: #0b5568;
  --accent: #f59e0b; --good: #059669; --good-soft: #dcf5ea; --warn: #d97706; --warn-soft: #fdf0d5;
  --bad: #dc2626; --bad-soft: #fde4e4; --info: #2563eb; --info-soft: #e1ebfd;
  --side: #0b1f33; --side-ink: #b7c6d9; --side-active: #163a57;
  --c1: #0e7490; --c2: #f59e0b; --c3: #6366f1; --c4: #10b981; --c5: #ec4899; --c6: #8b5cf6; --c7: #64748b;
  --shadow: 0 1px 2px rgba(15, 27, 45, .05), 0 4px 14px rgba(15, 27, 45, .05);
  --radius: 14px; --radius-sm: 9px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1420; --surface: #101d2c; --surface-2: #0d1926; --line: #1f3145; --line-strong: #2b4360;
    --ink: #e8eef6; --ink-2: #a9b8cb; --ink-3: #7188a3;
    --brand: #22b8d6; --brand-soft: #0f2f3b; --brand-deep: #7fdcf0;
    --good: #34d399; --good-soft: #0f3326; --warn: #fbbf24; --warn-soft: #3a2c0c; --bad: #f87171; --bad-soft: #3d1717;
    --info: #60a5fa; --info-soft: #14284a; --side: #07121d; --side-active: #123047;
    --c1: #22b8d6; --c2: #fbbf24; --c3: #818cf8; --c4: #34d399; --c5: #f472b6; --c6: #a78bfa; --c7: #94a3b8;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --bg: #0a1420; --surface: #101d2c; --surface-2: #0d1926; --line: #1f3145; --line-strong: #2b4360;
  --ink: #e8eef6; --ink-2: #a9b8cb; --ink-3: #7188a3;
  --brand: #22b8d6; --brand-soft: #0f2f3b; --brand-deep: #7fdcf0;
  --good: #34d399; --good-soft: #0f3326; --warn: #fbbf24; --warn-soft: #3a2c0c; --bad: #f87171; --bad-soft: #3d1717;
  --info: #60a5fa; --info-soft: #14284a; --side: #07121d; --side-active: #123047;
  --c1: #22b8d6; --c2: #fbbf24; --c3: #818cf8; --c4: #34d399; --c5: #f472b6; --c6: #a78bfa; --c7: #94a3b8;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; letter-spacing: -.01em; }
h2 { font-size: 15px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--ink-3); } .sub { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; } .center { text-align: center; }
.hide { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spread { justify-content: space-between; }
.gap-lg { gap: 18px; }
.stack > * + * { margin-top: 12px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------------------------------------------------------------- app shell */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.brand img { width: 34px; height: 34px; border-radius: 9px; background: #fff; padding: 3px; }
.brand b { display: block; font-size: 15px; letter-spacing: .01em; } .brand span { font-size: 11px; color: var(--side-ink); }
.nav-group { margin-top: 14px; padding: 0 10px; font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: #6f86a1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; margin: 2px 0; border-radius: 9px; color: var(--side-ink); font-weight: 500; }
.nav a:hover { background: #10293f; color: #fff; text-decoration: none; }
.nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; padding: 12px 8px 0; font-size: 12px; border-top: 1px solid #1a3550; }
.side-foot .who { color: #fff; font-weight: 600; } .side-foot button { margin-top: 8px; }
.main { min-width: 0; padding: 22px 26px 60px; max-width: 1500px; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.ribbon { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); border-radius: 999px; padding: 3px 12px; font-size: 12px; font-weight: 600; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; left: 0; top: 0; width: 264px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 14px; }
  .main { padding: 16px 14px 60px; }
}

/* ------------------------------------------------------------------- basics */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card h2 { margin-bottom: 2px; } .card .hint { color: var(--ink-3); font-size: 12px; margin-bottom: 10px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.grid { display: grid; gap: 16px; }
.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)); } .g21 { grid-template-columns: 2fr 1fr; } .g12 { grid-template-columns: 1fr 2fr; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .kpis { grid-template-columns: 1fr; } }
@media (max-width: 1100px) { .g3, .g4, .g21, .g12 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .g2, .g3, .g4, .g21, .g12 { grid-template-columns: 1fr; } }
.mt { margin-top: 16px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; min-height: 38px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 6px; border-radius: 8px; color: inherit; }
.icon-btn:hover { background: var(--surface-2); }

label.f { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 11px; min-height: 38px; }
.input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.field { min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.b-good { background: var(--good-soft); color: var(--good); } .b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); } .b-info { background: var(--info-soft); color: var(--info); }
.b-mute { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); } .b-brand { background: var(--brand-soft); color: var(--brand); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; box-shadow: var(--shadow); }
.filters .field { width: 158px; } .filters .field.sm { width: 132px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--ink-3); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

/* ------------------------------------------------------------------ tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; user-select: none; }
.tbl th.sortable { cursor: pointer; } .tbl th.sortable:hover { color: var(--brand); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tr.click { cursor: pointer; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 10px; color: var(--ink-2); font-size: 12.5px; }

/* --------------------------------------------------------------------- KPIs */
.kpi { position: relative; padding: 14px 16px 12px; overflow: hidden; cursor: pointer; transition: transform .12s, box-shadow .12s; }
.kpi:hover { transform: translateY(-2px); }
.kpi .lab { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.kpi .val { font-size: 26px; font-weight: 750; letter-spacing: -.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; font-weight: 700; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--ink-3); }
.kpi svg.spark { position: absolute; right: 10px; bottom: 8px; opacity: .9; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kc, var(--brand)); }

.attn { display: flex; gap: 10px; flex-wrap: wrap; }
.attn button { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; box-shadow: var(--shadow); }
.attn button:hover { border-color: var(--brand); }
.attn b { font-size: 20px; font-variant-numeric: tabular-nums; } .attn small { display: block; color: var(--ink-2); font-size: 12px; line-height: 1.25; }
.attn .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ------------------------------------------------------------------- charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-line { stroke: var(--line-strong); }
.chart .hit { cursor: pointer; }
.chart .bar { transition: opacity .12s; } .chart .bar:hover { opacity: .8; }
.tip { position: fixed; z-index: 200; pointer-events: none; background: #0b1f33; color: #fff; padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4; box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 260px; }
.tip b { color: #ffd580; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(96px, 30%) 1fr auto; align-items: center; gap: 10px; padding: 5px 0; cursor: pointer; border-radius: 8px; }
.hbar:hover { background: var(--surface-2); }
.hbar .nm { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .track { position: relative; height: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: visible; }
.hbar .fill { height: 100%; border-radius: 999px; background: var(--brand); }
.hbar .mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .55; }
.hbar .v { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; min-width: 70px; }
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center; }
.heat td { text-align: center; font-size: 12px; min-width: 64px; }

/* ------------------------------------------------------ drawer / modal / toast */
.scrim { position: fixed; inset: 0; background: rgba(8, 18, 30, .5); z-index: 90; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--bg); z-index: 91; display: flex; flex-direction: column; box-shadow: -10px 0 40px rgba(0,0,0,.25); animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.drawer-body { padding: 16px 20px 40px; overflow-y: auto; flex: 1; }
.modal { position: fixed; z-index: 95; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 16px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { width: min(820px, calc(100vw - 24px)); }
.modal h2 { font-size: 17px; margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
#toasts { position: fixed; z-index: 300; right: 16px; bottom: 16px; display: grid; gap: 8px; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 340px; }
.toast.err { background: var(--bad); color: #fff; } .toast.ok { background: var(--good); color: #fff; }

.empty { text-align: center; color: var(--ink-3); padding: 28px 10px; }
.skel { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: 8px; min-height: 16px; }
@keyframes sh { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.timeline { position: relative; margin-left: 8px; padding-left: 18px; border-left: 2px solid var(--line-strong); }
.timeline .ev { position: relative; padding: 0 0 14px; }
.timeline .ev::before { content: ""; position: absolute; left: -25px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }
.timeline .ev.bad::before { background: var(--bad); } .timeline .ev.mute::before { background: var(--ink-3); } .timeline .ev.good::before { background: var(--good); }
.map-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; border: 1px solid var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--good); }
@media print { .sidebar, .topbar, .filters, .btn { display: none !important; } .app { display: block; } }

/* ------------------------------------------------------------ rep route map (Leaflet) */
.rm-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.rm-bar input[type=range] { flex: 1; accent-color: var(--brand); min-width: 80px; }
.rm-clock { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 48px; text-align: right; }
.rm-map { height: 430px; border-radius: 12px; border: 1px solid var(--line); overflow: hidden; z-index: 0; }
.rm-pin { width: 34px; height: 34px; border-radius: 50% 50% 50% 8%; transform: rotate(-45deg); display: flex; align-items: center; justify-content: center; border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0,0,0,.35); background: #0e7490; }
.rm-pin span { transform: rotate(45deg); color: #fff; font: 700 13px var(--font); }
.rm-pin.order { background: #059669; } .rm-pin.off { background: #dc2626; } .rm-pin.visit { background: #0e7490; }
.rm-arrow { width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 14px solid #1B3A6B; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.rm-leg { background: rgba(255,255,255,.92); color: #1B3A6B; border: 1px solid #cfd8e3; border-radius: 999px; padding: 1px 8px; font: 600 11px var(--font); white-space: nowrap; text-align: center; width: max-content; margin: 0 auto; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.timeline .ev.active { background: var(--brand-soft); border-radius: 8px; margin-left: -6px; padding-left: 6px; }
.timeline .ev[data-i] { cursor: pointer; }
.rm-dark-tiles { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }

/* iOS Safari zooms the whole page when a field under 16px gets focus, and leaves it zoomed and cut off. */
@media (max-width: 900px) { input, select, textarea, .input { font-size: 16px; } }
button, .btn, .chip, .tabs button { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
