:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #f0efed;
  --border: #e2e0dc;
  --text: #1c1b1a;
  --muted: #6b6864;
  --accent: #e2001a;
  --ok: #1f8a4c;
  --warn: #c27c00;
  --bad: #c8102e;
  --early: #2563eb;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.06);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1c1c1c;
    --surface-2: #262626;
    --border: #333;
    --text: #ececec;
    --muted: #9b9b9b;
    --ok: #3fbf74;
    --warn: #f0a92b;
    --bad: #ff5a6e;
    --early: #6ea2ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button { font: inherit; color: inherit; }

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  background: var(--accent);
  color: #fff;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.04em;
}
.brand-title { font-size: 17px; }

.status { display: flex; align-items: center; gap: 10px; min-width: 0; }
.muted { color: var(--muted); }
#updated-at { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.demo { background: #fff4d6; border-color: #f0d68a; color: #7a5600; }
@media (prefers-color-scheme: dark) { .badge.demo { background: #3a2f10; border-color: #6b5520; color: #f6d47a; } }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.error { background: var(--bad); }

.icon-button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 18px;
}
.icon-button:hover { background: var(--surface-2); }

.layout {
  height: calc(100% - 56px);
  display: grid;
  grid-template-columns: 400px 1fr;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
}
.tabs button {
  flex: 1;
  padding: 12px 4px 10px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.count { font-weight: 500; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.banner {
  margin: 10px 12px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: var(--bad);
  font-size: 13px;
}

.filters { padding: 10px 12px 6px; display: grid; gap: 8px; }
#search {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chip {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 2px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.chip[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 1px; }

.panel-body { flex: 1; overflow-y: auto; min-height: 0; }
.tab-content { padding: 4px 0 16px; }

.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

.line-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 22px;
  padding: 0 6px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 12px;
  flex: none;
}

.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  width: 100%;
  text-align: left;
}
.row:hover, .row.selected { background: var(--surface-2); }
.row-main { min-width: 0; }
.row-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.delay {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.delay.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.delay.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.delay.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.delay.early { color: var(--early); background: color-mix(in srgb, var(--early) 12%, transparent); }
.delay.none { color: var(--muted); background: var(--surface-2); }

.section-title {
  margin: 12px 14px 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

table.summary { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.summary th, table.summary td { padding: 8px 14px; text-align: right; border-bottom: 1px solid var(--border); }
table.summary th:first-child, table.summary td:first-child { text-align: left; }
table.summary th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.summary tbody tr { cursor: pointer; }
table.summary tbody tr:hover { background: var(--surface-2); }

.alert-card {
  margin: 10px 12px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 4px solid var(--warn);
  background: var(--surface);
}
.alert-card.SEVERE { border-left-color: var(--bad); }
.alert-card.INFO { border-left-color: var(--early); }
.alert-card h3 { margin: 6px 0 4px; font-size: 15px; }
.alert-card p { margin: 6px 0 0; white-space: pre-line; }
.alert-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.tag { background: var(--surface-2); border-radius: 5px; padding: 1px 6px; }

.detail-head {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1;
}
.back { border: 0; background: none; cursor: pointer; font-size: 20px; padding: 0 4px; }
.detail-title { font-weight: 700; font-size: 16px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; padding: 12px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-all; }

.timeline { list-style: none; margin: 0; padding: 4px 14px 8px; }
.timeline li {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px 0;
  position: relative;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--line, var(--border));
}
.timeline li:first-child::before { top: 50%; }
.timeline li:last-child::before { bottom: 50%; }
.timeline .node {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--line, var(--muted));
  background: var(--surface);
  position: relative;
}
.timeline .skipped { color: var(--muted); text-decoration: line-through; }
.timeline .time { text-align: right; font-variant-numeric: tabular-nums; }
.timeline .time small { display: block; }

details.raw { margin: 8px 14px; }
details.raw summary { cursor: pointer; color: var(--muted); }
pre {
  background: var(--surface-2);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12px;
}

.feed-card { margin: 10px 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.feed-card h3 { margin: 0 0 6px; font-size: 14px; }
.feed-card a { color: var(--early); }
.feed-card .links { display: flex; gap: 12px; margin-top: 6px; }
.note { margin: 10px 14px; color: var(--muted); font-size: 13px; }
.note code { font-size: 12px; }

.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.vehicle-marker { background: none; border: 0; }
.vehicle-marker .pin {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 700 11px/1 system-ui, sans-serif;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.35);
}
.vehicle-marker .arrow {
  position: absolute;
  inset: -9px;
  pointer-events: none;
}
.vehicle-marker .arrow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom: 7px solid var(--c);
  border-top: 0;
}
.vehicle-marker.selected .pin { outline: 3px solid var(--text); outline-offset: 2px; }
.vehicle-marker.dim { opacity: 0.25; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 45vh 1fr; }
  .map-wrap { grid-row: 1; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--border); }
  .brand-title { display: none; }
  .tabs button { font-size: 13px; }
}
