:root {
    --bg: #0b0e14;
    --bg-elevated: #131826;
    --bg-input: #0f1420;
    --border: #232b3d;
    --text: #e7ebf3;
    --text-muted: #8b93a7;
    --brand: #6d5bff;
    --brand-hover: #8272ff;
    --brand-text: #ffffff;
    --danger: #ff5470;
    --danger-bg: rgba(255, 84, 112, 0.12);
    --success: #2fd889;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
    background: radial-gradient(circle at top, #141a2b 0%, var(--bg) 55%);
    color: var(--text);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    min-height: 100vh;
}

.site-header {
    border-bottom: 1px solid var(--border);
    background: rgba(11, 14, 20, 0.75);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

nav {
    max-width: 1080px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.9rem 1.25rem;
    padding: 0.9rem 1.5rem;
}

nav .brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.02em;
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/*
 * The real mark, the same file the favicon, the apple-touch icon and the
 * Open Graph card use — so the tab, the share preview and the header all
 * show one logo rather than three near-misses.
 *
 * background-image rather than `content: url(...)`: icon.svg carries a
 * viewBox but no width/height, so as generated content it has no
 * intrinsic size and browsers disagree about what to do. As a background
 * it is sized here and `contain` keeps its aspect ratio.
 */
nav .brand::before {
    content: "";
    display: inline-block;
    width: 1.7rem;
    height: 1.7rem;
    background: url("/assets/img/icon.svg") center / contain no-repeat;
}

nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: color 0.15s ease;
}

nav a:hover {
    color: var(--text);
}

main.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 4rem;
}

h1 {
    font-size: 1.75rem;
    letter-spacing: -0.02em;
    margin: 0 0 1.25rem;
}

h2 {
    font-size: 1.2rem;
    letter-spacing: -0.01em;
    margin: 0 0 0.9rem;
    color: var(--text);
}

p {
    color: var(--text-muted);
}

a {
    color: var(--brand-hover);
}

.error {
    color: var(--danger);
    background: var(--danger-bg);
    border: 1px solid rgba(255, 84, 112, 0.35);
    border-radius: var(--radius);
    padding: 0.65rem 0.9rem;
    font-size: 0.9rem;
}

/* Forms */
form {
    max-width: 380px;
}

form label {
    display: block;
    margin-bottom: 1rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

form select,
form input:not([type="hidden"]) {
    display: block;
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.65rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

form select:focus,
form input:not([type="hidden"]):focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(109, 91, 255, 0.25);
}

/* Inline filter/action forms (status toggles, logout, etc.) should not
   inherit the 380px form width or stacked label spacing above. */
form[style*="display:inline"] {
    max-width: none;
    display: inline;
}

button,
a.btn,
input[type="submit"] {
    appearance: none;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    border-radius: var(--radius);
    background: var(--brand);
    color: var(--brand-text);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.05s ease;
}

button:hover,
a.btn:hover {
    background: var(--brand-hover);
}

button:active,
a.btn:active {
    transform: scale(0.98);
}

button.btn-danger {
    background: var(--danger);
    color: #fff;
}

button.btn-danger:hover {
    background: var(--danger);
    filter: brightness(0.92);
}

nav button,
nav form button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 500;
    padding: 0.45rem 0.85rem;
}

nav button:hover {
    color: var(--text);
    border-color: var(--text-muted);
    background: transparent;
}

/* Danger-ish actions (delete) get a quiet outline instead of brand purple */
table form button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.82rem;
    padding: 0.4rem 0.7rem;
}

table form button:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: transparent;
}

/* Every admin action — create, edit, view, enable, disable, delete — is a
   button, whether it POSTs or navigates. Which of the two it is stays an
   HTML question (a link that changes nothing keeps being an <a>, so it
   opens in a new tab and does not need CSRF); the operator should not have
   to tell them apart by eye to find what they can do to a row.

   These row actions borrow the quiet outline of `table form button` above
   rather than the brand fill, because a five-row table of purple buttons
   reads as five calls to action and none of them is. */
table a.btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.82rem;
    padding: 0.4rem 0.7rem;
}

