/* ==========================================================================
   Gucci-Bot web UI
   Every colour is a token below, set per theme on <html data-theme="…">. The server renders the
   attribute from the theme cookie (WebThemes.cs), and wwwroot/theme.js switches it live.
   ========================================================================== */

/* ---- Themes ------------------------------------------------------------ */

:root,
[data-theme="midnight"] {
    /* Chart series, validated for colour-blind separation against this theme's surface. */
    --series-1: #7c7cff;
    --series-2: #d9772b;
    color-scheme: dark;
    --bg: #0b0d12;
    --glow-1: rgb(124 124 255 / 0.20);
    --glow-2: rgb(56 189 248 / 0.12);
    --surface: rgb(21 24 33 / 0.72);
    --raised: #171b25;
    --field: rgb(255 255 255 / 0.04);
    --line: rgb(255 255 255 / 0.08);
    --line-strong: rgb(255 255 255 / 0.16);
    --text: #eef0f6;
    --muted: #8d95a8;
    --accent: #7c7cff;
    --accent-2: #38bdf8;
    --on-accent: #ffffff;
    --ok: #34d399;
    --warn: #fbbf24;
    --error: #f87171;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
}

/* Black and gold, with the green-red-green stripe under the brand. */
[data-theme="gucci"] {
    /* Chart series, validated for colour-blind separation against this theme's surface. */
    --series-1: #b48d2c;
    --series-2: #3a86e0;
    color-scheme: dark;
    --bg: #0c0b09;
    --glow-1: rgb(212 175 55 / 0.16);
    --glow-2: rgb(31 122 69 / 0.18);
    --surface: rgb(26 23 17 / 0.76);
    --raised: #1c1914;
    --field: rgb(255 240 200 / 0.04);
    --line: rgb(255 236 180 / 0.09);
    --line-strong: rgb(255 236 180 / 0.18);
    --text: #f6efdf;
    --muted: #a99d84;
    --accent: #d4af37;
    --accent-2: #f1d77c;
    --on-accent: #1a1405;
    --ok: #3fae6a;
    --warn: #e7ae3c;
    --error: #d9534f;
    --stripe: linear-gradient(90deg, #1f7a45 0 33%, #b3202a 33% 67%, #1f7a45 67%);
    --shadow: 0 10px 30px rgb(0 0 0 / 0.45);
}

[data-theme="jellyfin"] {
    /* Chart series, validated for colour-blind separation against this theme's surface. */
    --series-1: #aa5cc3;
    --series-2: #2a9d8f;
    color-scheme: dark;
    --bg: #0d0e18;
    --glow-1: rgb(170 92 195 / 0.22);
    --glow-2: rgb(0 164 220 / 0.16);
    --surface: rgb(22 21 36 / 0.74);
    --raised: #181829;
    --field: rgb(255 255 255 / 0.04);
    --line: rgb(255 255 255 / 0.08);
    --line-strong: rgb(255 255 255 / 0.16);
    --text: #f0eef8;
    --muted: #938fae;
    --accent: #aa5cc3;
    --accent-2: #00a4dc;
    --on-accent: #ffffff;
    --ok: #3ddc97;
    --warn: #f5b942;
    --error: #ff6b81;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.4);
}

[data-theme="ember"] {
    /* Chart series, validated for colour-blind separation against this theme's surface. */
    --series-1: #e8602a;
    --series-2: #3987e5;
    color-scheme: dark;
    --bg: #110c0a;
    --glow-1: rgb(255 122 69 / 0.20);
    --glow-2: rgb(255 179 71 / 0.10);
    --surface: rgb(30 21 17 / 0.74);
    --raised: #1e1612;
    --field: rgb(255 230 210 / 0.04);
    --line: rgb(255 220 200 / 0.09);
    --line-strong: rgb(255 220 200 / 0.18);
    --text: #f8eee8;
    --muted: #ae9a8e;
    --accent: #ff7a45;
    --accent-2: #ffb347;
    --on-accent: #1f0d05;
    --ok: #4ade80;
    --warn: #facc15;
    --error: #f87171;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.4);
}

[data-theme="nord"] {
    /* Chart series, validated for colour-blind separation against this theme's surface. */
    --series-1: #2f9bc4;
    --series-2: #c9703c;
    color-scheme: dark;
    --bg: #1b2029;
    --glow-1: rgb(136 192 208 / 0.14);
    --glow-2: rgb(94 129 172 / 0.16);
    --surface: rgb(40 46 58 / 0.72);
    --raised: #262c37;
    --field: rgb(236 239 244 / 0.05);
    --line: rgb(236 239 244 / 0.09);
    --line-strong: rgb(236 239 244 / 0.18);
    --text: #eceff4;
    --muted: #9aa5b8;
    --accent: #88c0d0;
    --accent-2: #5e81ac;
    --on-accent: #1b2029;
    --ok: #a3be8c;
    --warn: #ebcb8b;
    --error: #bf616a;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.3);
}

[data-theme="daylight"] {
    /* Chart series, validated for colour-blind separation against this theme's surface. */
    --series-1: #4f46e5;
    --series-2: #eb6834;
    color-scheme: light;
    --bg: #f4f5f9;
    --glow-1: rgb(79 70 229 / 0.10);
    --glow-2: rgb(14 165 233 / 0.10);
    --surface: rgb(255 255 255 / 0.78);
    --raised: #ffffff;
    --field: #ffffff;
    --line: rgb(15 23 42 / 0.09);
    --line-strong: rgb(15 23 42 / 0.18);
    --text: #0f172a;
    --muted: #5b6478;
    --accent: #4f46e5;
    --accent-2: #0ea5e9;
    --on-accent: #ffffff;
    --ok: #059669;
    --warn: #b45309;
    --error: #dc2626;
    --shadow: 0 10px 30px rgb(15 23 42 / 0.08);
}

/* ---- Base -------------------------------------------------------------- */

:root {
    --radius: 14px;
    --radius-sm: 10px;
    --gradient: linear-gradient(135deg, var(--accent), var(--accent-2));
    --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
    --tabbar: 0px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(60rem 40rem at 10% -10%, var(--glow-1), transparent 60%),
        radial-gradient(50rem 35rem at 110% 10%, var(--glow-2), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    font: 15px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-feature-settings: "cv11", "ss01";
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

main {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.25rem calc(4rem + var(--tabbar));
}

h1 {
    font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin: 0 0 1.25rem;
}

h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
    margin: 2rem 0 0.75rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--error); }
.ok { color: var(--ok); }

code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
    font-size: 0.85em;
    padding: 0.1rem 0.35rem;
    border-radius: 6px;
    background: var(--field);
    border: 1px solid var(--line);
}

