/* ==========================================================================
   ktomm — design tokens
   One token set, redefined for dark mode (OS preference). No framework.
   ========================================================================== */
:root {
    color-scheme: light;
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e1e4ea;
    --border-strong: #c9ced8;
    --text: #15181e;
    --text-2: #4b5563;
    --text-3: #6b7280;
    --accent: #2a78d6;
    --accent-hover: #1c5cab;
    --accent-soft: #e4effb;
    --on-accent: #ffffff;
    --ok: #008300;
    --ok-soft: #e3f4e3;
    --warn: #a86f00;
    --warn-soft: #fff3d6;
    --danger: #c73b3a;
    --danger-soft: #fde7e7;
    --neutral-soft: #eceef2;
    --series-1: #2a78d6;
    --grid: #e6e9ef;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --sidebar-w: 236px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0f1116;
        --surface: #181b22;
        --surface-2: #1f232c;
        --border: #2a2f3a;
        --border-strong: #3a4150;
        --text: #f0efec;
        --text-2: #c3c2b7;
        --text-3: #8f94a0;
        --accent: #3987e5;
        --accent-hover: #6da7ec;
        --accent-soft: #1b2a40;
        --on-accent: #ffffff;
        --ok: #4cc26a;
        --ok-soft: #15301c;
        --warn: #eda100;
        --warn-soft: #3a2c08;
        --danger: #e66767;
        --danger-soft: #3b1a1a;
        --neutral-soft: #262b35;
        --series-1: #3987e5;
        --grid: #262b35;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    }
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.95rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 1rem; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--text-3); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.visually-hidden, .skip-link:not(:focus) {
    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:focus { position: fixed; top: 8px; left: 8px; z-index: 100; background: var(--surface); padding: 0.5rem 0.75rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Buttons, forms
   ========================================================================== */
.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.5rem 0.9rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 550; font-size: 0.9rem; line-height: 1.2; cursor: pointer;
    text-decoration: none; transition: background 0.12s, border-color 0.12s, color 0.12s;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn--danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn--danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn--ghost:hover { background: var(--accent-soft); color: var(--accent-hover); }
.btn--sm { padding: 0.3rem 0.6rem; font-size: 0.82rem; }
.btn.is-copied { color: var(--ok); border-color: var(--ok); }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
form.inline { display: inline; }

.field { margin-bottom: 1.1rem; }
.field label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.3rem; }
.field .hint { color: var(--text-3); font-size: 0.82rem; margin-top: 0.3rem; }
.field .error { color: var(--danger); font-size: 0.85rem; margin-top: 0.3rem; }
.input {
    width: 100%; padding: 0.6rem 0.75rem; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.input:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
.input.is-invalid { border-color: var(--danger); }
.input-group { display: flex; align-items: stretch; }
.input-group .input-prefix {
    display: flex; align-items: center; padding: 0 0.75rem; color: var(--text-3); font-size: 0.9rem;
    background: var(--surface-2); border: 1px solid var(--border-strong); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }

/* ==========================================================================
   Cards, badges, tables
   ========================================================================== */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.9rem; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .grid--2, .grid--3, .grid--4 { grid-template-columns: minmax(0, 1fr); } }

.stat { padding: 1rem 1.1rem; }
.stat .stat-label { font-size: 0.8rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat .stat-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 0.15rem; }
.stat .stat-sub { font-size: 0.82rem; color: var(--text-3); }

.badge {
    display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.15rem 0.55rem; border-radius: 999px;
    font-size: 0.78rem; font-weight: 600; line-height: 1.5; background: var(--neutral-soft); color: var(--text-2); white-space: nowrap;
}
.badge::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: currentColor; }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--failing { background: var(--danger-soft); color: var(--danger); }
.badge--unknown { background: var(--neutral-soft); color: var(--text-3); }
.badge--off { background: var(--warn-soft); color: var(--warn); }
.badge--plain::before { display: none; }

