:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --border: #e3e2de;
  --grid: #ecebe7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75746f;
  --accent: #2a78d6;
  --series: #2a78d6;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --neutral: #8a8984;
  --good-bg: #e7f5e7;
  --warning-bg: #fdf3dc;
  --critical-bg: #fbe8e8;
  --neutral-bg: #efeeeb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --border: #2f2f2d;
    --grid: #262624;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9a998f;
    --accent: #3987e5;
    --series: #3987e5;
    --good-bg: #16301a;
    --warning-bg: #3a2f12;
    --critical-bg: #3b1a1a;
    --neutral-bg: #262624;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --border: #2f2f2d; --grid: #262624;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #9a998f;
  --accent: #3987e5; --series: #3987e5;
  --good-bg: #16301a; --warning-bg: #3a2f12; --critical-bg: #3b1a1a; --neutral-bg: #262624;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); font-size: 17px; }
.brand span { font-weight: 400; color: var(--text-3); }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar form { margin: 0; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; margin-bottom: 16px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid > .card { margin-bottom: 0; }

/* Banners */
.banner { border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; border: 1px solid; }
.banner.critical { background: var(--critical-bg); border-color: var(--critical); }

/* Semàfor: sempre icona + text, mai només color */
.status {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 2px 10px 2px 8px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.status::before { font-size: 12px; line-height: 1; }
.status.ok { background: var(--good-bg); }
.status.ok::before { content: "●"; color: var(--good); }
.status.warn { background: var(--warning-bg); }
.status.warn::before { content: "▲"; color: var(--warning); }
.status.dead { background: var(--critical-bg); }
.status.dead::before { content: "✕"; color: var(--critical); }
.status.unknown, .status.inactive { background: var(--neutral-bg); color: var(--text-2); }
.status.unknown::before, .status.inactive::before { content: "○"; color: var(--neutral); }

.summary { display: flex; gap: 8px; flex-wrap: wrap; }

.reasons { margin: 6px 0 0; padding: 0 0 0 18px; color: var(--text-2); font-size: 13px; }
.reasons li { margin: 1px 0; }

/* Taules */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.station-cell a { font-weight: 600; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--text-3); }
dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Pestanyes de finestra temporal */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg a { padding: 4px 12px; color: var(--text-2); }
.seg a + a { border-left: 1px solid var(--border); }
.seg a.on { background: var(--accent); color: #fff; }
.seg a:hover { text-decoration: none; }

/* Gràfics */
.chart-card h3 { font-size: 14px; margin: 0; font-weight: 600; }
.chart-card .chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.chart { position: relative; height: 140px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .bar { fill: var(--series); }
.chart .bar.hover { opacity: .75; }
.chart .cross { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .empty { fill: var(--text-3); font-size: 13px; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; white-space: nowrap;
  background: var(--text); color: var(--surface); font-size: 12px;
  padding: 4px 8px; border-radius: 6px; transform: translate(-50%, -100%); margin-top: -8px;
}

/* Login */
.login { max-width: 360px; margin: 48px auto; }
.login label { display: block; font-size: 13px; color: var(--text-2); margin: 12px 0 4px; }
.login input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.login button { margin-top: 16px; width: 100%; padding: 9px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.errors { color: var(--critical); font-size: 13px; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
}