/* ---- Top bar ----------------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.7rem max(1.25rem, env(safe-area-inset-right)) 0.7rem max(1.25rem, env(safe-area-inset-left));
    border-bottom: 1px solid var(--line);
    isolation: isolate;
}

/* The frosted glass lives on a layer behind the bar, not on the bar itself: a backdrop-filter
   makes its element the frame of reference for position: fixed children, which would pin the
   phone tab bar to the bottom of this bar instead of the bottom of the screen. */
.topbar::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--surface);
    backdrop-filter: saturate(160%) blur(18px);
    -webkit-backdrop-filter: saturate(160%) blur(18px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: -0.01em;
    position: relative;
}

/* The Gucci theme's stripe, under the brand name only. */
.brand .name { position: relative; }
.brand .name::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -4px;
    height: 3px;
    border-radius: 2px;
    background: var(--stripe, transparent);
}

.mark {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 9px;
    background: var(--gradient);
    color: var(--on-accent);
    font-weight: 800;
    font-size: 1rem;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}

.mark.big { width: 3.25rem; height: 3.25rem; border-radius: 14px; font-size: 1.5rem; margin-bottom: 1.25rem; }

.tabs { display: flex; gap: 0.25rem; }

.tabs a {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.tabs a:hover { color: var(--text); background: var(--field); }

.tabs a.active {
    color: var(--text);
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
}

.tabs svg, .theme-picker svg, button.icon svg {
    width: 1.1rem;
    height: 1.1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tabs a.active svg { stroke: var(--accent); }

.tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ---- Theme picker ------------------------------------------------------ */

.theme-picker { position: relative; }

.theme-picker summary {
    list-style: none;
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 999px;
    cursor: pointer;
    color: var(--muted);
    border: 1px solid var(--line);
    background: var(--field);
    transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-picker summary::-webkit-details-marker { display: none; }
.theme-picker summary:hover,
.theme-picker[open] summary { color: var(--text); border-color: var(--line-strong); }
.theme-picker svg circle { fill: currentColor; stroke: none; }

.theme-picker .menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    min-width: 12rem;
    padding: 0.4rem;
    border-radius: var(--radius);
    background: var(--raised);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow);
    animation: pop 0.14s ease-out;
    z-index: 60;
}

.menu-label {
    padding: 0.35rem 0.6rem 0.45rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.theme-picker .menu button {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--text);
    text-align: left;
    font-weight: 500;
}

.theme-picker .menu button:hover { background: var(--field); }

.theme-picker .menu button[aria-pressed="true"] {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.theme-picker .menu button[aria-pressed="true"]::after {
    content: "✓";
    margin-left: auto;
    color: var(--accent);
    font-weight: 700;
}

.swatch {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 999px;
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.25);
    flex: none;
}

@keyframes pop {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

/* ---- Account ----------------------------------------------------------- */

form.account {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0.2rem 0.25rem 0.2rem 0.2rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--field);
}

.avatar {
    display: grid;
    place-items: center;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 999px;
    background: var(--gradient);
    color: var(--on-accent);
    font-size: 0.8rem;
    font-weight: 700;
}

.who { font-size: 0.88rem; font-weight: 500; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button.icon {
    display: grid;
    place-items: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: none;
    color: var(--muted);
}

button.icon:hover { color: var(--text); background: var(--field); transform: none; }

/* ---- Controls ---------------------------------------------------------- */

input, button {
    font: inherit;
    color: var(--text);
}

input:not([type="checkbox"]) {
    width: 100%;
    padding: 0.7rem 0.95rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--field);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder { color: var(--muted); opacity: 0.8; }

input:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

button {
    cursor: pointer;
    padding: 0.65rem 1.05rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--field);
    font-weight: 600;
    transition: transform 0.12s ease, box-shadow 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}

button:hover:not(:disabled) { border-color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: none; box-shadow: var(--ring); }
button:disabled { opacity: 0.45; cursor: default; }

button.primary {
    border: 0;
    background: var(--gradient);
    color: var(--on-accent);
    box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 30%, transparent);
}

