/* ProxyPanel UI. No inline styles anywhere (CSP style-src 'self'): every visual lives here.
   Themes: light by default, dark via prefers-color-scheme, both from the same tokens.
   Status is never colour-only: badges carry text and a shape (circle ok, diamond warn,
   square crit). Chart series use validated categorical slots 1-2 (blue, orange). */

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e5e8ed;
  --border: #dde1e7;
  --border-strong: #c3cad4;
  --text: #151a21;
  --text-2: #424b58;
  --text-3: #5b6472;
  --accent: #1f5fd6;
  --accent-hover: #184dae;
  --accent-soft: #e7eefc;
  --accent-contrast: #ffffff;
  --focus: #1f5fd6;
  --ok: #146c2e;
  --ok-bg: #e5f4e9;
  --ok-border: #b3dcbf;
  --warn: #8a5100;
  --warn-bg: #fff3dc;
  --warn-border: #efcf94;
  --crit: #b3261e;
  --crit-bg: #fde9e7;
  --crit-border: #f1bab4;
  --info: #1f5fd6;
  --info-bg: #e8effc;
  --info-border: #bdd0f4;
  --muted-fg: #4c5563;
  --muted-bg: #eceff3;
  --muted-border: #d6dbe2;
  --danger-bg: #c4302b;
  --danger-bg-hover: #a82823;
  --danger-fg: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --diff-add-bg: #e6f4ea;
  --diff-del-bg: #fdeaea;
  --scrim: rgb(12 16 22 / 45%);
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 7%);
  --shadow-lg: 0 16px 40px rgb(16 24 40 / 20%);
  --radius: 10px;
  --radius-sm: 7px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Cascadia Code", Consolas, "Liberation Mono", Menlo, monospace;
  --sidebar-w: 232px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1116;
    --surface: #161a20;
    --surface-2: #1c2128;
    --surface-3: #252b34;
    --border: #2b323c;
    --border-strong: #3c4550;
    --text: #e8ebef;
    --text-2: #bcc3cd;
    --text-3: #9aa3af;
    --accent: #72a6ff;
    --accent-hover: #8fb8ff;
    --accent-soft: #1b2944;
    --accent-contrast: #0a1322;
    --focus: #8fb8ff;
    --ok: #74d38f;
    --ok-bg: #12301c;
    --ok-border: #245436;
    --warn: #f3c552;
    --warn-bg: #3a2c0b;
    --warn-border: #5f4812;
    --crit: #ff8f85;
    --crit-bg: #3d1614;
    --crit-border: #6c2621;
    --info: #8fb8ff;
    --info-bg: #15223a;
    --info-border: #29426f;
    --muted-fg: #bcc3cd;
    --muted-bg: #232932;
    --muted-border: #343c47;
    --danger-bg: #f08b82;
    --danger-bg-hover: #f6a39c;
    --danger-fg: #230907;
    --series-1: #3987e5;
    --series-2: #d95926;
    --diff-add-bg: #12301c;
    --diff-del-bg: #3d1614;
    --scrim: rgb(0 0 0 / 60%);
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 16px 40px rgb(0 0 0 / 55%);
  }
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; }
h3 { font-size: 15px; margin: 16px 0 8px; }
p { margin: 0 0 8px; }
p:last-child { margin-bottom: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
ul, ol { padding-left: 20px; }
img { max-width: 100%; }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only, .sr-only-submit {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.skip-link:focus, .skip-link:focus-visible { top: 12px; }

.muted { color: var(--text-3); }
.small { font-size: 13px; }
.block { display: block; }
.link { font-weight: 550; }
.nowrap { white-space: nowrap; }
/* One-line value cut with an ellipsis; the full value is in the title (dom.clip). Never
   overflow-wrap:anywhere in intrinsically sized places (table cells, auto grid tracks, flex
   items): it lets the layout squeeze a column to one character and wrap letter by letter. */
.clip { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-stack { display: grid; gap: 2px; justify-items: start; min-width: 0; }
.cell-stack > .clip { justify-self: stretch; }
.num .cell-stack { justify-items: end; }
.cell-sub { font-size: 12.5px; color: var(--text-3); }
.noscript { margin: 24px; }

.app-boot { display: grid; place-items: center; min-height: 100vh; }
.boot-message { color: var(--text-3); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ------------------------------------------------------------------ shell */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 12px 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
}
.brand:hover { color: var(--text); }
.brand-logo { width: 28px; height: 28px; flex: none; }
.nav-list { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 550;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav-badge {
  min-width: 22px;
  padding: 0 7px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  background: var(--muted-bg);
  color: var(--muted-fg);
}
.nav-badge-crit { background: var(--danger-bg); color: var(--danger-fg); }
.nav-badge-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-border); }
.nav-scrim { display: none; }

.main-area { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: 8px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { display: none; }
.topbar-spacer { flex: 1; }
/* .btn (later in this file) sets display: inline-flex; the compound selector wins over it. */
.btn.menu-toggle { display: none; }
.menu-icon, .menu-icon::before, .menu-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
}
.menu-icon { position: relative; }
.menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
.menu-icon::before { top: -6px; }
.menu-icon::after { top: 6px; }
.server-clock { color: var(--text-3); font-size: 13.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid var(--muted-border);
  background: var(--muted-bg);
  color: var(--muted-fg);
}
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.status-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.status-crit { background: var(--crit-bg); color: var(--crit); border-color: var(--crit-border); }
.status-crit::before { border-radius: 1px; }
.topbar-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-user-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }

.main { width: 100%; max-width: 1440px; padding: 24px 28px 48px; }
.main:focus-visible { outline: none; }

@media (max-width: 1023px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 45;
    width: min(84vw, 300px);
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
    box-shadow: var(--shadow-lg);
  }
  .shell.nav-open .sidebar { transform: none; visibility: visible; }
  .nav-scrim { display: block; position: fixed; inset: 0; z-index: 40; background: var(--scrim); }
  .btn.menu-toggle { display: inline-flex; }
  .topbar { padding: 8px 16px; gap: 8px; }
  .topbar-brand { display: block; }
  .topbar-brand .brand { padding: 0; }
  .main { padding: 16px 16px 40px; }
}
@media (max-width: 640px) {
  .server-clock, .menu-label, .topbar-brand span { display: none; }
  .topbar-user-name { max-width: 90px; }
  .status-pill { font-size: 12px; padding: 2px 8px; }
}
@media (max-width: 400px) {
  .topbar-user-name { display: none; }
}

