/* Signal-box look: an enamel panel, round lamps and traces whose height tells the state.
   Each colour is light-dark(day, night): the system theme picks one, unless the header's switch
   set `data-theme` on <html> (static/js/theme.js). */
:root {
    color-scheme: light dark;
    --ground: light-dark(#D6DAD0, #191E1B);
    --plate: light-dark(#E9ECE4, #222823);
    --plate-deep: light-dark(#F2F4EE, #1D231F);
    --ink: light-dark(#1E2620, #DCE2D8);
    --ink-soft: light-dark(#3B443C, #B4BDB1);
    --muted: light-dark(#545D55, #98A296);
    --on-ink: light-dark(#E9ECE4, #191E1B);
    --rule: light-dark(#BEC4B8, #343B35);
    --rule-soft: light-dark(#D3D8CC, #2C332D);
    --rule-strong: light-dark(#A9B0A3, #4A524B);
    --go: light-dark(#14876A, #3FCB98);
    --go-ink: light-dark(#0F5E49, #5FD7AA);
    --go-wash: light-dark(#D3E6DC, #1E3329);
    --stop: light-dark(#C42E24, #FF5A4C);
    --stop-ink: light-dark(#A3241B, #FF8A7F);
    --stop-wash: light-dark(#F1DEDA, #3A2522);
    --stop-line: light-dark(#DDB5AE, #5A2F2A);
    --on-stop: light-dark(#FFFFFF, #191E1B);
    --caution: light-dark(#9A6A00, #F2B630);
    --caution-ink: light-dark(#7A5600, #F2B630);
    --caution-wash: light-dark(#F3E4BC, #3A3220);
    --off: light-dark(#6E776D, #7E887D);
    /* Day lamps wear a ring, night lamps glow. */
    --halo-stop: 0 0 0 4px light-dark(rgba(196, 46, 36, 0.2), transparent),
                 0 0 10px light-dark(transparent, rgba(255, 90, 76, 0.7));
    --halo-caution: 0 0 0 4px light-dark(rgba(154, 106, 0, 0.2), transparent),
                    0 0 10px light-dark(transparent, rgba(242, 182, 48, 0.55));
    --halo-go: 0 0 6px light-dark(transparent, rgba(63, 203, 152, 0.35));
    --shadow-tip: 0 6px 16px light-dark(rgba(30, 38, 32, 0.25), rgba(0, 0, 0, 0.45));

    --font-text: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-title: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;
}

:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

@font-face {
    font-display: swap;
    font-family: 'Barlow';
    font-weight: 400;
    src: url('../fonts/barlow-latin-400-normal.woff2') format('woff2');
}

@font-face {
    font-display: swap;
    font-family: 'Barlow';
    font-weight: 500;
    src: url('../fonts/barlow-latin-500-normal.woff2') format('woff2');
}

@font-face {
    font-display: swap;
    font-family: 'Barlow';
    font-weight: 600;
    src: url('../fonts/barlow-latin-600-normal.woff2') format('woff2');
}

@font-face {
    font-display: swap;
    font-family: 'Barlow Semi Condensed';
    font-weight: 600;
    src: url('../fonts/barlow-semi-condensed-latin-600-normal.woff2') format('woff2');
}

@font-face {
    font-display: swap;
    font-family: 'Barlow Semi Condensed';
    font-weight: 700;
    src: url('../fonts/barlow-semi-condensed-latin-700-normal.woff2') format('woff2');
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font-text);
    font-size: 15px;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
}

a {
    color: inherit;
}

a:hover {
    color: var(--go-ink);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--go);
    outline-offset: 2px;
}

h1, h2, h3 {
    font-family: var(--font-title);
    font-weight: 600;
    line-height: 1.15;
    text-wrap: balance;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.text-muted { color: var(--muted); }
.text-green { color: var(--go-ink); }
.text-red { color: var(--stop-ink); }

/* Header */
.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 32px;
    padding: 12px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px));
    border-bottom: 1px solid var(--rule);
}

@media (min-width: 720px) {
    .site-header {
        padding-inline: 40px;
    }
}

.site-header-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 32px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 20px;
    text-decoration: none;
}

.brand img {
    border-radius: 6px;
    box-shadow: 0 0 0 1px var(--rule);
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    font-weight: 500;
}

.site-nav a,
.header-link {
    padding: 6px 12px;
    border-radius: 4px;
    color: var(--muted);
    font-weight: 500;
    text-decoration: none;
    transition: color 120ms ease, background-color 120ms ease;
}

.site-nav a:hover,
.header-link:hover {
    color: var(--ink);
}

.site-nav a[aria-current="page"],
.header-link[aria-current="page"] {
    color: var(--ink);
    background: var(--plate);
    box-shadow: inset 0 0 0 1px var(--rule);
}

.theme-switch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: color 120ms ease, background-color 120ms ease;
}

.theme-switch:hover {
    color: var(--ink);
    background: var(--plate);
}

.theme-switch[hidden] {
    display: none;
}

.theme-icon {
    display: none;
}

.theme-switch[data-mode="system"] .theme-icon-system,
.theme-switch[data-mode="light"] .theme-icon-light,
.theme-switch[data-mode="dark"] .theme-icon-dark {
    display: block;
}

/* Page frame */
main {
    width: 100%;
}

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 36px max(16px, env(safe-area-inset-right, 0px)) 72px max(16px, env(safe-area-inset-left, 0px));
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.page-narrow {
    max-width: 1040px;
}

@media (min-width: 720px) {
    .page {
        padding-inline: 40px;
    }
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 16px 32px;
}

.page-head > div {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.page-head > .toolbar {
    flex-direction: row;
    gap: 10px;
}

.page-title {
    font-size: 40px;
    line-height: 1.05;
}

.page-lede {
    font-size: 18px;
    color: var(--ink-soft);
}

.section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px 16px;
}

.section-title {
    font-size: 20px;
}

.section-note {
    font-size: 13px;
    color: var(--muted);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.num {
    text-align: right;
    white-space: nowrap;
}

.back-link {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
}

/* Headline: the state that matters, as a sentence */
.headline {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 40px;
    line-height: 1.05;
}

.headline-sub {
    font-size: 18px;
    color: var(--ink-soft);
}

.headline-sub a {
    font-weight: 600;
}

/* Lamps */
.lamp {
    flex: none;
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--off);
}

.lamp-lg {
    width: 20px;
    height: 20px;
}

.lamp-up { background: var(--go); box-shadow: var(--halo-go); }
.lamp-down { position: relative; background: var(--stop); box-shadow: var(--halo-stop); }

/* A down lamp sends out a ring three times when it appears, then holds still: enough to catch
   the eye, short of the 5 s after which moving content must be pausable. */
.lamp-down::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--stop);
    opacity: 0;
    animation: ping 1.6s ease-out 3;
}

@keyframes ping {
    from { transform: scale(1); opacity: 0.7; }
    to { transform: scale(2.6); opacity: 0; }
}
.lamp-pending { background: var(--caution); box-shadow: var(--halo-caution); }
.lamp-paused { background: transparent; border: 2px solid var(--off); }

/* Panel: a plate set into the enamel */
.panel {
    background: var(--plate);
    border: 1px solid var(--rule);
    border-radius: 6px;
}

.panel-pad {
    padding: 18px 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.empty-state {
    padding: 28px 22px;
    color: var(--muted);
}

/* Traces: one bar per hour or day. The height tells the state, colour only confirms it. */
.trace {
    position: relative;
    display: grid;
    align-items: end;
    height: 30px;
    border-bottom: 1px solid var(--rule-strong);
    border-right: 2px solid var(--ink);
}

.trace-24 { grid-template-columns: repeat(24, minmax(0, 1fr)); }
.trace-90 { grid-template-columns: repeat(90, minmax(0, 1fr)); }
.trace-tall { height: 44px; }

.tick {
    position: relative;
    height: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.tick::before {
    content: "";
    flex: 1;
    margin: 0 1px;
    border-radius: 1px 1px 0 0;
    transition: filter 120ms ease;
}

.tick:hover::before {
    filter: brightness(1.2) saturate(1.1);
}

/* On load, bars rise from the baseline once. live.js marks the page settled after that, so the
   blocks it swaps in every 30 s do not rise again. */
.tick::before,
.lat::before {
    transform-origin: bottom;
    animation: rise 480ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.settled .tick::before,
.settled .lat::before {
    animation: none;
}

@keyframes rise {
    from { transform: scaleY(0); }
}

.trace-90 .tick::before {
    margin: 0 0.5px;
}

.tick-up::before { height: 26%; background: var(--go); }
.tick-partial::before { height: 42%; background: var(--caution); }
.tick-dip::before { height: 64%; background: var(--stop); }
.tick-down::before { height: 100%; margin: 0; background: var(--stop); border-radius: 0; }
.tick-none::before { flex: 0 0 3px; height: 3px; margin: 0; border-radius: 50%; background: var(--off); }

.tick-guide {
    border-left: 1px dashed var(--rule);
}

/* Tooltip of a bar, from its data-tip: a mouse convenience, the detail page lists the same
   figures in a table. Opens towards the middle of the trace so it stays on screen. */
.tick[data-tip]:hover::after,
.lat[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 5;
    width: max-content;
    max-width: 240px;
    padding: 8px 10px;
    border-radius: 4px;
    background: var(--ink);
    color: var(--on-ink);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    box-shadow: var(--shadow-tip);
    pointer-events: none;
    animation: tip-in 120ms ease-out;
}

@keyframes tip-in {
    from { opacity: 0; transform: translateY(-3px); }
}

.trace-24 .tick:nth-child(-n+12):hover::after,
.trace-90 .tick:nth-child(-n+45):hover::after,
.latency-chart .lat:nth-child(-n+12):hover::after {
    right: auto;
    left: 0;
}

.trace-axis {
    display: grid;
    font-size: 13px;
    color: var(--muted);
}

.trace-axis span {
    white-space: nowrap;
    overflow: visible;
}

.trace-axis span:last-child {
    display: flex;
    justify-content: flex-end;
    font-weight: 600;
    color: var(--ink);
}

/* Chips */
.chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.chip-down { background: var(--stop); color: var(--on-stop); }
.chip-up { background: var(--go-wash); color: var(--go-ink); }
.chip-caution { background: var(--caution-wash); color: var(--caution-ink); }

/* Buttons */
.button-primary,
.button-secondary,
.button-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 4px;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease, transform 80ms ease;
}

.button-primary:active,
.button-secondary:active,
.button-danger:active {
    transform: translateY(1px);
}

.button-primary {
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--on-ink);
}

.button-primary:hover {
    color: var(--on-ink);
    background: var(--ink-soft);
}

.button-secondary {
    border: 1px solid var(--rule-strong);
    background: var(--plate);
    color: var(--ink);
}

.button-secondary:hover {
    color: var(--ink);
    border-color: var(--ink);
}

.button-danger {
    border: 1px solid var(--stop);
    background: transparent;
    color: var(--stop-ink);
}

.button-danger:hover {
    background: var(--stop-wash);
    color: var(--stop-ink);
}

.button-small {
    padding: 5px 12px;
    font-size: 14px;
}

.inline-form {
    display: inline;
}

/* Segmented control made of links */
.segmented {
    display: inline-flex;
    flex-wrap: wrap;
    border: 1px solid var(--rule-strong);
    border-radius: 4px;
    overflow: hidden;
    font-weight: 500;
}

.segmented a {
    padding: 7px 14px;
    background: var(--plate);
    color: var(--ink);
    text-decoration: none;
    transition: background-color 120ms ease, color 120ms ease;
}

.segmented a:focus-visible {
    outline-offset: -3px;
}

.segmented a + a {
    border-left: 1px solid var(--rule-strong);
}

.segmented a[aria-current="true"] {
    background: var(--ink);
    color: var(--on-ink);
}

/* Search and plain fields */
.search-bar,
.field {
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid var(--rule);
    border-bottom: 2px solid var(--ink);
    border-radius: 4px 4px 0 0;
    background: var(--plate);
    color: var(--ink);
    font: inherit;
}

.search-bar::placeholder {
    color: var(--muted);
}

/* Tables */
.table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    padding: 10px 12px;
    text-align: left;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
}

.data-table td {
    padding: 8px 12px;
    border-top: 1px solid var(--rule-soft);
    vertical-align: top;
}

.data-table th:first-child,
.data-table td:first-child {
    padding-left: 20px;
}

.data-table th:last-child,
.data-table td:last-child {
    padding-right: 20px;
}

.data-table .num {
    text-align: right;
    white-space: nowrap;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

/* Banners */
.error-banner,
.success-banner {
    padding: 12px 16px;
    border-radius: 4px;
    font-weight: 500;
}

.error-banner {
    background: var(--stop-wash);
    border: 1px solid var(--stop-line);
    color: var(--stop-ink);
}

.success-banner {
    background: var(--go-wash);
    border: 1px solid var(--go);
    color: var(--go-ink);
}

.insecure-warning {
    max-width: 720px;
    margin: 24px auto 0;
}

.insecure-warning[hidden] {
    display: none;
}

/* Error pages */
.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 96px 24px;
    text-align: center;
}

.error-page h1 {
    font-size: 48px;
}

.error-page p {
    color: var(--muted);
}

@media (max-width: 640px) {
    .headline,
    .page-title {
        font-size: 32px;
    }
}

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