/*
 * ClashHub application shell, page layout, and responsive rules
 * ("Obsidian & Signal Teal" console design system).
 * Component styling lives in components.css; tokens live in theme.css.
 *
 * Shell structure (produced by fragments/layout.html):
 *   body.app-shell
 *     a.skip-link
 *     header.app-header
 *     div.app-body
 *       button.app-backdrop + aside.app-nav
 *       main.app-main > div.app-page
 */

/* ---------------------------------------------------------------------------
 * Reset
 * ------------------------------------------------------------------------ */

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

html {
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    min-width: 0;
    background: var(--bg);
    color: var(--text-1);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body,
h1, h2, h3, h4, h5, h6,
p, pre, figure { margin: 0; }

/* Static viewport-sized washes and grid preserve depth without a canvas or
 * moving backdrop that would keep the glass surfaces compositing at idle. */
body::before,
body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
}

body::before {
    background:
        radial-gradient(40% 28% at 50% 0%, var(--fx-horizon), transparent 75%),
        radial-gradient(44% 36% at 14% 8%, var(--fx-aurora-1), transparent 70%),
        radial-gradient(42% 34% at 88% 84%, var(--fx-aurora-3), transparent 72%),
        radial-gradient(48% 40% at 78% 12%, var(--fx-aurora-2), transparent 70%);
}

body::after {
    background-image:
        linear-gradient(var(--fx-grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--fx-grid-line) 1px, transparent 1px);
    background-size: 40px 40px;
    -webkit-mask-image: radial-gradient(68% 60% at 50% 42%, #000 22%, transparent 80%);
    mask-image: radial-gradient(68% 60% at 50% 42%, #000 22%, transparent 80%);
}

h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; }

ol, ul { margin: 0; padding: 0; list-style: none; }

/* Fieldsets group radio/segmented controls; the browser chrome (border,
 * margins, padding) is removed so groups render as plain stacked fields. */
fieldset {
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

legend {
    margin: 0;
    padding: 0;
}

input[type="file"] { max-width: 100%; }

button, input, select, textarea {
    margin: 0;
    padding: 0;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
}

button, select { text-transform: none; }
button { background: transparent; }
button, [role="button"] { cursor: pointer; }
button:disabled { cursor: default; }

a { color: inherit; text-decoration: none; }

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

table { border-collapse: collapse; border-color: inherit; text-indent: 0; }

[hidden], .hidden { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

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

/* ---------------------------------------------------------------------------
 * Application shell
 * ------------------------------------------------------------------------ */

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    overflow: hidden;
}

.app-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: none;
    height: var(--header-height);
    padding-inline: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--glass-border);
    background: var(--glass-surface-strong);
    box-shadow: var(--glass-edge);
    -webkit-backdrop-filter: var(--glass-filter);
    backdrop-filter: var(--glass-filter);
    z-index: 20;
}

.app-header__menu { display: none; }

.app-header__brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    color: var(--text-1);
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: -0.015em;
}

.app-header__brand img {
    width: 30px;
    height: 30px;
    flex: none;
    border: 1.5px solid color-mix(in srgb, var(--primary) 45%, transparent);
    border-radius: 8px;
    object-fit: cover;
}

.app-header__spacer { flex: 1 1 auto; }

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

.app-lang {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
}

.app-lang__link {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 9px;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    font-size: 0.75rem;
    font-weight: 600;
    transition: background-color var(--motion-fast) var(--ease-standard),
                color var(--motion-fast) var(--ease-standard);
}

.app-lang__link:hover { color: var(--text-1); }

.app-lang__link[aria-current] {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-1);
}

.skip-link {
    position: fixed;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 100;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 600;
    transform: translateY(-200%);
    transition: transform var(--motion-fast) var(--ease-standard);
}

.skip-link:focus-visible { transform: none; }

/* Body area under the header: navigation + main scroll container */

.app-body {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
}

.app-backdrop { display: none; }

