/* Dashboard styles. No external fonts or assets: everything works offline. */

:root {
  --bg: #e9edf1;
  --panel: #f8fafb;
  --line: #c8d0d8;
  --ink: #1b2430;
  --quiet: #566373;
  --off: #d3dae2;
  --ok: #1e8a63;
  --warn: #a86a00;
  --crit: #c23a24;
  --focus: #2f5fd0;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a2230;
    --panel: #222c3b;
    --line: #36424f;
    --ink: #e6ebf0;
    --quiet: #9aa6b4;
    --off: #303b4a;
    --ok: #3fb68b;
    --warn: #e0a53a;
    --crit: #ef6a52;
    --focus: #8fb0ff;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

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

/* ---------- top bar ---------- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
}

.top h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.top-status {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--quiet);
  font-size: 0.9rem;
}

.refresh {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
}
.refresh:hover { border-color: var(--ink); }
.refresh:disabled { opacity: 0.6; cursor: progress; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.banner {
  margin: 16px 0 0;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--warn);
  border-radius: 4px;
}
.banner[data-kind="error"] { border-left-color: var(--crit); }

.empty {
  margin: 32px 0 0;
  color: var(--quiet);
}

/* ---------- sections and units ---------- */

.section { margin-top: 28px; }

.section-title {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--quiet);
}

.unit-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Each unit reads like a rack unit: a full-width row with a status edge. */
.unit {
  --state: var(--off);
  display: grid;
  gap: 16px;
  padding: 16px 20px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--state);
  border-radius: 6px;
}
.unit[data-state="ok"] { --state: var(--ok); }
.unit[data-state="stale"] { --state: var(--warn); }
.unit[data-state="error"] { --state: var(--crit); }

.unit-head {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 16px;
  row-gap: 2px;
  align-items: baseline;
}

.unit-title {
  grid-column: 1;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
}

.unit-meta {
  grid-column: 1;
  margin: 0;
  color: var(--quiet);
  font-size: 0.9rem;
}

.unit-status {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  max-width: 52ch;
  font-size: 0.9rem;
  text-align: right;
}

/* Old numbers stay visible but are dimmed so they aren't mistaken for live ones. */
.unit[data-state="stale"] .gauges,
.unit[data-state="stale"] .unit-detail { opacity: 0.55; }

.lamp {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--state);
}

.unit-note {
  margin: 0;
  color: var(--quiet);
}

/* ---------- gauges ---------- */

.gauges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 28px;
}

.gauge-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 0.9rem;
}
.gauge-label { color: var(--quiet); overflow-wrap: anywhere; }
.gauge-value { font-weight: 600; white-space: pre; text-align: right; }

/* Segmented meter: 20 segments cut out with a mask. */
.meter {
  --fill: 0%;
  --lvl: var(--ok);
  position: relative;
  height: 12px;
  margin-top: 6px;
  background: var(--off);
  -webkit-mask-image: repeating-linear-gradient(90deg, #000 0 calc(5% - 2px), transparent calc(5% - 2px) 5%);
  mask-image: repeating-linear-gradient(90deg, #000 0 calc(5% - 2px), transparent calc(5% - 2px) 5%);
}
.meter[data-level="warn"] { --lvl: var(--warn); }
.meter[data-level="crit"] { --lvl: var(--crit); }
.meter[data-level="none"] { --fill: 0%; }

.meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill);
  background: var(--lvl);
}

.gauge.compact .meter { height: 8px; margin-top: 4px; }

/* ---------- details: disks, network, services ---------- */

.unit-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px 28px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.detail-title {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--quiet);
}

.detail-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.net-row,
.svc {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 0.9rem;
}

.net-name,
.svc-name { font-weight: 600; overflow-wrap: anywhere; }

.net-rates { display: flex; gap: 14px; color: var(--quiet); }

.svc-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--quiet);
}
.svc-state::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--off);
}
.svc[data-state="running"] .svc-state::before { background: var(--ok); }
.svc[data-state="stopped"] .svc-state { color: var(--crit); font-weight: 600; }
.svc[data-state="stopped"] .svc-state::before { background: var(--crit); }

/* ---------- feeds ---------- */

.feed-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.feed-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.feed-item:first-child { border-top: none; padding-top: 0; }
.feed-item:last-child { padding-bottom: 0; }

.feed-title {
  color: var(--ink);
  text-decoration: none;
  overflow-wrap: anywhere;
}
a.feed-title:hover { text-decoration: underline; }
a.feed-title:visited { color: var(--quiet); }

