/* NetworkQuality styles.
   Palette follows Printer Gateway: logo Blue (#3084d6) primary, Navy (#003355)
   deep accent, a cool steel-gray light theme where white cards lift off a
   tinted page, and a neutral near-black dark theme with outlined controls.
   theme.js sets <html data-theme="light|dark">; the media query below only
   applies if that script did not run. */

:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --text: #0f172a;
  --muted: #64748b;
  --line: #d9e1ea;
  --line-strong: #c3cedb;
  --soft: #e1e8f0;
  --accent: #3084d6;
  --accent-hover: #2873bd;
  --accent-text: #2270bd;
  --accent-ink: #ffffff;
  --accent-soft: rgba(48, 132, 214, .12);
  --navy: #003355;
  --brand-word: #003355;
  --good: #059669;
  --good-soft: rgba(5, 150, 105, .12);
  --warn: #c26a05;
  --warn-soft: rgba(217, 119, 6, .13);
  --bad: #dc2626;
  --bad-soft: rgba(220, 38, 38, .1);
  --ring: rgba(48, 132, 214, .45);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px -4px rgba(15, 23, 42, .08);
  --shadow-lg: 0 24px 60px -12px rgba(15, 23, 42, .28);
  --header-bg: rgba(255, 255, 255, .78);
  --backdrop: rgba(15, 23, 42, .42);
  --btn-bg: #ffffff;
  --btn-hover: #f6f8fb;
  --primary-bg: #3084d6;
  --primary-border: #3084d6;
  --primary-fg: #ffffff;
  --primary-hover: #2873bd;
  --primary-hover-border: #2873bd;
  --radius: 14px;
  --radius-sm: 9px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0a0a0a;
  --panel: #171717;
  --panel-2: #1c1c1c;
  --text: #fafafa;
  --muted: #a1a1a1;
  --line: rgba(255, 255, 255, .1);
  --line-strong: rgba(255, 255, 255, .18);
  --soft: #262626;
  --accent: #3084d6;
  --accent-hover: #4a96e0;
  --accent-text: #5aa2ff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(48, 132, 214, .16);
  --brand-word: #ffffff;
  --good: #34d399;
  --good-soft: rgba(52, 211, 153, .14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .14);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, .14);
  --ring: rgba(48, 132, 214, .55);
  --shadow-sm: none;
  --shadow: none;
  --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .7);
  --header-bg: rgba(10, 10, 10, .72);
  --backdrop: rgba(0, 0, 0, .62);
  /* Outlined, tinted controls like Printer Gateway's dark mode. */
  --btn-bg: transparent;
  --btn-hover: rgba(255, 255, 255, .05);
  --primary-bg: rgba(48, 132, 214, .1);
  --primary-border: rgba(48, 132, 214, .45);
  --primary-fg: #5aa2ff;
  --primary-hover: rgba(48, 132, 214, .2);
  --primary-hover-border: rgba(48, 132, 214, .7);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0a0a0a; --panel: #171717; --panel-2: #1c1c1c; --text: #fafafa; --muted: #a1a1a1;
    --line: rgba(255, 255, 255, .1); --line-strong: rgba(255, 255, 255, .18); --soft: #262626;
    --accent-text: #5aa2ff; --accent-soft: rgba(48, 132, 214, .16); --brand-word: #fff;
    --good: #34d399; --good-soft: rgba(52, 211, 153, .14); --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
    --bad: #f87171; --bad-soft: rgba(248, 113, 113, .14); --shadow-sm: none; --shadow: none;
    --header-bg: rgba(10, 10, 10, .72); --backdrop: rgba(0, 0, 0, .62);
    --btn-bg: transparent; --btn-hover: rgba(255, 255, 255, .05);
    --primary-bg: rgba(48, 132, 214, .1); --primary-border: rgba(48, 132, 214, .45); --primary-fg: #5aa2ff;
    --primary-hover: rgba(48, 132, 214, .2); --primary-hover-border: rgba(48, 132, 214, .7);
    color-scheme: dark;
  }
}

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

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
::selection { background: var(--accent-soft); }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 1.6rem; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; letter-spacing: -.01em; }
h3 { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 650; }
p { margin: 0; }
svg { flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.grow { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  transition: background-color .3s var(--ease), border-color .3s var(--ease), box-shadow .3s var(--ease);
}
.wrap {
  max-width: 1160px; margin: 0 auto; padding: 24px 16px 64px;
  display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr);
}

