/*
 * Creep: shared look of the applications. Works without JavaScript and under a strict content policy:
 * no inline styles are needed.
 *
 * Colours are defined three times: light, dark by system preference, and dark by choice
 * (data-theme="dark"). The two dark blocks must be identical; the tests check it, and the contrast.
 */

:root {
    color-scheme: light;
    --cr-bg: #f4f6fa;
    --cr-glow: #e1e9fb;
    --cr-surface: #ffffff;
    --cr-surface-2: #eef1f7;
    --cr-line: #d6dce7;
    --cr-line-strong: #8a93a6;
    --cr-text: #171c28;
    --cr-muted: #515b70;
    --cr-accent: #2650c0;
    --cr-on-accent: #ffffff;
    --cr-ok: #0e6847;
    --cr-warn: #7a5000;
    --cr-bad: #a82a2a;
    --cr-on-bad: #ffffff;
    --cr-idle: #566075;
    --cr-series-1: #2a78d6;
    --cr-series-2: #c2410c;
    --cr-series-3: #0f8a63;
    --cr-shadow: rgb(23 32 56 / 16%);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --cr-bg: #0b0e16;
        --cr-glow: #182340;
        --cr-surface: #121723;
        --cr-surface-2: #1a2130;
        --cr-line: #273044;
        --cr-line-strong: #5b6782;
        --cr-text: #e7eaf2;
        --cr-muted: #96a0b6;
        --cr-accent: #8aaaff;
        --cr-on-accent: #0a1022;
        --cr-ok: #55caa0;
        --cr-warn: #e3b260;
        --cr-bad: #f48282;
        --cr-on-bad: #200a0a;
        --cr-idle: #949db2;
        --cr-series-1: #3987e5;
        --cr-series-2: #d95926;
        --cr-series-3: #199e70;
        --cr-shadow: rgb(0 0 0 / 45%);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --cr-bg: #0b0e16;
    --cr-glow: #182340;
    --cr-surface: #121723;
    --cr-surface-2: #1a2130;
    --cr-line: #273044;
    --cr-line-strong: #5b6782;
    --cr-text: #e7eaf2;
    --cr-muted: #96a0b6;
    --cr-accent: #8aaaff;
    --cr-on-accent: #0a1022;
    --cr-ok: #55caa0;
    --cr-warn: #e3b260;
    --cr-bad: #f48282;
    --cr-on-bad: #200a0a;
    --cr-idle: #949db2;
    --cr-series-1: #3987e5;
    --cr-series-2: #d95926;
    --cr-series-3: #199e70;
    --cr-shadow: rgb(0 0 0 / 45%);
}

:root {
    --cr-radius: 12px;
    --cr-radius-small: 8px;
    --cr-font: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    --cr-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--cr-bg); }

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(1100px 400px at 50% -170px, var(--cr-glow) 0%, transparent 70%) no-repeat, var(--cr-bg);
    color: var(--cr-text);
    font: 15px/1.5 var(--cr-font);
}

h1, h2, h3, p, dl, dd { margin: 0; }

a { color: var(--cr-accent); }

button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--cr-accent); outline-offset: 2px; }

.cr-muted { color: var(--cr-muted); }

.cr-mono { font-family: var(--cr-mono); font-size: 13px; }

.cr-number { font-variant-numeric: tabular-nums; }

/* Header */

.cr-top {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--cr-bg);
    background: color-mix(in srgb, var(--cr-bg) 86%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--cr-line);
}

.cr-top-row { display: flex; align-items: center; gap: 28px; padding: 13px 32px; }

.cr-brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }

.cr-brand-mark { position: relative; display: inline-flex; flex: none; }

.cr-logo { width: 38px; height: 38px; border-radius: 50%; }

.cr-brand-mark .cr-dot { position: absolute; right: -1px; bottom: -1px; box-shadow: 0 0 0 3px var(--cr-bg); }

.cr-title { display: block; font-size: 16px; font-weight: 600; letter-spacing: .2px; }

.cr-subtitle { display: block; color: var(--cr-muted); font-size: 12px; }

.cr-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--cr-idle); }

