/* End Times Studio portal. Hand-written, no dependencies. Icons: Phosphor (wwwroot/icons.svg). */

@layer reset, tokens, base, layout, components, pages, utilities;

/* ------------------------------------------------------------------ tokens */

@layer tokens {
    :root {
        color-scheme: dark;

        /* Surfaces, darkest to lightest. */
        --bg: #090909;
        --surface-0: #0d0d0d;
        --surface-1: #141414;
        --surface-2: #1b1b1b;
        --surface-3: #242424;
        --surface-4: #2c2c2c;
        --surface-hover: #1a1a1a;

        --border: #222222;
        --border-strong: #2e2e2e;
        --hairline: rgb(255 255 255 / 0.05);

        --text: #f2ede3;
        --text-muted: #aaa396;
        --text-subtle: #8b8478;

        --accent: #d4af37;
        --accent-hover: #e6c45a;
        --accent-active: #b8962c;
        --accent-soft: rgb(212 175 55 / 0.12);
        --accent-border: rgb(212 175 55 / 0.38);
        --on-accent: #0b0b0b;

        --success: #86cf9f;
        --success-bg: rgb(134 207 159 / 0.09);
        --success-border: rgb(134 207 159 / 0.3);
        --warning: #ebb862;
        --warning-bg: rgb(235 184 98 / 0.09);
        --warning-border: rgb(235 184 98 / 0.32);
        --danger: #f0907c;
        --danger-bg: rgb(240 144 124 / 0.09);
        --danger-border: rgb(240 144 124 / 0.34);
        --danger-strong: #c9503a;
        --info: #93b8e6;
        --info-bg: rgb(147 184 230 / 0.09);
        --info-border: rgb(147 184 230 / 0.3);

        --focus: #f5d975;
        --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--focus);

        --space-1: 0.25rem;
        --space-2: 0.5rem;
        --space-3: 0.75rem;
        --space-4: 1rem;
        --space-5: 1.25rem;
        --space-6: 1.5rem;
        --space-7: 2rem;
        --space-8: 2.5rem;

        --radius-sm: 4px;
        --radius: 6px;
        --radius-lg: 10px;
        --radius-full: 999px;

        --text-xs: 0.75rem;
        --text-sm: 0.8125rem;
        --text-base: 0.9375rem;
        --text-md: 1.0625rem;
        --text-lg: 1.25rem;
        --text-xl: 1.5rem;
        --text-2xl: 1.75rem;

        --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        --mono: ui-monospace, "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;

        --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
        --shadow-lg: 0 16px 48px rgb(0 0 0 / 0.6);

        --sidebar-width: 15.5rem;
        --content-max: 76rem;
        --control-height: 2.5rem;
        --control-height-sm: 2rem;
        --ease: 140ms ease;
    }
}

/* ------------------------------------------------------------------ reset */

@layer reset {
    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

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

    body,
    h1,
    h2,
    h3,
    h4,
    p,
    figure,
    blockquote,
    dl,
    dd,
    ul,
    ol {
        margin: 0;
    }

    ul[class],
    ol[class] {
        padding: 0;
        list-style: none;
    }

    img,
    svg {
        display: block;
        max-width: 100%;
    }

    input,
    button,
    select,
    textarea {
        font: inherit;
        color: inherit;
    }

    button {
        cursor: pointer;
    }

    table {
        border-collapse: collapse;
    }
}

/* ------------------------------------------------------------------ base */

