/* NTU brand: navy #181c62 + red #d71440. Brand colors are used for chrome
   only; status colors (good/warning/serious/critical) stay reserved for state
   so NTU red is never mistaken for an outage. */
:root {
  color-scheme: light;
  --ntu-navy: #181c62;
  --ntu-red: #d71440;
  --page: #f6f6f9;
  --surface: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #85848f;
  --grid: #e4e4ec;
  --axis: #c3c2cc;
  --border: rgba(24, 28, 98, 0.12);
  --nodata: #e1e1e8;
  --hover: rgba(24, 28, 98, 0.04);
  --accent: #181c62;
  --series-1: #3b47b5;
  --series-2: #eb6834;
  --tile-rule: #181c62;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --offline: #85848f;
  --shadow: 0 1px 2px rgba(24, 28, 98, 0.05), 0 4px 16px rgba(24, 28, 98, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0c0d18;
    --surface: #171828;
    --text-primary: #f0f0f5;
    --text-secondary: #c2c2d0;
    --text-muted: #8c8c9c;
    --grid: #2a2b3d;
    --axis: #3a3b50;
    --border: rgba(255, 255, 255, 0.10);
    --nodata: #2a2b3d;
    --hover: rgba(255, 255, 255, 0.04);
    --accent: #9aa2f2;
    --series-1: #6c78e0;
    --series-2: #d95926;
    --tile-rule: #3b47b5;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { background: var(--page); }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text-primary);
  background: var(--page);
}
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }

