:root {
  --bg: #0b0e14;
  --bg-elev: #131824;
  --bg-elev2: #1b2233;
  --border: #263041;
  --text: #e6edf6;
  --muted: #8a97ab;
  --accent: #4c8dff;
  --accent-dim: #2b4a80;
  --yes: #2ec16b;
  --no: #ef4d55;
  --queue: #f2a93b;
  --unknown: #5b6578;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

button {
  font: inherit; cursor: pointer; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; padding: 8px 14px; font-weight: 600;
  transition: filter .15s, background .15s;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.ghost:hover { color: var(--text); background: var(--bg-elev2); }
button.danger { background: transparent; color: var(--no); border: 1px solid var(--no); }
button.danger:hover { background: rgba(239,77,85,.12); }
button.small { padding: 5px 10px; font-size: 12px; }

input, select {
  font: inherit; background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

/* ---- Login ---- */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.login-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: min(360px, 92vw); box-shadow: var(--shadow); text-align: center; }
.login-card h1 { margin: 6px 0 4px; font-size: 20px; }
.login-logo { font-size: 44px; }
.login-card input { margin: 18px 0 12px; }
.login-card button { width: 100%; }
.login-error { color: var(--no); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---- Layout ---- */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.brand { font-weight: 700; font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar { width: 340px; flex-shrink: 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; background: var(--bg-elev); min-height: 0; }
.main { flex: 1; overflow-y: auto; min-width: 0; }

/* ---- Sidebar ---- */
.add-box { padding: 14px; border-bottom: 1px solid var(--border); position: relative; }
.add-id { display: flex; gap: 8px; margin-bottom: 10px; }
.add-id input { flex: 1; }
.add-id button { flex-shrink: 0; }
.search-results { position: absolute; left: 14px; right: 14px; top: 56px; z-index: 20;
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 340px; overflow-y: auto; }
.search-results:empty { display: none; }
.search-item { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 10px; align-items: center; }
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--bg-elev); }
.search-item .si-main { flex: 1; min-width: 0; }
.search-item .si-brand { font-weight: 600; }
.search-item .si-addr { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-head { display: flex; justify-content: space-between; padding: 12px 16px 6px; font-weight: 600; }
.stations-list { overflow-y: auto; flex: 1; padding: 4px 8px 16px; }
.station-card { padding: 10px 12px; border-radius: 10px; cursor: pointer; display: flex; gap: 10px; align-items: center; margin-bottom: 4px; border: 1px solid transparent; }
.station-card:hover { background: var(--bg-elev2); }
.station-card.active { background: var(--bg-elev2); border-color: var(--accent-dim); }
.station-card .sc-main { flex: 1; min-width: 0; }
.station-card .sc-brand { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.station-card .sc-addr { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Status badge / dot ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.st-yes { background: rgba(46,193,107,.15); color: var(--yes); }
.st-no { background: rgba(239,77,85,.15); color: var(--no); }
.st-queue { background: rgba(242,169,59,.15); color: var(--queue); }
.st-unknown { background: rgba(91,101,120,.18); color: var(--muted); }
.dot.st-yes { background: var(--yes); } .dot.st-no { background: var(--no); }
.dot.st-queue { background: var(--queue); } .dot.st-unknown { background: var(--unknown); }

/* ---- Detail ---- */
.detail { padding: 22px 26px 60px; max-width: 1000px; }
.empty { display: grid; place-items: center; height: 100%; text-align: center; padding: 40px; }
.empty-icon { font-size: 52px; margin-bottom: 8px; }
.detail h2 { margin: 0 0 2px; font-size: 22px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-sub { color: var(--muted); margin: 2px 0 16px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 16px 0 26px; }
.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 20px; font-weight: 700; margin-top: 4px; }

.section { margin: 30px 0; }
.section h3 { margin: 0 0 4px; font-size: 16px; }
.section .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.range-tabs { display: inline-flex; gap: 4px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.range-tabs button { background: transparent; color: var(--muted); padding: 4px 12px; font-size: 12px; border-radius: 6px; }
.range-tabs button.active { background: var(--accent); color: #fff; }

/* ---- Heatmap ---- */
.heatmap { overflow-x: auto; }
.heat-grid { border-collapse: collapse; }
.heat-grid td, .heat-grid th { padding: 0; }
.heat-grid th { font-size: 10px; color: var(--muted); font-weight: 500; text-align: center; }
.heat-grid .rowlabel { font-size: 11px; color: var(--muted); padding-right: 8px; text-align: right; white-space: nowrap; }
.heat-cell { width: 22px; height: 22px; border: 1px solid var(--bg); border-radius: 3px; cursor: default; }
.heat-legend { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.heat-legend .bar { height: 12px; width: 140px; border-radius: 3px;
  background: linear-gradient(90deg, hsl(4 70% 48%), hsl(45 85% 50%), hsl(140 60% 45%)); }
.best-time { margin-top: 14px; padding: 12px 14px; background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 3px solid var(--yes); border-radius: 8px; }

/* ---- Timeline ---- */
.timeline-wrap { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; }
.timeline-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.timeline-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot-down { width: 10px; height: 10px; border-radius: 2px;
  background-image: repeating-linear-gradient(45deg, #2a3040 0 2px, #5b6578 2px 4px); }

/* ---- Marks table ---- */
.marks-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.marks-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 12px; }
.marks-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.marks-table tr:hover td { background: var(--bg-elev); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; background: var(--bg-elev2); color: var(--muted); }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; max-width: 90vw; }
.toast.err { border-color: var(--no); }

.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: 42vh; border-right: none; border-bottom: 1px solid var(--border); }
  .detail { padding: 16px; }
}