@layer base {
    body {
        min-height: 100vh;
        background: var(--bg);
        color: var(--text);
        font-family: var(--sans);
        font-size: var(--text-base);
        line-height: 1.55;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    h1,
    h2,
    h3,
    h4 {
        color: var(--text);
        font-weight: 650;
        line-height: 1.25;
        letter-spacing: -0.01em;
    }

    h1 {
        font-size: var(--text-2xl);
    }

    h2 {
        font-size: var(--text-lg);
    }

    h3 {
        font-size: var(--text-md);
    }

    h4 {
        font-size: var(--text-base);
    }

    a {
        color: var(--accent);
        text-decoration: none;
        text-underline-offset: 0.2em;
        transition: color var(--ease);
    }

    a:hover {
        color: var(--accent-hover);
        text-decoration: underline;
    }

    strong,
    b {
        font-weight: 650;
    }

    code,
    kbd,
    samp {
        font-family: var(--mono);
        font-size: 0.9em;
    }

    :focus-visible {
        outline: 2px solid var(--focus);
        outline-offset: 2px;
    }

    ::selection {
        background: var(--accent);
        color: var(--on-accent);
    }

    time {
        font-variant-numeric: tabular-nums;
    }
}

/* ------------------------------------------------------------------ layout */

@layer layout {
    .skip-link {
        position: absolute;
        top: var(--space-2);
        left: var(--space-2);
        z-index: 100;
        padding: var(--space-2) var(--space-4);
        border-radius: var(--radius);
        background: var(--accent);
        color: var(--on-accent);
        font-weight: 600;
        transform: translateY(-200%);
    }

    .skip-link:focus {
        transform: none;
        color: var(--on-accent);
        text-decoration: none;
    }

    /* App shell: fixed sidebar + fluid main column. */

    .app {
        min-height: 100vh;
    }

    .main {
        display: flex;
        flex-direction: column;
        min-width: 0;
        min-height: 100vh;
    }

    .content {
        display: grid;
        flex: 1;
        align-content: start;
        gap: var(--space-5);
        width: 100%;
        max-width: var(--content-max);
        padding: var(--space-6) var(--space-7) var(--space-8);
    }

    .content:focus {
        outline: none;
    }

    .footer {
        padding: var(--space-5) var(--space-7) var(--space-6);
        color: var(--text-subtle);
        font-size: var(--text-xs);
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    /* Brand */

    .brand {
        display: inline-flex;
        align-items: center;
        gap: var(--space-3);
        color: var(--text);
        text-decoration: none;
    }

    .brand:hover {
        color: var(--text);
        text-decoration: none;
    }

    .brand-mark {
        flex: none;
        width: 28px;
        height: 28px;
        border-radius: var(--radius-sm);
    }

    .brand-name {
        font-size: var(--text-sm);
        font-weight: 700;
        letter-spacing: 0.16em;
        line-height: 1.2;
        text-transform: uppercase;
        color: var(--accent);
    }

    .brand-name span {
        color: var(--text-muted);
        font-weight: 600;
    }

    /* Mobile top bar (hidden on desktop). */

    .topbar {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-4);
        padding: var(--space-3) var(--space-4);
        background: rgb(13 13 13 / 0.92);
        backdrop-filter: blur(8px);
    }

    /* Sidebar. On mobile it is a popover drawer; on desktop it is always visible. */

    .sidebar {
        display: flex;
        flex-direction: column;
        gap: var(--space-5);
        width: min(var(--sidebar-width), 85vw);
        padding: var(--space-5) var(--space-3) var(--space-4);
        border: 0;
        background: var(--surface-0);
        color: var(--text);
        overflow-y: auto;
    }

    .sidebar[popover] {
        position: fixed;
        inset: 0 auto 0 0;
        height: 100dvh;
        max-height: none;
        margin: 0;
        box-shadow: var(--shadow-lg);
    }

    .sidebar[popover]:not(:popover-open) {
        display: none;
    }

    .sidebar::backdrop {
        background: rgb(0 0 0 / 0.6);
    }

    .sidebar-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-2);
        padding: 0 var(--space-2);
    }

    .sidebar-nav {
        display: flex;
        flex: 1;
        flex-direction: column;
        gap: var(--space-5);
    }

    .nav-group {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .nav-label {
        padding: 0 var(--space-3) var(--space-2);
        color: var(--text-subtle);
        font-size: 0.6875rem;
        font-weight: 650;
        letter-spacing: 0.14em;
        text-transform: uppercase;
    }

    .nav-link {
        position: relative;
        display: flex;
        align-items: center;
        gap: var(--space-3);
        width: 100%;
        min-height: 2.25rem;
        padding: var(--space-2) var(--space-3);
        border: 0;
        border-radius: var(--radius);
        background: transparent;
        color: var(--text-muted);
        font-size: var(--text-base);
        font-weight: 500;
        text-align: left;
        text-decoration: none;
        transition: background-color var(--ease), color var(--ease);
    }

    .nav-link .icon {
        font-size: 1.15rem;
        color: var(--text-subtle);
        transition: color var(--ease);
    }

    .nav-link:hover {
        background: var(--surface-2);
        color: var(--text);
        text-decoration: none;
    }

    .nav-link:hover .icon {
        color: var(--text-muted);
    }

    .nav-link[aria-current="page"] {
        background: var(--accent-soft);
        color: var(--text);
        font-weight: 600;
    }

    .nav-link[aria-current="page"] .icon {
        color: var(--accent);
    }

    .nav-link[aria-current="page"]::before {
        content: "";
        position: absolute;
        top: 0.45rem;
        bottom: 0.45rem;
        left: calc(-1 * var(--space-3));
        width: 3px;
        border-radius: 0 3px 3px 0;
        background: var(--accent);
    }

    .sidebar-account {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .sidebar-account form {
        margin: 0;
    }

    .account-card {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-2) var(--space-3) var(--space-3);
        min-width: 0;
    }

    .account-text {
        display: flex;
        flex-direction: column;
        min-width: 0;
        line-height: 1.3;
    }

    .account-label {
        color: var(--text-subtle);
        font-size: var(--text-xs);
    }

    .account-name {
        overflow: hidden;
        color: var(--text);
        font-weight: 600;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    @media (min-width: 64rem) {
        .app {
            display: grid;
            grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
        }

        .topbar {
            display: none;
        }

        .sidebar[popover],
        .sidebar[popover]:not(:popover-open) {
            position: sticky;
            inset: auto;
            top: 0;
            display: flex;
            width: auto;
            height: 100vh;
            box-shadow: none;
        }
    }

    /* Browsers without the Popover API: show the sidebar inline above the content. */
    @supports not selector(:popover-open) {
        .sidebar[popover],
        .sidebar[popover]:not(:popover-open) {
            position: static;
            display: flex;
            width: auto;
            height: auto;
            box-shadow: none;
        }
    }

    /* Page header: breadcrumbs, title, actions. */

    .page-header {
        width: 100%;
        max-width: var(--content-max);
        padding: var(--space-7) var(--space-7) 0;
    }

    .breadcrumbs {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-1) var(--space-2);
        margin-bottom: var(--space-3);
        color: var(--text-subtle);
        font-size: var(--text-sm);
    }

    .breadcrumbs a {
        color: var(--text-muted);
    }

    .breadcrumbs a:hover {
        color: var(--accent-hover);
    }

    .breadcrumbs > * + *::before {
        content: "/";
        margin-right: var(--space-2);
        color: var(--text-subtle);
    }

    .breadcrumbs [aria-current="page"] {
        color: var(--text);
    }

    .page-title-row {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-4);
    }

    .page-title-group {
        display: flex;
        align-items: center;
        gap: var(--space-4);
        min-width: 0;
    }

    .page-title-line {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2) var(--space-3);
    }

    .page-title {
        overflow-wrap: anywhere;
    }

    .page-subtitle {
        margin-top: var(--space-1);
        color: var(--text-muted);
    }

    .page-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2);
    }

    /* Auth layout: centred card, no sidebar. */

    body.auth {
        display: flex;
        flex-direction: column;
        background:
            radial-gradient(60rem 30rem at 50% -10%, rgb(212 175 55 / 0.08), transparent 70%),
            var(--bg);
    }

    .auth-main {
        display: flex;
        flex: 1;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: var(--space-6);
        padding: var(--space-8) var(--space-4);
    }

    .auth-brand {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--space-3);
    }

    .auth-brand .brand-mark {
        width: 40px;
        height: 40px;
    }

    .auth-card {
        width: 100%;
        max-width: 25rem;
    }

    body.auth .footer {
        text-align: center;
    }

    /* Two-column page layout for detail pages. */

    .split {
        display: grid;
        gap: var(--space-5);
        align-items: start;
    }

    .split-main,
    .split-aside {
        display: grid;
        gap: var(--space-5);
        min-width: 0;
    }

    @media (min-width: 72rem) {
        .split {
            grid-template-columns: minmax(0, 1fr) 20rem;
        }
    }

    @media (max-width: 40rem) {
        .content {
            padding: var(--space-5) var(--space-4) var(--space-7);
        }

        .page-header {
            padding: var(--space-5) var(--space-4) 0;
        }

        .footer {
            padding-inline: var(--space-4);
        }

        .page-actions,
        .page-actions .btn {
            width: 100%;
        }

        h1 {
            font-size: var(--text-xl);
        }
    }
}

