/* hetzner_monitoring — design tokens
 * Dark-mode-first (SRE works at night). OKLCH color space gives
 * perceptual luminance constancy — distinguishable for Deuteranopia.
 * Typography: Geist Mono (tabular nums + slashed zero) + Inter.
 * Density: Linear-style (32px row height, 8/12 padding).
 */

:root {
  /* Surfaces */
  --bg:        #0A0A0B;  /* not pure black — vibrates on OLED */
  --surface:   #111113;
  --surface-2: #16161A;
  --border:    #1F1F23;
  --border-strong: #2A2A30;

  /* Status — OKLCH for perceptual equivalence */
  --saturated:    oklch(64% 0.20 25);    /* coral red, P95>85% */
  --healthy:      oklch(70% 0.14 155);   /* teal green */
  --underutil:    oklch(75% 0.15 75);    /* amber, actionable (downsize candidate) */
  --stale:        oklch(50% 0 0);        /* desaturated gray, chroma=0 — never confused with red */
  --info:         oklch(72% 0.12 230);   /* blue, info-only badges */

  /* Text */
  --text:         oklch(96% 0.005 250);
  --text-muted:   oklch(72% 0.01 250);
  --text-dim:     oklch(55% 0.01 250);

  /* Typography */
  --font-mono:    'Geist Mono', 'JetBrains Mono', ui-monospace, monospace;
  --font-ui:      'Inter', system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;

  /* Sizes */
  --size-hero:    28px;
  --size-body:    13px;
  --size-meta:    12px;
  --line-tight:   1.1;
  --line-table:   1.4;

  /* Density */
  --row-h:        32px;
  --pad-x:        12px;
  --pad-y:        8px;

  /* Misc */
  --radius:       6px;
  --shadow:       0 1px 0 oklch(100% 0 0 / 0.04);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--size-body);
  line-height: var(--line-table);
  font-feature-settings: "cv11";
}

.mono, .num {
  font-family: var(--font-mono);
  font-feature-settings: "tnum", "zero", "ss01";
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

/* App shell */
.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.app-header .title { font-weight: 600; }
.app-header .meta  { color: var(--text-muted); font-size: var(--size-meta); }
.app-header .spacer { flex: 1; }
.search-palette {
  flex: 0 0 280px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--size-meta);
}

/* Project tabs (Hetzner project filter) */
.project-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.project-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--size-meta);
  text-decoration: none;
  color: var(--text-muted);
  transition: background 0.1s ease, border-color 0.1s ease;
}
.project-tab:hover {
  background: var(--surface-2);
  text-decoration: none;
  color: var(--text);
}
.project-tab.active {
  background: var(--surface-2);
  border-color: var(--healthy);
  color: var(--text);
}
.project-tab .tab-label {
  font-family: var(--font-mono);
  font-weight: 500;
}
.project-tab .tab-count {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  background: var(--bg);
  border-radius: 10px;
  color: var(--text-dim);
}
.project-tab.active .tab-count {
  background: oklch(70% 0.14 155 / 0.15);
  color: var(--healthy);
}

/* Scorecards */
.scorecards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.scorecard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.scorecard .num {
  font-size: var(--size-hero);
  font-weight: 600;
  line-height: var(--line-tight);
}
.scorecard .label {
  font-size: var(--size-meta);
  color: var(--text-muted);
}
.scorecard.saturated .num { color: var(--saturated); }
.scorecard.underutil .num { color: var(--underutil); }
.scorecard.stale     .num { color: var(--stale); }
.scorecard.savings   .num { color: var(--healthy); }

/* Strip plot small-multiples block */
.strip-plot-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.strip-plot-section h2 {
  margin: 0 0 4px;
  font-size: var(--size-body);
  font-weight: 600;
}
.strip-plot-section .sub {
  color: var(--text-muted);
  font-size: var(--size-meta);
  margin-bottom: 12px;
}
.strip-row {
  display: grid;
  grid-template-columns: 80px 1fr 60px;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
}
.strip-row:first-child { border-top: none; }
.strip-row .role-label { font-size: var(--size-meta); color: var(--text-muted); }
.strip-row .count      { font-size: var(--size-meta); color: var(--text-dim); text-align: right; }