.app-nav {
    display: flex;
    flex-direction: column;
    flex: none;
    width: var(--sidebar-width);
    min-width: 0;
    border-right: 1px solid var(--glass-border);
    background: var(--glass-surface-strong);
    box-shadow: var(--glass-edge);
    -webkit-backdrop-filter: var(--glass-filter);
    backdrop-filter: var(--glass-filter);
    transition: width var(--motion-slow) var(--ease-standard);
}

.app-nav__scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-4) var(--space-3);
    display: grid;
    gap: var(--space-5);
    align-content: start;
}

.app-nav__group { display: grid; gap: 3px; }

.app-nav__group-label {
    margin: 0 0 4px;
    padding-inline: var(--space-3);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
    white-space: nowrap;
}

.app-nav__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 38px;
    padding: 0 var(--space-3);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-2);
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    transition: background-color var(--motion-fast) var(--ease-standard),
                border-color var(--motion-fast) var(--ease-standard),
                color var(--motion-fast) var(--ease-standard);
}

.app-nav__link .ui-icon { color: var(--text-3); transition: color var(--motion-fast) var(--ease-standard); }

.app-nav__link:hover {
    background: var(--state-hover);
    color: var(--text-1);
}
.app-nav__link:hover .ui-icon { color: var(--text-1); }

.app-nav__link[aria-current="page"] {
    border-color: color-mix(in srgb, var(--primary) 32%, transparent);
    background: var(--primary-container);
    color: var(--on-primary-container);
    font-weight: 600;
}

.app-nav__link[aria-current="page"]::before {
    content: "";
    position: absolute;
    left: -1px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: var(--radius-full);
    background: var(--primary);
}

.app-nav__link[aria-current="page"] .ui-icon { color: var(--primary); }

.app-nav__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.app-nav__footer {
    flex: none;
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: flex-end;
}

.app-nav__collapse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-3);
    cursor: pointer;
    transition: background-color var(--motion-fast) var(--ease-standard),
                border-color var(--motion-fast) var(--ease-standard),
                color var(--motion-fast) var(--ease-standard);
}

.app-nav__collapse:hover {
    border-color: var(--border);
    background: var(--state-hover);
    color: var(--text-1);
}

/* Collapsed icon rail. Desktop only (>=1024px): tablet widths always show
 * the full navigation even when the rail preference is stored. Labels stay
 * in the accessibility tree via the sr-only clip. */

@media (min-width: 1024px) {
    body.nav-rail .app-nav { width: var(--sidebar-rail-width); }
    body.nav-rail .app-nav__link { justify-content: center; padding: 0; }
    body.nav-rail .app-nav__group-label {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
    body.nav-rail .app-nav__label {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
    body.nav-rail .app-nav__collapse .ui-icon { transform: rotate(180deg); }

    /* Rail tooltips appear beside the icon instead of above it. */
    body.nav-rail .app-nav__link[data-tooltip]::after {
        left: calc(100% + 10px);
        bottom: auto;
        transform: translateY(-50%) scale(0.96);
    }

    body.nav-rail .app-nav__link[data-tooltip]:hover::after,
    body.nav-rail .app-nav__link[data-tooltip]:focus-visible::after {
        transform: translateY(-50%) scale(1);
    }
}

/* Below the desktop breakpoint the rail preference is dormant, so nav link
 * tooltips never render (their text is already visible). */
@media (max-width: 1023px) {
    .app-nav__link[data-tooltip]::after { content: none; }
}

body:not(.nav-rail) .app-nav__link[data-tooltip]::after { content: none; }

.app-main {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* ---------------------------------------------------------------------------
 * Page scaffolding
 * ------------------------------------------------------------------------ */

.app-page {
    max-width: var(--page-max);
    margin-inline: auto;
    padding: var(--space-6) var(--space-6) var(--space-8);
    display: grid;
    gap: var(--space-5);
    align-content: start;
}

.app-page--form { max-width: 980px; }
.app-page--narrow { max-width: 740px; }

/* One-shot page-content entrance with a small stagger, mirroring the auth
 * card. :where() keeps specificity at zero so a child that brings its own
 * animation or translate always wins over the entrance. */
:where(.app-page) > * {
    translate: 0 0;
    animation: fx-rise 320ms var(--ease-standard) backwards;
}

:where(.app-page) > :nth-child(2) { animation-delay: 50ms; }
:where(.app-page) > :nth-child(3) { animation-delay: 100ms; }
:where(.app-page) > :nth-child(n + 4) { animation-delay: 150ms; }

@keyframes fx-rise {
    from { opacity: 0; translate: 0 10px; }
}

/* Full-height editor workspace (admin template page). */
.app-main--workspace { display: flex; flex-direction: column; }

.app-workspace {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: var(--page-max);
    margin-inline: auto;
    padding: var(--space-4) var(--space-5) var(--space-5);
    display: flex;
    flex-direction: column;
}

.app-workspace .ui-editor-panel { flex: 1 1 auto; min-height: 0; }
.app-workspace form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.app-workspace .ui-editor--flush { flex: 1 1 auto; }

/* Form grids */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-5);
}

.form-grid > .span-2 { grid-column: 1 / -1; }

.form-stack { display: grid; gap: var(--space-5); align-content: start; }

.form-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
}