.feed-time {
  flex: none;
  color: var(--quiet);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ---------- overview cards ---------- */

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.unit.card { padding: 0; }
/* A section with a single card (like Network) keeps card width. */
.unit-grid > .unit { max-width: 420px; }

/* The whole card is one link to the machine's detail view. */
.card-link {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  padding: 16px 18px;
  color: inherit;
  text-decoration: none;
  border-radius: 0 5px 5px 0;
}
.card-link:hover .unit-title { text-decoration: underline; }
.card-link:focus-visible { outline-offset: -2px; }
.unit.card:hover { border-top-color: var(--quiet); border-right-color: var(--quiet); border-bottom-color: var(--quiet); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.card-head .unit-status { font-size: 0.85rem; }
.card-link .unit-meta { margin-top: -8px; }

.card-problem {
  margin: 0;
  color: var(--quiet);
  font-size: 0.85rem;
}

.card-gauges { display: grid; gap: 10px; }
.unit[data-state="stale"] .card-gauges { opacity: 0.55; }

.card-updates,
.update-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-size: 0.9rem;
}
.card-updates::before,
.update-summary::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--off);
  transform: translateY(-1px);
}
[data-level="ok"].card-updates::before, [data-level="ok"].update-summary::before { background: var(--ok); }
[data-level="warn"].card-updates::before, [data-level="warn"].update-summary::before { background: var(--warn); }
[data-level="crit"].card-updates::before, [data-level="crit"].update-summary::before { background: var(--crit); }
[data-level="crit"].card-updates, [data-level="crit"].update-summary { font-weight: 600; }

/* One line listing problems the meters don't show. */
.card-alert {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}
.card-alert::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  transform: translateY(-1px);
}
.card-alert[data-level="crit"] { color: var(--crit); }
.card-alert[data-level="crit"]::before { background: var(--crit); }
.card-alert-text {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card-more {
  align-self: flex-end;
  margin-top: auto; /* bottom of the card, whatever its neighbours' height */
  color: var(--quiet);
  font-size: 0.85rem;
}

/* ---------- counters and tables (unifi) ---------- */

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
}
.stat { display: flex; flex-direction: column; }

/* Detail view: devices on one row, clients on the next, columns aligned. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 140px));
  gap: 12px 24px;
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.1;
}
.stat-label {
  color: var(--quiet);
  font-size: 0.85rem;
}

.table-wrap { overflow-x: auto; }
.device-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.device-table th,
.device-table td {
  padding: 6px 16px 6px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.device-table th { color: var(--quiet); font-weight: 600; }
.device-table .dev-name { font-weight: 600; }

.dev-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-transform: capitalize;
}
.dev-state::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}
.dev-state[data-state="online"]::before { background: var(--ok); }
.dev-state[data-state="offline"] { color: var(--crit); font-weight: 600; }
.dev-state[data-state="offline"]::before { background: var(--crit); }

/* ---------- internet traffic (unifi) ---------- */

.traffic-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  font-size: 0.9rem;
}
.traffic-values { font-weight: 600; white-space: pre; }

.device-table .num { text-align: right; }
.traffic-table { max-width: 520px; }
.traffic-table .usage-total { font-weight: 700; }
.traffic-table .usage-part { color: var(--quiet); }
.traffic-table tbody th { font-weight: 600; color: var(--ink); }

.traffic-chart { margin: 8px 0 0; }
.tbars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 120px;
  padding-bottom: 1px;
  border-bottom: 1px solid var(--line);
}
.tbar {
  position: relative;
  flex: 1 1 0;
  min-width: 4px;
  height: 100%;
}
.tbar-rx,
.tbar-tx {
  position: absolute;
  bottom: 0;
  height: var(--h, 0%);
  border-radius: 2px 2px 0 0;
}
.tbar-rx { left: 0; right: 0; background: var(--quiet); opacity: 0.5; }
.tbar-tx { left: 25%; right: 25%; background: var(--ink); opacity: 0.8; }
.tbar.today .tbar-rx { background: var(--ok); opacity: 0.7; }
.tbar:hover .tbar-rx { opacity: 0.8; }

.traffic-axis {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  color: var(--quiet);
  font-size: 0.8rem;
}
.traffic-legend { display: flex; gap: 14px; }
.key-rx::before,
.key-tx::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 2px;
  vertical-align: -1px;
}
.key-rx::before { background: var(--quiet); opacity: 0.45; }
.key-tx::before { background: var(--ink); opacity: 0.8; }

/* ---------- detail view ---------- */

.detail-view { margin-top: 20px; }

.detail-back {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--ink);
  text-decoration: none;
}
.detail-back:hover { text-decoration: underline; }

.detail-unit .unit-title { font-size: 1.35rem; }
.unit-title:focus { outline: none; }

.update-detail {
  display: grid;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.update-detail .detail-title { margin: 0; }

.update-error {
  margin: 0;
  color: var(--crit);
}

.update-items {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  columns: 3 180px;
  column-gap: 24px;
  font-size: 0.9rem;
}
.update-items li {
  padding: 2px 0;
  overflow-wrap: anywhere;
  break-inside: avoid;
}

.update-hint {
  margin: 4px 0 0;
  color: var(--quiet);
  font-size: 0.9rem;
}

code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

/* ---------- small screens ---------- */

@media (max-width: 560px) {
  .page { padding: 16px 12px 32px; }
  .unit { padding: 14px 14px 16px; }
  .unit-head { grid-template-columns: 1fr; }
  .unit-status { grid-column: 1; grid-row: auto; max-width: none; text-align: left; margin-top: 4px; }
}
