:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --border: #deded8;
  --border-strong: #c8c8c0;
  --text: #1c1c1a;
  --text-2: #5d5d57;
  --text-3: #8a8a83;
  --accent: #1b5fd0;
  --accent-soft: #e5eefc;
  --error: #b42318;
  --error-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff5d6;
  --info: #3b5b7a;
  --info-soft: #e8eef4;
  --ok: #1a7f37;
  --heat-0: #f0f0ec;
  --heat-1: #d6e4fb;
  --heat-2: #9fc0f3;
  --heat-3: #5b93e6;
  --heat-4: #1b5fd0;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1c1c1b;
    --surface-2: #252523;
    --border: #33332f;
    --border-strong: #46463f;
    --text: #ececE8;
    --text-2: #a9a9a2;
    --text-3: #7c7c75;
    --accent: #6fa3ff;
    --accent-soft: #1d2b45;
    --error: #ff7b72;
    --error-soft: #3a1d1b;
    --warn: #e3b341;
    --warn-soft: #3a2f12;
    --info: #9cb8d6;
    --info-soft: #1f2a36;
    --ok: #56d364;
    --heat-0: #252523;
    --heat-1: #1d2b45;
    --heat-2: #24427a;
    --heat-3: #3667c0;
    --heat-4: #6fa3ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413;
  --surface: #1c1c1b;
  --surface-2: #252523;
  --border: #33332f;
  --border-strong: #46463f;
  --text: #ececE8;
  --text-2: #a9a9a2;
  --text-3: #7c7c75;
  --accent: #6fa3ff;
  --accent-soft: #1d2b45;
  --error: #ff7b72;
  --error-soft: #3a1d1b;
  --warn: #e3b341;
  --warn-soft: #3a2f12;
  --info: #9cb8d6;
  --info-soft: #1f2a36;
  --ok: #56d364;
  --heat-0: #252523;
  --heat-1: #1d2b45;
  --heat-2: #24427a;
  --heat-3: #3667c0;
  --heat-4: #6fa3ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
button, input, select { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 20px;
  padding: 0 16px; height: 48px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { color: var(--text); font-weight: 600; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-block; padding: 1px 6px; margin-right: 2px; border-radius: 4px;
  background: var(--text); color: var(--surface); font-family: var(--mono); font-size: 12px;
}
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav a {
  padding: 6px 10px; border-radius: var(--radius); color: var(--text-2); white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.pill {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
  font-size: 11px; line-height: 16px; text-align: center;
  background: var(--error-soft); color: var(--error);
}
.pill:empty { display: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.date-pick { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
.date-pick input {
  padding: 3px 6px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface);
}
.dataset { color: var(--text-3); font-size: 12px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-ghost, .btn {
  padding: 4px 10px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface);
}
.btn-ghost:hover, .btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- landing ---------- */
.landing { max-width: 760px; margin: 48px auto; padding: 0 16px; }
.landing h1 { font-size: 28px; margin-bottom: 8px; }
.lead { color: var(--text-2); font-size: 15px; margin: 0 0 24px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 40px 16px; border: 2px dashed var(--border-strong); border-radius: 10px;
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.drop strong { font-size: 16px; }
.drop span { color: var(--text-2); }
.samples, .note { margin-top: 28px; }
.samples h2, .note h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: 8px; }
.sample-list { display: flex; flex-wrap: wrap; gap: 8px; }
.note ul { margin: 0; padding-left: 18px; color: var(--text-2); }
.note li { margin-bottom: 4px; }
.progress { display: flex; align-items: center; gap: 10px; margin-top: 20px; color: var(--text-2); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error {
  margin-top: 20px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--error-soft); color: var(--error);
}

/* ---------- views ---------- */
#view { padding: 20px 16px 48px; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--text-2); }
.crumbs { color: var(--text-3); font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--text-2); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; min-width: 0;
}
.card > h2, .card > h3 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid-side { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 900px) {
  .grid-2, .grid-side { grid-template-columns: minmax(0, 1fr); }
  .topbar { gap: 10px; }
  .dataset { display: none; }
}
@media (max-width: 640px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 16px; }
  .nav { order: 3; width: 100%; }
  .topbar-right { margin-left: auto; }
}

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.stat .label { color: var(--text-3); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--text-2); font-size: 12px; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.kv dt { color: var(--text-3); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table-wrap.tall { max-height: 70vh; }
.table-wrap.mid { max-height: 460px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 5px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2);
  font-weight: 600; color: var(--text-2); font-size: 12px;
}
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tr.sel td { background: var(--accent-soft) !important; }
table.data tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.mono { font-family: var(--mono); font-size: 12px; }
table.data td.muted { color: var(--text-3); }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .desc-dot { color: var(--text-3); font-weight: 400; margin-left: 3px; cursor: help; }
table.data td.wrap { white-space: normal; }

/* timetable grid */
table.tt th.stopcol, table.tt td.stopcol {
  position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 220px; max-width: 280px;
  overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--border);
}
table.tt th.stopcol { z-index: 3; background: var(--surface-2); }
table.tt td { font-family: var(--mono); font-size: 12px; text-align: center; padding: 4px 7px; }
table.tt td.stopcol { font-family: var(--sans); text-align: left; font-size: 13px; }
table.tt th.jcol { text-align: center; font-family: var(--mono); font-weight: 500; font-size: 11px; }
table.tt th.jcol a { color: var(--text-2); }
table.tt td.timing { font-weight: 600; }
table.tt td.empty { color: var(--text-3); }
table.tt tr.timingrow td.stopcol { font-weight: 600; }

