:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c222b;
  --border: #30363d;
  --border-soft: rgba(48, 54, 61, 0.5);
  --fg: #c9d1d9;
  --fg-dim: #8b949e;
  --fg-faint: #6e7681;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, 0.12);
  --ok: #3fb950;
  --warn: #d29922;
  --crit: #f85149;
  /* 8px grid rhythm */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  /* Terminal-only monospace stack: Nerd Font first so PUA glyphs (icons from
     eza/lsd/neofetch) render. System mono as graceful fallback. */
  --font-mono: "JetBrainsMono Nerd Font Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* JetBrains Mono Nerd Font Mono Regular — self-hosted, subset to
   ASCII + Latin-1/Extended + symbol blocks + Nerd Font PUA. 367 KB. */
@font-face {
  font-family: "JetBrainsMono Nerd Font Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/JetBrainsMonoNerdFontMono-Regular.subset-a6ff6f22eb.woff2") format("woff2");
  unicode-range:
    U+0020-007F,
    U+00A0-00FF,
    U+0100-017F, U+0180-024F,
    U+2000-206F,
    U+2190-21FF,
    U+2500-257F, U+2580-259F, U+25A0-25FF,
    U+2600-26FF, U+2700-27BF,
    U+E000-E00A, U+E0A0-E0D7,
    U+E200-E2A9, U+E300-E3E3, U+E5FA-E6C0, U+E700-E7E5, U+E800-E8A2,
    U+EA60-EBEB, U+EC00-EC1B, U+EE00-EE0B,
    U+F000-F2E0, U+F300-F32F, U+F400-F4A8, U+F500-FD46;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Header ===== */
header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.4px;
}

nav { display: flex; gap: var(--s-1); }

.tab {
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid transparent;
  padding: var(--s-1) var(--s-3);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.tab:hover { color: var(--fg); }
.tab.active {
  color: var(--fg);
  background: var(--bg-3);
  border-color: var(--border);
}

.refresh-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  color: var(--fg-dim);
  font-size: 12px;
}

.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-3);
}
.pill.ok { color: var(--ok); border-color: rgba(63, 185, 80, 0.4); }
.pill.warn { color: var(--warn); border-color: rgba(210, 153, 34, 0.4); }
.pill.crit { color: var(--crit); border-color: rgba(248, 81, 73, 0.4); }

button {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: var(--s-1) var(--s-3);
  font: inherit;
  font-size: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--fg); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 var(--s-1);
  font-size: 10px;
  font-family: inherit;
  color: var(--fg-dim);
}

/* ===== Main / Views ===== */
main { padding: var(--s-5); }

.view { display: none; }
.view.active { display: block; }

/* ===== Stats row (one-line summary above the grid) =====
   Subtle, type-only, no card chrome. Sparklines are inline canvases
   that get drawn from app.js using last-N fetches. */
.stats-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-3);
  margin-bottom: var(--s-4);
  padding: var(--s-2) var(--s-3);
  color: var(--fg-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
}
.stats-row .stat {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  white-space: nowrap;
}
.stats-row .stat-label {
  color: var(--fg-faint);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
}
.stats-row .stat-value {
  color: var(--fg);
  font-weight: 500;
}
.stats-row .stat-value.ok   { color: var(--ok); }
.stats-row .stat-value.warn { color: var(--warn); }
.stats-row .stat-value.crit { color: var(--crit); }
.stats-row .stat-sep { color: var(--fg-faint); user-select: none; }
.stats-row .spark {
  display: inline-block;
  width: 72px;
  height: 20px;
  vertical-align: middle;
}
/* Refined: last-refresh updates with a brief flash when a fetch lands */
.last-refresh-flash {
  animation: lrf-flash 0.6s ease-out;
}
@keyframes lrf-flash {
  0%   { color: var(--accent); }
  100% { color: var(--fg-dim); }
}
/* Subtle pulse on the refresh button while a fetch is in flight */
button.pulse { animation: btn-pulse 1.1s ease-in-out infinite; }
@keyframes btn-pulse {
  0%, 100% { border-color: var(--border); }
  50%      { border-color: var(--accent); }
}

/* ===== Dashboard grid (12-column) =====
   Cards opt into a span via .span-N. The default (span 4) is the "small" card.
   No empty cells: spans always sum to 12 per row. */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--s-4);
  align-items: start;        /* cards size to content; no fake-stretch */
}

.grid.loading > .card { opacity: 0.55; transition: opacity 0.2s; }

.card {
  grid-column: span 4;            /* default: 1/3 width */
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-4);
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.card:hover { border-color: rgba(88, 166, 255, 0.5); }

.card.span-6  { grid-column: span 6; }   /* 1/2  */
.card.span-8  { grid-column: span 8; }   /* 2/3  */
.card.span-12 { grid-column: span 12; }  /* full */

.card h2 {
  margin: 0 0 var(--s-3) 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--fg-dim);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}
.card h2 .meta {
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fg-faint);
  font-weight: 400;
}

.card .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-2);
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--border-soft);
}
.card .row:last-child { border-bottom: 0; }

.card .row .label { color: var(--fg-dim); }
.card .row .value { color: var(--fg); font-weight: 500; }
.card .row .value.ok { color: var(--ok); }
.card .row .value.warn { color: var(--warn); }
.card .row .value.crit { color: var(--crit); }
.card .muted { color: var(--fg-dim); font-size: 12px; }

