:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #dce8ff;
  background: #07101f;
  --panel: rgba(13, 24, 43, 0.92);
  --panel-2: rgba(18, 32, 56, 0.92);
  --line: rgba(124, 160, 210, 0.22);
  --muted: #8da1bf;
  --accent: #54d6ff;
  --good: #3ee58f;
  --warn: #f5b544;
  --bad: #ff6d7a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(36, 84, 214, .25), transparent 36rem),
    radial-gradient(circle at 80% 20%, rgba(35, 177, 75, .12), transparent 30rem),
    linear-gradient(180deg, #07101f, #0a1220 42%, #070b13);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), rgba(0,0,0,.15));
}
header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 31, .82);
  backdrop-filter: blur(14px);
}
h1, h2, h3, p { margin: 0; }
h1 { letter-spacing: .02em; }
header p, .section-subtitle { margin-top: .25rem; color: var(--muted); }
main { position: relative; display: grid; gap: 1rem; padding: 1rem; }
.panel, .tab, .tabs {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.03);
}
.panel { padding: 1rem; }
.grid { display: grid; gap: .75rem; margin-top: .75rem; }
.grid.five { grid-template-columns: 1.15fr 1fr 1fr 1fr 1.35fr; }
.grid.two { grid-template-columns: 1fr 1fr; }
label { display: grid; gap: .35rem; font-weight: 700; font-size: .9rem; color: #cfe0fb; }
input, select {
  width: 100%;
  padding: .68rem .75rem;
  border: 1px solid rgba(130, 164, 210, .28);
  border-radius: 12px;
  color: #eaf3ff;
  background: rgba(4, 10, 20, .74);
  font: inherit;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(84,214,255,.12); }
button, #csvLink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  padding: 0 .9rem;
  border: 1px solid rgba(84,214,255,.22);
  border-radius: 12px;
  color: white;
  background: linear-gradient(180deg, #2454d6, #1a3d9a);
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(36,84,214,.18);
}
button:hover, #csvLink:hover { filter: brightness(1.12); }
#csvLink { background: linear-gradient(180deg, #2f8b63, #1f6449); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .9rem; }
.status, .note { color: var(--muted); margin-top: .65rem; }
.note { background: rgba(245,181,68,.10); border: 1px solid rgba(245,181,68,.28); border-radius: 14px; padding: .85rem; }
.ops-panel {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr .75fr 1fr 1fr 1fr;
  gap: .65rem;
  margin-top: .9rem;
  padding: .8rem;
  border: 1px solid rgba(84,214,255,.16);
  border-radius: 16px;
  background: rgba(4,10,20,.38);
}
.check { display: flex; align-items: center; gap: .45rem; line-height: 1.25; }
.check input { width: auto; accent-color: var(--accent); }
.route-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .8rem;
  max-height: 7.8rem;
  overflow: auto;
}
.route-chip {
  min-height: 2rem;
  padding: 0 .65rem;
  border: 1px solid color-mix(in srgb, var(--route-color) 60%, transparent);
  background: linear-gradient(180deg, color-mix(in srgb, var(--route-color) 22%, #07101f), rgba(4,10,20,.68));
  box-shadow: none;
}
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .45rem;
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(14px);
}
.tabs button { background: transparent; color: #b9c7de; box-shadow: none; }
.tabs button.active { color: #05101f; background: linear-gradient(180deg, #54d6ff, #7df2c1); border-color: transparent; }
.tab { display: none; padding: 1rem; }
.tab.active { display: block; }
.story { display: grid; gap: .6rem; margin-bottom: 1rem; }
.story-item {
  padding: .9rem 1rem;
  border-radius: 16px;
  background: linear-gradient(90deg, rgba(84,214,255,.12), rgba(125,242,193,.05));
  border: 1px solid rgba(84,214,255,.18);
  color: #e9f5ff;
  font-size: 1.02rem;
}
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.card, .chart, .route-card, .bus-card, .event, .event-chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03);
}
.card { padding: .95rem; position: relative; overflow: hidden; }
.card::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
}
.card small, .mini-metric small { display: block; color: var(--muted); font-weight: 850; text-transform: uppercase; letter-spacing: .05em; font-size: .72rem; }
.card strong { display: block; margin-top: .25rem; font-size: 1.65rem; color: white; }
.card span, .mini-metric span { display: block; margin-top: .2rem; color: var(--muted); }
.replay-bar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.map-card { overflow: hidden; border-radius: 16px; border: 1px solid var(--line); background: #07101f; }
#map { min-height: 620px; width: 100%; background: #091220; }
.leaflet-container { background: #091220; }
.leaflet-control, .leaflet-popup-content-wrapper, .leaflet-popup-tip { filter: saturate(.8); }
.charts { display: grid; gap: 1rem; margin-top: .75rem; }
.chart { padding: .9rem; }
.bars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; align-items: end; height: 150px; margin-top: .75rem; border-bottom: 1px solid rgba(130,164,210,.22); }
.bar { min-height: 2px; background: linear-gradient(180deg, #54d6ff, #2454d6); border-radius: 5px 5px 0 0; position: relative; }
.bar:hover::after { content: attr(title); position: absolute; bottom: 100%; left: 0; background: #0b1426; color: white; padding: .35rem; border-radius: .4rem; white-space: nowrap; z-index: 4; font-size: .8rem; border: 1px solid var(--line); }
.rank-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .85rem; margin-top: .85rem; }
.route-card, .bus-card { padding: .95rem; position: relative; overflow: hidden; }
.route-card::before, .bus-card::before, .event::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--route-color, var(--accent));
}
.route-card-head, .bus-card-head { display: flex; align-items: center; gap: .8rem; margin-bottom: .8rem; }
.route-card-head h3, .bus-card-head h3 { font-size: 1.15rem; }
.route-card-head p, .bus-card-head p { color: var(--muted); font-size: .9rem; margin-top: .1rem; }
.route-badge {
  display: grid; place-items: center; flex: 0 0 3.1rem; height: 3.1rem; border-radius: 50%;
  color: white; background: var(--route-color); font-weight: 900; box-shadow: 0 0 0 5px color-mix(in srgb, var(--route-color) 18%, transparent);
}
.bus-dot { width: 1rem; height: 1rem; border-radius: 50%; background: var(--route-color); box-shadow: 0 0 0 5px color-mix(in srgb, var(--route-color) 18%, transparent); }
.bus-card-head strong { margin-left: auto; color: #06101f; background: #7df2c1; padding: .25rem .5rem; border-radius: 999px; font-size: .72rem; text-transform: uppercase; }
.status-parked .bus-card-head strong { background: #f5b544; }
.status-stale .bus-card-head strong { background: #8b96a8; color: white; }
.status-mixed .bus-card-head strong { background: #54d6ff; }
.metric-grid.small { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .45rem; }
.mini-metric { padding: .55rem; border-radius: 12px; background: rgba(4,10,20,.42); border: 1px solid rgba(130,164,210,.14); }
.mini-metric strong { display: block; margin-top: .1rem; font-size: 1.05rem; color: white; }
.progress-row { display: grid; grid-template-columns: auto 1fr; gap: .6rem; align-items: center; margin-top: .8rem; color: var(--muted); font-size: .86rem; }
.progress-row div { height: .45rem; background: rgba(255,255,255,.08); border-radius: 999px; overflow: hidden; }
.progress-row i { display: block; height: 100%; background: linear-gradient(90deg, var(--route-color), #54d6ff); border-radius: inherit; }
.card-actions { display: flex; gap: .45rem; margin-top: .8rem; }
.card-actions button { min-height: 2rem; padding: 0 .65rem; font-size: .86rem; background: rgba(84,214,255,.12); color: #dff7ff; box-shadow: none; }
.route-pills { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .75rem; }
.route-pills span { display: inline-flex; padding: .22rem .48rem; border-radius: 999px; color: white; background: color-mix(in srgb, var(--route-color) 60%, #07101f); font-size: .78rem; }
.meta { color: var(--muted); display: grid; gap: .15rem; font-size: .93rem; }
.events { display: grid; gap: .55rem; margin-top: .75rem; }
.event { padding: .85rem .85rem .85rem 1rem; position: relative; }
.event strong { display: block; color: white; }
.event.high { border-color: rgba(255,109,122,.55); background: rgba(255,109,122,.08); }
.event-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.event-chip { padding: .75rem; }
.event-chip strong { display: block; font-size: 1.45rem; color: white; }
.event-chip span { color: var(--muted); }
.event-group { display: grid; gap: .55rem; margin: 1rem 0 1.25rem; }
.event-group h3 { margin-bottom: .15rem; }
.table-wrap { max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 14px; margin-top: .75rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .55rem .65rem; border-bottom: 1px solid rgba(130,164,210,.14); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: #0e1b30; z-index: 1; color: #dce8ff; }
@media (max-width: 1200px) { .ops-panel { grid-template-columns: 1fr 1fr; } .grid.five, .grid.two, .cards, .rank-grid { grid-template-columns: 1fr 1fr; } .event-summary { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { header, .grid.five, .grid.two, .cards, .rank-grid, .replay-bar, .ops-panel, .metric-grid.small { grid-template-columns: 1fr; display: grid; } .tabs { position: static; } #map { min-height: 520px; } }

.route-tools {
  display: grid;
  gap: .65rem;
}
.route-diagnostics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  color: var(--muted);
  font-size: .88rem;
}
#refreshRoutesBtn {
  min-height: 2.1rem;
  padding: 0 .75rem;
  border-radius: 999px;
  border: 1px solid rgba(120, 180, 255, .35);
  color: var(--text);
  background: rgba(80, 140, 255, .10);
}
.route-line {
  filter: drop-shadow(0 0 4px rgba(255,255,255,.15));
}
.route-line.selected {
  filter: drop-shadow(0 0 8px rgba(255,255,255,.45));
}
.bus-marker.moving {
  filter: drop-shadow(0 0 8px rgba(255,255,255,.35));
}
.bus-marker.stopped {
  filter: drop-shadow(0 0 5px rgba(245,181,68,.45));
}


/* Human Minutes v1 */
.journey-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}
.journey-card,
.journey-answer {
  border: 1px solid rgba(255,255,255,.12);
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.035));
  border-radius: 18px;
  padding: 1rem;
}
.journey-card.primary { border-color: rgba(87, 212, 255, .5); }
.journey-card.warn { border-color: rgba(245, 181, 68, .45); }
.journey-card small,
.answer-item small { color: #9fb0c7; text-transform: uppercase; letter-spacing: .06em; }
.journey-card h3,
.journey-answer h3 { margin: .35rem 0 .55rem; }
.answer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .75rem;
}
.answer-item {
  background: rgba(0,0,0,.22);
  border-radius: 14px;
  padding: .8rem;
}
.answer-item strong { display:block; margin-top:.25rem; font-size:1.05rem; }
