/* LT Viewer — flat theme (light / dark follows the system). */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e5e9f2;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --sidebar: #111827;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1f2937;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, Consolas, monospace;
  /* Chart palette: completed, in progress, assigned, searching, scheduled, no driver, cancelled, other */
  --c0: #22c55e; --c1: #8b5cf6; --c2: #3b82f6; --c3: #f59e0b; --c4: #06b6d4; --c5: #ef4444; --c6: #94a3b8; --c7: #ec4899;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #0f172a;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #1f2a3c;
    --primary-soft: #1e1b4b;
    --sidebar: #070b14;
    --sidebar-active: #172033;
    --success-soft: #052e16;
    --danger-soft: #3b0a0a;
    --warning-soft: #3a2504;
    --info-soft: #0b2350;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); font-weight: 400; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.inline { display: inline; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 15px; padding: 4px 8px 22px; }
.logo:hover { text-decoration: none; }
.logo-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 13px; letter-spacing: 0.04em; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--sidebar-text); font-weight: 500; }
.nav-item:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #334155; color: #fff; display: grid; place-items: center; font-weight: 700; }
.who { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1; }
.who b { color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.who span { font-size: 11px; color: #94a3b8; }
.icon-btn { background: transparent; border: 0; color: inherit; padding: 6px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(127, 127, 127, 0.18); }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; height: 60px; padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.menu-btn { display: none; color: var(--text); }
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; color: var(--muted); }
.crumbs .current { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.crumbs .sep { opacity: 0.5; }
.page { padding: 26px 28px; width: 100%; max-width: 1480px; }
.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 18px; margin-top: auto; }

/* ---------- Page header & controls ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin-top: 4px; }
.range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.segmented a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; font-size: 13px; }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.on { background: var(--primary); color: #fff; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin-bottom: 18px; }
.kpi { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi div { display: flex; flex-direction: column; min-width: 0; }
.kpi span { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi b { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; }
.kpi small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-icon { width: 44px; height: 44px; border-radius: 12px; display: grid !important; place-items: center; font-size: 18px !important; font-weight: 700 !important; flex-shrink: 0; }
.tone-indigo { background: #eef2ff; color: #4f46e5 !important; }
.tone-blue { background: #dbeafe; color: #2563eb !important; }
.tone-green { background: #dcfce7; color: #16a34a !important; }
.tone-red { background: #fee2e2; color: #dc2626 !important; }
.tone-teal { background: #ccfbf1; color: #0d9488 !important; }
.tone-amber { background: #fef3c7; color: #d97706 !important; }
.tone-violet { background: #ede9fe; color: #7c3aed !important; }
.tone-slate { background: #e2e8f0; color: #475569 !important; }

/* ---------- Panels & grids ---------- */
.panel, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-2 > .panel, .grid-3 > .panel { margin-bottom: 0; }
.grid-2, .grid-3 { margin-bottom: 18px; }
.span-2:only-child { grid-column: 1 / -1; }
.link { font-weight: 500; font-size: 13px; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .axis.strong { fill: var(--text); font-weight: 500; }
.c-0 { fill: var(--c0); stroke: var(--c0); background: var(--c0); }
.c-1 { fill: var(--c1); stroke: var(--c1); background: var(--c1); }
.c-2 { fill: var(--c2); stroke: var(--c2); background: var(--c2); }
.c-3 { fill: var(--c3); stroke: var(--c3); background: var(--c3); }
.c-4 { fill: var(--c4); stroke: var(--c4); background: var(--c4); }
.c-5 { fill: var(--c5); stroke: var(--c5); background: var(--c5); }
.c-6 { fill: var(--c6); stroke: var(--c6); background: var(--c6); }
.c-7 { fill: var(--c7); stroke: var(--c7); background: var(--c7); }
rect.c-0, rect.c-1, rect.c-2, rect.c-3, rect.c-4, rect.c-5, rect.c-6, rect.c-7 { stroke: none; }
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut { width: 170px; height: 170px; flex-shrink: 0; }
.donut .arc { fill: none; stroke-width: 26; }
.donut .arc.empty { stroke: var(--border); }
.donut-total { fill: var(--text); font-size: 30px; font-weight: 700; }
.donut-label { fill: var(--muted); font-size: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; color: var(--muted); font-size: 12px; text-transform: capitalize; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.legend-list { list-style: none; padding: 0; margin: 0; flex: 1; min-width: 150px; display: grid; gap: 8px; }
.legend-list li { display: flex; align-items: center; gap: 8px; text-transform: capitalize; }
.legend-list li span { flex: 1; color: var(--muted); }

/* ---------- Lists, pills, tables ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li .truncate { flex: 1; }
.pill, .chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.pill.green { background: var(--success-soft); color: var(--success); }
.pill.red { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warning-soft); color: var(--warning); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
th a { color: inherit; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.truncate-cell, table.docs td { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }

/* ---------- Forms & buttons ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%; transition: border-color 0.15s, box-shadow 0.15s; }
input[type="date"] { width: auto; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full, label.wide { grid-column: 1 / -1; }
.form-actions, .actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; grid-column: 1 / -1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select { width: auto; }
form.query { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.filter-box { max-width: 260px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 9px 16px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 600; font-size: 13px; transition: background 0.15s, border-color 0.15s; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.small { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.success { background: var(--success-soft); color: var(--success); }

/* ---------- Existing database pages ---------- */
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat span { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.stat b { font-size: 19px; font-weight: 700; word-break: break-word; }
.tabs { display: flex; gap: 6px; margin-bottom: 18px; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; width: fit-content; max-width: 100%; }
.tabs a { padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--primary); color: #fff; }
pre.json { margin: 0; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; max-height: 75vh; overflow: auto; background: var(--surface-2); border-radius: 10px; padding: 14px; }
details.result summary { cursor: pointer; margin-bottom: 8px; }
.bar { display: inline-block; width: 80px; height: 6px; background: var(--border); border-radius: 3px; vertical-align: middle; overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--primary); }

/* ---------- Sign in ---------- */
body.auth, body.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #eef2ff 0%, #f4f6fb 60%); }
@media (prefers-color-scheme: dark) { body.auth, body.center { background: var(--bg); } }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 30px; display: grid; gap: 14px; }
.auth-card .logo { color: var(--text); padding: 0 0 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; z-index: 20; transition: left 0.2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: grid; }
  .page { padding: 18px 16px; }
  .topbar { padding: 0 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
