/* ============================================================
   POCO Host Monitor — UI v2 "paper & ink"
   Design language ported verbatim from ai-gateway / video-downloader:
     cream paper sheet on lavender field, graph-paper substrate,
     2px black outlines, zero-blur offset shadows,
     Instrument Serif display / Instrument Sans UI / JetBrains Mono data.

   CONTRACT: every class name and id consumed by the inline JS is preserved.
   Legacy dark-theme token names (--panel, --muted, --blue …) are re-declared
   and remapped onto the paper palette because the JS writes them inline.
   ============================================================ */

/* ─── Self-hosted fonts (latin subset, woff2) ────── */
@font-face {
  font-family: 'Instrument Sans';
  font-style: normal; font-weight: 400 700; font-display: swap;
  src: url('/static/fonts/InstrumentSans-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Instrument Serif';
  font-style: normal; font-weight: 400; font-display: swap;
  src: url('/static/fonts/InstrumentSerif-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Instrument Serif';
  font-style: italic; font-weight: 400; font-display: swap;
  src: url('/static/fonts/InstrumentSerif-400-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal; font-weight: 400 700; font-display: swap;
  src: url('/static/fonts/JetBrainsMono-400.woff2') format('woff2');
}

/* ─── Design tokens ─────────────────────────────── */
:root {
  /* clico palette */
  --bg-page: #c8bff5;
  --bg-card: #f6f3ec;
  --bg-subtle: #efebe0;
  --ink: #0a0a0a;
  --highlight: #c1f04c;
  --brand-blue: #5b5bd6;
  --brand-orange: #f26b3a;

  /* legacy names the markup/JS references inline — remapped onto paper */
  --bg: #c8bff5;          /* page field */
  --panel: #ffffff;       /* card surface */
  --panel2: #f6f3ec;      /* nested surface */
  --border: #0a0a0a;
  --border-light: rgba(10, 10, 10, 0.12);
  --text: #0a0a0a;
  --text2: #2c2c31;
  --muted: #5c5c62;

  /* data-series colors, darkened for legibility on cream */
  --blue:   #3f5fd0;
  --green:  #4a7c0f;
  --yellow: #a86a00;
  --orange: #d1541f;
  --red:    #c02718;
  --purple: #7b4bc4;
  --cyan:   #1f7e91;
  --pink:   #c04a8f;

  --radius: 6px;
  --radius-lg: 10px;

  --shadow-hard: 2px 2px 0 var(--border);
  --shadow-btn: 3px 3px 0 var(--border);
  --shadow-btn-hover: 5px 5px 0 var(--border);
  --shadow-card: 4px 4px 0 var(--border);

  --mono: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
  --serif: 'Instrument Serif', Georgia, serif;
  --font: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 250ms cubic-bezier(0.34, 1.56, 0.64, 1);
  --grid-line: rgba(120, 100, 80, 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  font-size: 14px;
}
::selection { background: var(--highlight); color: var(--ink); }

/* ─── Top bar ───────────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 0 max(18px, calc((100% - 1720px) / 2 + 18px));
  height: 62px;
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  background-image:
    linear-gradient(90deg, var(--grid-line) 1px, transparent 0),
    linear-gradient(var(--grid-line) 1px, transparent 0);
  background-size: 24px 24px;
}
.topbar .title {
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 9px;
  padding-top: 3px;
  min-width: 0;
}
.topbar .title .up {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 10px;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  background: var(--highlight);
  color: var(--ink);
  white-space: nowrap;
  align-self: center;
  margin-top: -2px;
}
.topbar .actions { display: flex; gap: 9px; align-items: center; padding-right: 3px; }

/* dropdown buttons = interactive → they get the offset shadow */
.dropdown { position: relative; }
.dd-btn {
  background: var(--panel);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-hard);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: var(--transition);
}
.dd-btn:hover { box-shadow: 4px 4px 0 var(--border); transform: translate(-2px, -2px); }
.dd-btn:active { box-shadow: 1px 1px 0 var(--border); transform: translate(1px, 1px); }
.dd-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 7px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  min-width: 186px;
  z-index: 200;
  overflow: hidden;
}
.dd-menu.open { display: block; }
.dd-item {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text2);
  border-bottom: 1px solid var(--border-light);
  transition: background 120ms linear;
}
.dd-item:last-child { border-bottom: none; }
.dd-item:hover { background: var(--highlight); color: var(--ink); }
.dd-item.active { background: var(--bg-subtle); color: var(--ink); }
.dd-item.active::after { content: ' ✓'; font-family: var(--mono); }
.dd-item.active:hover { background: var(--highlight); }

.live-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--highlight);
  border: 2px solid var(--border);
  display: inline-block;
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ─── Layout ────────────────────────────────────── */
.content {
  max-width: 1720px;
  margin: 0 auto;
  padding: 22px max(18px, calc((100% - 1720px) / 2 + 18px)) 10px;
}
/* hard shadows eat the right/bottom gutter → compensate in the gaps */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(132px, auto);
  gap: 16px 18px;
  margin-bottom: 20px;
}
@media (max-width: 1180px) { .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(470px, 1fr));
  gap: 16px 18px;
  margin-bottom: 20px;
}
.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 18px;
  margin-bottom: 20px;
}
@media (max-width: 1000px) {
  .charts-grid { grid-template-columns: 1fr; }
  .bottom-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .topbar { height: auto; padding: 12px 14px; flex-wrap: wrap; }
  .topbar .title { font-size: 21px; }
  .content { padding: 16px 16px 8px 14px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
}

/* ─── Panels (cards) ───────────────────────────── */
.panel {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.panel-header {
  padding: 12px 17px 12px 16px;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  background: var(--bg-card);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 10px;
}
.panel-header .sub {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 100%;
  margin-right: 2px;
}
.panel-header .sub .pill { flex-shrink: 0; }
/* the pill nested inside .sub must not inherit .sub's own chrome */
.panel-header .sub:has(.pill) {
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
}
.panel-header .sub {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text2);
  background: var(--bg-subtle);
  border: 1.5px solid var(--border);
  border-radius: 99px;
  padding: 2px 9px;
  white-space: nowrap;
}
.panel-body { padding: 14px 16px; }

/* ─── Stat panels ──────────────────────────────── */
.stat-panel {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-hard);
  padding: 13px 15px 13px;
  position: relative;
  overflow: hidden;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background-image:
    linear-gradient(90deg, var(--grid-line) 1px, transparent 0),
    linear-gradient(var(--grid-line) 1px, transparent 0);
  background-size: 22px 22px;
}
.stat-panel > * { position: relative; z-index: 1; }
.stat-panel .stat-title {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.11em;
  margin-bottom: 6px;
}
.stat-panel .stat-val {
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.stat-panel .stat-unit {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0;
}
.stat-panel .stat-spark { margin-top: 6px; height: 26px; display: block; flex: 0 0 auto; }
/* no-sparkline cards keep the same vertical rhythm */
.stat-panel:not(:has(.stat-spark)) .stat-val { margin-bottom: 32px; }
.stat-panel .stat-sub {
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted);
  margin-top: auto;
  padding-top: 6px;
  min-height: calc(2 * 1.45em + 6px);   /* uniform 2-line slot => rows match */
  overflow-wrap: anywhere;
}
/* sparkline sits above the sub line, not stretched by the flex column */
.stat-panel .stat-spark { flex: 0 0 auto; }
.stat-panel .stat-val { flex: 0 0 auto; }
/* the flagship card — highlighter fill instead of a coloured border */
.stat-panel.accent { background: var(--highlight); }
.stat-panel.accent .stat-title { color: #33430c; }
.stat-panel.accent .stat-sub { color: #33430c; }

/* ─── Services grid ────────────────────────────── */
.svc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 8px 9px;
}
.svc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  min-width: 0;
}
.svc-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}
.svc-up { background: var(--highlight); }
.svc-down {
  background: repeating-linear-gradient(-45deg,
    var(--brand-orange) 0 3px, #fff 3px 6px);
}
.svc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-port {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 700;
  white-space: nowrap;
}

/* ─── Tables ───────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 8px 10px;
  border-top: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text2);
  border-bottom: 1px solid var(--border-light);
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}
td.mono, th.mono { font-family: var(--mono); }
tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: rgba(10, 10, 10, 0.022); }
tbody tr:hover, tbody tr:nth-child(even):hover { background: var(--highlight); }
.table-scroll { overflow-x: auto; }

/* ─── Power estimation panel ───────────────────── */
.pwr-live .stat-panel { box-shadow: none; min-width: 0; width: auto; }
.pwr-live {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 14px;
  margin-bottom: 18px;
  align-items: stretch;
}
@media (max-width: 700px) { .pwr-live { grid-template-columns: 1fr; } }
.pwr-sect {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 7px;
  margin-bottom: 12px;
  border-bottom: 2px solid var(--border);
}
.pwr-hero {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 14px;
  margin-bottom: 20px;
}
@media (max-width: 1180px) { .pwr-hero { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 460px)  { .pwr-hero { grid-template-columns: 1fr; } }
.pwr-cell {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 0;
}
.pwr-cell.lime { background: var(--highlight); }
.pwr-cell .k {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.pwr-cell.lime .k { color: #33430c; }
.pwr-cell .v {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.pwr-cell .u { font-size: 11px; color: var(--muted); font-weight: 700; }
.pwr-cell.lime .u { color: #33430c; }
.pwr-cell .n {
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted);
  margin-top: 5px;
  overflow-wrap: anywhere;
}
.pwr-cell.lime .n { color: #33430c; }
.pwr-note {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--border-light);
  line-height: 1.7;
}
.pwr-note b { color: var(--text); }

/* status pills — border + fill only, NO shadow (they are not buttons) */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--bg-subtle);
  color: var(--ink);
  white-space: nowrap;
}
.pill-on { background: var(--highlight); }
.pill-off {
  background: repeating-linear-gradient(-45deg,
    rgba(242,107,58,.35) 0 5px, rgba(255,255,255,.8) 5px 10px);
}

/* ─── Charts ───────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 186px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius);
  padding: 6px 4px 2px;
}

/* ─── Footer ───────────────────────────────────── */
.footer {
  text-align: center;
  font-family: var(--mono);
  font-size: 10.5px;
  color: #3a3350;
  padding: 8px 18px 30px;
  letter-spacing: 0.03em;
}
.footer a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1.5px solid var(--ink);
  padding-bottom: 1px;
}
.footer a:hover { background: var(--highlight); }