/* ------------------------------------------------------------------ page structure */

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 20px;
}
.page-heading { min-width: 0; }
.page-title { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.page-title:focus-visible { outline-offset: 4px; }
.page-subtitle { margin: 4px 0 0; color: var(--text-3); }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.section { margin-top: 28px; }
.section-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 12px; }
.section-title { margin: 0; font-size: 18px; font-weight: 650; }
.section-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 16px; }
.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-crit { border-color: var(--crit-border); box-shadow: inset 0 3px 0 var(--crit), var(--shadow); }
.card-warn { border-color: var(--warn-border); box-shadow: inset 0 3px 0 var(--warn), var(--shadow); }
.card-title { margin: 0; font-size: 13px; font-weight: 650; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text-3); }
.card-body { display: grid; gap: 10px; min-width: 0; }
.card-headline { margin: 0; font-size: 16px; }
.card-footer { margin-top: auto; padding-top: 4px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Key column: as wide as its keys but at most 45 % (long keys wrap at spaces); the value column
   always gets the rest, so values such as «28.09.2026 18:08 с 198.51.100.17» wrap at spaces. */
.kv { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr); gap: 4px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--text-3); overflow-wrap: break-word; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: break-word; }

.stat { min-width: 0; }
.stat-value { margin: 0; font-size: 28px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-label { margin: 2px 0 0; font-size: 13px; color: var(--text-3); }
.stat-note { margin: 4px 0 0; font-size: 12.5px; color: var(--text-3); }
.stat-pair { display: flex; flex-wrap: wrap; gap: 12px 28px; }
.mini-list, .route-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.mini-list li { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.route-item { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.route-title { font-weight: 600; min-width: 0; }
.route-error { flex-basis: 100%; font-size: 13px; color: var(--crit); }

/* Request log details dialog and the traffic page's group of unknown names. */
.request-line { margin: 0 0 8px; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; overflow-wrap: anywhere; }
.unknown-names { margin-top: 20px; padding: 12px 14px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); }
.unknown-names > summary { cursor: pointer; font-weight: 600; }
.unknown-names[open] > summary { margin-bottom: 8px; }
.unknown-names .table-wrap { max-width: 40rem; box-shadow: none; background: var(--surface-2); }
.unknown-names .table { color: var(--text-2); }

.footnote { margin-top: 18px; font-size: 13px; color: var(--text-3); }
.tz-note { margin: 0; font-size: 13px; color: var(--text-3); }

/* ------------------------------------------------------------------ badges and callouts */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--muted-border);
  background: var(--muted-bg);
  color: var(--muted-fg);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 20px;
  white-space: nowrap;
  vertical-align: middle;
}
.badge::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-border); }
.badge-warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-border); }
.badge-warn::before { border-radius: 1px; transform: rotate(45deg) scale(0.9); }
.badge-crit { color: var(--crit); background: var(--crit-bg); border-color: var(--crit-border); }
.badge-crit::before { border-radius: 1px; }
.badge-info { color: var(--info); background: var(--info-bg); border-color: var(--info-border); }
.badge-muted::before { background: transparent; border: 1.5px solid currentColor; }
/* A long badge inside a table cell wraps at spaces instead of widening the table. */
.badge-wrap { white-space: normal; border-radius: 10px; text-align: left; }
.badges { display: inline-flex; flex-wrap: wrap; gap: 4px; }