button.primary:hover:not(:disabled) {
    box-shadow: 0 8px 26px color-mix(in srgb, var(--accent) 45%, transparent);
    transform: translateY(-1px);
}

button.link {
    background: none;
    border: 0;
    padding: 0;
    color: var(--accent);
    font-weight: 500;
}

button.link:hover { text-decoration: underline; }

a.button {
    display: inline-flex;
    align-items: center;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--field);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
    transition: border-color 0.15s ease;
}

a.button:hover, label.button:hover { border-color: var(--accent); }

label.button {
    display: inline-flex;
    align-items: center;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--field);
    color: var(--text);
    font-weight: 600;
    white-space: nowrap;
    transition: border-color 0.15s ease;
}

a.link { color: var(--accent); text-decoration: none; font-weight: 500; }
a.link:hover { text-decoration: underline; }

.row { display: flex; gap: 0.6rem; margin-bottom: 1.25rem; flex-wrap: wrap; align-items: center; }
.row input { flex: 1 1 14rem; width: auto; }

.spread { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.spread h1 { margin: 0; }
.actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.links { display: flex; gap: 1.25rem; flex-wrap: wrap; }

/* Movies | Series */
.segmented {
    display: inline-flex;
    padding: 0.25rem;
    border-radius: 999px;
    background: var(--field);
    border: 1px solid var(--line-strong);
}

.segmented button {
    border: 0;
    border-radius: 999px;
    padding: 0.45rem 1rem;
    background: none;
    color: var(--muted);
}

.segmented button:hover:not(:disabled) { color: var(--text); }

.segmented button.on {
    background: var(--gradient);
    color: var(--on-accent);
    box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ---- Cards: notes, results, queue rows --------------------------------- */

.note {
    position: relative;
    padding: 1rem 1.15rem 1rem 1.3rem;
    margin-bottom: 1.25rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: rise 0.2s ease-out;
}

.note::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--muted);
}