.cr-dot.cr-ok { background: var(--cr-ok); }

.cr-dot.cr-warn { background: var(--cr-warn); }

.cr-dot.cr-bad { background: var(--cr-bad); }

.cr-tabs { display: flex; flex: 1; gap: 4px; overflow-x: auto; scrollbar-width: none; }

.cr-tabs::-webkit-scrollbar { display: none; }

.cr-tabs a { padding: 6px 12px; border-radius: var(--cr-radius-small); color: var(--cr-muted); text-decoration: none; white-space: nowrap; }

.cr-tabs a:hover { color: var(--cr-text); }

.cr-tabs a[aria-current="page"] { color: var(--cr-text); background: var(--cr-surface-2); }

.cr-user { display: flex; align-items: center; gap: 14px; margin-left: auto; font-size: 13px; white-space: nowrap; }

.cr-user a { color: var(--cr-muted); }

.cr-role { padding: 1px 7px; border: 1px solid var(--cr-line); border-radius: 999px; color: var(--cr-accent); font-size: 11px; }

.cr-databar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 28px;
    padding: 8px 32px;
    border-top: 1px solid var(--cr-line);
    font-size: 12.5px;
}

.cr-datum { display: flex; align-items: center; gap: 8px; white-space: nowrap; }

.cr-datum b { font-weight: 600; font-variant-numeric: tabular-nums; }

.cr-datum span { color: var(--cr-muted); }

.cr-datum .cr-meter { width: 54px; margin: 0; }

/* Layout */

.cr-main { max-width: 1240px; margin: 0 auto; padding: 28px 32px 56px; }

.cr-main.cr-narrow { max-width: 460px; }

.cr-main > section + section { margin-top: 34px; }

.cr-section-title { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }

.cr-section-title h2 { color: var(--cr-muted); font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }

.cr-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr)); }

.cr-grid.cr-tiles { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }

.cr-card { min-width: 0; padding: 18px; background: var(--cr-surface); border: 1px solid var(--cr-line); border-radius: var(--cr-radius); }

.cr-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }

.cr-card-head h3 { font-size: 16px; font-weight: 600; }

.cr-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin-top: 14px; font-size: 13px; }

.cr-facts dt { color: var(--cr-muted); }

.cr-facts dd { text-align: right; overflow-wrap: anywhere; }

.cr-tile-label { display: flex; justify-content: space-between; gap: 8px; color: var(--cr-muted); font-size: 12px; }

.cr-tile-value { margin-top: 2px; font-size: 25px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }

.cr-tile-detail { color: var(--cr-muted); font-size: 12px; }

/* Meter: a <progress> element, so it needs neither scripts nor inline styles. */

.cr-meter {
    display: block;
    width: 100%;
    height: 5px;
    margin-top: 12px;
    border: 0;
    border-radius: 4px;
    overflow: hidden;
    appearance: none;
    background: var(--cr-line);
    color: var(--cr-accent);
}

.cr-meter::-webkit-progress-bar { background: var(--cr-line); }

.cr-meter::-webkit-progress-value { background: var(--cr-accent); }

.cr-meter::-moz-progress-bar { background: var(--cr-accent); }

.cr-meter.cr-warn::-webkit-progress-value { background: var(--cr-warn); }

.cr-meter.cr-warn::-moz-progress-bar { background: var(--cr-warn); }

.cr-meter.cr-bad::-webkit-progress-value { background: var(--cr-bad); }

.cr-meter.cr-bad::-moz-progress-bar { background: var(--cr-bad); }

/* Status: always with its text, never colour alone. */

.cr-pill {
    --cr-tone: var(--cr-idle);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    white-space: nowrap;
    color: var(--cr-tone);
    background: color-mix(in srgb, var(--cr-tone) 10%, transparent);
}

.cr-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--cr-tone); }

.cr-pill.cr-ok { --cr-tone: var(--cr-ok); }

.cr-pill.cr-warn { --cr-tone: var(--cr-warn); }

.cr-pill.cr-bad { --cr-tone: var(--cr-bad); }

.cr-pill.cr-busy { --cr-tone: var(--cr-accent); }