.callout {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--info-border);
  background: var(--info-bg);
  color: var(--text);
  display: grid;
  gap: 8px;
  justify-items: start;
}
.callout-warn { border-color: var(--warn-border); background: var(--warn-bg); }
.callout-crit { border-color: var(--crit-border); background: var(--crit-bg); }
.callout-ok { border-color: var(--ok-border); background: var(--ok-bg); }
.callout p { margin: 0; }

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger-bg); color: var(--danger-fg); }
.btn-danger:hover { background: var(--danger-bg-hover); border-color: var(--danger-bg-hover); color: var(--danger-fg); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--crit); }
.btn-danger-ghost:hover { background: var(--crit-bg); color: var(--crit); }
.btn-sm { min-height: 30px; padding: 3px 10px; font-size: 13.5px; border-radius: 7px; }
.btn-block { width: 100%; }
/* A long label (e.g. «Откатить к состоянию до этого изменения…») wraps at spaces. */
.btn-wrap { white-space: normal; text-align: left; }
/* Compact value-like button inside a table cell (a client IP that sets the filter). */
.btn-cell { min-height: 26px; padding: 1px 6px; margin-left: -6px; font-weight: 550; color: var(--accent); }
.btn.sr-only-submit { padding: 0; min-height: 0; border: 0; }
.btn.is-done { color: var(--ok); border-color: var(--ok-border); background: var(--ok-bg); }
.btn.is-failed { color: var(--crit); border-color: var(--crit-border); background: var(--crit-bg); }
.link-button { padding-left: 4px; padding-right: 4px; color: var(--accent); font-weight: 650; }
.btn-primary:disabled:hover { background: var(--accent); }

@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .nav-link { min-height: 46px; }
}

/* ------------------------------------------------------------------ forms */

.form { display: grid; gap: 0; }
.form-narrow { max-width: 460px; }
.field { display: grid; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field-label { font-weight: 600; font-size: 14px; }
.field-note { font-weight: 400; font-size: 13px; color: var(--text-3); }
.req { color: var(--crit); }
.input {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1.35;
}
.input:hover { border-color: var(--text-3); }
.input:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--accent); border-radius: 8px; }
.input:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--crit); }
textarea.input { min-height: 72px; resize: vertical; }
select.input { padding-right: 28px; }
.input-short { max-width: 200px; }
.input-code { max-width: 180px; font-family: var(--mono); font-size: 18px; letter-spacing: 0.25em; }
.hint { margin: 0; font-size: 13px; color: var(--text-3); }
.hint-warn { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--text-2); }
.effect {
  margin: 0;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface-2);
  border-left: 3px solid var(--info-border);
  border-radius: 0 6px 6px 0;
}
.effect-label { font-weight: 650; color: var(--text); }
.field-error { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--crit); }
.form-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--crit-border);
  background: var(--crit-bg);
  color: var(--crit);
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.counter { justify-self: end; font-size: 12px; color: var(--text-3); }
.fieldset { border: 0; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; min-width: 0; }
.fieldset legend { margin-bottom: 6px; padding: 0; }
.check-row { display: flex; align-items: flex-start; gap: 9px; }
.check-row input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.check-row label { cursor: pointer; }
.check-row-strong {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-weight: 600;
  margin: 8px 0;
}
.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.field-pair .effect { grid-column: 1 / -1; }
@media (max-width: 480px) {
  .field-pair { grid-template-columns: minmax(0, 1fr); }
}

