/* box-monitor — dark-first, with a selected light mode (not an auto flip).
   Palette roles are declared once here and referenced by role everywhere. */

:root {
  color-scheme: dark;

  --page:           #0d0d0d;
  --surface-1:      #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);

  /* Categorical slots — validated as a set against the dark surface. */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;

  /* Status palette — fixed, never themed, always paired with icon + label. */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;

  --page:           #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  /* Room for the iOS home indicator when installed. */
  padding-bottom: env(safe-area-inset-bottom);
}

/* --- chrome --- */

header.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--page);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

.topbar .sub {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  display: block;
  margin-top: 2px;
}

.iconbtn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  min-height: 34px;
}
.iconbtn:hover { color: var(--text-primary); }

main { padding: 16px; max-width: 900px; margin: 0 auto; }

.refreshing { opacity: 0.55; transition: opacity 120ms; }

/* --- banners --- */

.banner {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--surface-1);
}

/* --- alerts --- */

.alert-list { display: grid; gap: 8px; margin-bottom: 20px; }

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--sev, var(--warning));
  font-size: 13px;
}
.alert .who { font-weight: 600; }
.alert .what { color: var(--text-secondary); }

.sev-critical { --sev: var(--critical); }
.sev-serious  { --sev: var(--serious); }
.sev-warning  { --sev: var(--warning); }
.sev-good     { --sev: var(--good); }

/* --- section headings --- */

h2.section {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 24px 0 10px;
}
h2.section:first-child { margin-top: 0; }

/* --- app tiles --- */

.grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid { grid-template-columns: 1fr 1fr; } }

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--font);
  color: inherit;
}
.tile:hover { border-color: var(--text-muted); }

.tile-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.tile-name { font-size: 15px; font-weight: 600; flex: 1; }
.tile-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }

/* Status dot always ships beside a text label — never color alone. */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.status .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--sev, var(--text-muted));
  flex: none;
}

.tile-stats { display: flex; gap: 16px; margin-top: 10px; }
.stat .label {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 1px;
}
.stat .value { font-size: 15px; font-weight: 600; }

/* --- charts --- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 2px;
}
.card-title { font-size: 14px; font-weight: 600; flex: 1; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

.linkbtn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  padding: 4px 6px;
  min-height: 24px;
}
.linkbtn:hover { color: var(--text-primary); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }

svg.chart { display: block; width: 100%; overflow: visible; }
svg.chart text { font-family: var(--font); }

.small-multiples { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .small-multiples { grid-template-columns: 1fr 1fr; } }

/* --- table view (the accessible twin of every chart) --- */

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
table.data th, table.data td {
  text-align: right;
  padding: 5px 8px;
  border-bottom: 1px solid var(--gridline);
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--text-muted); font-weight: 500; }
.table-wrap { max-height: 260px; overflow: auto; }

/* --- uptime strip --- */

.strip { display: flex; gap: 2px; height: 26px; align-items: stretch; }
.strip i { flex: 1; border-radius: 2px; background: var(--seg, var(--text-muted)); }

/* --- login --- */

.login {
  max-width: 320px;
  margin: 18vh auto 0;
  padding: 24px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.login h1 { font-size: 18px; margin: 0 0 4px; }
.login p { font-size: 13px; color: var(--text-muted); margin: 0 0 18px; }
.login input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 16px; /* 16px avoids iOS zoom-on-focus */
  font-family: var(--font);
  margin-bottom: 10px;
}
.login button {
  width: 100%;
  padding: 11px;
  border-radius: 8px;
  border: none;
  background: var(--series-1);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
}
.login .error { color: var(--critical); font-size: 13px; margin-top: 10px; }

.empty { color: var(--text-muted); font-size: 13px; padding: 18px 0; text-align: center; }

/* --- tooltip --- */

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 90ms;
}
.tooltip.on { opacity: 1; }
.tooltip .tt-time { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-key { width: 10px; height: 2px; border-radius: 1px; }
.tooltip .tt-val { font-variant-numeric: tabular-nums; font-weight: 600; }