/* ------------------------------------------------------------ animations */

@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(.92); } 55% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(48, 132, 214, .45); }
  70% { box-shadow: 0 0 0 12px rgba(48, 132, 214, 0); }
  100% { box-shadow: 0 0 0 0 rgba(48, 132, 214, 0); }
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); } 40%, 60% { transform: translateX(5px); }
}
@keyframes draw { from { stroke-dashoffset: 30; } to { stroke-dashoffset: 0; } }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(3%, -4%) scale(1.06); }
}
@keyframes slide-in { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }

.reveal { animation: fade-up .5s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 55ms); }

/* ---------------------------------------------------------------- header */

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px max(20px, calc((100vw - 1160px) / 2 + 16px));
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.top form { margin: 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.05rem; letter-spacing: -.02em; color: var(--brand-word); text-decoration: none; }
.brand .logo { width: 30px; height: 30px; }
.brand b { color: var(--accent); font-weight: 750; }
.brand .tag {
  font-size: .68rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent-text); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px;
}
.logo .pulse { stroke-dasharray: 30; animation: draw 1.1s .15s var(--ease) both; }
.who { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .86rem; }
.who .avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, #3084d6, #003355); color: #fff; font-size: .72rem; font-weight: 700; text-transform: uppercase;
}

.tabs { position: relative; display: flex; gap: 2px; padding: 3px; background: var(--soft); border-radius: 11px; }
.tabs button {
  position: relative; z-index: 1; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: .9rem;
  padding: 6px 14px; border-radius: 8px; cursor: pointer; box-shadow: none;
  transition: color .2s var(--ease);
}
.tabs button:hover { color: var(--text); background: none; border-color: transparent; }
.tabs button[aria-selected="true"] { color: var(--text); }
.tabs .indicator {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; width: 0;
  background: var(--panel); border-radius: 8px; box-shadow: var(--shadow-sm), 0 0 0 1px var(--line);
  transition: transform .35s var(--ease), width .35s var(--ease);
}

/* Theme toggle: sun and moon swap with a spin. */
.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 36px; height: 36px; padding: 0; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--soft); color: var(--text); border-color: transparent; }
.icon-btn svg { grid-area: 1 / 1; width: 19px; height: 19px; transition: transform .5s var(--spring), opacity .25s var(--ease); }
/* Shows the mode it switches to: a moon in light mode, a sun in dark. */
.icon-btn .sun { transform: rotate(90deg) scale(.4); opacity: 0; }
:root[data-theme="dark"] .icon-btn .moon { transform: rotate(-90deg) scale(.4); opacity: 0; }
:root[data-theme="dark"] .icon-btn .sun { transform: none; opacity: 1; }

::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* -------------------------------------------------------------- controls */

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 600; font-size: .92rem; line-height: 1.3;
  border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--line); background: var(--btn-bg); color: var(--text);
  padding: 8px 14px; box-shadow: var(--shadow-sm);
  transition: background-color .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease),
    box-shadow .18s var(--ease), transform .12s var(--ease), opacity .18s;
}
button:hover { background: var(--btn-hover); border-color: var(--line-strong); }
button:active:not(:disabled) { transform: translateY(1px) scale(.985); }
button:disabled { opacity: .5; cursor: not-allowed; }
button svg { width: 16px; height: 16px; }
button.primary { background: var(--primary-bg); border-color: var(--primary-border); color: var(--primary-fg); }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover-border); }
button.big { padding: 12px 24px; font-size: 1rem; border-radius: 12px; }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 45%, transparent); color: var(--bad); }
button.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
button.ghost:hover { background: var(--soft); color: var(--text); }
button.link { border: 0; background: none; box-shadow: none; color: var(--muted); padding: 6px 8px; }
button.link:hover { color: var(--text); background: var(--soft); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, tr:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--ring);
}