.filters {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filters-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; }
.filters-actions { align-items: center; }
.filters-actions .check-row { flex: 1 1 280px; }
.field-inline { margin: 0; flex: 1 1 170px; min-width: 150px; }
.preset-group { display: flex; flex-wrap: wrap; gap: 6px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 16px; margin-bottom: 12px; }
.toolbar-field { display: grid; gap: 4px; min-width: min(100%, 240px); }
.toolbar-field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.live-summary { margin: 0; color: var(--text-2); font-size: 14px; font-variant-numeric: tabular-nums; }
.toolbar .check-row { align-self: center; }

/* Phones: tighter page header and filters. Tables switch to cards by measurement
   (components/table.js), not by this breakpoint. */
@media (max-width: 719px) {
  .page-title { font-size: 22px; }
  .page-header { margin-bottom: 14px; }
  .filters { padding: 12px; }
  .field-inline { flex-basis: 100%; min-width: 0; }
  .toolbar-field { min-width: 100%; }
}
.more { display: flex; justify-content: center; margin-top: 14px; }

/* ------------------------------------------------------------------ tables */

/* Column sizing (auto table layout):
   - text columns wrap at spaces only; numbers, dates and times stay on one line;
   - host / id columns (td.col-host, td.col-id) have a fixed width and a one-line .clip value
     whose intrinsic width is contained, so a long host is cut with an ellipsis (full value in
     the title and in the details) instead of widening the table or wrapping per character;
   - when the table still does not fit, components/table.js switches it to cards (.is-cards). */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.table-sizer { height: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); overflow-wrap: normal; }
.table thead th {
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.3;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; }
.table td.num { white-space: nowrap; }
.table tfoot td { background: var(--surface-2); font-weight: 650; border-top: 1px solid var(--border-strong); border-bottom: 0; }
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-align: inherit;
  cursor: pointer;
}
.num .th-sort { justify-content: flex-end; }
.th-sort:hover { color: var(--text); }
.th-arrow { flex: none; font-size: 10px; color: var(--text-3); }
.table td.col-host { width: 28ch; max-width: 28ch; }
.table td.col-id { width: 18ch; max-width: 18ch; }
.table:not(.is-cards) td.col-host .clip, .table:not(.is-cards) td.col-id .clip { contain: inline-size; }
/* ...but a squeezed table never cuts a host or an id to a few letters: this minimum counts in the
   table's natural width, so when it does not fit, components/table.js switches to cards instead. */
.table:not(.is-cards) td.col-host .clip { min-width: 16ch; }
.table:not(.is-cards) td.col-id .clip { min-width: 10ch; }
/* A note under the user name takes the width the name column already has; it never sets it. */
.table:not(.is-cards) .user-note { contain: inline-size; }
.table .col-time { white-space: nowrap; }
.row-empty td { text-align: center; color: var(--text-3); padding: 28px 12px; }
.row-muted td { color: var(--text-3); }
.row-error td:first-child { box-shadow: inset 3px 0 var(--crit); }
.row-denied td:first-child { box-shadow: inset 3px 0 var(--warn); }
.row-selected td { background: var(--accent-soft); }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.row-note { display: block; margin-top: 3px; }
.user-name-cell { display: grid; gap: 3px; min-width: 9rem; justify-items: start; }
.user-name { font-weight: 650; max-width: 14rem; }
.user-note { color: var(--text-3); font-size: 13px; max-width: 16rem; }
.user-cell { font-weight: 600; max-width: 12rem; }
.approx { color: var(--warn); font-weight: 700; }
.result-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-width: 11rem; }
.code { color: var(--text-3); font-size: 12.5px; }
.code-text { flex-basis: 100%; color: var(--text-2); font-size: 13px; }
.details-button { min-width: 32px; padding-left: 6px; padding-right: 6px; font-weight: 700; }

/* Cards: the label/value pairs of a row flow into columns of at least 17rem, so a wide screen
   shows two or three pairs per line and a phone one. */