.card .divider {
  height: 1px;
  background: var(--border);
  margin: var(--s-3) 0;
}

.card .note {
  color: var(--fg-faint);
  font-size: 11px;
  margin-top: var(--s-2);
}

/* Big number for primary metric (e.g. CPU Usage) */
.metric {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  margin-bottom: var(--s-2);
}
.metric .num {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}
.metric .unit { color: var(--fg-dim); font-size: 13px; }
.metric .num.ok   { color: var(--ok); }
.metric .num.warn { color: var(--warn); }
.metric .num.crit { color: var(--crit); }

.bar {
  background: var(--bg-3);
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease, background 0.2s ease;
}
.bar > span.warn { background: var(--warn); }
.bar > span.crit { background: var(--crit); }

/* Per-core sub-grid: fixed 5 columns on wide so 10 cores = 2 clean rows of 5 */
.per-core {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--s-2) var(--s-3);
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px solid var(--border);
}
.per-core .core {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: var(--s-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.per-core .core .name { color: var(--fg-dim); }
.per-core .core .val  { color: var(--fg); font-weight: 500; }
.per-core .core .val.ok   { color: var(--ok); }
.per-core .core .val.warn { color: var(--warn); }
.per-core .core .val.crit { color: var(--crit); }
.per-core .core .bar { grid-column: 1 / -1; margin-top: 0; }

/* Disks card — compact row layout; long paths wrap on narrow widths */
.disk-list { display: flex; flex-direction: column; }
.disk-list .disk-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-2);
  padding: var(--s-1) 0;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--border-soft);
}
.disk-list .disk-row:last-child { border-bottom: 0; }
.disk-list .disk-row .mount {
  color: var(--fg);
  overflow-wrap: anywhere;     /* break long mount paths on mobile */
  min-width: 0;
  flex: 1 1 auto;
}
.disk-list .disk-row .use {
  color: var(--fg-dim);
  white-space: nowrap;
  flex: 0 0 auto;
}
.disk-list .disk-row .use.warn { color: var(--warn); }
.disk-list .disk-row .use.crit { color: var(--crit); }

/* Network table */
.table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-2);
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--fg-dim);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.table tbody td {
  padding: 6px var(--s-3);
  border-bottom: 1px solid var(--border-soft);
  color: var(--fg);
  font-size: 12px;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-3); }
.table td.right, .table th.right { text-align: right; }
.table td.muted { color: var(--fg-dim); }
.table td .up   { color: var(--ok); }
.table td .down { color: var(--fg-faint); }

/* Error / utilities */
.error {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--crit);
  color: var(--crit);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius);
  margin-top: var(--s-3);
}

.muted { color: var(--fg-dim); }
.hidden { display: none !important; }

/* ===== Terminal ===== */
#term-container {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-2);
  min-height: 400px;
  height: calc(100vh - 180px);
}

/* Nerd Font stack applies to the terminal only — keeps the dashboard on
   SF Mono for tighter text rendering. !important overrides xterm.js's
   inline font-family on .xterm-renderer so the woff2 actually takes effect. */
#term-container,
.xterm,
.xterm .xterm-screen,
.xterm .xterm-renderer {
  font-family: var(--font-mono) !important;
}

.term-controls {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  margin-bottom: var(--s-2);
}

/#term-status.value.ok   { color: var(--ok); }
#term-status.value.crit { color: var(--crit); }

/* ===== Responsive =====
   Mobile:  < 641px  → 1 col, full-width cards, header stacks
   Tablet:  641–1024 → 2-col rhythm, network full
   Desktop: 1025+   → 12-col grid (default)
   Wide:    1601+   → slightly roomier (16 → 20px gap) */
@media (max-width: 640px) {
  header { gap: var(--s-2); padding: var(--s-2) var(--s-3); }
  header h1 { font-size: 14px; }
  .refresh-bar {
    width: 100%;
    margin-left: 0;
    order: 99;
    justify-content: space-between;
  }
  main { padding: var(--s-3); }
  .grid { grid-template-columns: 1fr; gap: var(--s-3); }
  /* Stats row: drop the sparkline on mobile to keep it single-line */
  .stats-row .spark { display: none; }
  .stats-row { font-size: 11px; gap: var(--s-1) var(--s-2); padding: var(--s-1) var(--s-2); }
  .card,
  .card.span-6, .card.span-8, .card.span-12 { grid-column: 1 / -1; }
  #term-container { height: calc(100vh - 220px); }
  .per-core { grid-template-columns: repeat(2, 1fr); }
  .metric .num { font-size: 24px; }
  /* Network table: hide the long IPs column to keep tx/rx readable */
  .table th.hide-narrow, .table td.hide-narrow { display: none; }
  .table th, .table td { padding: 6px 8px; font-size: 11px; }
}

@media (min-width: 641px) and (max-width: 1024px) {
  /* Consistent 2-col rhythm on tablet — no half-rows, no orphans.
     Network becomes 1/2 too; the table is in .table-wrap with horizontal
     scroll so it stays usable. */
  .grid { grid-template-columns: repeat(2, 1fr); gap: var(--s-3); }
  .card,
  .card.span-4, .card.span-6, .card.span-8, .card.span-12 { grid-column: span 1; }
  .per-core { grid-template-columns: repeat(5, 1fr); }
}

@media (min-width: 1601px) {
  .grid { gap: var(--s-5); }
  main { padding: var(--s-6); }
}
