/* PathGuard monitoring pages (overview, routers, router, changes, events, admin, sign-in).
   Builds on the tokens and components of app.css; no inline styles anywhere (CSP).
   Calm and dense: small type for numbers, colour only for state. Colours come from the CSS variables
   only, so the light and the dark theme both work. */

/* Grids that never overflow a 320 px phone (app.css uses fixed minimums) */
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.grid-cards, .rgrid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(310px, 100%), 1fr)); }

/* Text helpers */
.txt-ok { color: var(--ok); }
.txt-bad { color: var(--down); }
.txt-warn { color: var(--warn); }
.txt-drained { color: var(--drained); }
.sans { font-family: var(--font-body); }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.page-head h1 { overflow-wrap: anywhere; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; flex-wrap: wrap; }
select.compact { width: auto; padding: 4px 8px; font-size: .82rem; }
.flash.info { background: var(--accent-soft); }
.flash.small { font-size: .8rem; padding: 7px 10px; }
.empty.card { padding: 28px 16px; }

/* ------------------------------------------------------------------ overview */
.ov-top { gap: 10px; }

/* KPI strip (app.css .kpis/.kpi): linked tiles, state tones, compact on phones. Separators are drawn by
   each tile (not by the grid background), so an incomplete last row leaves blank surface, not a grey block. */
.ov-kpis { grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); background: var(--surface); }
/* routers table on phones: keep the router column readable, the table scrolls sideways in .table-wrap */
.rtable td:first-child { min-width: 170px; }
.ov-kpis .kpi { --kpi-accent: transparent; align-content: start; min-width: 0;
  box-shadow: -1px 0 0 var(--line), 0 -1px 0 var(--line), -1px -1px 0 var(--line), inset 0 -3px 0 var(--kpi-accent); }
a.kpi { color: var(--ink); text-decoration: none; position: relative; }
a.kpi:hover { background: var(--surface-2); text-decoration: none; }
a.kpi:focus-visible { outline-offset: -2px; }
.kpi .kpi-sub { font-style: normal; white-space: nowrap; }
.kpi.t-ok b { color: var(--ok); }
.kpi.t-warn b { color: var(--warn); }
.kpi.t-bad b { color: var(--bad); }
.kpi.t-down b { color: var(--down); }
.kpi.t-drained b { color: var(--drained); }
.ov-kpis .kpi.t-bad, .ov-kpis .kpi.t-down { --kpi-accent: var(--down-soft); }
.ov-kpis .kpi.t-drained { --kpi-accent: var(--drained-soft); }

/* Status line above the overview cards */
.statusline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .84rem; }
.statusline .sep { width: 1px; height: 16px; background: var(--line); margin: 0 4px; }
.statusline .push { margin-left: auto; }
.strip-text { flex: 1 1 260px; min-width: 0; overflow-wrap: anywhere; font-size: .86rem; }

/* Toolbar (filters live outside the refreshed region) */
.ov-toolbar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }

/* Kill switch control (a <details> so the form needs no script) */
.killctl { position: relative; }
.killctl summary { list-style: none; }
.killctl summary::-webkit-details-marker { display: none; }
.killctl[open] summary { background: var(--surface-2); }
.killform { position: absolute; right: 0; top: calc(100% + 6px); width: min(380px, calc(100vw - 32px)); z-index: 15; box-shadow: var(--shadow); }

/* Region groups */
.ov-regions { display: grid; gap: 20px; }
.region-group { display: grid; gap: 10px; min-width: 0; }
.region-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.region-head h2 { display: inline-flex; align-items: center; gap: 8px; font-size: 1rem; }
.region-head h2 .ico { width: 16px; height: 16px; color: var(--muted); }
.region-head .meta { color: var(--muted); font-size: .8rem; }
.region-head .push { margin-left: auto; }

/* Router cards (overview) */
.rcard { gap: 8px; }
.rcard.sev-ok { box-shadow: inset 3px 0 0 var(--ok); }
.rcard.sev-warn { box-shadow: inset 3px 0 0 var(--warn); }
.rcard.sev-bad { box-shadow: inset 3px 0 0 var(--bad); }
.rcard.sev-down { box-shadow: inset 3px 0 0 var(--down); }
.rcard.sev-drained { box-shadow: inset 3px 0 0 var(--drained); }
.rcard.sev-off { box-shadow: inset 3px 0 0 var(--line); }
.rcard-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.rcard-h .row { gap: 6px; }
.rname { font: 700 .92rem var(--font-mono); color: var(--ink); overflow-wrap: anywhere; }
.rcard.is-stale { border-color: var(--warn); }
.rcard.is-disabled { opacity: .65; }
.stale-note { background: var(--warn-soft); color: var(--ink); border-radius: 7px; padding: 5px 9px; font-size: .78rem; }
.ublock { display: grid; gap: 2px; }
.unote { color: var(--muted); font-size: .74rem; line-height: 1.4; padding-left: 2px; overflow-wrap: anywhere; }
.egress { white-space: normal; }
.egress + .egress::before { content: " · "; }
.card-foot > span { min-width: 0; }

/* Sparkline: worst upstream loss, last hour */
.spark { width: 100%; height: 34px; display: block; }
.spark .ln { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark .ln.bad { stroke: var(--bad); }
.spark .th { stroke: var(--bad); stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; vector-effect: non-scaling-stroke; }
.spark-empty { height: 34px; display: grid; place-items: center; color: var(--muted); font-size: .74rem; border: 1px dashed var(--line); border-radius: 6px; }

/* Bottom of the overview: providers + alerts side by side, last changes full width */
.ov-bottom { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); }
.ov-bottom .ov-changes { grid-column: 1 / -1; }
.ptable td { vertical-align: middle; }