.note.ok::before { background: var(--ok); }
.note.warn::before, .note.connecting::before { background: var(--warn); }
.note.error::before { background: var(--error); }
.note strong { font-weight: 650; }
.note p { margin: 0.4rem 0 0; }
.note pre { white-space: pre-wrap; margin: 0.5rem 0 0; color: var(--muted); font-size: 0.85rem; }
.note details { margin-top: 0.75rem; }
.note details summary { cursor: pointer; }
.note details .release { padding-left: 0.85rem; border-left: 2px solid var(--line-strong); }

/* The waiting-for-connection banner gets a small pulse, so it reads as "in progress". */
.note.connecting strong::before {
    content: "";
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    margin-right: 0.5rem;
    border-radius: 999px;
    background: var(--warn);
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: 0.25; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.release { margin-top: 0.6rem; }
.release .muted { font-size: 0.85rem; }
.title { font-weight: 600; letter-spacing: -0.005em; }

ul.results, ul.queue { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; }

/* Search results: poster, details, action. */
ul.results li {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
    animation: rise 0.2s ease-out;
}

ul.results li:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow);
}

.poster {
    width: 4.5rem;
    aspect-ratio: 2 / 3;
    border-radius: 9px;
    overflow: hidden;
    background: var(--gradient);
    display: grid;
    place-items: center;
    color: var(--on-accent);
    font-size: 1.5rem;
    font-weight: 800;
    box-shadow: 0 6px 16px rgb(0 0 0 / 0.25);
}

.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }

.info { min-width: 0; }
.info .meta { color: var(--accent); font-size: 0.82rem; font-weight: 600; margin-top: 0.1rem; }

.info .overview {
    color: var(--muted);
    font-size: 0.88rem;
    margin-top: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cta { display: flex; align-items: center; gap: 0.5rem; justify-content: flex-end; }

/* Queue and season rows. */
ul.queue li {
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
}

.bar {
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
    margin: 0.55rem 0 0.4rem;
    background: var(--field);
    box-shadow: inset 0 0 0 1px var(--line);
}

.bar span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--gradient);
    transition: width 0.5s ease;
}

.code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
    font-size: 0.8em;
    font-weight: 600;
    color: var(--accent);
    margin-right: 0.5rem;
}

ul.seasons li { padding: 0.85rem 1rem; }

.check { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; }
.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); margin: 0; flex: none; }

.badge {
    display: inline-flex;
    align-items: center;
    margin-left: 0.4rem;
    padding: 0.12rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    background: var(--field);
    border: 1px solid var(--line);
    white-space: nowrap;
}

.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.badge.ok { margin-left: 0; color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }

/* The raw request line: kept for support, sized so it never competes with the explanation. */
.trace { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.76rem; opacity: 0.7; word-break: break-word; }

/* ---- Sign-in ----------------------------------------------------------- */

main.auth {
    min-height: calc(100vh - 4rem);
    display: grid;
    place-items: center;
    padding-top: 1rem;
}

.auth-card {
    width: min(100%, 24rem);
    padding: 2rem 1.75rem;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    animation: rise 0.25s ease-out;
}

.auth-card h1 { margin-bottom: 0.25rem; }
.auth-card > .muted { margin: 0 0 1.5rem; }