table a.btn:hover {
    background: transparent;
    border-color: var(--text-muted);
    color: var(--text);
}

/* Wraps the contents of a row's action cell — a mixed bag of links and
   one-button forms — so they sit on a single baseline and wrap as a unit
   on a narrow screen, instead of being spaced by whatever whitespace the
   markup happens to have between the tags.

   It has to be an element inside the cell, never the <td> itself: laying
   out a table cell as flex stops it being a table cell, and the row comes
   apart. */
.row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

/* The create action above a table, and the submit/cancel pair under a
   form. Full size here: this one is the call to action. */
.page-actions,
.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.page-actions {
    margin: 0 0 1.25rem;
}

.form-actions {
    margin-top: 1.5rem;
}

/* Cards / sections */
section {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Catalog / channel & link lists */
ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
}

ul li a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: border-color 0.15s ease, transform 0.05s ease;
}

ul li a:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
}

ul li a img {
    border-radius: 6px;
    flex-shrink: 0;
}

/* Simple nav-style link lists (admin dashboard) shouldn't be grid cards */
main.container > ul {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* Tables (admin CRUD screens) — scroll horizontally rather than overflow
   the viewport once columns no longer fit on a narrow screen. */
table {
    width: 100%;
    min-width: 480px;
    border-collapse: collapse;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
}

.table-scroll {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
}

.table-scroll table {
    margin-bottom: 0;
}

thead {
    background: rgba(255, 255, 255, 0.03);
}

th, td {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

td form {
    display: inline;
    max-width: none;
}

/* Video player */
#player {
    display: block;
    width: 100%;
    max-width: 960px;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

#player-status {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------------
   Public site: hero, auth cards, catalog browsing, cinema watch layout.
   Admin screens intentionally keep the plainer table/form styling above.
   ------------------------------------------------------------------- */

.hero {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1.1rem;
    padding: 3.5rem 0 3rem;
}

.hero .eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--brand-hover);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.hero .eyebrow::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(47, 216, 137, 0.18);
}

.hero h1 {
    font-size: clamp(2rem, 4vw, 3.1rem);
    line-height: 1.1;
    margin: 0;
    max-width: 20ch;
}

.hero p.lead {
    color: var(--text-muted);
    font-size: 1.05rem;
    max-width: 46ch;
    margin: 0;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.btn.btn-lg {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
}

.btn.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn.btn-ghost:hover {
    background: var(--bg-elevated);
    border-color: var(--text-muted);
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
    width: 100%;
}

.feature-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.4rem;
}

.feature-card .icon {
    font-size: 1.4rem;
    display: inline-flex;
    width: 2.4rem;
    height: 2.4rem;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    background: rgba(109, 91, 255, 0.15);
    margin-bottom: 0.9rem;
}

.feature-card h3 {
    font-size: 1rem;
    margin: 0 0 0.4rem;
    color: var(--text);
}

.feature-card p {
    margin: 0;
    font-size: 0.88rem;
}

/* Auth pages (login/register): centered card instead of a plain form
   floating at the top of the page. */
.auth-shell {
    display: flex;
    justify-content: center;
    padding-top: 2rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.auth-card h1 {
    font-size: 1.5rem;
    margin-bottom: 0.3rem;
}

.auth-card p.lead {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 0 1.5rem;
}

.auth-card form {
    max-width: none;
}

.auth-card .switch {
    margin-top: 1.25rem;
    margin-bottom: 0;
    font-size: 0.88rem;
    text-align: center;
}

/* Catalog toolbar: just a search box now — category list and per-category
   channel list are both single flat grids (see .browse-grid). */
.catalog-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.5rem;
}

.catalog-search {
    display: block;
    width: 100%;
    max-width: 240px;
    margin: 0;
    padding: 0.5rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    font-size: 0.88rem;
}

.catalog-search:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(109, 91, 255, 0.25);
}

/* Browse cards — shared by the category-list page and the per-category
   channel-list page (catalog is now a two-step drill-down: categories,
   then channels within one category). */
.browse-grid {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.browse-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 1.1rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text);
    text-decoration: none;
    text-align: center;
    transition: border-color 0.15s ease, transform 0.1s ease, background 0.15s ease;
    position: relative;
}