.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1.25rem; padding: 0 1.25rem; } /* relative: keeps absolutely-positioned .visually-hidden cells inside the scroll box */
table.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.6rem 0.65rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-title { font-weight: 600; }
.table .cell-sub { color: var(--text-3); font-size: 0.82rem; max-width: 36ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Half-width cards: keep their tables inside the card instead of scrolling. */
.grid .table-wrap { margin: 0; padding: 0; }
.grid .table th, .grid .table td { padding-left: 0.4rem; padding-right: 0.4rem; }
.grid .table .cell-sub { max-width: 22ch; }
.grid .table th:first-child, .grid .table td:first-child { padding-left: 0; }
.grid .table th:last-child, .grid .table td:last-child { padding-right: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.empty { color: var(--text-3); text-align: center; padding: 2rem 1rem; }

.bar-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.bar-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.25rem 0.75rem; align-items: center; font-size: 0.9rem; }
.bar-list .bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-list .bar-value { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 600; }
.bar-list .bar-track { display: block; grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar-list .bar-fill { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }

/* ==========================================================================
   Flash messages
   ========================================================================== */
.flashes { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.flash {
    display: flex; justify-content: space-between; gap: 1rem; align-items: center;
    padding: 0.7rem 0.9rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--surface); font-size: 0.92rem; transition: opacity 0.2s;
}
.flash--leaving { opacity: 0; }
.flash--success { border-color: var(--ok); background: var(--ok-soft); color: var(--text); }
.flash--warning { border-color: var(--warn); background: var(--warn-soft); }
.flash--error { border-color: var(--danger); background: var(--danger-soft); }
.flash button { border: 0; background: transparent; color: inherit; font-size: 1.1rem; cursor: pointer; line-height: 1; padding: 0.2rem; }

/* ==========================================================================
   Public shell (home, login, warning, errors)
   ========================================================================== */
.public { min-height: 100vh; display: flex; flex-direction: column; }
.public-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem 16px; }
.public-card { width: 100%; max-width: 480px; padding: 2rem; }
.public-card.wide { max-width: 560px; }
.public-footer { text-align: center; color: var(--text-3); font-size: 0.82rem; padding: 1rem 16px 1.5rem; }
.public-footer a { color: inherit; }
.brand { display: inline-flex; align-items: center; gap: 0.55rem; font-weight: 750; font-size: 1.25rem; letter-spacing: -0.02em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 1.6rem; height: 1.6rem; border-radius: 0.45rem; background: var(--accent); color: var(--on-accent); display: inline-grid; place-items: center; font-size: 0.95rem; font-weight: 800; }
.hero { text-align: center; }
.hero h1 { font-size: 2rem; margin: 1rem 0 0.5rem; }
.hero p { color: var(--text-2); font-size: 1.05rem; }
.hero .brand { font-size: 1.6rem; }
.hero .brand-mark { width: 2.2rem; height: 2.2rem; font-size: 1.25rem; border-radius: 0.6rem; }

.warning-head { display: flex; gap: 0.9rem; align-items: flex-start; }
.warning-icon { flex: none; width: 2.6rem; height: 2.6rem; border-radius: 50%; background: var(--warn-soft); color: var(--warn); display: grid; place-items: center; font-size: 1.4rem; font-weight: 800; }
.warning-facts { margin: 1rem 0 1.25rem; padding: 0.9rem 1rem; background: var(--surface-2); border-radius: var(--radius-sm); font-size: 0.9rem; display: grid; gap: 0.35rem; }
.warning-facts dt { color: var(--text-3); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.warning-facts dd { margin: 0 0 0.35rem; word-break: break-all; }
.warning-facts dd:last-child { margin-bottom: 0; }

/* ==========================================================================
   Admin shell — sidebar on desktop, collapsible top bar on phones
   ========================================================================== */
.admin { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
/* Grid children default to min-width:auto, which lets a wide table push the
   whole page wider than the viewport; cap them so tables scroll inside .table-wrap. */
.sidebar, .content { min-width: 0; }
.sidebar {
    background: var(--surface); border-right: 1px solid var(--border);
    padding: 1.1rem 1rem; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 0; height: 100vh;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.nav-toggle { display: none; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); width: 2.4rem; height: 2.4rem; cursor: pointer; color: var(--text); font-size: 1.2rem; }
.nav { display: flex; flex-direction: column; gap: 0.15rem; }
.nav a {
    display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.7rem; border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 550; font-size: 0.92rem;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .nav-icon { width: 1.1rem; text-align: center; opacity: 0.8; }
.nav-section { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); font-weight: 650; margin: 0.6rem 0.7rem 0.2rem; }
.sidebar-foot { margin-top: auto; display: grid; gap: 0.5rem; font-size: 0.85rem; color: var(--text-3); }
.sidebar-foot .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .btn { justify-content: center; }
.env-badge { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.08em; padding: 0.1rem 0.4rem; border-radius: 4px; background: var(--warn-soft); color: var(--warn); }

.content { padding: 1.5rem clamp(16px, 3vw, 2.5rem) 3rem; max-width: 1240px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 0.75rem 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .lede { color: var(--text-3); margin: 0.2rem 0 0; font-size: 0.92rem; }
.breadcrumbs { font-size: 0.85rem; color: var(--text-3); margin-bottom: 0.4rem; }
.breadcrumbs a { color: inherit; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.toolbar .search { flex: 1 1 240px; display: flex; gap: 0.4rem; }
.toolbar .search .input { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip { padding: 0.3rem 0.7rem; border-radius: 999px; font-size: 0.82rem; font-weight: 550; border: 1px solid var(--border); color: var(--text-2); background: var(--surface); }
.chip:hover { text-decoration: none; background: var(--surface-2); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 1rem; font-size: 0.88rem; color: var(--text-3); }

.short-url { display: inline-flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.short-url code { font-size: 1.05rem; font-weight: 600; color: var(--text); background: var(--surface-2); padding: 0.25rem 0.55rem; border-radius: var(--radius-sm); word-break: break-all; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.45rem 1.25rem; font-size: 0.92rem; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-word; }
.target-url { word-break: break-all; }

/* ==========================================================================
   Chart (single series, columns, SVG rendered server-side)
   ========================================================================== */
.chart { width: 100%; margin: 0; } /* reset the UA figure margins */
.chart svg { width: 100%; height: auto; display: block; overflow: hidden; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .bar rect { fill: var(--series-1); transition: opacity 0.12s; }
.chart .bar .hit { fill: transparent; }
.chart .bar:hover rect.mark, .chart .bar:focus rect.mark { opacity: 0.75; }
.chart .bar .tip { opacity: 0; pointer-events: none; transition: opacity 0.12s; }
.chart .bar:hover .tip, .chart .bar:focus .tip { opacity: 1; }
.chart .bar:focus { outline: none; }
.chart .tip rect { fill: var(--text); }
.chart .tip text { fill: var(--surface); font-size: 11px; font-weight: 600; font-family: var(--font); }
.chart .value-label { fill: var(--text-2); font-size: 11px; font-weight: 600; font-family: var(--font); }
.chart-meta { display: flex; justify-content: space-between; gap: 1rem; color: var(--text-3); font-size: 0.82rem; margin-top: 0.4rem; }
details.table-view summary { cursor: pointer; color: var(--accent); font-size: 0.85rem; margin-top: 0.5rem; }

/* ==========================================================================
   Responsive: phone layout
   ========================================================================== */
@media (max-width: 820px) {
    .admin { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 0.75rem 16px; }
    .nav-toggle { display: inline-grid; place-items: center; }
    .nav, .sidebar-foot, .nav-section { display: none; }
    .admin.nav-open .nav { display: flex; }
    .admin.nav-open .sidebar-foot { display: grid; margin-top: 0.5rem; }
    .admin.nav-open .nav-section { display: block; }
    .content { padding: 1rem 16px 2.5rem; }
    .page-head h1 { font-size: 1.35rem; }
    .table-wrap { margin: 0; padding: 0; }
    .table .cell-sub { max-width: 22ch; }
    .kv { grid-template-columns: 1fr; gap: 0.1rem 0; }
    .kv dt { margin-top: 0.5rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }

/* Utilities (CSP forbids inline style attributes) */
.mt { margin-top: 1rem; }
.narrow { max-width: 640px; }
.text-danger { color: var(--danger); }
.bar-list .bar-fill { width: 0; }