.table-cards.is-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.table-cards.is-cards, .table-cards.is-cards tbody, .table-cards.is-cards tfoot { display: block; width: 100%; }
.table-cards.is-cards tr {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  column-gap: 28px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}
.table-cards.is-cards tbody tr:last-child { border-bottom: 0; }
.table-cards.is-cards tfoot tr { background: var(--surface-2); border-top: 1px solid var(--border-strong); border-bottom: 0; }
.table-cards.is-cards td {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  width: auto;
  max-width: none;
  padding: 4px 0;
  border: 0;
  background: none;
  text-align: right;
}
.table-cards.is-cards td::before {
  content: attr(data-label);
  flex: none;
  max-width: 45%;
  text-align: left;
  font-weight: 600;
  color: var(--text-3);
  font-size: 13px;
}
.table-cards.is-cards td > * { min-width: 0; }
.table-cards.is-cards td.card-span { grid-column: 1 / -1; }
.table-cards.is-cards tfoot td:empty { display: none; }
.table-cards.is-cards .row-empty { display: block; }
.table-cards.is-cards .row-empty td { justify-content: center; }
.table-cards.is-cards .row-empty td::before { content: none; }
.table-cards.is-cards td.num { white-space: normal; }
.table-cards.is-cards .clip { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; text-align: right; }
.table-cards.is-cards .row-error td:first-child, .table-cards.is-cards .row-denied td:first-child { box-shadow: none; }
.table-cards.is-cards .row-error { box-shadow: inset 3px 0 var(--crit); }
.table-cards.is-cards .row-denied { box-shadow: inset 3px 0 var(--warn); }
.table-cards.is-cards tbody tr:hover td { background: none; }
.table-cards.is-cards .cell-stack, .table-cards.is-cards .user-name-cell { justify-items: end; min-width: 0; }
.table-cards.is-cards .user-name, .table-cards.is-cards .user-cell, .table-cards.is-cards .user-note { max-width: 100%; }
.table-cards.is-cards .result-cell { justify-content: flex-end; min-width: 0; }
.table-cards.is-cards .code-text { text-align: right; }
.table-cards.is-cards .row-actions { justify-content: flex-end; }
.table-cards.is-cards .badge-wrap { text-align: right; }

/* ------------------------------------------------------------------ loading / empty / error */

.state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 16px;
  color: var(--text-3);
  text-align: center;
  flex-wrap: wrap;
}
.state-error { color: var(--crit); flex-direction: column; }
.state-empty { border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.spinner {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -3px;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ alerts, capabilities */

.alerts, .caps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.alert {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 6px;
}
.alert-warn { border-left-color: var(--warn); }
.alert-crit { border-left-color: var(--crit); background: var(--crit-bg); border-color: var(--crit-border); border-left-color: var(--crit); }
.alert-cleared { border-left-color: var(--border-strong); background: var(--surface); opacity: 0.85; }
.alert-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--text-3); }
.alert-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.alert-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.caps li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.caps li:last-child { border-bottom: 0; }
.audit-head .callout { margin-bottom: 16px; }

/* ------------------------------------------------------------------ dialogs */

.dialog {
  width: min(560px, calc(100vw - 32px));
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: var(--scrim); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 6px; }
.dialog-title { margin: 0; font-size: 19px; font-weight: 700; }
.dialog-close { margin: -6px -8px 0 0; font-size: 22px; line-height: 1; min-width: 36px; }
.dialog-body { padding: 8px 20px 14px; overflow-y: auto; overscroll-behavior: contain; }
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 14px 14px;
}
.dialog-wide { width: min(780px, calc(100vw - 32px)); }
.dialog-danger { border-top: 4px solid var(--crit); }
.dialog-session { width: min(460px, calc(100vw - 32px)); }
.dialog-list { margin: 8px 0; display: grid; gap: 6px; }
.dialog-lead { color: var(--text-2); }
.session-countdown { font-variant-numeric: tabular-nums; font-size: 1.1em; }
.drawer {
  margin: 0 0 0 auto;
  width: min(540px, 100vw);
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  border-radius: 14px 0 0 14px;
  border-right: 0;
}
.drawer .dialog-body { flex: 1; }
.drawer .dialog-actions { border-radius: 0 0 0 14px; }
@media (max-width: 560px) {
  .dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .drawer { width: 100vw; border-radius: 0; border-left: 0; }
  .drawer .dialog-actions { border-radius: 0; }
  .dialog-header { padding: 14px 16px 4px; }
  .dialog-body { padding: 8px 16px 12px; }
  .dialog-actions { padding: 10px 16px 14px; }
  .dialog-actions .btn { flex: 1 1 auto; }
}