.browse-card:hover {
    border-color: var(--brand);
    background: var(--bg-elevated);
    transform: translateY(-2px);
}

.browse-card .logo {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: contain;
    background: #fff;
    padding: 0.35rem;
}

.browse-card .logo-fallback {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--brand-hover));
}

.browse-card .name {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
}

.browse-card .count {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
}

.hidden {
    display: none !important;
}

.empty-state {
    background: var(--bg-elevated);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

/* Profile page: subscription_key display + copy button */
.key-field {
    display: flex;
    gap: 0.5rem;
    max-width: 480px;
}

.key-field input {
    flex: 1;
    padding: 0.65rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9rem;
}

.hint {
    max-width: 480px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Cinema / watch layout */
.watch-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 1.5rem;
    align-items: start;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    margin-bottom: 0.9rem;
}

.back-link:hover {
    color: var(--text);
}

.watch-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}

.watch-title h1 {
    margin: 0;
    font-size: 1.4rem;
}

.badge-live {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge-live::before {
    content: "";
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: var(--danger);
}

.channel-switcher h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 0.8rem;
}

.channel-switcher-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 70vh;
    overflow-y: auto;
}

.channel-switcher-list a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.channel-switcher-list a:hover {
    background: var(--bg-input);
    color: var(--text);
}

.channel-switcher-list a.active {
    background: var(--bg-input);
    border-color: var(--brand);
    color: var(--text);
}

.channel-switcher-list img,
.channel-switcher-list .logo-fallback-sm {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: contain;
    background: #fff;
    flex-shrink: 0;
}

.channel-switcher-list .logo-fallback-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--brand-hover));
}

@media (max-width: 900px) {
    .watch-layout {
        grid-template-columns: 1fr;
    }

    .channel-switcher-list {
        max-height: none;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: visible;
        padding-bottom: 0.3rem;
    }

    .channel-switcher-list a {
        flex-shrink: 0;
    }
}

/* Small screens: tighten spacing, shrink headings, stack nav/actions,
   and let form-embedded inputs (extend-days, etc.) shrink instead of
   forcing horizontal overflow. */
@media (max-width: 640px) {
    nav {
        padding: 0.75rem 1rem;
        gap: 0.6rem 0.9rem;
    }

    main.container {
        padding: 1.5rem 1rem 3rem;
    }

    h1 {
        font-size: 1.4rem;
    }

    section {
        padding: 1.1rem;
    }

    ul {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }

    td input[type="number"] {
        width: 4em;
    }
}

/* --- Recordings ("watch later") --- */
.recordings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.recording-list {
    list-style: none;
    padding: 0;
    margin: 1.25rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.recording-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
}