/* Needs Attention list */
.attention-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.attention-list h2 {
  margin: 0;
  padding: 12px 16px;
  font-size: var(--size-body);
  border-bottom: 1px solid var(--border);
}
.attention-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 12px;
  align-items: center;
  height: var(--row-h);
  padding: 0 var(--pad-x);
  border-top: 1px solid var(--border);
}
.attention-row:first-of-type { border-top: none; }
.attention-row .marker { font-size: 14px; }
.attention-row .name { font-family: var(--font-mono); font-size: var(--size-body); }
.attention-row .reason { color: var(--text-muted); font-size: var(--size-meta); }
.attention-row.up      .marker { color: var(--saturated); }
.attention-row.down    .marker { color: var(--underutil); }
.attention-row.warn    .marker { color: var(--info); }
.attention-row.unknown .marker { color: var(--stale); }

/* Confidence badge */
.confidence { color: var(--text-dim); margin-left: 4px; }

/* Auth pages */
.auth-card {
  max-width: 360px;
  margin: 80px auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.auth-card h1 { font-size: var(--size-hero); margin: 0 0 16px; font-weight: 600; }
.auth-card label { display: block; margin-top: 12px; font-size: var(--size-meta); color: var(--text-muted); }
.auth-card input[type="email"],
.auth-card input[type="password"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--size-body);
}
.auth-card .btn {
  margin-top: 16px;
  width: 100%;
  padding: 10px;
  background: var(--healthy);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
}
.auth-card .alert {
  padding: 10px 12px;
  background: oklch(30% 0.15 25);
  color: var(--saturated);
  border-radius: var(--radius);
  font-size: var(--size-meta);
  margin-bottom: 12px;
}

/* Empty states / banners */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: var(--size-meta);
}
.banner.warn { background: oklch(30% 0.10 75); color: var(--underutil); }
.banner.error { background: oklch(30% 0.15 25); color: var(--saturated); }

/* Server detail */
.server-detail {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
}
.server-detail .charts,
.server-detail .timeline-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.metric-band-chart { display: block; width: 100%; height: 140px; }

.timeline-event {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  font-size: var(--size-meta);
}
.timeline-event:first-child { border-top: none; }
.timeline-event .ts { color: var(--text-dim); font-family: var(--font-mono); }

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--size-body);
}
.table th, .table td {
  text-align: left;
  padding: var(--pad-y) var(--pad-x);
  border-bottom: 1px solid var(--border);
}
.table th {
  font-size: var(--size-meta);
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
}
.table td.num { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.table tr:hover td { background: var(--surface-2); }

/* Cluster grouping (details/summary) for /r/:role node tables */
.cluster-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.cluster-group[open] {
  border-color: var(--border-strong);
}
.cluster-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--surface);
  user-select: none;
  list-style: none;
}
.cluster-summary::-webkit-details-marker { display: none; }
.cluster-summary::before {
  content: "▸";
  color: var(--text-dim);
  font-size: 11px;
  width: 12px;
  transition: transform 0.15s ease;
}
.cluster-group[open] .cluster-summary::before { transform: rotate(90deg); }
.cluster-summary:hover { background: var(--surface-2); }
.cluster-summary .cluster-name {
  font-weight: 600;
  min-width: 220px;
}
.cluster-summary .cluster-name a {
  color: var(--text);
  text-decoration: none;
}
.cluster-summary .cluster-name a:hover {
  text-decoration: underline;
  color: var(--healthy);
}
.cluster-summary .cluster-meta {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--size-meta);
  color: var(--text-muted);
}
.cluster-summary .cluster-stats {
  display: flex;
  gap: 8px;
}
.cluster-summary .stat {
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
  font-size: var(--size-meta);
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-muted);
}
.cluster-summary .stat.saturated {
  background: oklch(30% 0.15 25);
  color: var(--saturated);
  font-weight: 600;
}
.cluster-group .table {
  border-top: 1px solid var(--border);
}

/* Cluster charts button in cluster summary */
.btn-chart {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text);
  text-decoration: none;
  transition: background 0.1s ease, border-color 0.1s ease;
}
.btn-chart:hover {
  background: var(--surface-2);
  border-color: var(--healthy);
  color: var(--healthy);
  text-decoration: none;
}

