/* ThermoCam Fleet Manager */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8fafb;
  --line: #e1e6eb;
  --text: #152230;
  --muted: #5f6f80;
  --faint: #8a98a6;
  --brand: #1f8f73;
  --brand-strong: #17735c;
  --brand-soft: #e3f5ef;
  --ok: #1e9e5a;
  --ok-soft: #e4f6ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --crit: #c53030;
  --crit-soft: #fdeaea;
  --info: #2b6cb0;
  --info-soft: #e8f1fb;
  --offline: #8a98a6;
  /* The fleet cards' status corner (white text on all three). */
  --corner-online: #1a8a4e;
  --corner-offline: #6b7a89;
  --corner-down: #c53030;
  --chart: #1f8f73;
  --chart-2: #9fd8c8;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 2px 8px rgba(16, 32, 48, .05);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
/* Dark: data-theme is set by theme.js (saved choice, else the system's). */
:root[data-theme="dark"] {
  --bg: #0d1620;
  --panel: #142130;
  --panel-2: #192838;
  --line: #26384b;
  --text: #e6edf3;
  --muted: #9fb0c0;
  --faint: #6f8294;
  --brand: #3dd8b0;
  --brand-strong: #5ee6c2;
  --brand-soft: #143a33;
  --ok: #4ade80;
  --ok-soft: #133524;
  --warn: #f6c35b;
  --warn-soft: #3a2e14;
  --crit: #f87171;
  --crit-soft: #3d1a1d;
  --info: #7cb4f0;
  --info-soft: #172c44;
  --offline: #6f8294;
  --corner-online: #1f8a50;
  --corner-offline: #4d5f71;
  --corner-down: #c53030;
  --chart: #3dd8b0;
  --chart-2: #1f6b5a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 14px; }

/* --- buttons and inputs ----------------------------------------------------- */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); padding: 7px 12px; line-height: 1.2;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover { border-color: var(--faint); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--brand-strong); }
:root[data-theme="dark"] button.primary { color: #062018; }
button.danger { color: var(--crit); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--panel-2); }
button.small { padding: 4px 8px; font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
textarea { width: 100%; min-height: 80px; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.field input, label.field select, label.field textarea { font-size: 14px; font-weight: 400; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; color: var(--muted); }
/* Password with a show/hide button inside the field. */
.password { position: relative; display: grid; }
.password input { width: 100%; padding-right: 40px; }
.password .reveal { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); padding: 5px; }
.reveal svg { width: 18px; height: 18px; display: block; }
.reveal .eye-off, .reveal[aria-pressed="true"] .eye { display: none; }
.reveal[aria-pressed="true"] .eye-off { display: block; }

/* --- login ------------------------------------------------------------------ */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.login .brand { margin-bottom: 18px; }
.login form { display: grid; gap: 14px; }
.login button.primary { justify-content: center; padding: 10px; }
.error-text { color: var(--crit); font-size: 13px; min-height: 18px; }

/* --- shell ------------------------------------------------------------------ */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
a.brand { color: var(--text); border-radius: 8px; }
a.brand:hover { text-decoration: none; color: var(--brand); }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--brand);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px;
}
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 56px;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: var(--muted); padding: 7px 12px; border-radius: 7px; font-weight: 600;
}
.topbar nav a:hover { text-decoration: none; background: var(--panel-2); color: var(--text); }
.topbar nav a.active { color: var(--brand); background: var(--brand-soft); }
.topbar .user { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.user-menu { position: relative; }
.user-menu .who { color: var(--text); font-weight: 600; max-width: 220px; }
.user-menu .who.active { color: var(--brand); }
.user-menu .who-name { overflow: hidden; text-overflow: ellipsis; }
.user-menu .who svg { width: 16px; height: 16px; flex: none; transition: transform .12s ease; }
.user-menu .who[aria-expanded="true"] svg { transform: rotate(180deg); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 170px; z-index: 30; padding: 5px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
  display: grid; gap: 2px;
}
.menu-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); font-weight: 500;
}
.menu-item:hover, .menu-item.active { background: var(--panel-2); text-decoration: none; }
/* Sun while dark (switches to bright), half moon while bright. */
.theme-toggle { padding: 5px; }
.theme-toggle svg { width: 18px; height: 18px; display: block; }
.theme-toggle .moon, :root[data-theme="dark"] .theme-toggle .sun { display: block; }
.theme-toggle .sun, :root[data-theme="dark"] .theme-toggle .moon { display: none; }
.login-wrap > .theme-toggle { position: fixed; top: 12px; right: 16px; }
main { max-width: 1440px; margin: 0 auto; padding: 20px; }
@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 10px; height: auto; min-height: 56px; flex-wrap: wrap; }
  .topbar nav a { padding: 6px 8px; }
  .user-menu .who { max-width: 130px; }
  main { padding: 16px; }
}