/* ---------- badges ---------- */
.line-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 22px; padding: 0 6px; border-radius: 4px;
  font-weight: 700; font-size: 12px; line-height: 1; color: #fff; white-space: nowrap;
}
.line-badge.lg { min-width: 44px; height: 32px; font-size: 16px; border-radius: 6px; }
a.line-badge:hover { text-decoration: none; filter: brightness(1.1); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.tag.error { background: var(--error-soft); color: var(--error); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.tag.ok { color: var(--ok); }

/* ---------- controls ---------- */
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.controls label { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
input.search, select.sel {
  padding: 5px 9px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
}
input.search { min-width: 240px; }
@media (max-width: 640px) { input.search { min-width: 0; width: 100%; } }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  padding: 3px 10px; border-radius: 14px; border: 1px solid var(--border-strong); background: var(--surface);
  cursor: pointer; font-size: 13px;
}
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.pager { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--text-2); font-size: 13px; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.empty-note { color: var(--text-3); padding: 16px 0; }

/* ---------- map ---------- */
.map { height: 420px; border-radius: var(--radius); border: 1px solid var(--border); z-index: 0; }
.map.tall { height: calc(100vh - 170px); min-height: 400px; }
.leaflet-container { background: var(--surface-2); font: inherit; }
.base-tiles { filter: saturate(0.35) brightness(1.04); }
.dark-tiles .base-tiles { filter: invert(1) hue-rotate(180deg) saturate(0.3) brightness(0.85) contrast(0.9); }
.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }

/* ---------- calendar ---------- */
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.month h3 { font-size: 13px; margin-bottom: 6px; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.month-grid .dow { font-size: 10px; color: var(--text-3); text-align: center; }
.day {
  aspect-ratio: 1; border-radius: 4px; font-size: 11px; display: flex; align-items: center; justify-content: center;
  background: var(--heat-0); color: var(--text-2); cursor: pointer; border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}
.day.none { cursor: default; opacity: .45; }
.day.h1 { background: var(--heat-1); }
.day.h2 { background: var(--heat-2); color: var(--text); }
.day.h3 { background: var(--heat-3); color: #fff; }
.day.h4 { background: var(--heat-4); color: #fff; }
.day.sel { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.legend { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-3); }
.legend .day { width: 14px; height: 14px; aspect-ratio: auto; cursor: default; }

/* ---------- issues ---------- */
.issue { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 8px; }
.issue summary { padding: 9px 12px; cursor: pointer; display: flex; gap: 10px; align-items: center; list-style: none; }
.issue summary::-webkit-details-marker { display: none; }
.issue summary .count { margin-left: auto; color: var(--text-3); font-variant-numeric: tabular-nums; }
.issue .examples { padding: 0 12px 10px 12px; font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.issue .examples div { padding: 1px 0; }

/* table list */
.table-list { display: flex; flex-direction: column; gap: 2px; }
.table-list a { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; border-radius: var(--radius); color: var(--text); }
.table-list a:hover { background: var(--surface-2); text-decoration: none; }
.table-list a.active { background: var(--accent-soft); color: var(--accent); }
.table-list .n { color: var(--text-3); font-variant-numeric: tabular-nums; font-size: 12px; }
.tables-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; }
@media (max-width: 760px) { .tables-layout { grid-template-columns: minmax(0, 1fr); } }

.tooltip {
  position: fixed; z-index: 2000; max-width: 320px; padding: 6px 9px; border-radius: 5px;
  background: var(--text); color: var(--surface); font-size: 12px; pointer-events: none;
}
.dir-arrow { color: var(--text-3); }
.sep { color: var(--text-3); margin: 0 4px; }
.callout {
  margin: -8px 0 24px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--text); border-left: 3px solid var(--accent);
}