/* ------------------------------------------------------------------ apply progress and result */

.progress { display: flex; align-items: flex-start; gap: 16px; }
.progress-lead { color: var(--text-2); }
.progress-step { font-weight: 650; margin: 0; }
.apply-result { display: grid; gap: 10px; }
.apply-verdict { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.apply-verdict p { margin: 0; }
.apply-message { margin: 0; color: var(--text-2); }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 14px; margin: 0; font-size: 13.5px; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.notices { padding: 10px 12px; background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: var(--radius-sm); }
.notices h3 { margin: 0 0 6px; font-size: 14px; }
.notices ul { margin: 0; display: grid; gap: 4px; }
.steps-title { margin: 6px 0; font-size: 14px; }
.steps, .steps-plain { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 13.5px; }
.steps-plain { list-style: decimal; padding-left: 22px; gap: 10px; font-size: 14px; }
.step { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 2px 8px; align-items: baseline; }
.step-icon { font-weight: 700; text-align: center; }
.step-ok .step-icon { color: var(--ok); }
.step-fail .step-icon { color: var(--crit); }
.step-fail .step-name { color: var(--crit); font-weight: 650; }
.step-ms { color: var(--text-3); font-variant-numeric: tabular-nums; }
.step-info { grid-column: 2 / -1; color: var(--text-3); font-size: 13px; overflow-wrap: anywhere; }
.steps-details summary { cursor: pointer; font-weight: 600; font-size: 14px; padding: 4px 0; }
.steps-details[open] summary { margin-bottom: 6px; }

/* ------------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  display: grid;
  gap: 10px;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px 10px 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}
.toast-ok { border-left-color: var(--ok); }
.toast-warn { border-left-color: var(--warn); }
.toast-crit { border-left-color: var(--crit); }
.toast-icon::before { content: "i"; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; font-size: 12px; font-weight: 800; color: var(--info); background: var(--info-bg); }
.toast-ok .toast-icon::before { content: "✓"; color: var(--ok); background: var(--ok-bg); }
.toast-warn .toast-icon::before { content: "!"; color: var(--warn); background: var(--warn-bg); }
.toast-crit .toast-icon::before { content: "✕"; color: var(--crit); background: var(--crit-bg); }
.toast-body { min-width: 0; }
.toast-title { margin: 0; font-weight: 650; }
.toast-message { margin: 2px 0 0; color: var(--text-2); font-size: 14px; }
.toast-items { margin: 6px 0 0; padding-left: 18px; font-size: 13.5px; color: var(--text-2); display: grid; gap: 3px; }
.toast-actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.toast-close { min-width: 30px; font-size: 18px; line-height: 1; }
@media (max-width: 480px) {
  .toasts { right: 8px; left: 8px; bottom: 8px; width: auto; }
}

/* ------------------------------------------------------------------ strength meter, switch */

.strength { display: grid; gap: 4px; }
.strength-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.strength-seg { height: 6px; border-radius: 3px; background: var(--surface-3); }
/* score 0-1: one red segment, 2: two amber, 3: three green, 4: all green */
.strength-score-0 .strength-seg:nth-child(1), .strength-score-1 .strength-seg:nth-child(1) { background: var(--crit); }
.strength-score-2 .strength-seg:nth-child(-n+2) { background: var(--warn); }
.strength-score-3 .strength-seg:nth-child(-n+3) { background: var(--ok); }
.strength-score-4 .strength-seg { background: var(--ok); }
.strength.strength-level-pending .strength-seg { background: var(--surface-3); }
.strength-text { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); }
.strength-level-bad .strength-text { color: var(--crit); }
.strength-warnings { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-3); }

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  background: var(--surface-3);
  cursor: pointer;
  transition: background-color 0.15s;
  vertical-align: middle;
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
  transition: transform 0.15s;
}
.switch[aria-checked="true"] { background: var(--ok); border-color: var(--ok); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(18px); }
.switch:focus-visible { outline-offset: 2px; border-radius: 13px; }