/* top bar */
.topbar { background: var(--ntu-navy); color: #fff; border-bottom: 4px solid var(--ntu-red); }
.topbar-inner { max-width: 960px; margin: 0 auto; padding: 22px 20px 20px; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; flex: none; border-radius: 10px; background: #fff url("favicon.svg") center / 40px no-repeat; }
.brand p { margin: 2px 0 0; font-size: 13px; color: rgba(255, 255, 255, 0.72); }
.refresh { font-size: 12px; color: rgba(255, 255, 255, 0.72); white-space: nowrap; }

.page { max-width: 960px; margin: 0 auto; padding: 24px 20px 48px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px 0; flex-wrap: wrap; }

/* banner */
.banner {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px; margin-bottom: 20px;
  border-radius: 10px; color: #fff; background: var(--offline);
}
.banner.up { background: var(--good); }
.banner.degraded { background: var(--warning); color: #0b0b0b; }
.banner.partial { background: var(--serious); color: #0b0b0b; }
.banner.major { background: var(--critical); }
.banner-title { font-size: 18px; font-weight: 650; }
.banner-sub { font-size: 13px; opacity: 0.9; }
.banner-icon { width: 28px; height: 28px; flex: none; }

/* status icon + label */
.st { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.st-icon { width: 16px; height: 16px; flex: none; }

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 4px 12px; font: inherit; font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--surface); font-weight: 600; }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* timeline: one row per node */
.timeline { padding: 6px 20px 4px; }
.tl-node { padding: 12px 0 10px; }
.tl-node + .tl-node { border-top: 1px solid var(--grid); }
.tl-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.tl-name { font-weight: 600; }
.tl-loc { font-weight: 400; font-size: 12px; color: var(--text-muted); margin-left: 8px; }
.timeline .bars { height: 36px; margin-top: 0; }

/* node switcher */
.node-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin: 32px 0 12px; }
.node-bar .section-title { margin: 0; }
.node-tabs button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 16px; font-size: 14px; }
.node-tabs button[aria-pressed="true"] .st-icon circle { stroke: var(--surface); stroke-width: 1.5; }
.timeline-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 4px 20px 16px; font-size: 12px; color: var(--text-secondary); }
.timeline-legend .bar { display: inline-block; width: 8px; height: 12px; margin-right: 6px; vertical-align: -1px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; border-top: 3px solid var(--tile-rule); }
.tile-label { font-size: 12px; color: var(--text-muted); }
.tile-value { font-size: 20px; font-weight: 600; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-value small { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.tile-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* groups & monitors */
.group-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 6px; }
.monitor { border-top: 1px solid var(--grid); }
.monitor:first-of-type { border-top: 0; }
.monitor-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center;
  width: 100%; padding: 12px 20px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.monitor-row:hover { background: var(--hover); }
.monitor-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.monitor-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 550; }
.monitor-name span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.monitor-target { font-size: 12px; color: var(--text-muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.monitor-meta { display: flex; gap: 14px; align-items: center; font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chev { width: 14px; height: 14px; color: var(--text-muted); transition: transform .15s; }
.monitor.open .chev { transform: rotate(90deg); }

.bars { grid-column: 1 / -1; display: flex; gap: 2px; height: 30px; margin-top: 6px; }
.bar { flex: 1 1 0; min-width: 2px; border-radius: 2px; background: var(--nodata); }
.bar.good { background: var(--good); }
.bar.warning { background: var(--warning); }
.bar.serious { background: var(--serious); }
.bar.critical { background: var(--critical); }
.bars .bar:hover { opacity: 0.7; }
.bars-axis { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.bars-axis::before, .bars-axis::after { content: none; }
.bars-axis .rule { flex: 1; height: 1px; background: var(--grid); }

.detail { padding: 4px 20px 18px; }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.detail-stats { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.detail-stats b { color: var(--text-primary); font-weight: 600; }
.err { font-size: 12px; color: var(--text-secondary); margin-top: 6px; word-break: break-all; }

/* charts */
.chart { position: relative; padding: 8px 12px 12px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-size: 11px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); }
.legend i { display: inline-block; width: 12px; height: 2px; border-radius: 1px; vertical-align: middle; margin-right: 6px; }
.empty { padding: 24px 20px; color: var(--text-muted); font-size: 14px; }

/* incident history calendar */
.section-title { font-size: 20px; font-weight: 650; margin: 36px 0 8px; }
.cal-nav { display: inline-flex; gap: 6px; }
.cal-nav button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-primary); font-size: 18px; line-height: 1; cursor: pointer;
}
.cal-nav button:disabled { opacity: 0.35; cursor: default; }
.cal-nav button:focus-visible { outline: 2px solid var(--accent); }
.cal-months { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 24px; padding: 18px 20px 6px; }
.cal-title { font-weight: 600; margin-bottom: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { font-size: 11px; color: var(--text-muted); text-align: center; padding-bottom: 2px; }
.cal-day {
  aspect-ratio: 1; border: 0; border-radius: 6px; padding: 0; cursor: pointer;
  font: inherit; font-size: 12px; font-variant-numeric: tabular-nums; color: #fff; background: var(--nodata);
}
.cal-day.nodata { color: var(--text-muted); }
.cal-day.good { background: var(--good); }
.cal-day.warning { background: var(--warning); color: #0b0b0b; }
.cal-day.serious { background: var(--serious); color: #0b0b0b; }
.cal-day.critical { background: var(--critical); }
.cal-day.future { background: none; color: var(--text-muted); opacity: 0.5; cursor: default; }
.cal-day.today { font-weight: 700; }
.cal-day.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal-day:not(.future):hover { filter: brightness(0.92); }
.cal-day:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 10px 20px 14px; font-size: 12px; color: var(--text-secondary); }
.cal-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--nodata); }
.cal-swatch.good { background: var(--good); }
.cal-swatch.warning { background: var(--warning); }
.cal-swatch.serious { background: var(--serious); }
.cal-swatch.critical { background: var(--critical); }
.cal-detail { border-top: 1px solid var(--grid); padding: 14px 20px 8px; }
.sev-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--nodata); }
.sev-dot.warning { background: var(--warning); }
.sev-dot.serious { background: var(--serious); }
.sev-dot.critical { background: var(--critical); }
.day-date { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.day-none { font-size: 14px; color: var(--text-muted); }
.incident { padding: 6px 0 10px; }
.incident-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.incident-title.ongoing { color: var(--critical); }
.incident-desc { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }
.incident-time { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; font-weight: 500; padding: 0 8px; border-radius: 999px; border: 1px solid currentColor; }

/* tooltip */
.tooltip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; line-height: 1.5; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
}
.tooltip b { font-weight: 600; }
.tooltip .row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.tooltip .row span:last-child { color: var(--text-primary); }

footer { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 32px; }

@media (max-width: 640px) {
  .topbar-inner { flex-direction: column; align-items: flex-start; padding: 18px 14px 16px; }
  .page { padding: 16px 12px 40px; }
  .monitor-row { padding: 12px 14px; }
  .monitor-meta .hide-sm { display: none; }
  .detail { padding: 4px 14px 16px; }
  .timeline { padding: 12px 14px 4px; }
  .timeline-legend { padding: 4px 14px 14px; }
}
