/* Run Stream web app. Colors are tokens; dark is the default look, light
   follows the device setting. Chart color is slot 1 of the reference palette. */
:root {
  color-scheme: dark;
  --bg: #111111;
  --surface: #191919;
  --surface-2: #222222;
  --border: #2c2c2c;
  --text: #efefef;
  --text-2: #9c9c9c;
  --grid: #2a2a2a;
  --series: #338ced;
  --accent: #338ced;
  --good: #2fd14a;
  --warning: #fbb315;
  --critical: #eb6263;
  --radius: 12px;
  --gutter: 16px;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f6f6;
    --surface: #ffffff;
    --surface-2: #f0f0f0;
    --border: #e2e2e2;
    --text: #191919;
    --text-2: #666666;
    --grid: #ececec;
    --series: #257de0;
    --accent: #2370cd;
    --good: #006c10;
    --warning: #a86b00;
    --critical: #c8302f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
code { font-size: 0.9em; }
[hidden] { display: none !important; }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 2000;  /* above Leaflet's controls (1000) */
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; }
.bar-right { display: flex; align-items: center; gap: 12px; }
.net { font-size: 12px; color: var(--warning); }
button { font: inherit; cursor: pointer; }
.link { background: none; border: 0; color: var(--text-2); padding: 4px; }
.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 12px 16px; font-weight: 600;
}
.danger {
  background: none; color: var(--critical); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
}

main { max-width: 960px; margin: 0 auto; padding: 16px var(--gutter) 40px; }
h1 { font-size: 22px; margin: 4px 0 4px; }
h2 { font-size: 15px; font-weight: 600; color: var(--text-2); margin: 28px 0 10px; }
.muted { color: var(--text-2); }
.error { color: var(--critical); min-height: 1.4em; }

/* login */
.login { max-width: 380px; margin: 40px auto; }
.login form { display: grid; gap: 10px; margin-top: 16px; }
.login label { font-size: 13px; color: var(--text-2); }
.login input {
  font: inherit; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

/* run list */
.runs { display: grid; gap: 10px; }
.run-card {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; color: var(--text);
}
.run-card:active { background: var(--surface-2); }
.run-date { font-weight: 600; }
.run-stats { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--text-2); }
.run-stats b { color: var(--text); font-weight: 600; }
.empty { text-align: center; padding: 48px 0; }
/* bell */
.bell {
  position: relative; display: grid; place-items: center; width: 40px; height: 40px;
  background: none; border: 0; border-radius: 50%; color: var(--text); padding: 0;
}
.bell:hover, .bell[aria-expanded="true"] { background: var(--surface-2); }
.bell-count {
  position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--critical); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.bell-panel {
  position: fixed; z-index: 2100; right: var(--gutter);
  top: calc(62px + env(safe-area-inset-top));
  width: min(380px, calc(100vw - 2 * var(--gutter))); max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35); padding: 12px;
}
.bell-panel h2 { margin: 2px 4px 10px; color: var(--text); }
.bell-panel .notify { margin: 0 0 10px; background: var(--surface-2); }
.bell-list { list-style: none; margin: 0; padding: 0; }
.bell-item {
  display: grid; gap: 2px; padding: 10px 10px 10px 18px; border-radius: 10px; color: var(--text); position: relative;
}
.bell-item:hover { background: var(--surface-2); }
.bell-item.unread::before {
  content: ""; position: absolute; left: 6px; top: 16px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}
.bell-title { font-weight: 600; }
.bell-body { color: var(--text-2); font-size: 14px; }
.bell-time { color: var(--text-2); font-size: 12px; }
.bell-empty { padding: 10px; }

.notify {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin: 4px 0 14px; color: var(--text-2);
}
.notify .primary { padding: 8px 14px; }
.notify-actions { display: flex; gap: 8px; }

/* state badges: always icon + label, never color alone */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.live { color: var(--good); }
.badge.live::before { animation: pulse 1.4s ease-in-out infinite; }
.badge.paused { color: var(--warning); }
.badge.paused::before { border-radius: 1px; }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .badge.live::before { animation: none; } }

/* run view */
.run-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.run-head h1 { margin-right: auto; }
.statusline { color: var(--text-2); font-size: 13px; margin: 4px 0 16px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 12px; color: var(--text-2); }
.tile .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile .unit { font-size: 14px; font-weight: 400; color: var(--text-2); margin-left: 3px; }
.tile.hero { grid-column: span 2; }
.tile.hero .value { font-size: 40px; }

#map {
  height: 300px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); margin-top: 16px; z-index: 0;
}
.map-empty { display: grid; place-items: center; color: var(--text-2); }

/* charts */
.charts { display: grid; gap: 10px; }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 6px; }
.chart-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.chart-title { font-weight: 600; }
.chart-read { color: var(--text-2); }
.chart-read b { color: var(--text); }
.chart svg { display: block; width: 100%; height: 150px; touch-action: pan-y; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .tick { fill: var(--text-2); font-size: 11px; }
.chart .cursor { stroke: var(--text-2); stroke-width: 1; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-2); font-weight: 500; font-size: 12px; }
tr:last-child td { border-bottom: 0; }

details { margin-top: 28px; }
summary { cursor: pointer; color: var(--text-2); font-weight: 600; font-size: 15px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.metric .k { font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.metric .v { font-size: 17px; }

.actions { margin-top: 32px; display: flex; justify-content: flex-end; }

@media (max-width: 480px) {
  .tile .value { font-size: 24px; }
  .tile.hero { grid-column: auto; }
  .tile.hero .value { font-size: 30px; }
  #map { height: 240px; }
}
