:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --accent: #2a78d6;
  --other: #b5b3ab;
  --good: #006300;
  --bad: #d03b3b;
  --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --s4:#eda100;
  --s5:#e87ba4; --s6:#008300; --s7:#4a3aa7; --s8:#e34948;
  --tip-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface-1: #1a1a19;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
    --accent: #3987e5; --other: #5a5955; --good: #0ca30c; --bad: #e66767;
    --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500;
    --s5:#d55181; --s6:#008300; --s7:#9085e9; --s8:#e66767;
    --tip-bg: #242423;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
  --accent: #3987e5; --other: #5a5955; --good: #0ca30c; --bad: #e66767;
  --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500;
  --s5:#d55181; --s6:#008300; --s7:#9085e9; --s8:#e66767;
  --tip-bg: #242423;
}
* { box-sizing: border-box; }
.limits-panel { margin-bottom: 18px; }
.limits-context { color: var(--text-secondary); font-size: 12px; margin-bottom: 8px; }
.limits-device { font-size: 13px; margin: 8px 0; }
.limits-panel .grid2 { align-items: stretch; margin-bottom: 0; }
.limits-card { display: flex; flex-direction: column; }
.limits-card h2 { margin-bottom: 12px; }
.limit-window + .limit-window { margin-top: 14px; }
.limit-heading, .limit-reset { display: flex; justify-content: space-between; gap: 6px 16px; flex-wrap: wrap; }
.limit-name { font-weight: 500; }
.limit-value { font-variant-numeric: tabular-nums; }
.limit-meter { height: 5px; background: var(--grid); margin: 7px 0; overflow: hidden; border-radius: 2px; }
.limit-fill { height: 100%; background: var(--accent); }
.limit-expired .limit-fill { background: var(--other); }
.limit-expired .limit-value, .limit-local-time { color: var(--text-secondary); }
.limit-reset { font-size: 12px; }
.limit-forecast { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.limit-observed { margin-top: auto; padding-top: 14px; }
.limit-when { display: inline-flex; align-items: center; gap: 6px; }
.limit-alarm { background: none; border: 0; padding: 0; margin: 0; line-height: 0; color: var(--text-secondary); cursor: pointer; }
.limit-alarm svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.limit-alarm:hover { background: none; color: inherit; }
.limit-alarm[aria-pressed="true"] { color: var(--accent); }
.limit-alarm[aria-pressed="true"] svg path:first-child { fill: currentColor; }
.limit-alarm:disabled { opacity: .35; cursor: default; }
.alarm { display: flex; align-items: center; gap: 14px; background: var(--accent); color: #fff; border-radius: 8px; padding: 10px 14px; margin: 6px 0 10px; font-size: 14px; }
.alarm button { background: #fff; color: var(--accent); border-color: #fff; font-weight: 600; }
.alarm button:hover { background: #fff; filter: brightness(0.95); }
.settings .checks.ring-choice { flex-direction: row; align-items: center; gap: 16px; flex-wrap: wrap; }
.settings .ring-choice input[type="radio"] { accent-color: var(--accent); margin: 0; }
.settings input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
.settings output { font-variant-numeric: tabular-nums; color: var(--text-secondary); font-size: 13px; min-width: 40px; text-align: right; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: 0 16px 48px;
}
.wrap { max-width: 1200px; margin: 0 auto; }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 22px 0 8px; }
header .brand { display: inline-flex; align-items: center; gap: 10px; }
header .logo { width: 34px; height: 34px; border-radius: 8px; }
header .app-version { font: 400 12px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text-muted); white-space: nowrap; }
header .update-note { font: 600 12px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--accent); background: none; border: 1px solid var(--accent); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
header .update-note:hover { background: var(--accent); color: #fff; }
/* Heading face: Blox by Brian Kent (freeware, readme kept in resources/blox). Uppercase glyphs slant one way, lowercase the other, so the heading is forced uppercase. */
@font-face {
  font-family: 'Blox BRK';
  src: url('../resources/blox/Blox2.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}
header h1 {
  font: normal 36px/1 'Blox BRK', system-ui, -apple-system, "Segoe UI", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0;
  position: relative; top: 1px;
  /* the 3D hatching is ~1px wide; put the heading on its own layer so Chromium uses
     grayscale antialiasing instead of subpixel (ClearType) colour fringes */
  transform: translateZ(0);
  will-change: transform;
}
header .sub { color: var(--text-secondary); font-size: 13px; }
/* the freshness lines: last scan, next automatic scan, last upload */
header .sub .sub-line { line-height: 1.4; }
header .sub .sub-line.bad { color: var(--bad); }
header .spacer { flex: 1; }
button, select, textarea, input[type="text"], input[type="number"], input[type="date"] {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px;
}
button { cursor: pointer; }
button:hover { background: var(--grid); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
/* theme toggle: shows the theme it switches to, a moon in light mode and a sun in dark */
#theme { padding: 5px 7px; line-height: 0; }
#theme svg { width: 16px; height: 16px; display: block; }
#theme .sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme .sun { display: block; }
  :root:not([data-theme="light"]) #theme .moon { display: none; }
}
:root[data-theme="dark"] #theme .sun { display: block; }
:root[data-theme="dark"] #theme .moon { display: none; }
.tabs { display: inline-flex; gap: 4px; }
.tabs button { color: var(--text-secondary); }
.tabs button[aria-pressed="true"] { color: var(--text-primary); border-color: var(--text-primary); font-weight: 600; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
.seg button { padding: 5px 11px; color: var(--text-secondary); }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
/* Rows are spaced by each group's top margin rather than a row gap, so the zero-height
   line break before Metric (.filters-line, inserted by app.js) costs no space. */
.filters { position: relative; display: flex; flex-wrap: wrap; gap: 0 14px; align-items: center; padding: 0 96px 18px 0; }
.filters > div { display: flex; flex-wrap: wrap; align-items: center; min-width: 0; margin-top: 10px; }
.filters > div[hidden] { display: none; }
.filters > .filters-line { flex-basis: 100%; height: 0; margin: 0; }
/* the Daily view's day picker: previous, the date, next */
.daypick { gap: 4px; }
.daypick button { padding: 4px 9px; font-size: 16px; line-height: 1; }
.daypick input[type="date"] { padding: 4px 8px; font-variant-numeric: tabular-nums; }
/* Refresh sits at the top right of the filter area, beside the first row, whatever wraps below it. */
.filters > .filters-end { position: absolute; right: 0; top: 0; } /* its 10px top margin places it beside the first row */
header .sub { min-width: 0; }
.filters label, .field > label { color: var(--text-muted); font-size: 12px; margin-right: 6px; text-transform: uppercase; letter-spacing: .04em; }
.status { border: 1px solid var(--border); background: var(--surface-1); border-radius: 8px; padding: 8px 12px; margin: 6px 0 10px; font-size: 13px; color: var(--text-secondary); }
.status.bad { border-color: var(--bad); color: var(--bad); }
.status .status-cancel { font-size: 12px; padding: 2px 8px; margin-left: 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tile .lbl { color: var(--text-secondary); font-size: 13px; }
.tile .val { font-size: 28px; font-weight: 600; line-height: 1.15; margin-top: 4px; }
.tile .note { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px 12px; margin-bottom: 16px; min-width: 0; }
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 2px; }
.card .desc { color: var(--text-muted); font-size: 12px; margin-bottom: 10px; }
.chart { width: 100%; overflow: visible; }
.chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 2px; font-size: 12px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.axis text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.grid line { stroke: var(--grid); stroke-width: 1; }
.grid line.divider { stroke: var(--axis); }
.baseline { stroke: var(--axis); stroke-width: 1; }
.bar { transition: opacity .12s; }
.hit { fill: transparent; cursor: default; }
.hit:hover { fill: rgba(128,128,128,0.08); }
.lbl-val { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.lbl-cat { fill: var(--text-primary); font-size: 12px; }
.marker line { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.marker text { fill: var(--text-muted); font-size: 10px; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line.today { stroke: var(--accent); }
.line.ref { stroke: var(--text-muted); stroke-dasharray: 4 3; }
.dot { fill: var(--accent); stroke: var(--surface-1); stroke-width: 2; }
.cross { stroke: var(--axis); stroke-width: 1; }
.note { color: var(--text-muted); font-size: 12px; margin-top: 8px; }
#tip {
  position: fixed; pointer-events: none; z-index: 10; display: none;
  background: var(--tip-bg); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.14);
  max-width: 280px;
}
#tip .t { color: var(--text-secondary); margin-bottom: 4px; }
#tip .r { display: flex; align-items: center; gap: 8px; margin: 2px 0; }
#tip .r b { font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
#tip .r i { width: 12px; height: 2px; display: inline-block; border-radius: 1px; }
#tip .r span { color: var(--text-secondary); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 7px; vertical-align: -1px; }
.tablewrap { overflow-x: auto; }
.muted { color: var(--text-muted); }
.empty { color: var(--text-muted); padding: 24px 0; text-align: center; }
.foot { color: var(--text-muted); font-size: 12px; line-height: 1.6; }
.foot code, .settings code { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; }
/* settings */
.settings #bk-list { margin-top: 12px; }
.settings #bk-list td button, .bk-preview button { font-size: 12px; margin-right: 6px; }
.bk-preview { margin-top: 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; }
.bk-preview h3 { margin: 0 0 4px; font-size: 14px; }
.bk-preview .tablewrap { margin: 10px 0; }
.bk-preview td.change-replace, .bk-preview td.change-add, .bk-preview td.change-remove { font-weight: 600; }
.bk-preview td.change-invalid { color: var(--bad); font-weight: 600; }
.bk-preview td.change-same { color: var(--text-muted); }
.settings .field { display: grid; grid-template-columns: 140px 1fr auto; gap: 8px; align-items: center; margin: 8px 0; }
.settings .field input[type="text"] { width: 100%; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.settings .hint { grid-column: 2 / 4; color: var(--text-muted); font-size: 12px; margin-top: -4px; }
.settings .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.settings table input[type="text"], .settings table input[type="number"] { width: 90px; padding: 3px 6px; font-size: 12.5px; text-align: right; }
.settings table input[type="text"].name { width: 180px; text-align: left; }
.settings td.model { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.settings .changed { border-color: var(--accent); }
.settings input[type="color"] { width: 32px; height: 24px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-1); cursor: pointer; vertical-align: middle; }
.settings input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.settings input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }
.settings td.model input[type="color"] { margin-right: 8px; }
.settings td > button:not([hidden]) + span { margin-left: 8px; }
.settings .checks { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 6px; }
.settings .checks label { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text-primary); }
.settings .checks input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.settings .checks label.off { color: var(--text-muted); }
.settings > .card > .hint { color: var(--text-muted); font-size: 12px; }
.settings .hint.bad { color: var(--bad); }
.settings .actions input[type="text"] { width: 240px; }
@media (max-width: 640px) { .settings .field { grid-template-columns: 1fr; } .settings .hint { grid-column: 1; } }

/* Desktop alarm actions */
.limit-action { font-size: 11px; padding: 2px 6px; }
.limit-warn { font-size: 11px; padding: 2px 4px; }
.alarm { flex-wrap: wrap; }
.action-banner .action-run, .action-dismiss { flex-basis: 100%; }
.action-dismiss { display: flex; justify-content: flex-end; }
.action-banner:empty { display: none; }
.action-run { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 7px 0; font-size: 12px; }
.action-run span { flex: 1; min-width: 180px; overflow-wrap: anywhere; }
.action-run button { font-size: 12px; white-space: nowrap; }
.action-dialog { width: min(620px, calc(100vw - 48px)); max-height: calc(100vh - 48px); overflow-y: auto; padding: 22px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1); color: var(--text-primary); }
.action-dialog::backdrop { background: rgba(0,0,0,.45); }
/* Close: an X floating over the top-right corner, quiet until hovered or focused */
.action-dialog .action-x { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; padding: 0; border-color: transparent; background: transparent; color: var(--text-muted); font-size: 22px; line-height: 1; border-radius: 8px; }
.action-dialog .action-x:hover, .action-dialog .action-x:focus-visible { background: var(--grid); border-color: var(--border); color: var(--text-primary); }
.action-dialog h2 { padding-right: 36px; }
.action-dialog h2 { margin: 0 0 8px; font-size: 18px; }
.action-dialog label { display: block; margin: 12px 0 5px; text-transform: none; letter-spacing: normal; color: var(--text-primary); font-size: 13px; }
.action-dialog .hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; overflow-wrap: anywhere; }
.action-dialog .hint.bad { color: var(--bad); }
.action-dialog textarea { width: 100%; resize: vertical; }
.action-dialog input[type="text"], .action-dialog select { width: 100%; min-width: 0; }
.action-dialog .action-check { display: flex; align-items: center; gap: 8px; }
.action-dialog input[type="checkbox"] { accent-color: var(--accent); }
.action-inline { display: flex; gap: 8px; margin: 10px 0; align-items: center; }
.action-inline input, .action-inline select { flex: 1; }
.action-inline button { flex-shrink: 0; }
@media (max-width: 640px) { .action-inline { flex-wrap: wrap; } }
.action-dialog input[type="time"], .action-dialog input[type="datetime-local"] { width: auto; }
.action-days { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0 4px; }
.action-days label { margin: 0; }
.schedule-row { border-top: 1px solid var(--border); }
.schedule-row .hint { font-size: 12px; color: var(--text-muted); }
.schedule-row .hint.bad { color: var(--bad); }
.schedule-name { font-size: 13.5px; }