.form-footer--divider {
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}

/* Auth pages (login / registration) use a standalone centered shell. */
.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: var(--space-4);
}

/* Fixed corner controls (theme menu + language links) floating outside
 * the centered auth card. position: fixed keeps the single-child grid
 * centering of .auth-shell untouched. */
.auth-controls {
    position: fixed;
    top: var(--space-3);
    right: var(--space-4);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ---------------------------------------------------------------------------
 * Responsive behavior
 * ------------------------------------------------------------------------ */

/* Usage board: the trend spans both tablet columns, then shares the first
 * desktop row with a ring panel once three columns fit. */
@media (min-width: 768px) {
    .ui-board { grid-template-columns: repeat(2, 1fr); }
    .ui-board__trend { grid-column: 1 / -1; }
}

@media (min-width: 1200px) {
    .ui-board { grid-template-columns: repeat(3, 1fr); }
    .ui-board__trend { grid-column: span 2; }
}

@media (max-width: 1023px) {
    .app-nav__collapse { display: none; }
}

/* Touch shell (phones and tablets): below desktop width the fixed
 * sidebar becomes an overlay drawer, every interactive control meets the
 * 44px touch-target minimum, wide tables collapse into labeled cards, and
 * the form footer stays reachable. >=1024px restores the pointer-first
 * desktop layout. */
@media (max-width: 1023px) {
    .app-header__menu { display: inline-flex; }

    /* The drawer overlays the viewport, including the header. */
    body.navigation-open { overflow: hidden; }

    .app-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 40;
        border: 0;
        padding: 0;
        background: var(--scrim);
        visibility: hidden;
        opacity: 0;
        transition: opacity var(--motion-md) var(--ease-standard),
                    visibility var(--motion-md) var(--ease-standard);
    }

    body.navigation-open .app-backdrop { visibility: visible; opacity: 1; }

    .app-nav {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 50;
        width: min(18rem, calc(100vw - 3rem));
        height: 100vh;
        height: 100dvh;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform var(--motion-md) var(--ease-standard),
                    visibility 0s linear var(--motion-md);
        box-shadow: var(--shadow-3);
    }

    body.navigation-open .app-nav {
        transform: none;
        visibility: visible;
        transition-delay: 0s;
    }

    /* Comfortable touch targets and no iOS input zoom. Every interactive
     * control, including small and combined icon buttons, menu items, and
     * inline toggles, reaches at least 44px. */
    .ui-button { min-height: 44px; }
    .ui-button--sm { min-height: 44px; }
    .ui-button--icon { width: 44px; min-height: 44px; }
    .ui-button--icon.ui-button--sm { width: 44px; min-height: 44px; }
    .ui-menu__item { min-height: 44px; }
    .ui-perm-filter .ui-input { min-height: 44px; font-size: 1rem; }
    .password-toggle { width: 44px; height: 44px; }
    .password-input { padding-right: 56px; }
    .ui-flash__close { width: 44px; height: 44px; margin: -2px -10px -2px 0; }
    .permission-option { min-height: 44px; }
    .collapse-all-button { min-height: 44px; }
    .collapse-group-toggle { min-height: 44px; }
    .sortable-handle { width: 44px; height: 44px; }
    .ui-input, .ui-select, .ui-textarea {
        min-height: 44px;
        font-size: 1rem;
    }
    .ui-check-line { min-height: 44px; }
    .app-nav__link, .app-lang__link { min-height: 44px; }
    input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }

    /* Sticky action bar for forms so save is always reachable. */
    .form-footer {
        position: sticky;
        bottom: 0;
        z-index: 8;
        margin-inline: calc(-1 * var(--space-4));
        margin-bottom: calc(-1 * var(--space-7));
        padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border);
        background: var(--surface);
        box-shadow: var(--shadow-sticky-footer);
    }

    .form-footer > .ui-button { flex: 1 1 auto; }

    /* Data tables collapse into labeled card rows. Wide-table minimums and
     * bounded heights are lifted so cards, empty states, and pagination
     * participate in normal document flow. */
    .ui-table-scroll { overflow: visible; background: transparent; }
    .ui-table-scroll--tall { max-height: none; overflow-y: visible; }

    .ui-data-table { display: block; width: 100%; min-width: 0; table-layout: auto; }

    .ui-data-table--wide,
    .ui-data-table--xwide { min-width: 0; }

    .ui-data-table colgroup { display: none; }

    .ui-data-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    .ui-data-table tbody { display: grid; gap: var(--space-3); }

    .ui-data-table tbody tr {
        display: block;
        padding: var(--space-2) 0;
        border: 1px solid var(--glass-border);
        border-radius: var(--radius-lg);
        background: var(--glass-surface);
        box-shadow: var(--shadow-1);
        overflow: hidden;
    }

    .ui-data-table tbody td {
        display: grid;
        grid-template-columns: max-content minmax(0, 1fr);
        align-items: start;
        gap: var(--space-3);
        min-height: 44px;
        padding: var(--space-2) var(--space-3);
        border: 0;
        border-bottom: 1px solid var(--border);
        text-align: left;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .ui-data-table tbody td:last-child { border-bottom: 0; }

    .ui-data-table tbody td::before {
        content: attr(data-label);
        color: var(--text-3);
        font-family: var(--font-mono);
        font-size: var(--fs-xs);
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        overflow-wrap: anywhere;
        padding-top: 3px;
    }

    .ui-data-table tbody td > * { min-width: 0; grid-column: 2; }

    .ui-data-table tbody td.table-empty-cell {
        display: block;
        min-height: 0;
        text-align: center;
    }

    .ui-data-table tbody td.table-empty-cell::before { content: none; }

    /* Card cells wrap long values instead of hard-clipping at the card
     * edge; base .cell-truncate otherwise keeps desktop nowrap. */
    .ui-data-table .cell-truncate { max-width: 100%; overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; }

    /* The action area owns a full card row so stacked buttons and the
     * expanded row menu never overlap data columns. */
    .ui-data-table .cell-actions,
    .ui-data-table .mobile-action-cell {
        position: static;
        grid-column: 1 / -1;
        box-shadow: none;
        background: var(--glass-surface-2);
        text-align: left;
    }

    .ui-data-table .cell-actions::before,
    .ui-data-table .mobile-action-cell::before { margin-bottom: var(--space-2); }

    /* Text action buttons fill the card row two per line; icon-only controls
     * keep their stable square size. Scope this to marked action cells because
     * usage boards reuse .ui-row-actions for inline chip stacks. */
    .ui-data-table .cell-actions .ui-row-actions,
    .ui-data-table .mobile-action-cell .ui-row-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
    }

    .ui-data-table .cell-actions .ui-row-actions > .ui-button:not(.ui-button--icon),
    .ui-data-table .cell-actions .ui-row-actions > form,
    .ui-data-table .mobile-action-cell .ui-row-actions > .ui-button:not(.ui-button--icon),
    .ui-data-table .mobile-action-cell .ui-row-actions > form,
    .ui-data-table .cell-actions .ui-row-actions > .ui-snapshot-rename,
    .ui-data-table .mobile-action-cell .ui-row-actions > .ui-snapshot-rename { width: 100%; }

    .ui-snapshot-rename > summary { width: 100%; }
    .ui-snapshot-rename[open] { grid-column: 1 / -1; align-items: stretch; }
    .ui-snapshot-rename__actions { width: 100%; }
    .ui-snapshot-rename__actions .ui-button { flex: 1 1 0; }

    /* Row action menus expand inline inside the card instead of an
     * absolutely positioned popover that the card would clip. The header
     * theme menu keeps its popover treatment. */
    .ui-data-table .ui-menu-anchor { display: block; width: 100%; }

    .ui-data-table .ui-menu-anchor > .ui-button { width: 100%; }

    .ui-data-table .ui-menu {
        position: static;
        display: grid;
        width: 100%;
        min-width: 0;
        margin-top: var(--space-2);
        padding: var(--space-2) 0 0;
        border: 0;
        border-top: 1px solid var(--border);
        border-radius: 0;
        box-shadow: none;
    }

    .ui-data-table .ui-menu__item { width: 100%; }

    .ui-row-actions { justify-content: flex-start; display: flex; }
    .ui-row-actions .ui-button { flex: 1 1 auto; }
    .ui-row-actions form { flex: 1 1 auto; display: flex; }
    .ui-row-actions form .ui-button { width: 100%; }

    .ui-data-table td .ui-row-actions { flex-wrap: wrap; }

    .ui-pagination { flex-direction: column; align-items: stretch; }
    .ui-pagination__links { width: 100%; }
    .ui-pagination__link { flex: 1 1 0; justify-content: center; min-height: 44px; }

    .ui-bulk-bar { padding: var(--space-3); }
    .ui-bulk-bar__actions { width: 100%; }
    .ui-bulk-bar__actions .ui-button { flex: 1 1 auto; }

    .ui-segmented { display: flex; width: 100%; }
    .ui-segmented__item { flex: 1 1 0; justify-content: center; min-height: 44px; }

    .ui-editor { min-height: 50vh; }
    .ui-editor, .ui-editor-gutter { font-size: var(--fs-lg); }

    /* Priority sort rows become two-line cards. */
    .sortable-priority-row {
        display: grid !important;
        grid-template-columns: 44px 2rem minmax(0, 1fr) 44px 44px;
        align-items: center;
        gap: var(--space-2);
    }

    .sortable-priority-row > [data-sortable-handle] { grid-row: 1 / span 2; }
    .sortable-priority-position { grid-row: 1 / span 2; }
    .sortable-priority-name { grid-row: 1; grid-column: 3; }
    .sortable-priority-status { grid-row: 2; grid-column: 3; }
    .sortable-priority-row > [data-sortable-move="UP"] { grid-row: 1 / span 2; }
    .sortable-priority-row > [data-sortable-move="DOWN"] { grid-row: 1 / span 2; }

    .ui-data-table .sortable-handle,
    .ui-data-table [data-sortable-move] { width: 44px; height: 44px; }
}