/* ------------------------------------------------------------------ connection card */

.credcard { display: grid; gap: 12px; }
.credcard .callout { margin: 0; } /* spacing comes from the grid gap */
.cred-rows { display: grid; gap: 8px; }
.cred-row, .cred-url {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr) auto;
  gap: 8px 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.cred-url { grid-template-columns: minmax(0, 1fr) auto; }
.cred-url .cred-label { grid-column: 1 / -1; }
.cred-url .hint { grid-column: 1 / -1; }
.cred-label { font-size: 13px; font-weight: 650; color: var(--text-3); }
.cred-value { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; user-select: all; }
.cred-value-wrap { font-size: 13.5px; word-break: break-all; }
.secret { letter-spacing: 0.08em; }
.probe { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; font-size: 14px; }
.cred-apply { font-size: 14px; color: var(--text-2); padding-top: 8px; border-top: 1px solid var(--border); }
.clipboard-buffer { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; }
@media (max-width: 420px) {
  .cred-row { grid-template-columns: minmax(0, 1fr) auto; }
  .cred-row .cred-label { grid-column: 1 / -1; }
}

/* ------------------------------------------------------------------ diffs and code */

.diff, .code-block {
  margin: 8px 0 0;
  padding: 10px 0;
  max-height: 55vh;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.code-block { padding: 10px 12px; white-space: pre; }
.diff-line { display: block; padding: 0 12px; white-space: pre; }
.diff-add { background: var(--diff-add-bg); }
.diff-del { background: var(--diff-del-bg); }
.diff-same { color: var(--text-3); }
.diff-gap { color: var(--text-3); font-style: italic; text-align: center; }
.legend-inline { display: flex; flex-wrap: wrap; gap: 8px; font-size: 13px; }
.diff-key { padding: 1px 6px; border-radius: 4px; font-family: var(--mono); }

/* ------------------------------------------------------------------ charts */

.chart-figure { margin: 0 0 16px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: grid; gap: 8px; }
.chart-scroll { overflow-x: auto; }
.chart { display: block; max-width: 100%; height: auto; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart-axis { fill: var(--text-3); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.series-1 { fill: var(--series-1); background: var(--series-1); }
.series-2 { fill: var(--series-2); background: var(--series-2); }
.chart-missing { fill: var(--border-strong); }
.chart-hit { fill: transparent; cursor: default; }
.chart-col.is-hover .series-1, .chart-col.is-hover .series-2 { opacity: 0.8; }
.chart-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--text-2); }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.chart-readout { margin: 0; font-size: 13px; color: var(--text-2); min-height: 20px; }
.sharebar { display: inline-block; width: 90px; height: 8px; vertical-align: middle; }
.sharebar-track { fill: var(--surface-3); }
.sharebar-fill { fill: var(--series-1); }
.share-cell { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* ------------------------------------------------------------------ tabs */

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  flex: none;
  padding: 9px 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.is-active, .tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel:focus-visible { outline-offset: 4px; }

/* ------------------------------------------------------------------ restore preview */

.restore-list { list-style: none; margin: 8px 0 12px; padding: 0; display: grid; gap: 8px; }
.restore-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.restore-item ul { margin: 6px 0 0; display: grid; gap: 3px; font-size: 14px; }
.restore-item .check-row { margin-top: 8px; }
.restore-removed { border-color: var(--warn-border); }

/* ------------------------------------------------------------------ login page */

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-main { width: min(420px, 100%); display: grid; gap: 14px; }
.login-card {
  padding: 28px 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-title { margin: 0; font-size: 18px; font-weight: 750; }
.login-subtitle { margin: 0; font-size: 13px; color: var(--text-3); }
.login-heading { margin: 0 0 16px; font-size: 22px; }
.login-foot { margin: 0; text-align: center; font-size: 13px; color: var(--text-3); }
@media (max-width: 420px) {
  .login-card { padding: 22px 18px 18px; }
}

/* ------------------------------------------------------------------ forced colours */

@media (forced-colors: active) {
  .badge, .status-pill, .switch, .strength-seg { border: 1px solid CanvasText; }
  .switch[aria-checked="true"] .switch-knob { background: Highlight; }
  .series-1, .series-2, .sharebar-fill { fill: CanvasText; }
}