/* Alerts and compact lists */
.alerts { list-style: none; margin: 0; padding: 0; display: grid; }
.alerts li { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 8px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: .84rem; }
.alerts li:last-child { border-bottom: 0; }
.alert-msg { overflow-wrap: anywhere; }
.table-wrap.mini table { font-size: .8rem; }
.table-wrap.mini th { font-size: .64rem; padding: 6px 10px; }
.table-wrap.mini td { padding: 6px 10px; }

/* ------------------------------------------------------------------ router list */
.rtable td { vertical-align: top; }
.rtable tbody tr.sev-bad td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.rtable tbody tr.sev-down td:first-child { box-shadow: inset 3px 0 0 var(--down); }
.rtable tbody tr.sev-drained td:first-child { box-shadow: inset 3px 0 0 var(--drained); }
.rtable tbody tr.sev-warn td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.rtable tr.group-row td { padding-block: 7px; }
.rtable tr.group-row:hover { background: none; }
.grp { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.grp .ico { width: 15px; height: 15px; color: var(--muted); }
.grp .muted { font-weight: 500; }
.uline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 1px 0; }
.uline .nm { font-weight: 600; min-width: 52px; }

/* ------------------------------------------------------------------ router page */
.hdr-region { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hdr-region .ico { width: 14px; height: 14px; }
.region-link { font-weight: 600; }
.hdr-actions .btn .ico { width: 15px; height: 15px; }
.upanels { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); }
.upanel.is-disabled { opacity: .7; }
.upanel .card-head h3 { font-size: 1.02rem; }
.uprofile { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 8px; align-items: baseline; font-size: .8rem; margin-top: -4px; }
.uprofile .lbl { font: 650 .64rem var(--font-body); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.uprofile > span:last-child { overflow-wrap: anywhere; }
.uprofile .badge { margin-left: 2px; }
.uhead-live { display: grid; gap: 4px; }
.uhead-live .row { gap: 6px; }
.uhead-live .mt { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; margin-left: auto; }
.reasons { margin: 0; padding-left: 1.1em; color: var(--muted); font-size: .76rem; }
.ubody { display: grid; gap: 8px; min-width: 0; }
.ufacts { display: grid; gap: 4px; font-size: .8rem; }
.ufact { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; align-items: baseline; }
.ufact .lbl { font: 650 .64rem var(--font-body); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ufact > span:last-child { overflow-wrap: anywhere; }
.ubar { width: 100%; height: 6px; display: block; }
.ubar-bg { fill: var(--surface-2); }
.ubar-fg { fill: var(--ok); }
.ubar-fg.warm { fill: var(--warn); }
.ubar-fg.hot { fill: var(--down); }
.chart-box.short { height: 120px; }
.chart-empty { display: grid; place-items: center; height: 72px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: .8rem; text-align: center; padding: 8px; }

/* "Why" panel */
.why .why-kv { font-size: .84rem; }
.why-sub { display: grid; gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; }
.why-sub .plain-list { font-size: .84rem; }
.blocked li::before { content: "⏸ "; color: var(--warn); }
.notes li::before { content: "· "; color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; font-size: .82rem; }
.timeline li { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 8px; align-items: baseline; }

/* Confirmation (drain / restore / freeze / unfreeze) */
.confirm { border: 2px solid var(--accent); box-shadow: var(--shadow); scroll-margin-top: 72px; }
.confirm h2 { font-size: 1.1rem; }
.confirm-form { max-width: none; }
pre.code .dim { color: var(--code-dim); }

/* Actions */
.act-list { display: grid; gap: 6px; }
.act-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.act-row .nm { font-weight: 600; min-width: 70px; }

/* Command progress */
.cmd-status { border-left: 4px solid var(--warn); }
.cmd-status.done { border-left-color: var(--line); }
.cmd-status .working::after { content: " …"; }
.cmd-status h3 { font-size: .95rem; }

/* Diff and code */
.diff .hdr { color: var(--code-dim); }
.secret { border: 2px solid var(--warn); }
.secret-value { white-space: pre-wrap; word-break: break-all; user-select: all; }

/* ------------------------------------------------------------------ changes, events */
.filters { grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); align-items: end; gap: 10px 12px; padding: 12px 14px; }
.filters .field label { font-size: .76rem; }
.filters select, .filters input { padding: 5px 8px; font-size: .84rem; }
.filter-btns { align-self: end; padding-bottom: 1px; }
.filter-help { grid-column: 1 / -1; color: var(--muted); font-size: .74rem; }
.etable td.msg { min-width: 240px; overflow-wrap: anywhere; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; }

/* Admin */
.utable td { vertical-align: middle; }
.test-notify { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }

/* Sign-in and account */
.login-card { gap: 14px; padding: 22px 22px 18px; }
.login-brand { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.login-card .form .btn { width: 100%; }
.account-card { max-width: 560px; }

@media (max-width: 640px) {
  .ov-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi { padding: 9px 10px; }
  .kpi b { font-size: 1.15rem; }
  .kpi .kpi-sub { display: block; white-space: normal; }
  .statusline .push { margin-left: 0; width: 100%; }
  .statusline .sep { display: none; }
  .killctl { width: 100%; }
  .killform { position: static; width: 100%; margin-top: 8px; }
  .region-head .push { margin-left: 0; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }
  .alerts li { grid-template-columns: auto minmax(0, 1fr); }
  .alerts li .alert-msg { grid-column: 1 / -1; }
  .uhead-live .mt { margin-left: 0; width: 100%; }
  .chart-box { height: 160px; }
  .filters .field.dt { grid-column: 1 / -1; }
  .toolbar .count { margin-left: 0; }
}
