:root,
:root[data-theme="light"] {
    color-scheme: light;
    --bg: #EFEDEA;
    --ink: #00040A;
    --muted: #68636a;
    --line: #d9d4cc;
    --brand: #8F0768;
    --brand-strong: #00040A;
    --brand-gold: #BE9346;
    --panel: #ffffff;
    --surface-soft: #E2DED7;
    --surface-subtle: #f8f7f5;
    --surface-raised: #ffffff;
    --field-bg: #ffffff;
    --header-bg: #00040A;
    --header-ink: #ffffff;
    --success: #16834b;
    --danger: #c93245;
    --info: #087da8;
    --warning: #b66f00;
    --shadow-sm: 0 1px 2px rgba(0, 4, 10, .06), 0 5px 16px rgba(0, 4, 10, .04);
    --shadow-md: 0 10px 30px rgba(0, 4, 10, .09);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #00040A;
    --ink: #EFEDEA;
    --muted: #b5b0b4;
    --line: #353943;
    --brand: #c4499f;
    --brand-strong: #EFEDEA;
    --brand-gold: #d1aa63;
    --panel: #11151c;
    --surface-soft: #242932;
    --surface-subtle: #171b23;
    --surface-raised: #1b2029;
    --field-bg: #0c1016;
    --header-bg: #00040A;
    --header-ink: #EFEDEA;
    --success: #43c77d;
    --danger: #ff6b78;
    --info: #55bce2;
    --warning: #f3bd58;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .25), 0 7px 18px rgba(0, 0, 0, .18);
    --shadow-md: 0 14px 34px rgba(0, 0, 0, .28);
}

html {
    background: var(--bg);
}

body {
    color: var(--ink);
    background: var(--bg);
    transition: background-color .18s ease, color .18s ease;
}

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

:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--brand-gold) 65%, transparent);
    outline-offset: 2px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 3px solid var(--brand-gold);
    color: var(--header-ink);
    background: var(--header-bg);
    box-shadow: 0 5px 18px rgba(0, 4, 10, .16);
}

.topbar-inner {
    min-height: 72px;
}

.brand-logo {
    width: clamp(164px, 12vw, 220px);
    height: 54px;
    border-radius: 6px;
}

.nav {
    gap: 8px;
}

.topbar-user {
    display: grid;
    gap: 1px;
    padding: 0 10px;
    text-align: right;
    line-height: 1.2;
}

.topbar-user strong {
    color: var(--header-ink);
    font-size: 14px;
}

.topbar-user small {
    color: #d7d3cf;
    font-size: 12px;
}

.topbar-icon,
.sidebar-collapse,
.sidebar-backdrop {
    border: 0;
}

.topbar-icon {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .2);
    color: var(--header-ink);
    background: rgba(255, 255, 255, .07);
    font-size: 22px;
}

.topbar-icon:hover {
    border-color: var(--brand-gold);
    background: rgba(190, 147, 70, .17);
}

.sidebar-mobile-toggle {
    display: none;
}

.app-frame {
    grid-template-columns: 286px minmax(0, 1fr);
    gap: clamp(20px, 2vw, 34px);
    padding-top: 28px;
}

.sidebar {
    top: 94px;
    max-height: calc(100vh - 116px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow-sm);
    transition: width .2s ease, transform .2s ease;
}

.sidebar-heading {
    position: sticky;
    top: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 30px;
    align-items: center;
    gap: 11px;
    min-height: 78px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.sidebar-avatar {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: #ffffff;
    background: var(--brand);
    font-family: var(--font-title);
    font-size: 20px;
    font-weight: 800;
}

.sidebar-title {
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 900;
    letter-spacing: .08em;
}

.sidebar-user {
    display: grid;
    gap: 1px;
    margin: 2px 0 0;
    line-height: 1.25;
}

.sidebar-user strong,
.sidebar-user span,
.sidebar-user small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user strong {
    color: var(--ink);
    font-size: 13px;
}

.sidebar-user span,
.sidebar-user small {
    color: var(--muted);
    font-size: 11px;
}

.sidebar-collapse {
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
    background: var(--surface-subtle);
    font-size: 22px;
}

.sidebar-nav {
    gap: 5px;
    margin: 0;
    padding: 12px 10px 18px;
}

.side-card {
    position: relative;
    gap: 2px;
    min-height: 52px;
    padding: 10px 34px 10px 13px;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--ink);
    background: transparent;
    transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}