/* ------------------------------------------------------------------ components */

@layer components {
    /* Icons */

    .icon {
        display: inline-block;
        flex: none;
        width: 1.15em;
        height: 1.15em;
        fill: currentColor;
        vertical-align: -0.2em;
    }

    .icon-lg {
        width: 1.5em;
        height: 1.5em;
    }

    /* Stacks */

    .stack {
        display: grid;
        gap: var(--space-4);
    }

    .stack-lg {
        display: grid;
        gap: var(--space-5);
    }

    .stack-sm {
        display: grid;
        gap: var(--space-2);
    }

    .cluster {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2) var(--space-3);
    }

    /* Buttons */

    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-2);
        min-height: var(--control-height);
        padding: 0 var(--space-4);
        border: 1px solid transparent;
        border-radius: var(--radius);
        background: var(--surface-3);
        color: var(--text);
        font-size: var(--text-sm);
        font-weight: 600;
        line-height: 1;
        white-space: nowrap;
        text-decoration: none;
        cursor: pointer;
        transition: background-color var(--ease), border-color var(--ease), color var(--ease);
    }

    .btn:hover {
        text-decoration: none;
    }

    .btn:focus-visible {
        outline: none;
        box-shadow: var(--focus-ring);
    }

    .btn:disabled,
    .btn[aria-disabled="true"] {
        opacity: 0.5;
        pointer-events: none;
    }

    .btn .icon {
        font-size: 1.1em;
    }

    .btn-primary {
        background: var(--accent);
        color: var(--on-accent);
    }

    .btn-primary:hover {
        background: var(--accent-hover);
        color: var(--on-accent);
    }

    .btn-primary:active {
        background: var(--accent-active);
    }

    .btn-secondary {
        background: var(--surface-3);
        color: var(--text);
    }

    .btn-secondary:hover {
        background: var(--surface-4);
        color: var(--text);
    }

    .btn-ghost {
        background: transparent;
        color: var(--text-muted);
    }

    .btn-ghost:hover {
        background: var(--surface-2);
        color: var(--text);
    }

    .btn-danger {
        background: rgb(240 144 124 / 0.14);
        color: var(--danger);
    }

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

    .btn-sm {
        min-height: var(--control-height-sm);
        padding: 0 var(--space-3);
        font-size: var(--text-xs);
    }

    .btn-block {
        width: 100%;
    }

    .btn-icon {
        width: var(--control-height);
        padding: 0;
    }

    .btn-icon.btn-sm {
        width: var(--control-height-sm);
    }

    /* Cards */

    .card {
        min-width: 0;
        border-radius: var(--radius-lg);
        background: var(--surface-1);
    }

    .card-header {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        justify-content: space-between;
        gap: var(--space-3) var(--space-4);
        padding: var(--space-5) var(--space-5) 0;
    }

    .card-header:only-child {
        padding-bottom: var(--space-5);
    }

    .card-title {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        font-size: var(--text-md);
        font-weight: 650;
    }

    .card-title .icon {
        color: var(--text-subtle);
    }

    .card-description {
        margin-top: var(--space-1);
        color: var(--text-muted);
        font-size: var(--text-sm);
    }

    .card-actions {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .card-body {
        padding: var(--space-5);
    }

    .card-body > * + * {
        margin-top: var(--space-4);
    }

    .card-body.flush {
        padding: var(--space-4) 0 0;
    }

    .card-footer {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-end;
        gap: var(--space-2) var(--space-3);
        padding: 0 var(--space-5) var(--space-5);
    }

    .card-footer.between {
        justify-content: space-between;
    }

    .card-danger {
        background:
            linear-gradient(rgb(240 144 124 / 0.05), rgb(240 144 124 / 0.05)),
            var(--surface-1);
    }

    .card-danger .card-title,
    .card-danger .card-title .icon {
        color: var(--danger);
    }

    /* Alerts */

    .alert {
        display: flex;
        align-items: flex-start;
        gap: var(--space-3);
        padding: var(--space-3) var(--space-4);
        border-left: 3px solid var(--border-strong);
        border-radius: var(--radius);
        background: var(--surface-2);
        color: var(--text);
        font-size: var(--text-sm);
    }

    .alert-icon {
        margin-top: 0.1rem;
        font-size: 1.1rem;
    }

    .alert-body {
        flex: 1;
        min-width: 0;
    }

    .alert-title {
        display: block;
        margin-bottom: var(--space-1);
        font-weight: 650;
    }

    .alert ul {
        margin: 0;
        padding-left: var(--space-5);
    }

    .alert-success {
        border-left-color: var(--success);
        background: var(--success-bg);
    }

    .alert-success .alert-icon {
        color: var(--success);
    }

    .alert-info {
        border-left-color: var(--info);
        background: var(--info-bg);
    }

    .alert-info .alert-icon {
        color: var(--info);
    }

    .alert-warning {
        border-left-color: var(--warning);
        background: var(--warning-bg);
    }

    .alert-warning .alert-icon {
        color: var(--warning);
    }

    .alert-danger {
        border-left-color: var(--danger);
        background: var(--danger-bg);
    }

    .alert-danger .alert-icon {
        color: var(--danger);
    }

    /* The validation summary tag helper adds this class when there are no errors. */
    .validation-summary-valid {
        display: none;
    }

    /* Badges (status) */

    .badge {
        display: inline-flex;
        align-items: center;
        gap: 0.4em;
        min-height: 1.4rem;
        padding: 0 0.55rem;
        border-radius: var(--radius-full);
        background: var(--surface-3);
        color: var(--text-muted);
        font-size: var(--text-xs);
        font-weight: 600;
        line-height: 1;
        white-space: nowrap;
    }

    .badge::before {
        content: "";
        width: 0.4rem;
        height: 0.4rem;
        border-radius: 50%;
        background: currentColor;
    }

    .badge-plain::before {
        display: none;
    }

    .badge-success {
        background: var(--success-bg);
        color: var(--success);
    }

    .badge-warning {
        background: var(--warning-bg);
        color: var(--warning);
    }

    .badge-danger {
        background: var(--danger-bg);
        color: var(--danger);
    }

    .badge-info {
        background: var(--info-bg);
        color: var(--info);
    }

    .badge-accent {
        background: var(--accent-soft);
        color: var(--accent);
    }

    .badge-list {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-1) var(--space-2);
    }

    /* Chips (roles, channels, permissions) */

    .chip-list {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-1) var(--space-2);
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .chip {
        display: inline-flex;
        align-items: center;
        gap: 0.35em;
        min-height: 1.5rem;
        padding: 0 0.5rem;
        border-radius: var(--radius-sm);
        background: var(--surface-3);
        color: var(--text);
        font-size: var(--text-xs);
        font-weight: 500;
        line-height: 1;
        white-space: nowrap;
    }

    .chip .icon {
        color: var(--text-subtle);
    }

    .chip-mono {
        font-family: var(--mono);
        font-weight: 400;
    }

    .chip-accent {
        background: var(--accent-soft);
        color: var(--accent);
    }

    .chip-empty {
        color: var(--text-subtle);
        font-size: var(--text-sm);
    }

    a.chip:hover {
        background: var(--surface-4);
        color: var(--accent-hover);
        text-decoration: none;
    }

    /* Forms */

    .field {
        display: grid;
        gap: var(--space-2);
        min-width: 0;
    }

    label,
    .label {
        color: var(--text);
        font-size: var(--text-sm);
        font-weight: 550;
    }

    .label-optional {
        color: var(--text-subtle);
        font-weight: 400;
    }

    input:where([type="text"], [type="password"], [type="email"], [type="search"], [type="number"], [type="url"], :not([type])),
    select,
    textarea {
        width: 100%;
        min-height: var(--control-height);
        padding: var(--space-2) var(--space-3);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--surface-0);
        color: var(--text);
        font-size: var(--text-base);
        caret-color: var(--accent);
        transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
    }

    input::placeholder,
    textarea::placeholder {
        color: var(--text-subtle);
    }

    input:where([type="text"], [type="password"], [type="email"], [type="search"], [type="number"], [type="url"], :not([type])):hover,
    select:hover,
    textarea:hover {
        border-color: var(--border-strong);
    }

    input:where([type="text"], [type="password"], [type="email"], [type="search"], [type="number"], [type="url"], :not([type])):focus-visible,
    select:focus-visible,
    textarea:focus-visible {
        border-color: var(--accent);
        outline: none;
        box-shadow: 0 0 0 3px var(--accent-soft);
    }

    input[readonly] {
        border-color: transparent;
        background: var(--surface-2);
        color: var(--text-muted);
        cursor: default;
    }

    input[readonly]:focus-visible {
        border-color: transparent;
        box-shadow: none;
    }

    .input-validation-error,
    input[aria-invalid="true"] {
        border-color: var(--danger) !important;
    }

    select {
        padding-right: 2.25rem;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='%23aaa396'%3E%3Cpath d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E");
        background-position: right 0.75rem center;
        background-repeat: no-repeat;
        background-size: 0.9rem;
        cursor: pointer;
    }

    input[type="search"]::-webkit-search-cancel-button {
        filter: grayscale(1) brightness(1.5);
    }

    .field-help {
        color: var(--text-muted);
        font-size: var(--text-xs);
    }

    .field-validation-error,
    .field-error {
        color: var(--danger);
        font-size: var(--text-xs);
    }

    .field-validation-valid {
        display: none;
    }

    .input-icon {
        position: relative;
    }

    .input-icon > .icon {
        position: absolute;
        top: 50%;
        left: var(--space-3);
        color: var(--text-subtle);
        transform: translateY(-50%);
        pointer-events: none;
    }

    .input-icon > input {
        padding-left: 2.25rem;
    }

    .form-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
        gap: var(--space-4);
    }

    .form-section {
        display: grid;
        gap: var(--space-4);
    }

    .form-section + .form-section {
        padding-top: var(--space-4);
    }

    .form-section-title {
        font-size: var(--text-base);
        font-weight: 650;
    }

    .form-section-description {
        margin-top: calc(-1 * var(--space-3));
        color: var(--text-muted);
        font-size: var(--text-sm);
    }

    .form-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2) var(--space-3);
    }

    .form-actions form {
        margin: 0;
    }

    fieldset {
        min-width: 0;
        margin: 0;
        padding: 0;
        border: 0;
    }

    legend {
        margin-bottom: var(--space-2);
        padding: 0;
        color: var(--text);
        font-size: var(--text-sm);
        font-weight: 550;
    }

    fieldset > .field-help,
    .choice-list + .field-help {
        margin-top: var(--space-2);
    }

    /* Choice cards: a bordered row per checkbox. */

    .choice-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
        gap: var(--space-2);
    }

    .choice {
        display: flex;
        align-items: flex-start;
        gap: var(--space-3);
        padding: var(--space-3);
        border-radius: var(--radius);
        background: var(--surface-2);
        color: var(--text);
        font-weight: 400;
        cursor: pointer;
        transition: background-color var(--ease);
    }

    .choice:hover {
        background: var(--surface-3);
    }

    .choice:has(input:checked) {
        background: var(--accent-soft);
    }

    .choice:has(input:focus-visible) {
        box-shadow: var(--focus-ring);
    }

    .choice-text {
        display: grid;
        gap: 0.1rem;
        min-width: 0;
    }

    .choice-title {
        font-size: var(--text-sm);
        font-weight: 600;
    }

    .choice-description {
        color: var(--text-muted);
        font-size: var(--text-xs);
        overflow-wrap: anywhere;
    }

    input[type="checkbox"],
    input[type="radio"] {
        flex: none;
        width: 1rem;
        height: 1rem;
        margin: 0.15rem 0 0;
        accent-color: var(--accent);
    }

    input[type="checkbox"]:focus-visible {
        outline: none;
    }

    /* Toolbar: filters above a table. */

    .toolbar {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-end;
        gap: var(--space-3);
        padding: 0 var(--space-5) var(--space-4);
    }

    .toolbar .field {
        flex: 0 1 11rem;
    }

    .toolbar .field-grow {
        flex: 1 1 16rem;
    }

    .toolbar .form-actions {
        flex: none;
    }

    /* Tables */

    .table-wrap {
        overflow-x: auto;
    }

    .card-header + .table-wrap {
        margin-top: var(--space-4);
    }

    .table-wrap.boxed {
        border-radius: var(--radius);
        background: var(--surface-0);
    }

    .table {
        width: 100%;
        font-size: var(--text-sm);
        font-variant-numeric: tabular-nums;
    }

    .table th,
    .table td {
        padding: var(--space-3) var(--space-4);
        border-bottom: 1px solid var(--hairline);
        text-align: left;
        vertical-align: middle;
    }

    .table th:first-child,
    .table td:first-child {
        padding-left: var(--space-5);
    }

    .table th:last-child,
    .table td:last-child {
        padding-right: var(--space-5);
    }

    .table thead th {
        padding-top: var(--space-2);
        padding-bottom: var(--space-2);
        border-bottom: 0;
        background: var(--surface-0);
        color: var(--text-subtle);
        font-size: var(--text-xs);
        font-weight: 600;
        letter-spacing: 0.04em;
        white-space: nowrap;
    }

    .table tbody th {
        font-weight: 600;
    }

    .table tbody tr {
        transition: background-color var(--ease);
    }

    .table tbody tr:hover {
        background: var(--surface-hover);
    }

    .table tbody tr:last-child > * {
        border-bottom: 0;
    }

    .table .num {
        text-align: right;
    }

    .table .nowrap {
        white-space: nowrap;
    }

    .table .cell-actions {
        width: 1%;
        text-align: right;
        white-space: nowrap;
    }

    .cell-sub {
        display: block;
        margin-top: 0.15rem;
        color: var(--text-subtle);
        font-size: var(--text-xs);
        font-weight: 400;
    }

    .cell-wrap {
        min-width: 14rem;
        overflow-wrap: anywhere;
    }

    .table-footer {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        padding: var(--space-4) var(--space-5);
        color: var(--text-muted);
        font-size: var(--text-sm);
    }

    /* Pagination */

    .pagination {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
    }

    .pagination-status {
        padding: 0 var(--space-2);
        color: var(--text-muted);
        font-size: var(--text-sm);
        white-space: nowrap;
    }

    /* Key/value lists */

    .kv {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
        gap: var(--space-4) var(--space-5);
    }

    .kv-stacked {
        grid-template-columns: 1fr;
    }

    .kv dt {
        margin-bottom: var(--space-1);
        color: var(--text-subtle);
        font-size: var(--text-xs);
        font-weight: 600;
    }

    .kv dd {
        margin: 0;
        overflow-wrap: anywhere;
    }

    /* Empty state */

    .empty {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-8) var(--space-5);
        color: var(--text-muted);
        text-align: center;
    }

    .empty-icon {
        display: grid;
        place-items: center;
        width: 3rem;
        height: 3rem;
        border-radius: var(--radius-lg);
        background: var(--surface-3);
        color: var(--text-subtle);
        font-size: 1.4rem;
    }

    .empty-title {
        color: var(--text);
        font-size: var(--text-md);
        font-weight: 650;
    }

    .empty p {
        max-width: 32rem;
    }

    /* Avatar */

    .avatar {
        display: inline-grid;
        flex: none;
        place-items: center;
        width: 2rem;
        height: 2rem;
        border-radius: 50%;
        background: var(--accent-soft);
        color: var(--accent);
        font-size: var(--text-sm);
        font-weight: 700;
        line-height: 1;
        text-transform: uppercase;
    }

    .avatar-lg {
        width: 3rem;
        height: 3rem;
        font-size: var(--text-lg);
    }

    /* Simple link list (e.g. assigned users). */

    .link-list {
        display: grid;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .link-list a {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-2) 0;
        color: var(--text);
    }

    .link-list a:hover {
        color: var(--accent-hover);
        text-decoration: none;
    }

    .link-list .avatar {
        width: 1.6rem;
        height: 1.6rem;
        font-size: var(--text-xs);
    }

    /* Eyebrow: small uppercase kicker above a heading. */

    .eyebrow {
        display: block;
        color: var(--text-subtle);
        font-size: 0.6875rem;
        font-weight: 650;
        letter-spacing: 0.14em;
        text-transform: uppercase;
    }
}