/* Multi-line chart container + interactive tooltip */
.ml-chart-wrap {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 12px 12px;
  margin-bottom: 8px;
}
.ml-chart-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 6px;
  font-size: var(--size-body);
}
.multi-line-chart .ml-line {
  pointer-events: none;
  transition: stroke-width 0.1s ease, opacity 0.1s ease;
}
.ml-cursor { pointer-events: none; }
.ml-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  z-index: 10;
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.ml-tooltip .ml-tt-ts {
  color: var(--text-muted);
  font-size: 10px;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.ml-tooltip .ml-tt-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 6px;
  align-items: center;
  line-height: 1.5;
}
.ml-tt-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ml-tt-val  { color: var(--text); font-feature-settings: "tnum"; font-weight: 600; }

.ml-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.ml-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.ml-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.ml-node-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Node role badges (M / W / replica#) */
.node-badge {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 3px;
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 600;
  margin-right: 6px;
  vertical-align: middle;
}
.node-badge--master  { background: oklch(72% 0.12 230 / 0.20); color: var(--info); }
.node-badge--worker  { background: var(--bg); color: var(--text-dim); border: 1px solid var(--border-strong); }
.node-badge--replica { background: oklch(70% 0.14 155 / 0.18); color: var(--healthy); }
.node-badge--other   { background: var(--bg); color: var(--text-dim); }

/* Strip-plot SVG markers */
.dot          { fill: var(--text-dim); cursor: pointer; transition: r 0.1s ease, stroke-width 0.1s ease; stroke: var(--bg); stroke-width: 1; }
.dot.saturated { fill: var(--saturated); }
.dot.healthy   { fill: var(--healthy); }
.dot.underutil { fill: var(--underutil); }
.strip-plot a:hover .dot {
  r: 9;
  stroke: var(--text);
  stroke-width: 2;
  filter: brightness(1.2) drop-shadow(0 0 4px var(--text));
}
.target-band   { fill: var(--surface-2); }
.axis          { stroke: var(--border-strong); stroke-width: 1; }
.axis-text     { fill: var(--text-dim); font-size: 10px; font-family: var(--font-mono); }

/* Sub-strip label (for CPU vs RAM rows) */
.strip-row .submetric {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Spend bar — stacked horizontal segments showing $/mo split per deployment */
.spend-bar {
  display: flex;
  width: 100%;
  height: 22px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-2);
  margin: 12px 0 16px;
  border: 1px solid var(--border);
}
.spend-bar-seg {
  height: 100%;
  border-right: 1px solid var(--surface);
  transition: filter 0.1s ease;
  cursor: help;
}
.spend-bar-seg:hover {
  filter: brightness(1.3);
}
.spend-bar-seg:last-child { border-right: none; }

/* Gauges — horizontal pressure bars */
.gauges {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 12px 0 4px;
}
.gauge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
}
.gauge-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.gauge-pct {
  font-family: var(--font-mono);
  font-feature-settings: "tnum", "zero", "ss01";
  font-size: 16px;
  font-weight: 600;
}
.gauge-pct.saturated { color: var(--saturated); }
.gauge-pct.underutil { color: var(--underutil); }
.gauge-pct.savings   { color: var(--healthy); }
.gauge-track {
  position: relative;
  height: 10px;
  background: var(--bg);
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  overflow: visible;
}
.gauge-fill {
  height: 100%;
  background: var(--text-dim);
  border-radius: 2px 0 0 2px;
  transition: width 0.2s ease;
}
.gauge-fill.saturated { background: var(--saturated); }
.gauge-fill.underutil { background: var(--underutil); }
.gauge-fill.savings   { background: var(--healthy); }
.gauge-mark {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: var(--text-dim);
}
.gauge-mark--danger { background: var(--saturated); }
.gauge-detail {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

/* Responsive */
@media (max-width: 880px) {
  .scorecards { grid-template-columns: repeat(2, 1fr); }
  .server-detail { grid-template-columns: 1fr; }
  .gauges       { grid-template-columns: 1fr; }
}