form.login { display: flex; flex-direction: column; gap: 1rem; }

form.login label:not(.check) {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
}

form.login button.primary { width: 100%; padding: 0.8rem; margin-top: 0.25rem; }
form.login .validation-errors { margin: 0; padding: 0.75rem 1rem 0.75rem 2rem; }

/* ---- Blazor's own failure bar ------------------------------------------ */

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 var(--tabbar) 0;
    z-index: 1000;
    padding: 0.85rem 1.25rem;
    background: var(--raised);
    border-top: 3px solid var(--error);
    box-shadow: 0 -6px 20px rgb(0 0 0 / 0.35);
}

#blazor-error-ui .reload { color: var(--accent); margin-left: 0.5rem; }

/* ---- Phones ------------------------------------------------------------ */

@media (max-width: 640px) {
    :root { --tabbar: calc(4rem + env(safe-area-inset-bottom)); }

    body { font-size: 15px; }

    /* 16px or more, or iOS zooms the page in on every focus. */
    input:not([type="checkbox"]) { font-size: 16px; }

    main { padding: 1.25rem 1rem calc(2rem + var(--tabbar)); }

    .topbar { gap: 0.75rem; padding-top: max(0.6rem, env(safe-area-inset-top)); }

    /* The tabs become an app-style bar along the bottom of the screen. */
    .tabs {
        position: fixed;
        z-index: 50;
        left: 0;
        right: 0;
        bottom: 0;
        height: var(--tabbar);
        padding: 0.4rem 0.75rem env(safe-area-inset-bottom);
        justify-content: space-around;
        background: var(--surface);
        border-top: 1px solid var(--line);
        backdrop-filter: saturate(160%) blur(18px);
        -webkit-backdrop-filter: saturate(160%) blur(18px);
    }

    .tabs a {
        flex: 1;
        flex-direction: column;
        justify-content: center;
        gap: 0.2rem;
        font-size: 0.72rem;
        border-radius: 12px;
        max-width: 8rem;
    }

    .tabs a.active { background: none; box-shadow: none; color: var(--accent); }
    .tabs svg { width: 1.35rem; height: 1.35rem; }

    .who { display: none; }
    form.account { padding: 0.15rem; gap: 0.15rem; }

    /* Search: the Movies/Series switch spans the width, then the field and button share a row. */
    .row.search .segmented { width: 100%; }
    .row.search .segmented button { flex: 1; }
    .row.search input { flex-basis: 0; min-width: 0; }

    /* Results: poster beside the text, action full width underneath. */
    ul.results li { grid-template-columns: auto 1fr; gap: 0.85rem; align-items: start; }
    .poster { width: 4rem; }
    .cta { grid-column: 1 / -1; justify-content: stretch; }
    .cta > button, .cta > a.button { flex: 1; justify-content: center; }
    .cta .badge { flex: none; }

    .spread .actions { width: 100%; }
    .spread .actions > * { flex: 1; justify-content: center; }

    .auth-card { padding: 1.75rem 1.25rem; }
    main.auth { min-height: calc(100vh - 8rem); }
}

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


/* ==========================================================================
   Metrics & admin
   ========================================================================== */

.small { font-size: 0.8rem; }

.card {
    padding: 1.1rem 1.2rem 1.2rem;
    margin-bottom: 1.25rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
}

.card header { margin-bottom: 1rem; }
.card header h2 { margin: 0; }
.card header p { margin: 0.35rem 0 0; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 0 1.25rem; }

.refreshing { opacity: 0.55; transition: opacity 0.2s ease; }

/* Sub-navigation inside Admin. */
.subnav {
    display: flex;
    gap: 0.25rem;
    margin: 0 0 1.5rem;
    padding: 0.25rem;
    border-radius: 999px;
    background: var(--field);
    border: 1px solid var(--line);
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
}

.subnav a {
    padding: 0.4rem 0.95rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
}

.subnav a:hover { color: var(--text); }
.subnav a.active { color: var(--on-accent); background: var(--gradient); }