/* A button doing work: label fades, spinner takes its place. */
.spinner {
  width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; flex: none;
}
button.is-busy { position: relative; pointer-events: none; }
button.is-busy > :not(.spinner) { opacity: 0; }
button.is-busy { color: transparent !important; }
button.is-busy .spinner { position: absolute; inset: 0; margin: auto; color: var(--text); }
button.primary.is-busy .spinner { color: var(--primary-fg); }
button.danger.is-busy .spinner { color: var(--bad); }
button.is-done { color: var(--good); border-color: color-mix(in srgb, var(--good) 45%, transparent); background: var(--good-soft); }

label { display: block; font-weight: 600; font-size: .87rem; }
label .hint { font-weight: 400; color: var(--muted); margin-left: 4px; }
label input, label select, label textarea { display: block; margin-top: 6px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px; width: 100%;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background-color .3s var(--ease);
}
:root[data-theme="dark"] input, :root[data-theme="dark"] select, :root[data-theme="dark"] textarea { background: rgba(255, 255, 255, .03); }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--ring); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath d='M5.3 7.3a1 1 0 0 1 1.4 0L10 10.6l3.3-3.3a1 1 0 1 1 1.4 1.4l-4 4a1 1 0 0 1-1.4 0l-4-4a1 1 0 0 1 0-1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
}
textarea { resize: vertical; min-height: 72px; }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

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

body.center {
  display: grid; place-items: center; padding: 24px 16px; position: relative; overflow-x: hidden;
}
.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.backdrop::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(48, 132, 214, .12), transparent 45%, rgba(0, 51, 85, .12));
}
.backdrop span {
  position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55;
  animation: float 14s ease-in-out infinite;
}
.backdrop span:nth-child(1) { width: 42vmax; height: 42vmax; left: -12vmax; top: -14vmax; background: rgba(48, 132, 214, .35); }
.backdrop span:nth-child(2) { width: 36vmax; height: 36vmax; right: -12vmax; bottom: -14vmax; background: rgba(0, 51, 85, .3); animation-delay: -7s; }
:root[data-theme="dark"] .backdrop span:nth-child(1) { background: rgba(48, 132, 214, .22); }
:root[data-theme="dark"] .backdrop span:nth-child(2) { background: rgba(28, 91, 149, .25); }
/* Faint grid that fades out from the centre. */
.backdrop::after {
  content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 10%, transparent 65%);
  mask-image: radial-gradient(ellipse at center, #000 10%, transparent 65%);
  opacity: .6;
}
.corner { position: fixed; top: 14px; right: 14px; z-index: 5; }
.auth { width: min(420px, 100%); display: grid; gap: 22px; justify-items: center; }
.auth > .brand { font-size: 1.25rem; animation: fade-up .5s var(--ease) both; }
.auth > .brand .logo { width: 38px; height: 38px; }
.login {
  width: 100%; display: grid; gap: 18px; padding: 30px;
  box-shadow: var(--shadow-lg);
  animation: fade-up .55s .08s var(--ease) both;
}
:root[data-theme="dark"] .login { box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, .04) inset; }
.login .intro { display: grid; gap: 6px; }
.login form { display: grid; gap: 16px; }
.login button.primary { width: 100%; padding: 11px 14px; margin-top: 4px; }
.footnote { color: var(--muted); font-size: .8rem; display: inline-flex; align-items: center; gap: 6px; animation: fade-in .6s .3s both; }
.footnote svg { width: 14px; height: 14px; }

.error {
  display: flex; gap: 10px; align-items: flex-start;
  color: var(--bad); font-weight: 600; font-size: .9rem;
  background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent);
  border-radius: var(--radius-sm); padding: 10px 12px;
  animation: shake .45s var(--ease);
}
.error.small { font-size: .84rem; }
.error svg { width: 18px; height: 18px; margin-top: 1px; }

.notice {
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  background: var(--panel-2); border-radius: var(--radius-sm); padding: 14px 16px; display: grid; gap: 10px;
  animation: fade-up .4s var(--ease) both;
}
.notice.bad { border-left-color: var(--bad); background: var(--bad-soft); color: var(--text); }
.notice.good { border-left-color: var(--good); background: var(--good-soft); }
.notice strong { display: flex; align-items: center; gap: 8px; }
.notice strong svg { width: 18px; height: 18px; color: var(--good); }
.secret { font-size: 1.05rem; font-weight: 700; user-select: all; letter-spacing: .02em; }