.cr-pill.cr-busy::before { animation: cr-blink 1.2s infinite; }

@keyframes cr-blink { 50% { opacity: .25; } }

/* Buttons */

.cr-button {
    display: inline-block;
    padding: 7px 14px;
    border: 1px solid var(--cr-line);
    border-radius: var(--cr-radius-small);
    background: var(--cr-surface-2);
    color: var(--cr-text);
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.cr-button:hover:not(:disabled) { border-color: var(--cr-accent); }

.cr-button:disabled { opacity: .5; cursor: default; }

.cr-button.cr-ghost { background: transparent; }

.cr-button.cr-primary { background: var(--cr-accent); border-color: var(--cr-accent); color: var(--cr-on-accent); font-weight: 600; }

.cr-button.cr-danger { background: var(--cr-bad); border-color: var(--cr-bad); color: var(--cr-on-bad); font-weight: 600; }

.cr-button.cr-wide { display: block; width: 100%; }

.cr-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* Forms */

.cr-field { display: block; margin-bottom: 14px; }

.cr-field > span { display: block; margin-bottom: 4px; }

.cr-input {
    display: block;
    width: 100%;
    padding: 8px 11px;
    background: var(--cr-surface);
    border: 1px solid var(--cr-line-strong);
    border-radius: var(--cr-radius-small);
}

.cr-input::placeholder { color: var(--cr-muted); }

textarea.cr-input { resize: vertical; }

.cr-hint { display: block; margin-top: 4px; color: var(--cr-muted); font-size: 12.5px; }

.cr-check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.cr-check input { width: 17px; height: 17px; flex: none; accent-color: var(--cr-accent); }

.cr-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }

.cr-toolbar .cr-input { flex: 1; width: auto; min-width: min(200px, 100%); }

.cr-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.cr-chip { padding: 4px 11px; border: 1px solid var(--cr-line); border-radius: 999px; background: transparent; color: var(--cr-muted); font-size: 13px; cursor: pointer; }

.cr-chip[aria-pressed="true"] { color: var(--cr-text); background: var(--cr-surface-2); border-color: var(--cr-accent); }

/*
 * Validation: the field gets a red border and its message floats under it. Several can be lit at once.
 *   <div class="cr-control cr-invalid">
 *     <input class="cr-input" aria-invalid="true" aria-describedby="e1"><span class="cr-bubble" id="e1">...</span>
 *   </div>
 */

.cr-control { position: relative; min-width: 0; }

/* Room for the message, so it does not cover what comes next. */
.cr-control.cr-invalid { margin-bottom: 28px; }

.cr-invalid .cr-input, .cr-input[aria-invalid="true"] { border-color: var(--cr-bad); box-shadow: 0 0 0 1px var(--cr-bad); }

.cr-bubble {
    position: absolute;
    top: calc(100% + 6px);
    left: 4px;
    z-index: 6;
    width: max-content;
    max-width: calc(100% - 8px);
    padding: 2px 9px;
    border-radius: 6px;
    background: var(--cr-bad);
    color: var(--cr-on-bad);
    font-size: 12px;
    line-height: 1.5;
    box-shadow: 0 6px 16px var(--cr-shadow);
}

.cr-bubble::before { content: ""; position: absolute; bottom: 100%; left: 12px; border: 5px solid transparent; border-bottom-color: var(--cr-bad); }

.cr-icon-button { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; }

.cr-icon-button svg { width: 18px; height: 18px; }

/* A button that drops a menu. It is a <details>, so it opens and closes without scripts. */
.cr-dropdown { position: relative; }

.cr-dropdown > summary { list-style: none; cursor: pointer; }

.cr-dropdown > summary::-webkit-details-marker { display: none; }

.cr-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 6; display: flex; flex-direction: column; min-width: 190px; padding: 6px; background: var(--cr-surface); border: 1px solid var(--cr-line); border-radius: var(--cr-radius-small); box-shadow: 0 10px 28px var(--cr-shadow); }

.cr-menu > a, .cr-menu > button { padding: 8px 10px; background: transparent; border: 0; border-radius: 6px; color: var(--cr-text); font-size: 14px; text-align: left; text-decoration: none; white-space: nowrap; cursor: pointer; }