/* ---- Stat tiles -------------------------------------------------------- */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: 0.75rem; margin: 1rem 0 1.25rem; }

.stat {
    padding: 0.95rem 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
}

.stat-label { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.stat-value { font-size: 1.65rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; margin: 0.25rem 0 0.2rem; }
.stat-delta { font-size: 0.78rem; font-weight: 600; }
.stat-delta.good { color: var(--ok); }
.stat-delta.bad { color: var(--error); }
.stat-delta.flat { color: var(--muted); font-weight: 500; }

/* ---- Charts ------------------------------------------------------------ */

.chart { --axis: 2.9rem; }

.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1.1rem; list-style: none; padding: 0; margin: 0 0 0.85rem; font-size: 0.85rem; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 0.45rem; }
.legend .key { width: 0.75rem; height: 0.75rem; border-radius: 3px; flex: none; }

.plot { position: relative; height: 13rem; margin-left: var(--axis); }

.gridline { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--line); }
.gridline span {
    position: absolute;
    right: calc(100% + 0.5rem);
    top: -0.55rem;
    font-size: 0.72rem;
    color: var(--muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.columns { position: absolute; inset: 0; display: grid; }

.column {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    height: 100%;
    border-radius: 6px;
    outline: none;
}

.column:hover, .column:focus-visible { background: color-mix(in srgb, var(--text) 5%, transparent); }

.stack {
    width: min(24px, 72%);
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
    border-radius: 4px 4px 0 0;
    overflow: hidden;
}

.stack span { flex-basis: 0; min-height: 2px; }
.column:hover .stack, .column:focus-visible .stack { filter: brightness(1.15); }

.tip {
    display: none;
    position: absolute;
    top: 0.25rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    min-width: 8.5rem;
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    background: var(--raised);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow);
    font-size: 0.8rem;
    white-space: nowrap;
    pointer-events: none;
}

.column:first-child .tip, .column:nth-child(2) .tip { left: 0; transform: none; }
.column:last-child .tip, .column:nth-last-child(2) .tip { left: auto; right: 0; transform: none; }
.column:hover .tip, .column:focus-visible .tip { display: block; }
.tip strong { display: block; margin-bottom: 0.3rem; font-weight: 600; }
.tip .row { display: flex; align-items: center; gap: 0.45rem; margin: 0.1rem 0 0; flex-wrap: nowrap; color: var(--muted); }
.tip .row b { color: var(--text); font-variant-numeric: tabular-nums; }
.tip .line { width: 0.8rem; height: 2px; border-radius: 1px; flex: none; }
.tip .total { border-top: 1px solid var(--line); padding-top: 0.25rem; margin-top: 0.25rem; }

.xaxis { display: grid; margin: 0.45rem 0 0 var(--axis); font-size: 0.72rem; color: var(--muted); }
.xaxis span { text-align: center; white-space: nowrap; overflow: visible; }

/* Area chart: SVG stretched to the plot, stroke kept at 2px regardless. */
svg.area { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
svg.area polygon { fill-opacity: 0.12; stroke: none; }
svg.area polyline { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }

.hover-only .column { border-radius: 0; }
.hover-only .column:hover, .hover-only .column:focus-visible { background: none; }
.hover-only .column::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    border-left: 1px solid var(--line-strong);
    opacity: 0;
}

.hover-only .dot {
    position: absolute;
    left: 50%;
    width: 10px;
    height: 10px;
    margin: 0 0 -5px -5px;
    border-radius: 999px;
    box-shadow: 0 0 0 2px var(--raised);
    opacity: 0;
}

.hover-only .column:hover::before, .hover-only .column:focus-visible::before,
.hover-only .column:hover .dot, .hover-only .column:focus-visible .dot { opacity: 1; }

/* Part-to-whole bar. */
.share-bar { display: flex; gap: 2px; height: 0.9rem; border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.share-bar span { min-width: 4px; }
.share-bar .empty { flex: 1; background: var(--field); }

.legend.big { display: grid; grid-template-columns: 1fr; gap: 0.5rem; margin: 0; color: var(--text); }
.legend.big li { display: grid; grid-template-columns: auto 1fr auto 3.2rem; gap: 0.6rem; align-items: center; }
.legend.big b { font-variant-numeric: tabular-nums; }
.legend.big .muted { text-align: right; font-variant-numeric: tabular-nums; }

/* Ranked horizontal bars. */
ol.barlist { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }

ol.barlist li {
    display: grid;
    grid-template-columns: minmax(6rem, 10rem) 1fr 2.5rem;
    align-items: center;
    gap: 0.75rem;
    border-radius: 8px;
    outline: none;
}

ol.barlist .name { font-size: 0.88rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ol.barlist .note-line { display: block; font-size: 0.74rem; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
ol.barlist .track { height: 0.75rem; border-radius: 0 4px 4px 0; overflow: hidden; }
ol.barlist .fill { display: block; height: 100%; min-width: 3px; border-radius: 0 4px 4px 0; }
ol.barlist .value { font-size: 0.85rem; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
ol.barlist li:hover .fill, ol.barlist li:focus-visible .fill { filter: brightness(1.15); }

/* The table view behind every chart. */
.table-view { margin-top: 1rem; }
.table-view summary { cursor: pointer; color: var(--muted); font-size: 0.82rem; }

.table-view table, table.audit { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table-view table { margin-top: 0.6rem; }
.table-view th, .table-view td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.table-view th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }

/* ---- Admin: services --------------------------------------------------- */

.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }

.health-card {
    padding: 0.95rem 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
}

.health-card p { margin: 0.4rem 0; }
.health-head { display: flex; align-items: center; gap: 0.55rem; }
.health-head .badge { margin-left: auto; }
.health-facts { display: flex; gap: 0.85rem; font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.status-dot { width: 0.6rem; height: 0.6rem; border-radius: 999px; background: var(--muted); flex: none; }
.ok .status-dot { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.warn .status-dot { background: var(--warn); box-shadow: 0 0 0 4px color-mix(in srgb, var(--warn) 20%, transparent); }
.bad .status-dot { background: var(--error); box-shadow: 0 0 0 4px color-mix(in srgb, var(--error) 20%, transparent); animation: pulse 1.4s ease-in-out infinite; }

.badge.bad { color: var(--error); background: color-mix(in srgb, var(--error) 12%, transparent); border-color: color-mix(in srgb, var(--error) 30%, transparent); }
.badge.off, .badge.source { color: var(--muted); }
.badge.source { margin-left: 0.35rem; font-size: 0.68rem; padding: 0 0.4rem; }
.health-card .badge, td .badge { margin-left: 0; }
.health-card .badge { margin-left: auto; }

.facts dl { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.9rem 1.5rem; }
.facts dt { color: var(--muted); font-size: 0.78rem; font-weight: 500; }
.facts dd { margin: 0.15rem 0 0; font-weight: 500; overflow-wrap: anywhere; }

/* ---- Admin: audit ------------------------------------------------------ */

.filters { display: grid; grid-template-columns: 2fr repeat(3, minmax(0, 1fr)); gap: 0.6rem; margin-bottom: 1rem; }

select {
    font: inherit;
    color: var(--text);
    width: 100%;
    padding: 0.65rem 2.2rem 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E") no-repeat right 0.8rem center;
    appearance: none;
    cursor: pointer;
}

select:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
select option { background: var(--raised); color: var(--text); }

.table-wrap { border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; background: var(--surface); }

table.audit th {
    text-align: left;
    padding: 0.7rem 0.9rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    background: var(--field);
    border-bottom: 1px solid var(--line);
}

table.audit td { padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.audit tr:last-child td { border-bottom: 0; }
table.audit tbody tr:hover { background: color-mix(in srgb, var(--text) 3%, transparent); }
table.audit td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.audit .details { max-width: 22rem; }
.detail-text { font-size: 0.82rem; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.who-cell { display: flex; align-items: center; gap: 0.55rem; }
.avatar.small { width: 1.6rem; height: 1.6rem; font-size: 0.72rem; flex: none; }

.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; }

/* ---- Admin: settings --------------------------------------------------- */

.settings .setting {
    display: grid;
    grid-template-columns: 1fr minmax(12rem, 16rem);
    gap: 1rem 2rem;
    align-items: center;
    padding: 0.9rem 0;
    border-top: 1px solid var(--line);
}

.settings .setting:first-of-type { border-top: 0; padding-top: 0; }
.settings .setting.dirty .setting-text label::after { content: " •"; color: var(--accent); }
.setting-text label { font-weight: 600; }
.setting-text p { margin: 0.2rem 0 0; }
.setting-control { display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; }
.setting-control > input, .setting-control > select, .setting-control .number { width: 100%; }
.setting-control .number { display: flex; align-items: center; gap: 0.5rem; }
button.link.small { font-size: 0.8rem; }

/* A switch built on a real checkbox, so it stays keyboard- and screen-reader-friendly. */
.switch { position: relative; display: inline-block; width: 2.9rem; height: 1.65rem; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--field);
    border: 1px solid var(--line-strong);
    transition: background-color 0.2s ease;
}
.switch span::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: calc(1.65rem - 8px);
    height: calc(1.65rem - 8px);
    border-radius: 999px;
    background: var(--muted);
    transition: transform 0.2s ease, background-color 0.2s ease;
}
.switch input:checked + span { background: var(--gradient); border-color: transparent; }
.switch input:checked + span::after { transform: translateX(1.25rem); background: #fff; }
.switch input:focus-visible + span { box-shadow: var(--ring); }
.switch input:disabled + span { opacity: 0.5; }

.icon-editor { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.icon-editor .mark.big { margin: 0; }
label.button.file { position: relative; cursor: pointer; overflow: hidden; }
label.button.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.mark.image { object-fit: cover; padding: 0; background: var(--field); }

.save-bar {
    position: sticky;
    bottom: calc(1rem + var(--tabbar));
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.6rem;
    padding: 0.7rem 0.8rem;
    border-radius: var(--radius);
    background: var(--raised);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow);
    transform: translateY(1rem);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.save-bar.visible { opacity: 1; transform: none; pointer-events: auto; }
.save-bar .muted { margin-right: auto; }

@media (max-width: 640px) {
    .filters { grid-template-columns: 1fr 1fr; }
    .filters input { grid-column: 1 / -1; }
    .filters select:last-child { grid-column: 1 / -1; }

    .plot { height: 11rem; }
    .kpis { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 1.35rem; }

    /* The audit table folds into one card per entry. */
    .table-wrap { border: 0; background: none; overflow: visible; }
    table.audit thead { display: none; }
    table.audit, table.audit tbody, table.audit tr, table.audit td { display: block; width: 100%; }
    table.audit tr {
        margin-bottom: 0.75rem;
        padding: 0.4rem 0;
        border-radius: var(--radius);
        border: 1px solid var(--line);
        background: var(--surface);
    }
    table.audit td { border: 0; padding: 0.35rem 0.9rem; display: grid; grid-template-columns: 5rem 1fr; gap: 0.1rem 0.5rem; }
    table.audit td::before { content: attr(data-label); grid-column: 1; color: var(--muted); font-size: 0.75rem; font-weight: 600; padding-top: 0.1rem; }
    table.audit td > * { grid-column: 2; }
    table.audit td > .badge { justify-self: start; }
    table.audit td:first-child { white-space: normal; }
    table.audit .details { max-width: none; }

    .settings .setting { grid-template-columns: 1fr; gap: 0.6rem; }
    .setting-control { align-items: stretch; }
    .setting-control .switch { align-self: flex-start; }
    .setting-control button.link { align-self: flex-start; }

    ol.barlist li { grid-template-columns: 7rem 1fr 2.2rem; }
    .legend.big li { grid-template-columns: auto 1fr auto 2.8rem; }
}