/* ------------------------------------------------------------- dashboard */

.hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap; padding: 28px;
}
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(600px 220px at 100% 0%, var(--accent-soft), transparent 70%);
}
.hero > div { position: relative; flex: 1; min-width: 240px; display: grid; gap: 8px; }
.hero > .hero-actions { flex: none; min-width: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.hero h1 { display: flex; align-items: center; gap: 10px; }
.hero h1 .state-icon { width: 28px; height: 28px; display: none; }
.hero[data-state="running"] h1 .state-icon.run { display: block; color: var(--accent); }
.hero[data-state="done"] h1 .state-icon.ok { display: block; color: var(--good); }
.hero[data-state="error"] h1 .state-icon.err { display: block; color: var(--bad); }
.state-icon.ok path { stroke-dasharray: 30; animation: draw .6s .1s var(--ease) both; }
.hero[data-state="done"] .state-icon.ok { animation: pop .5s var(--spring); }
#status { max-width: 62ch; transition: opacity .2s; }
.hero[data-state="idle"] #start:not(:disabled) { animation: pulse-ring 2.4s ease-out infinite; }
.hero[data-state="running"] h1 .state-icon.run { animation: blink 1.2s ease-in-out infinite; }

.progress {
  position: relative; height: 8px; border-radius: 999px; background: var(--soft); overflow: hidden; margin-top: 6px;
}
.progress .bar {
  position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, #3084d6, #1c5b95, #3084d6);
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
  transition: width .6s var(--ease);
}
.progress-meta { display: flex; justify-content: space-between; gap: 12px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.tile {
  position: relative; overflow: hidden;
  display: grid; gap: 6px; padding: 18px 20px; min-height: 140px; align-content: start;
  transition: border-color .3s var(--ease), box-shadow .3s var(--ease), transform .25s var(--ease), background-color .3s var(--ease);
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow), 0 10px 24px -12px rgba(15, 23, 42, .22); }
.tile-head { display: flex; align-items: center; gap: 9px; }
.tile-icon {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--soft); color: var(--muted); transition: background-color .3s, color .3s;
}
.tile-icon svg { width: 16px; height: 16px; }
.tile-head h3 { flex: 1; }
.tile .state { width: 20px; height: 20px; display: grid; place-items: center; }
.tile .state svg { width: 18px; height: 18px; }
.tile .value {
  font-size: 2.2rem; font-weight: 720; letter-spacing: -.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums; margin-top: 6px; transform-origin: left center;
}
.tile .value small { font-size: .9rem; font-weight: 600; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.tile .value.pop { animation: pop .45s var(--spring); }
.tile .sub { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.grade {
  justify-self: start; display: inline-flex; align-items: center; gap: 6px;
  font-size: .74rem; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  animation: fade-up .35s var(--ease) both;
}
.grade::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.grade.excellent, .grade.good { color: var(--good); background: var(--good-soft); }
.grade.fair { color: var(--warn); background: var(--warn-soft); }
.grade.poor { color: var(--bad); background: var(--bad-soft); }
/* Running: blue edge, a sweeping highlight and a blinking dot. */
.tile[data-state="running"] { border-color: color-mix(in srgb, var(--accent) 60%, transparent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tile[data-state="running"] .tile-icon { background: var(--accent-soft); color: var(--accent-text); }
.tile[data-state="running"] h3 { color: var(--accent-text); }
.tile[data-state="running"]::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, var(--accent-soft) 50%, transparent 70%);
  background-size: 250% 100%; animation: shimmer 1.8s linear infinite;
}
.tile[data-state="running"] .state::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite;
}
.tile[data-state="done"] .tile-icon { background: var(--good-soft); color: var(--good); }
.tile[data-state="done"] .state { color: var(--good); animation: pop .45s var(--spring); }
.tile[data-state="failed"] .tile-icon { background: var(--warn-soft); color: var(--warn); }
.tile[data-state="failed"] .state { color: var(--warn); animation: pop .45s var(--spring); }
.tile[data-state="failed"] .value { color: var(--muted); }
.tile[data-state="failed"] .sub { color: var(--warn); }
.tile[data-state="idle"] .value { color: var(--muted); opacity: .6; }
.tile .state .ok, .tile .state .warn { display: none; }
.tile[data-state="done"] .state .ok, .tile[data-state="failed"] .state .warn { display: block; }

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

.table-wrap { overflow-x: auto; margin: 0 -22px -10px; padding: 0 22px 10px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .89rem; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; transition: background-color .15s; }
th { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; background: var(--panel-2); }
th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap-cell { white-space: normal; min-width: 160px; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { animation: fade-in .35s var(--ease) both; }
tbody tr:hover td { background: var(--panel-2); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-soft); }
tr.clickable td:first-child { position: relative; }
tr.clickable td:first-child::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px;
  background: var(--accent); transform: scaleY(0); transition: transform .2s var(--ease);
}
tr.clickable:hover td:first-child::before { transform: scaleY(1); }
tr.removing td { opacity: 0; transform: translateX(16px); transition: opacity .25s, transform .25s; }
td.actions { text-align: right; }
td.actions button { padding: 5px 10px; font-size: .8rem; margin-left: 4px; border-radius: 7px; gap: 5px; }
td.actions button svg { width: 13px; height: 13px; }
tr.loading td { cursor: progress; opacity: .6; }
.empty {
  display: grid; justify-items: center; gap: 8px; text-align: center;
  color: var(--muted); padding: 30px 12px 22px; animation: fade-in .4s both;
}
.empty svg { width: 36px; height: 36px; opacity: .55; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: .74rem; font-weight: 700; background: var(--soft); color: var(--muted); margin-left: 6px;
}
td > .badge:first-child { margin-left: 0; }
.badge.good { color: var(--good); background: var(--good-soft); }
.badge.bad { color: var(--bad); background: var(--bad-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.good::before, .badge.bad::before, .badge.warn::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good::before { animation: blink 2.4s infinite; }
.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head h2 { display: flex; align-items: center; gap: 10px; }
.section-head h2 .count { font-size: .75rem; font-weight: 650; color: var(--muted); background: var(--soft); padding: 1px 8px; border-radius: 999px; }
.section-head select { width: auto; min-width: 220px; }

/* Skeleton rows while a table loads. */
.skeleton { display: grid; gap: 10px; padding: 6px 0; }
.skeleton span {
  height: 14px; border-radius: 6px;
  background: linear-gradient(90deg, var(--soft) 25%, var(--panel-2) 50%, var(--soft) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
.skeleton span:nth-child(3n + 2) { width: 86%; }
.skeleton span:nth-child(3n) { width: 72%; }

/* ------------------------------------------------------------ run detail */

.detail { display: grid; gap: 22px; }
.detail section { display: grid; gap: 10px; padding-top: 18px; border-top: 1px solid var(--line); animation: fade-up .45s var(--ease) both; }
.detail section:first-child { border-top: 0; padding-top: 0; }
.detail section:nth-child(2) { animation-delay: .04s; }
.detail section:nth-child(3) { animation-delay: .08s; }
.detail section:nth-child(4) { animation-delay: .12s; }
.detail section:nth-child(5) { animation-delay: .16s; }
.detail section:nth-child(6) { animation-delay: .2s; }
.detail section:nth-child(7) { animation-delay: .24s; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 20px; margin: 0; align-items: start; }
.kv .wide { grid-column: 1 / -1; }
.kv div { display: grid; gap: 2px; align-content: start; }
.kv dt { color: var(--muted); font-size: .76rem; }
.kv dd { margin: 0; font-weight: 620; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.trace { display: grid; gap: 14px; }
.trace table { max-width: 760px; }
.detail .note {
  color: var(--warn); font-size: .85rem; background: var(--warn-soft);
  border-radius: 8px; padding: 8px 12px;
}
details { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; }
details summary { cursor: pointer; color: var(--muted); font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; border-radius: 6px; }
details summary::-webkit-details-marker { display: none; }
details summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .2s var(--ease); margin: 0 2px;
}
details[open] summary::before { transform: rotate(45deg); }
details summary:hover { color: var(--text); }
pre { margin: 12px 0 2px; padding: 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: 360px; font-size: .78rem; animation: fade-in .3s both; }

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

dialog {
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text);
  padding: 0; width: min(920px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(14px) scale(.97);
  transition: opacity .22s var(--ease), transform .28s var(--ease), overlay .28s allow-discrete, display .28s allow-discrete;
}
dialog[open] { opacity: 1; transform: none; }
@starting-style { dialog[open] { opacity: 0; transform: translateY(14px) scale(.97); } }
dialog::backdrop {
  background: var(--backdrop); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .25s var(--ease), overlay .28s allow-discrete, display .28s allow-discrete;
}
dialog[open]::backdrop { opacity: 1; }
@starting-style { dialog[open]::backdrop { opacity: 0; } }
.dialog-head {
  display: flex; align-items: center; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2; background: var(--header-bg);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.dialog-body { padding: 22px; }
dialog.narrow { width: min(480px, calc(100vw - 24px)); }
dialog.ask { width: min(420px, calc(100vw - 24px)); }
dialog.ask .dialog-body { display: grid; gap: 16px; }
dialog.ask .ask-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); }
dialog.ask.danger .ask-icon { background: var(--bad-soft); color: var(--bad); }
dialog.ask .ask-icon svg { width: 20px; height: 20px; }
dialog.ask h2 { font-size: 1.1rem; }
dialog.ask .actions { display: flex; justify-content: flex-end; gap: 10px; }
dialog.ask.danger button.primary { background: var(--bad); border-color: var(--bad); color: #fff; }
:root[data-theme="dark"] dialog.ask.danger button.primary { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 45%, transparent); color: var(--bad); }

/* Settings: checkboxes drawn as switches. */
.checks { display: grid; gap: 4px; margin: 14px 0 4px; }
.check {
  display: flex; gap: 14px; align-items: center; padding: 10px 12px; border-radius: 10px; cursor: pointer;
  transition: background-color .15s;
}
.check:hover { background: var(--panel-2); }
.check > span { flex: 1; }
.check .hint { display: block; margin-left: 0; font-size: .82rem; }
.check input {
  order: 2; appearance: none; flex: none; width: 40px; height: 23px; margin: 0; padding: 0;
  border-radius: 999px; background: var(--soft); border: 1px solid var(--line-strong); position: relative; cursor: pointer;
  transition: background-color .25s var(--ease), border-color .25s var(--ease);
}
.check input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .3s var(--spring);
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { transform: translateX(17px); }
.check input:disabled { opacity: .45; cursor: not-allowed; }
.check:has(input:disabled) { color: var(--muted); cursor: not-allowed; }

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

.toasts {
  position: fixed; z-index: 100; right: 16px; bottom: 16px; display: grid; gap: 10px;
  width: min(380px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 12px 14px; font-size: .9rem; font-weight: 550;
  animation: slide-in .35s var(--spring) backwards;
}
.toast svg { width: 18px; height: 18px; margin-top: 1px; }
.toast.good svg { color: var(--good); }
.toast.bad svg { color: var(--bad); }
.toast.info svg { color: var(--accent-text); }
.toast.leaving { opacity: 0; transform: translateY(8px) scale(.97); transition: opacity .25s, transform .25s; }

#tab-incidents, #tab-results, #tab-admins { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
.tab-panel { animation: fade-up .35s var(--ease) both; }

@media (max-width: 640px) {
  .top { padding: 10px 16px; }
  .tabs { order: 5; width: 100%; }
  .tabs button { flex: 1; }
  .hero { padding: 22px; }
  .hero > .hero-actions { width: 100%; }
  .hero > .hero-actions button { flex: 1; }
  .card { padding: 18px; }
  .table-wrap { margin: 0 -18px -10px; padding: 0 18px 10px; }
  .who .name, .top form button span, .brand .tag { display: none; }
  .top { gap: 8px; }
  .top .brand { margin-right: auto; }
  .top > .grow { display: none; }

  /* Tables become a list of cards: one per row, one line per column. */
  .table-wrap { overflow-x: visible; margin: 0; padding: 0; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards { max-width: none; }
  table.cards thead { display: none; }
  table.cards tbody { display: grid; gap: 10px; }
  table.cards tr {
    border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 6px 14px;
  }
  table.cards td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 8px 0; border-bottom: 1px solid var(--line); white-space: normal;
    text-align: right; overflow-wrap: anywhere; min-width: 0;
  }
  table.cards td::before {
    content: attr(data-label); flex: none; max-width: 45%; text-align: left;
    color: var(--muted); font-size: .78rem; font-weight: 600;
  }
  table.cards td:not([data-label])::before { content: none; }
  table.cards td:not([data-label]) { justify-content: flex-end; }
  table.cards td:empty { display: none; }
  table.cards tr td:last-child { border-bottom: 0; }
  /* The first column names the card. */
  table.cards td:first-child { font-weight: 650; }
  table.cards td.wrap-cell { min-width: 0; }
  table.cards td input { width: 120px; flex: none; }
  table.cards td.actions { flex-wrap: wrap; }
  table.cards tbody tr:hover td { background: none; }
  table.cards tr.clickable:hover td { background: none; }
  table.cards tr.clickable:hover { background: var(--accent-soft); }
  table.cards tr.clickable td:first-child::before {
    content: attr(data-label); position: static; transform: none; width: auto; height: auto; background: none; border-radius: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

#tab-settings { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }

.hint { font-weight: 400; color: var(--muted); }
td .hint { margin-left: 6px; font-size: .85rem; }

/* Verdicts */
.badge.warn { color: var(--warn); }
.tile[data-verdict] { border-left-width: 4px; }
.tile[data-verdict="pass"] { border-left-color: var(--good); }
.tile[data-verdict="warn"] { border-left-color: var(--warn); }
.tile[data-verdict="fail"] { border-left-color: var(--bad); }
.reasons { margin: 6px 0 0; padding-left: 20px; color: var(--warn); font-size: .92rem; }
.reasons:empty { display: none; }
.verdict { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.verdict ul { margin: 0; padding-left: 20px; }
.tile .value { overflow-wrap: anywhere; }

/* Charts */
.charts { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 14px; }
.chart { margin: 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 6px; }
.chart figcaption { font-size: .85rem; display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: baseline; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .tone-a .line { stroke: var(--accent); }
.chart .tone-b .line { stroke: var(--good); }
.chart .tone-c .line { stroke: var(--bad); }
.chart .tone-a .dot { fill: var(--accent); }
.chart .tone-b .dot { fill: var(--good); }
.chart .tone-c .dot { fill: var(--bad); }
.chart .legend { color: var(--muted); }
.chart .legend::before { content: ""; display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.chart .legend.tone-a::before { background: var(--accent); }
.chart .legend.tone-b::before { background: var(--good); }
.chart .legend.tone-c::before { background: var(--bad); }

/* Client trace command and uploads */
.command { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.command pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: none; }
.client-trace { border-top: 1px solid var(--line); padding: 10px 0; }
.client-trace pre { white-space: pre; }
.client-trace button { margin-top: 8px; }
#client-traces h3 { margin-top: 16px; }

/* Admin extras */
a.button { display: inline-block; text-decoration: none; }
.profile { display: grid; gap: 10px; margin-top: 10px; }
.profile-tests { display: grid; gap: 8px 18px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); padding-left: 26px; }
.logo-preview { max-height: 40px; max-width: 200px; }
.brand img { max-height: 28px; max-width: 180px; vertical-align: middle; }
.save-bar { position: sticky; bottom: 0; padding: 12px 0; background: var(--bg); }
#settings-form { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
#thresholds input { width: 110px; }
.dialog-actions { justify-content: flex-end; margin-top: 16px; }
.support { text-align: center; }
details > summary .hint { font-weight: 400; color: var(--muted); margin-left: 6px; }

/* Printing a result: just the result, on white. */
@media print {
  :root { --bg: #fff; --panel: #fff; --text: #000; --muted: #444; --line: #bbb; --soft: #f2f2f2; }
  .no-print, .top, dialog::backdrop { display: none !important; }
  .card { border: 0; padding: 0; }
  .wrap { max-width: none; padding: 0; }
  pre { max-height: none; overflow: visible; white-space: pre-wrap; }
  /* With a result dialog open, print its contents instead of the page behind. */
  body:has(dialog[open]) > :not(dialog) { display: none !important; }
  dialog[open] { position: static; width: auto; max-height: none; border: 0; }
  .dialog-head { position: static; padding: 0 0 12px; }
  .dialog-body { padding: 0; }
}