.cr-menu > a:hover, .cr-menu > button:hover { background: var(--cr-surface-2); }

.cr-dialog.cr-large { width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto; }

/* Tables */

.cr-table-wrap { overflow-x: auto; background: var(--cr-surface); border: 1px solid var(--cr-line); border-radius: var(--cr-radius); }

.cr-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.cr-table th { padding: 10px 14px; border-bottom: 1px solid var(--cr-line); color: var(--cr-muted); font-size: 12px; font-weight: 500; text-align: left; white-space: nowrap; }

.cr-table td { padding: 9px 14px; border-bottom: 1px solid var(--cr-line); vertical-align: top; }

.cr-table tr:last-child td { border-bottom: 0; }

.cr-table tbody tr:hover { background: var(--cr-surface-2); }

.cr-table .cr-end { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.cr-empty { padding: 28px; color: var(--cr-muted); text-align: center; }

/* Messages */

.cr-note { --cr-tone: var(--cr-line); padding: 12px 14px; border: 1px solid var(--cr-line); border-left: 3px solid var(--cr-tone); border-radius: var(--cr-radius-small); background: var(--cr-surface); }

.cr-note + .cr-note { margin-top: 8px; }

.cr-note.cr-ok { --cr-tone: var(--cr-ok); }

.cr-note.cr-warn { --cr-tone: var(--cr-warn); }

.cr-note.cr-bad { --cr-tone: var(--cr-bad); }

.cr-dialog { width: min(440px, calc(100vw - 32px)); padding: 22px; color: var(--cr-text); background: var(--cr-surface); border: 1px solid var(--cr-line); border-radius: var(--cr-radius); box-shadow: 0 20px 50px var(--cr-shadow); }

.cr-dialog::backdrop { background: rgb(6 9 16 / 62%); backdrop-filter: blur(2px); }

.cr-dialog h2 { margin-bottom: 8px; font-size: 17px; }

.cr-toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: 380px; padding: 11px 15px; background: var(--cr-surface-2); border: 1px solid var(--cr-line); border-radius: 10px; box-shadow: 0 10px 30px var(--cr-shadow); }

.cr-code { display: block; padding: 10px 12px; overflow: auto; background: var(--cr-surface-2); border-radius: var(--cr-radius-small); font: 12.5px/1.6 var(--cr-mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Charts (drawn by creep-charts.js) */

.cr-chart { position: relative; margin-top: 10px; }

.cr-chart canvas { display: block; width: 100%; height: 86px; }

.cr-legend { display: inline-flex; gap: 12px; }

.cr-legend span::before { content: ""; display: inline-block; width: 10px; height: 3px; margin-right: 5px; border-radius: 2px; vertical-align: middle; background: var(--cr-series-1); }

.cr-legend .cr-series-2::before { background: var(--cr-series-2); }

.cr-legend .cr-series-3::before { background: var(--cr-series-3); }

.cr-tip { position: absolute; bottom: calc(100% + 4px); z-index: 4; padding: 4px 8px; background: var(--cr-surface-2); border: 1px solid var(--cr-line); border-radius: 6px; box-shadow: 0 6px 18px var(--cr-shadow); font-size: 12px; white-space: nowrap; pointer-events: none; }

/* Without a live connection, old values must not look current. */
.cr-stale .cr-tile-value, .cr-stale .cr-datum b, .cr-stale .cr-chart { opacity: .4; }

@media (max-width: 760px) {
    /* On a phone the header would take too much of the screen if it stayed. */
    .cr-top { position: relative; }
    .cr-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .cr-brand > span:last-child { min-width: 0; }
    .cr-top-row { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
    .cr-brand { flex: 1; min-width: 0; }
    .cr-tabs { order: 3; flex-basis: 100%; }
    .cr-databar { gap: 6px 16px; padding: 8px 16px; }
    .cr-datum span.cr-detail { display: none; }
    .cr-main { padding: 20px 16px 40px; }
    .cr-toast { right: 16px; bottom: 16px; left: 16px; }
}

@media (max-width: 420px) {
    .cr-user .cr-user-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