/* ------------------------------------------------------------------ pages */

@layer pages {
    /* Builds: launcher banner */

    .launcher-banner {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-4) var(--space-5);
        padding: var(--space-5);
        border-radius: var(--radius-lg);
        background:
            linear-gradient(100deg, rgb(212 175 55 / 0.12), transparent 60%),
            var(--surface-1);
    }

    .launcher-banner-icon {
        display: grid;
        flex: none;
        place-items: center;
        width: 3rem;
        height: 3rem;
        border-radius: var(--radius-lg);
        background: var(--accent-soft);
        color: var(--accent);
        font-size: 1.5rem;
    }

    .launcher-banner-text {
        flex: 1 1 18rem;
        min-width: 0;
    }

    .launcher-banner-text h2 {
        font-size: var(--text-md);
    }

    .launcher-banner-text p {
        margin-top: var(--space-1);
        color: var(--text-muted);
        font-size: var(--text-sm);
    }

    /* Builds: latest build hero */

    .build-latest {
        display: grid;
        gap: var(--space-4);
        padding: var(--space-5);
        border-radius: var(--radius);
        background: var(--surface-2);
    }

    .build-latest-head {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3) var(--space-5);
    }

    .build-version {
        color: var(--accent);
        font-family: var(--mono);
        font-weight: 700;
        letter-spacing: 0;
    }

    .build-latest .build-version {
        margin-top: var(--space-1);
        font-size: var(--text-xl);
        line-height: 1.1;
    }

    .build-meta {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2) var(--space-5);
        color: var(--text-muted);
        font-size: var(--text-sm);
    }

    .build-meta > * {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
    }

    .build-meta .icon {
        color: var(--text-subtle);
    }

    .build-notes {
        padding: var(--space-3) var(--space-4);
        border-radius: var(--radius-sm);
        background: var(--surface-3);
    }

    .build-notes-text {
        margin-top: var(--space-1);
        font-size: var(--text-sm);
        white-space: pre-line;
        overflow-wrap: anywhere;
    }

    .section-heading {
        padding: var(--space-5) var(--space-5) var(--space-3);
        color: var(--text-subtle);
        font-size: var(--text-xs);
        font-weight: 650;
        letter-spacing: 0.12em;
        text-transform: uppercase;
    }

    @media (max-width: 40rem) {
        .launcher-banner .btn,
        .build-latest-head .btn {
            width: 100%;
        }
    }
}

/* ------------------------------------------------------------------ utilities */

@layer utilities {
    /* Shell visibility lives here so it overrides component display values (e.g. .btn). */
    @media (min-width: 64rem) {
        .sidebar-close {
            display: none;
        }
    }

    @supports not selector(:popover-open) {
        .topbar button[popovertarget],
        .sidebar-close {
            display: none;
        }
    }

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

    .subtle {
        color: var(--text-subtle);
    }

    .mono {
        font-family: var(--mono);
    }

    .text-sm {
        font-size: var(--text-sm);
    }

    .text-xs {
        font-size: var(--text-xs);
    }

    .nowrap {
        white-space: nowrap;
    }

    .narrow {
        max-width: 44rem;
    }

    .visually-hidden {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
        border: 0;
    }

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