/* --- panels and tiles ------------------------------------------------------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.panel > h2, .panel > .panel-head { margin-bottom: 12px; }
.panel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { margin-right: auto; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.tile .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.tile.crit { border-color: var(--crit); background: var(--crit-soft); }
.tile.warn { border-color: var(--warn); background: var(--warn-soft); }
.tile.ok .value { color: var(--ok); }
/* Tiles that open something: a page, or a history chart. */
.tile.link { cursor: pointer; color: inherit; display: block; transition: border-color .1s ease, box-shadow .1s ease; }
.tile.link:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(16, 32, 48, .1); text-decoration: none; }
.tile.link:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* --- pills ------------------------------------------------------------------ */
.pill {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px;
  font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warning, .pill.amber { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.critical, .pill.red { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.pill.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.pill.green { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--offline); flex: none; }
.dot.ok, .dot.green { background: var(--ok); }
.dot.warning, .dot.amber { background: var(--warn); }
.dot.critical, .dot.red { background: var(--crit); }
.dot.info { background: var(--info); }
.dot.pulse { box-shadow: 0 0 0 0 rgba(30, 158, 90, .5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 6px rgba(30, 158, 90, 0); } 100% { box-shadow: 0 0 0 0 rgba(30, 158, 90, 0); } }

/* --- fleet ------------------------------------------------------------------ */
.summary { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 16px; }
.summary .tile { cursor: pointer; }
.summary .tile.active { outline: 2px solid var(--brand); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { width: 240px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); cursor: pointer;
}
.chip.active { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 10px;
  border-left: 4px solid var(--ok); transition: transform .08s ease, box-shadow .08s ease; color: inherit;
}
.card:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(16, 32, 48, .1); text-decoration: none; }
.card.warning { border-left-color: var(--warn); }
.card.critical { border-left-color: var(--crit); }
.card.offline { border-left-color: var(--offline); background: var(--panel-2); }
.card.offline .card-body { opacity: .55; filter: grayscale(1); }
.card-top { display: flex; align-items: flex-start; gap: 8px; }
.card-title { font-size: 16px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--muted); }
/* Connection status in the card's top right corner; "seen …" stays below it. */
.card-status { margin: -14px -16px 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.card-status > .small { padding-right: 16px; }
.status-corner {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px 7px; border-radius: 0 11px 0 10px;
  font-size: 13px; font-weight: 700; color: #fff; background: var(--corner-offline); white-space: nowrap;
}
.status-corner.online { background: var(--corner-online); }
.status-corner.down { background: var(--corner-down); }
.status-corner .dot.live { background: #fff; box-shadow: 0 0 0 0 rgba(255, 255, 255, .6); animation: pulse-white 2s infinite; }
@keyframes pulse-white { 70% { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); } }
.card-issue {
  font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 7px; display: flex; gap: 6px; align-items: center;
}
.card-issue.critical { background: var(--crit-soft); color: var(--crit); }
.card-issue.warning { background: var(--warn-soft); color: var(--warn); }
.card-issue.info { background: var(--info-soft); color: var(--info); }
.card-issue .more { margin-left: auto; font-weight: 500; opacity: .8; white-space: nowrap; }
.card-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; }
.metric .k { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .03em; }
.metric .v { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.card-foot { display: flex; align-items: flex-end; gap: 10px; font-size: 12px; color: var(--muted); }
.card-foot svg { margin-left: auto; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }

/* --- device page ------------------------------------------------------------ */
.device-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.device-head .crumb { color: var(--muted); }
.device-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a {
  padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count {
  margin-left: 5px; font-size: 11px; background: var(--crit-soft); color: var(--crit); border-radius: 999px; padding: 1px 6px;
}
.issue-list { display: grid; gap: 8px; }
.issue {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: start; padding: 10px 12px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2);
}
.issue.critical { border-color: var(--crit); background: var(--crit-soft); }
.issue.warning { border-color: var(--warn); background: var(--warn-soft); }
.issue.acked { opacity: .55; }
.issue .title { font-weight: 650; }
.issue .detail { grid-column: 2; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.issue .dot { margin-top: 6px; }

/* --- tables ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel);
  position: sticky; top: 0;
}
table.data th.sortable { cursor: pointer; }
table.data th.sorted::after { content: " \25BE"; }
table.data th.sorted.asc::after { content: " \25B4"; }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--panel-2); }
table.data tr.selected td { background: var(--brand-soft); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.detail-row > td { background: var(--panel-2); padding: 14px; }

/* --- measurements browser --------------------------------------------------- */
.selection-bar {
  position: sticky; top: 56px; z-index: 10; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}
.selection-bar .count { font-weight: 650; }
.hands { display: flex; gap: 6px; flex-wrap: wrap; }
.hand-badge {
  display: inline-flex; gap: 4px; align-items: center; border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 6px; font-size: 12px; background: var(--panel);
}
.hand-badge.bad { border-color: var(--warn); color: var(--warn); }
.hand-badge.partner { opacity: .55; border-style: dashed; }
.files { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.files .file-row {
  display: grid; grid-template-columns: 24px 22px 1fr auto auto auto; gap: 8px; align-items: center;
  padding: 5px 10px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.files .file-row:last-child { border-bottom: 0; }
.files .file-row .name { overflow-wrap: anywhere; }
.files .file-row .name.link { cursor: pointer; color: var(--brand); }
.files .file-row.indent-1 { padding-left: 34px; }
.files .file-row.indent-2 { padding-left: 58px; }
.files .file-row.indent-3 { padding-left: 82px; }
.crumbs { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.crumbs a { cursor: pointer; }
.checks-list { display: grid; gap: 4px; font-size: 13px; }
.checks-list .chk { display: flex; gap: 8px; align-items: baseline; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.thumbs figure { margin: 0; font-size: 11px; color: var(--muted); }
.thumbs img { width: 100%; border-radius: 6px; border: 1px solid var(--line); display: block; cursor: zoom-in; }

/* --- logs ------------------------------------------------------------------- */
pre.log {
  background: #0b1219; color: #d7e2ec; border-radius: 8px; padding: 12px; margin: 0; overflow: auto;
  max-height: 65vh; white-space: pre-wrap; word-break: break-word; line-height: 1.5;
}
pre.log .l-error { color: #ff8b8b; }
pre.log .l-warn { color: #f6c35b; }
pre.log .l-ok { color: #6ee7b7; }
pre.block {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0;
  overflow: auto; max-height: 360px; white-space: pre;
}

/* --- charts ----------------------------------------------------------------- */
.chart { display: block; overflow: visible; }
.chart.natural { max-width: 100%; height: auto; }
.chart-box { width: 100%; min-height: 20px; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .axis { stroke: var(--line); }
.chart .grid { stroke: var(--line); stroke-dasharray: 2 3; }
.chart .bar { fill: var(--chart); }
.chart .bar.dim { fill: var(--chart-2); }
.chart .bar:hover { opacity: .8; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; }
.chart .line.forecast { stroke-dasharray: 5 4; }
.chart .band { fill: var(--chart); opacity: .14; }
.chart .today { stroke: var(--faint); stroke-dasharray: 3 3; }
/* Vitals: one chart each, separated by a line; a click opens the history. */
.vital { cursor: pointer; border-radius: 6px; }
.vital + .vital { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.vital > .small { display: flex; gap: 8px; }
.vital-open { margin-left: auto; color: var(--brand); opacity: 0; transition: opacity .1s ease; }
.vital:hover .vital-open, .vital:focus-visible .vital-open { opacity: 1; }
.vital:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
/* History explorer (Charts.explorer). */
.explorer { outline: none; border-radius: 8px; }
.explorer:focus-visible { outline: 2px solid var(--brand); outline-offset: 4px; }
.explorer-readout {
  display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: baseline; min-height: 38px; margin-bottom: 10px;
  padding: 8px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; font-variant-numeric: tabular-nums;
}
.explorer-readout .time { font-weight: 650; min-width: 210px; }
.explorer-readout b { font-size: 15px; }
.explorer-readout b.yes { color: var(--ok); }
.explorer-readout b.no { color: var(--crit); }
.chart text.label { fill: var(--text); font-weight: 600; font-size: 12px; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart .cross.pinned { stroke: var(--text); stroke-dasharray: none; }
.chart .marker { fill: var(--chart); stroke: var(--panel); stroke-width: 2; pointer-events: none; }
.chart .state-yes { fill: var(--ok); }
.chart .state-no { fill: var(--crit); }
.chart .state-none { fill: var(--panel-2); stroke: var(--line); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; background: var(--chart); }
.legend .dashed::before { background: transparent; border-top: 2px dashed var(--chart); height: 0; width: 14px; vertical-align: 3px; }
.legend .band::before { opacity: .25; }
.meter { height: 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; }
.meter > div { height: 100%; background: var(--brand); }
.meter.warn > div { background: var(--warn); }
.meter.crit > div { background: var(--crit); }

/* --- modal, toast ----------------------------------------------------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(8, 16, 24, .55); z-index: 50; display: grid; place-items: center; padding: 16px;
}
.modal {
  background: var(--panel); border-radius: 14px; border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
  width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; padding: 22px;
}
.modal.wide { max-width: 980px; }
.modal h2 { margin-bottom: 14px; }
.modal .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal img.full { max-width: 100%; border-radius: 8px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 9px; box-shadow: var(--shadow);
  font-size: 13px; max-width: 380px;
}
.toast.error { background: var(--crit); color: #fff; }
.secret {
  font-family: var(--mono); font-size: 18px; padding: 10px 12px; background: var(--brand-soft); border-radius: 8px;
  user-select: all; overflow-wrap: anywhere;
}
.json-tree { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.json-tree details { margin-left: 14px; }
.json-tree summary { cursor: pointer; margin-left: -14px; }
.json-tree .k { color: var(--info); }
.json-tree .s { color: var(--ok); }
.json-tree .n { color: var(--warn); }
.json-tree .b { color: var(--crit); }
.thermal-wrap { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.thermal-wrap canvas.frame { image-rendering: pixelated; width: 480px; max-width: 100%; border-radius: 8px; cursor: crosshair; }
.thermal-wrap canvas.scale { width: 18px; height: 360px; border-radius: 4px; }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Connect tab, journal, thermal viewer */
.row.stretch { align-items: stretch; flex-wrap: nowrap; }
.row.wrap { flex-wrap: wrap; }
input.narrow { width: 80px; }
a.btn { display: inline-block; text-decoration: none; color: inherit; }
.scale-labels { display: flex; flex-direction: column; justify-content: space-between; }
.thermal-viewer { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.tv-image { position: relative; width: 730px; max-width: 100%; min-width: 0;
  padding-right: 90px; box-sizing: border-box; }
.tv-image canvas.frame { display: block; width: 100%; max-width: 100%; height: auto;
  aspect-ratio: 4 / 3; image-rendering: pixelated; border-radius: 8px; cursor: crosshair; }
/* Keep the legend out of intrinsic canvas sizing: its height follows the image. */
.tv-scale { position: absolute; top: 0; bottom: 0; right: 0; width: 80px;
  display: flex; gap: 8px; align-items: stretch; }
.tv-image canvas.scale { display: block; width: 18px; height: 100%; min-height: 0;
  flex: 0 0 18px; border-radius: 4px; }
.tv-scale .scale-labels { min-width: 0; white-space: nowrap; }
.tv-side { flex: 1; min-width: min(260px, 100%); }
.tv-side > * + * { margin-top: 12px; }
.rgb-view { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.rgb-view img { width: 720px; max-width: 100%; }
.rgb-side { flex: 1; min-width: 240px; }
.rgb-side > * + * { margin-top: 12px; }
.shot-options { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
img.full { max-width: 100%; display: block; }
.spots { display: flex; gap: 6px; flex-wrap: wrap; }
img.test-rgb { cursor: zoom-in; border-radius: 8px; }
.vnc-screen { height: 72vh; background: #000; border-radius: 8px; overflow: hidden; margin-top: 10px; }
.vnc-screen:fullscreen { height: 100vh; border-radius: 0; }
.card-live { padding: 0 14px 8px; gap: 6px; }
.journal-entry { padding: 10px 0; border-bottom: 1px solid var(--line); }
.journal-entry:last-child { border-bottom: 0; }
.journal-text { white-space: pre-wrap; margin-top: 4px; }
.panel.inner { box-shadow: none; background: var(--panel-2, var(--panel)); }
.sw-list { max-height: 360px; overflow-y: auto; }
tr.pickable { cursor: pointer; }
tr.picked td { background: var(--brand-soft); }

/* --- system banner and alerts (admin) ----------------------------------------- */
.sys-banner {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; padding: 10px 14px;
  border-radius: var(--radius); border: 1px solid var(--warn); background: var(--warn-soft); color: var(--text);
}
.sys-banner.critical { border-color: var(--crit); background: var(--crit-soft); }
.sys-banner:hover { text-decoration: none; }
.sys-banner .go { margin-left: auto; color: var(--brand); font-weight: 600; }
.rules { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
td.pre { white-space: pre-wrap; }

/* --- roles (admin › users) -------------------------------------------------- */
.grants { display: flex; flex-wrap: wrap; gap: 6px; }
.grant {
  font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--faint);
  background: var(--panel-2);
}
.grant.yes { color: var(--ok); background: var(--ok-soft); border-color: transparent; text-decoration: none; font-weight: 600; }
table.data th.center, table.data td.center { text-align: center; }
table.roles .yes { color: var(--ok); font-weight: 700; font-size: 15px; }
table.roles td:first-child { min-width: 240px; }

/* --- audit log (admin) ------------------------------------------------------ */
.audit-cloud { display: grid; gap: 8px; }
.audit-group { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.audit-topic {
  min-width: 130px; justify-content: flex-start; padding: 4px 8px; font-size: 12px; font-weight: 700;
  background: transparent; border-color: transparent; color: var(--faint); text-transform: uppercase; letter-spacing: .04em;
}
.audit-topic.on { color: var(--text); }
.audit-chip { font-size: 12px; padding: 3px 10px; display: inline-flex; gap: 6px; align-items: center; color: var(--faint); }
.audit-chip .n { font-weight: 500; color: var(--faint); font-variant-numeric: tabular-nums; }
.audit-chip.active.info { background: var(--info-soft); color: var(--info); border-color: var(--info); }
.audit-chip.active.amber { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.audit-chip.active.green { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.audit-chip.active.brand { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.audit-chip.active:not(.info):not(.amber):not(.green):not(.brand) { background: var(--panel-2); color: var(--text); border-color: var(--faint); }
.audit-chip.zero .n { opacity: .5; }
.chart .bar-hit { fill: transparent; cursor: pointer; }
.chart .bar.hover { opacity: .75; }
td a { cursor: pointer; }