/* Phone-only density: tighter page padding and a 320px-safe header. The
 * role chip stays visually hidden (screen readers keep it) so the row
 * still fits; the brand name remains visible with an ellipsis so the
 * product context survives on small screens. */
@media (max-width: 767px) {
    body { font-size: 0.875rem; }

    body[data-page-art] .ui-page-header {
        min-height: 64px;
        padding-inline-end: 68px;
    }

    body[data-page-art="admin-main-template"] .ui-editor-bar {
        min-height: 64px;
        padding-inline-end: 68px;
    }

    body[data-page-art] .ui-page-header::after,
    body[data-page-art="admin-main-template"] .ui-editor-bar::after {
        width: 58px;
        height: 58px;
    }

    .ui-auth[data-page-art]::after {
        inset-inline-start: var(--space-3);
        top: -34px;
        width: 82px;
        height: 82px;
    }

    .app-page { padding: var(--space-4) var(--space-4) var(--space-7); gap: var(--space-5); }

    .app-header { padding-inline: var(--space-1); gap: var(--space-1); }

    .app-header__brand span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-header__role {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    .ui-page-header { flex-direction: column; align-items: stretch; }
    .ui-page-header__actions { width: 100%; }
    .ui-page-header__actions > .ui-button { flex: 1 1 auto; }

    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .form-grid > .span-2 { grid-column: auto; }

    .ui-menu { right: auto; left: 0; }

    .ui-flash-region { right: var(--space-2); bottom: var(--space-2); }

    .app-workspace { padding: var(--space-3); }
    .ui-editor-bar__tools { width: 100%; }
    .ui-editor-bar__tools .ui-button { flex: 1 1 auto; }
    .ui-doc pre { padding-top: var(--space-8); }

    .ui-snapshot-workbench,
    .ui-snapshot-notices { grid-template-columns: minmax(0, 1fr); }
    .ui-snapshot-card__footer > .ui-button { width: 100%; }
}

/* ---------------------------------------------------------------------------
 * Glass fallbacks
 * ------------------------------------------------------------------------ */

/* Browsers without backdrop-filter support get solid surfaces and full
 * borders instead of translucent glass, keeping content crisp. This
 * block lives in app.css (the last stylesheet) so its equal-specificity
 * overrides win against the component rules above. */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .app-header,
    .app-nav,
    .ui-section,
    .ui-kpi,
    .ui-auth,
    .ui-editor-panel,
    .ui-menu,
    .ui-dialog,
    .ui-flash,
    .ui-bulk-bar,
    .ui-ring__tip {
        background: var(--surface);
        border-color: var(--border);
    }

    .ui-dialog__actions,
    .ui-editor-bar { background: var(--surface-2); }

    .ui-button--outline { background: var(--surface); }
    .ui-button--outline:not(:disabled):hover { background: var(--surface-2); }

    .ui-segmented { background: var(--surface-2); }

    @media (max-width: 1023px) {
        .form-footer {
            background: var(--surface);
            border-color: var(--border);
        }

        .ui-data-table tbody tr {
            background: var(--surface);
            border-color: var(--border);
        }

        .ui-data-table .cell-actions,
        .ui-data-table .mobile-action-cell { background: var(--surface-2); }
    }
}