.side-card:hover {
    border-color: var(--line);
    color: var(--brand);
    background: var(--surface-subtle);
}

.side-card strong {
    font-size: 13px;
    line-height: 1.25;
}

.side-card span {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.3;
}

a.side-card.is-active {
    border-color: var(--brand);
    color: #ffffff;
    background: var(--brand);
    box-shadow: 0 5px 14px color-mix(in srgb, var(--brand) 24%, transparent);
}

a.side-card.is-active span {
    color: rgba(255, 255, 255, .8);
}

a.side-card.is-active::before {
    content: "";
    position: absolute;
    left: -4px;
    top: 10px;
    bottom: 10px;
    width: 3px;
    border-radius: 3px;
    background: var(--brand-gold);
}

.sidebar-group {
    gap: 5px;
}

.sidebar-group > summary .side-card {
    min-height: 60px;
    border-color: var(--line);
    background: var(--surface-subtle);
}

.sidebar-group[open] > summary .side-card {
    border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
    color: var(--brand);
    background: color-mix(in srgb, var(--brand) 7%, var(--panel));
}

.sidebar-group summary .side-card::after {
    right: 12px;
    color: currentColor;
}

.sidebar-subnav {
    gap: 3px;
    margin: 3px 0 7px 15px;
    padding: 4px 0 4px 10px;
    border-left: 1px solid color-mix(in srgb, var(--brand-gold) 65%, var(--line));
}

.sidebar-subnav .side-card {
    min-height: 45px;
    padding-top: 8px;
    padding-bottom: 8px;
}

.sidebar-group-label {
    margin: 9px 10px 3px;
    color: var(--brand-gold);
    font-size: 10px;
    letter-spacing: .08em;
}

.sidebar-backdrop {
    display: none;
}

body.sidebar-collapsed .app-frame {
    grid-template-columns: 76px minmax(0, 1fr);
}

body.sidebar-collapsed .sidebar-heading {
    grid-template-columns: 42px;
    justify-content: center;
}

body.sidebar-collapsed .sidebar-identity,
body.sidebar-collapsed .side-card span,
body.sidebar-collapsed .side-card strong,
body.sidebar-collapsed .sidebar-group-label,
body.sidebar-collapsed .sidebar-subnav {
    display: none;
}

body.sidebar-collapsed .sidebar-collapse {
    position: absolute;
    top: 24px;
    right: -14px;
    z-index: 5;
    display: grid;
    place-items: center;
    color: var(--ink);
    background: var(--panel);
    box-shadow: var(--shadow-sm);
}

body.sidebar-collapsed .sidebar-nav {
    padding-inline: 8px;
}

body.sidebar-collapsed .side-card,
body.sidebar-collapsed .sidebar-group > summary .side-card {
    min-height: 44px;
    padding: 0;
}

body.sidebar-collapsed .side-card::after {
    content: attr(data-short);
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border: 0;
    color: currentColor;
    font-size: 12px;
    font-weight: 900;
    opacity: .82;
    transform: none;
}

body.sidebar-collapsed .sidebar-group summary .side-card::after,
body.sidebar-collapsed .sidebar-group[open] summary .side-card::after {
    content: attr(data-short);
    inset: 0;
    transform: none;
}

.panel {
    border-color: var(--line);
    background: var(--panel);
    box-shadow: var(--shadow-sm);
}

.panel.wide {
    padding: clamp(24px, 2.4vw, 42px);
}

h1 {
    color: var(--brand);
    letter-spacing: 0;
}

h2,
h3,
h4,
label,
strong {
    color: inherit;
}

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

.section-card,
.tile,
button.tile,
.record-section,
.record-item,
.form-shell,
.form-hero,
.form-section,
.form-submit-card,
.alert,
.notice,
.permission-group,
.list li {
    border-color: var(--line);
    color: var(--ink);
    background: var(--surface-subtle);
}

.tile,
button.tile {
    position: relative;
    background: var(--surface-raised);
    box-shadow: 0 1px 0 rgba(0, 4, 10, .02);
    transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease;
}