.recording-main {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.recording-channel,
.recording-window {
    font-size: 0.85rem;
    color: #94a3b8;
}

.recording-error {
    font-size: 0.85rem;
    color: #f87171;
}

.recording-side {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: rgba(148, 163, 184, 0.2);
    color: #cbd5e1;
}

.badge.status-scheduled { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.badge.status-recording { background: rgba(234, 179, 8, 0.2); color: #fde047; }
.badge.status-completed { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.badge.status-failed { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.badge.status-cancelled { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }

/* Subscription lifecycle (admin subscription list). 'expiring' is the
   3-day warning window, not a stored status — see Subscription.php. */
.badge.status-active { background: rgba(47, 216, 137, 0.18); color: #6ee7b7; }
.badge.status-expiring { background: rgba(234, 179, 8, 0.2); color: #fde047; }
.badge.status-expired { background: rgba(255, 84, 112, 0.16); color: #fca5a5; }
.badge.status-suspended { background: rgba(234, 179, 8, 0.2); color: #fde047; }
.badge.status-banned { background: rgba(255, 84, 112, 0.16); color: #fca5a5; }
.badge.status-pending { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }

.muted {
    color: var(--text-muted);
    font-size: 0.85em;
}

/* The whole point of the list: rows about to lapse have to be spottable
   without reading the dates. */
tbody tr.expiring-soon {
    background: rgba(234, 179, 8, 0.09);
    box-shadow: inset 3px 0 0 #fde047;
}

/* Filter tabs (admin subscription list) — links, not a select, so each
   filter is one click and carries its own count. */
.filter-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.filter-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-decoration: none;
}

.filter-tab:hover {
    border-color: var(--brand);
    color: var(--text);
}

.filter-tab.is-active {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--brand-text);
}

.filter-tab-count {
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    opacity: 0.8;
}

@media (max-width: 640px) {
    .recording-item {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Signup-closed notice (partials/signup_notice.php) — used on the home
   hero, the login card, and /register while REGISTRATION_ENABLED is off. */
.notice {
    margin: 1.25rem 0 0;
    padding: 1rem 1.1rem;
    background: rgba(109, 91, 255, 0.12);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}

.notice p {
    margin: 0 0 0.9rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.notice strong {
    color: var(--text);
}

/* Public plan list (partials/plan_cards.php) — every string inside a
   card comes from the admin's "Public listing" fields on the plan. The
   cards sit side by side as a pricing row, with one column raised. */
.plans {
    padding: 1rem 0 3.5rem;
}

.plans-head {
    text-align: center;
    margin: 0 auto 2rem;
    max-width: 34rem;
}

.plans-head h2 {
    margin: 0 0 0.4rem;
}

.plans-head p {
    margin: 0;
    color: var(--text-muted);
}

.plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    /* Stretch, not start: the columns of a pricing row line up at the
       bottom so the call-to-action buttons share one baseline. */
    align-items: stretch;
}

/* Two to four plans are pinned to a single row (the template adds
   .is-row) so they can be compared across; more than that keeps the
   wrapping auto-fit above. */
.plan-grid.is-row {
    grid-template-columns: repeat(var(--plan-count, 3), minmax(0, 1fr));
    max-width: 62rem;
    margin: 0 auto;
}

.plan-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.4rem;
}

.plan-card.is-highlighted {
    border-color: var(--brand);
    background: linear-gradient(180deg, rgba(109, 91, 255, 0.14), var(--bg-elevated) 55%);
    box-shadow: 0 0 0 1px var(--brand), var(--shadow);
    /* Lifted out of the row rather than made taller, so the highlighted
       column reads first without breaking the shared grid. */
    padding-block: 2rem;
    margin-block: -0.5rem;
    z-index: 1;
}

.plan-badge {
    position: absolute;
    top: -0.7rem;
    right: 1.2rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.plan-card h3 {
    margin: 0;
    font-size: 1.15rem;
}

.plan-price {
    margin: 0;
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}

.plan-price strong {
    font-size: 1.9rem;
    line-height: 1;
}

.plan-price span {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.plan-description {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.plan-features {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
}

.plan-features li {
    padding-left: 1.3rem;
    position: relative;
}

.plan-features li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: 700;
}

.plan-card .btn {
    margin-top: auto;
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
    text-align: center;
}

/* Narrow screens can't hold a row of columns: drop the lift and let the
   grid wrap, then stack outright on phones. */
@media (max-width: 860px) {
    .plan-grid.is-row {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }

    .plan-card.is-highlighted {
        padding-block: 1.5rem;
        margin-block: 0;
    }
}

@media (max-width: 560px) {
    .plan-grid,
    .plan-grid.is-row {
        grid-template-columns: 1fr;
    }
}

/* Android APK download band on the home page. The hero and the "Any
   screen" feature card link to /app.apk too — this is the wide,
   unmissable one at the foot of the page. */
.app-cta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1.2rem;
    margin: 0 0 3rem;
    padding: 1.8rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.app-cta h2 {
    margin: 0 0 0.4rem;
    font-size: 1.3rem;
}

.app-cta p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
    max-width: 52ch;
}

.app-cta .hint {
    margin-top: 0.4rem;
    font-size: 0.82rem;
}

.feature-card p a {
    font-size: 0.88rem;
    font-weight: 600;
}

/* ------------------------------------------------------------------
   Charts (templates/partials/chart_*.php)

   Every chart sits on --bg-elevated, and the four series colours below
   were picked against that exact surface: each one clears 3:1 contrast
   on it, sits inside one lightness band so no series shouts louder than
   another, and every adjacent pair stays apart under deuteranopia and
   protanopia. Swapping a colour here for something prettier is likely
   to quietly break one of those — re-check it against the surface, not
   against a white page.

   Green and red never touch: they are the pair colour-blind readers
   cannot separate, so wherever both appear (pool occupancy) the violet
   sits between them, and every segment is labelled as well as coloured.
   ------------------------------------------------------------------ */
:root {
    --viz-series: #7b6bff;
    --viz-good: #199e70;
    --viz-danger: #d94057;
    --viz-info: #3987e5;
}

.chart {
    margin: 0;
}

.chart-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

/* Recessive by design: hairline, solid, one step off the surface. The
   data is the only thing on the page allowed to be loud. */
.chart-grid {
    stroke: var(--border);
    stroke-width: 1;
}

.chart-tick {
    fill: var(--text-muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.chart-value {
    fill: var(--text);
    font-size: 12px;
    font-weight: 600;
}

.chart-empty {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

.chart-bars,
.chart-stacked {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    /* Explicit, because the site-wide `ul` rule above turns every list
       into a multi-column card grid — which would lay two bars of a
       ranked list side by side and destroy the comparison. */
    grid-template-columns: 1fr;
    gap: 0.85rem;
}

/* Same reason: `ul li a` styles list links as bordered cards, which a
   bar's own label must not become. */
.chart-bars-label a,
.chart-bars-label a:hover {
    display: inline;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    font-size: inherit;
    font-weight: inherit;
    transform: none;
}

.chart-bars-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.3rem;
}

.chart-bars-label {
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.chart-bars-label.is-muted {
    color: var(--text-muted);
    font-style: italic;
}

.chart-bars-label a {
    color: var(--text);
    text-decoration: none;
}

.chart-bars-label a:hover {
    text-decoration: underline;
}

.chart-bars-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.chart-bars-track,
.chart-stacked-track {
    background: var(--bg-input);
    border-radius: 4px;
    height: 14px;
    overflow: hidden;
}

.chart-bars-fill {
    display: block;
    height: 100%;
    border-radius: 0 4px 4px 0;
}

/* The 2px gap between segments is the surface showing through, which is
   what keeps neighbouring colours apart — a stroke round each segment
   would add ink that isn't data. */
.chart-stacked-track {
    display: flex;
    gap: 2px;
    height: 22px;
    background: transparent;
}

.chart-stacked-part {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 3px;
    border-radius: 3px;
}

.chart-stacked-value {
    font-size: 0.72rem;
    font-weight: 700;
    color: rgba(11, 14, 20, 0.85);
}

.chart-legend {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 1.1rem;
    margin: 0 0 0.9rem;
    padding: 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.chart-legend li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chart-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    display: inline-block;
}

/* A chart plus its heading. Also the wrapper for the <details> table
   under each chart — the numbers stay reachable without a mouse or a
   working eye for colour. */
.chart-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.2rem 1.3rem 1.3rem;
}

.chart-card h2,
.chart-card h3 {
    margin: 0 0 0.2rem;
    font-size: 1.05rem;
}

.chart-card .chart-note {
    margin: 0 0 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.chart-card details {
    margin-top: 1rem;
}

.chart-card details summary {
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
}

.chart-grid-2 {
    display: grid;
    /* Wide enough that a daily chart's 'compact' viewBox lands near 1:1
       with its rendered size; below that the row collapses to one column
       and each chart gets the full width instead of shrinking its text. */
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 1.2rem;
    margin: 1.5rem 0;
}

/* Stat tiles: the handful of numbers worth reading before any chart. */
.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.stat-tile {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
}

.stat-tile .label {
    display: block;
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 0.25rem;
}

.stat-tile .value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.stat-tile .sub {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* Holds the shared-scale stacked bar: the track inside is only as wide as
   its share of the biggest row, so the empty remainder has to be real
   space rather than a shrunken flex child. */
.chart-stacked-row {
    display: block;
    width: 100%;
}