/* Users who prefer reduced transparency get the pre-glass solid look. */
@media (prefers-reduced-transparency: reduce) {
    body::before,
    body::after { content: none; }

    .app-header,
    .app-nav,
    .ui-section,
    .ui-panel,
    .ui-kpi,
    .ui-auth,
    .ui-editor-panel,
    .ui-menu,
    .ui-dialog,
    .ui-flash,
    .ui-bulk-bar,
    .ui-ring__tip,
    .ui-data-table thead th {
        background: var(--surface);
        border-color: var(--border);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .ui-dialog__actions,
    .ui-editor-bar { background: var(--surface-2); }

    .ui-dialog::backdrop {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .ui-button--outline { background: var(--surface); }
    .ui-button--outline:not(:disabled):hover { background: var(--surface-2); }

    .ui-segmented { background: var(--surface-2); }

    @media (max-width: 1023px) {
        .form-footer {
            background: var(--surface);
            border-color: var(--border);
            -webkit-backdrop-filter: none;
            backdrop-filter: none;
        }

        .ui-data-table tbody tr {
            background: var(--surface);
            border-color: var(--border);
        }

        .ui-data-table .cell-actions,
        .ui-data-table .mobile-action-cell { background: var(--surface-2); }
    }
}

/* ---------------------------------------------------------------------------
 * Reduced motion
 * ------------------------------------------------------------------------ */

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