.tile:hover,
button.tile:hover {
    border-color: var(--brand-gold);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.tile span,
.record-section > p,
.section-card-header p {
    color: var(--muted);
}

.button,
button {
    border-color: var(--brand);
    color: #ffffff;
    background: var(--brand);
}

.button:hover,
button:hover {
    filter: brightness(1.06);
}

.button.secondary,
button.secondary {
    border-color: var(--brand-gold);
    color: var(--ink);
    background: var(--surface-raised);
}

input,
select,
textarea,
.option-item {
    border-color: var(--line);
    color: var(--ink);
    background: var(--field-bg);
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid color-mix(in srgb, var(--brand-gold) 32%, transparent);
    border-color: var(--brand);
}

.table-wrap {
    border-color: var(--line);
    background: var(--surface-raised);
    box-shadow: var(--shadow-sm);
}

th {
    color: #ffffff;
    background: #00040A;
}

td {
    border-color: var(--line);
    color: var(--ink);
    background: var(--surface-raised);
}

tbody tr:nth-child(even) td {
    background: color-mix(in srgb, var(--surface-soft) 30%, var(--surface-raised));
}

tbody tr:hover td {
    background: color-mix(in srgb, var(--brand-gold) 10%, var(--surface-raised));
}

.badge {
    border-color: var(--line);
    color: var(--brand);
    background: color-mix(in srgb, var(--brand) 8%, var(--surface-raised));
}

.badge.off {
    color: var(--muted);
    background: var(--surface-soft);
}

.alert.success {
    border-color: var(--success);
    color: var(--success);
    background: color-mix(in srgb, var(--success) 9%, var(--panel));
}

.alert.error {
    border-color: var(--danger);
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 8%, var(--panel));
}

.alert.warning {
    border-color: var(--warning);
    color: var(--ink);
    background: color-mix(in srgb, var(--warning) 9%, var(--panel));
}

.notice {
    border-color: var(--brand-gold);
    color: var(--ink);
    background: color-mix(in srgb, var(--brand-gold) 10%, var(--panel));
}

.bar-track,
.stacked-bar {
    background: var(--surface-soft);
}

.donut::after {
    border-color: var(--line);
    background: var(--panel);
}

.session-timeout-modal {
    color: var(--ink);
    background: var(--panel);
}

:root[data-theme="dark"] .brand-logo {
    background: #ffffff;
}

:root[data-theme="dark"] img:not(.brand-logo) {
    opacity: .94;
}

@media (max-width: 900px) {
    .topbar-inner {
        min-height: 66px;
        flex-direction: row;
        align-items: center;
        padding: 6px 0;
    }

    .sidebar-mobile-toggle {
        display: inline-flex;
    }

    .brand-logo {
        width: 148px;
        height: 48px;
    }

    .topbar-user {
        display: none;
    }

    .app-frame,
    body.sidebar-collapsed .app-frame {
        grid-template-columns: 1fr;
        padding-top: 18px;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 300;
        width: min(330px, calc(100vw - 52px));
        max-height: 100vh;
        border-radius: 0 8px 8px 0;
        transform: translateX(-105%);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 250;
        display: block;
        width: 100%;
        height: 100%;
        padding: 0;
        border-radius: 0;
        background: rgba(0, 4, 10, .62);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }

    body.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-collapse {
        display: none;
    }

    body.sidebar-collapsed .sidebar-heading {
        grid-template-columns: 42px minmax(0, 1fr);
        justify-content: initial;
    }

    body.sidebar-collapsed .sidebar-identity,
    body.sidebar-collapsed .side-card span,
    body.sidebar-collapsed .side-card strong,
    body.sidebar-collapsed .sidebar-group-label,
    body.sidebar-collapsed .sidebar-subnav {
        display: initial;
    }

    body.sidebar-collapsed .sidebar-user,
    body.sidebar-collapsed .sidebar-identity,
    body.sidebar-collapsed .sidebar-nav,
    body.sidebar-collapsed .sidebar-subnav {
        display: grid;
    }

    body.sidebar-collapsed .side-card,
    body.sidebar-collapsed .sidebar-group > summary .side-card {
        min-height: 52px;
        padding: 10px 34px 10px 13px;
    }

    body.sidebar-collapsed .side-card::after {
        inset: auto;
    }
}

@media (max-width: 560px) {
    .topbar-inner,
    .page,
    .app-frame {
        width: min(100% - 24px, 1920px);
    }

    .nav {
        margin-left: auto;
    }

    .nav .button.secondary {
        min-height: 38px;
        padding-inline: 12px;
    }

    .panel,
    .panel.wide {
        padding: 18px;
    }
}

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