:root {
    color-scheme: light;
    --ink: #231f20;
    --ink-hover: #3b3435;
    --muted: #635a50;
    --gold: #caa763;
    --gold-dark: #675638;
    --gold-soft: #f2e8d5;
    --paper: #fff;
    --background: #f5f3ee;
    --line: #d8cdbd;
    --field-line: #928271;
    --radius: 8px;
    font-family: "Segoe UI", Inter, Arial, sans-serif;
    color: var(--ink);
    background: var(--background);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
h1, h2, p, ol, ul, dl, dd { margin: 0; }
a { color: var(--gold-dark); }
button, input { font: inherit; }
button { cursor: pointer; }
button, a, input, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--gold-dark); outline-offset: 3px; }

.auth-page {
    min-height: 100vh;
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: clamp(16px, 5vw, 40px);
    background: radial-gradient(ellipse at 45% 32%, #fff 0, var(--background) 58%, #eee7dc 100%);
}

.auth-card {
    --auth-space: clamp(22px, 6vw, 36px);
    width: min(100%, 420px);
    padding: var(--auth-space);
    border: 1px solid var(--line);
    border-top: 5px solid var(--gold);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: 0 18px 48px #231f2026;
    overflow: hidden;
}

.wordmark {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--background);
    font-size: 1.13rem;
    font-weight: 750;
    white-space: nowrap;
}
.wordmark img { display: block; object-fit: contain; }
.auth-brand {
    display: grid;
    justify-items: center;
    gap: 4px;
    margin: calc(-1 * var(--auth-space)) calc(-1 * var(--auth-space)) 24px;
    padding: 15px 18px 18px;
    border-bottom: 1px solid var(--gold);
    background: var(--ink);
    color: var(--background);
}
.auth-brand img { display: block; width: min(100%, 236px); height: auto; }
.auth-brand span { font-size: .875rem; font-weight: 650; letter-spacing: .12em; text-transform: uppercase; }
.auth-card h1 { margin-bottom: 22px; font-size: clamp(1.55rem, 5vw, 1.9rem); line-height: 1.15; letter-spacing: -.025em; text-transform: uppercase; }
.auth-card form > .button { width: 100%; margin-top: 4px; }
.auth-card .form-actions > .button { flex: 1; }
.auth-logout { margin-top: 16px; }

.stack { display: grid; gap: 16px; }
.field { min-width: 0; display: grid; gap: 7px; }
.field label { font-weight: 650; font-size: .94rem; }
.field input {
    width: 100%;
    min-height: 45px;
    padding: 10px 12px;
    border: 1px solid var(--field-line);
    border-radius: 6px;
    color: inherit;
    background-color: var(--paper);
}
.field input:focus { border-color: var(--gold-dark); }
.field small, .hint { color: var(--muted); font-size: .9rem; line-height: 1.5; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-weight: 650;
    text-align: center;
    text-decoration: none;
}
.button-primary { color: var(--background); background: var(--ink); }
.button-primary:hover { background: var(--ink-hover); }
.button-secondary { color: var(--ink); background: var(--paper); border-color: var(--line); }
.button-secondary:hover { border-color: var(--gold-dark); background: var(--background); }
.notice {
    margin-bottom: 16px;
    border: 1px solid #bcdcc7;
    border-radius: 6px;
    padding: 11px 13px;
    color: #1c5035;
    background: #edf9f1;
    line-height: 1.45;
}
.notice-error { border-color: #efcacc; color: #8d2329; background: #fff3f3; }

.workspace {
    min-height: 100vh;
    min-height: 100svh;
    display: grid;
    grid-template: auto 1fr auto / 224px minmax(0, 1fr);
    grid-template-areas: "header header" "sidebar main" "sidebar footer";
}
.skip-link { position: fixed; top: -100px; left: 12px; z-index: 20; background: var(--paper); padding: 10px; }
.skip-link:focus { top: 10px; }
.topbar {
    grid-area: header;
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    min-height: 62px;
    padding: 8px clamp(16px, 3vw, 30px);
    border-top: 5px solid var(--gold);
    border-bottom: 1px solid #caa76366;
    background: var(--ink);
}
.brand { display: flex; text-decoration: none; }
.account { min-width: 0; display: flex; align-items: center; margin-left: auto; gap: 12px; }
.account-name { max-width: 200px; color: var(--background); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.sign-out, .nav-toggle {
    padding: 8px 10px;
    min-height: 40px;
    border: 1px solid #caa76380;
    border-radius: 6px;
    color: var(--background);
    background: var(--ink);
    font-size: .9rem;
    font-weight: 650;
    white-space: nowrap;
}
.sign-out:hover, .nav-toggle:hover { color: var(--gold-soft); border-color: var(--gold); background: var(--ink-hover); }
.topbar :focus-visible { outline-color: var(--gold); }
.nav-toggle { display: none; }
.menu-glyph { display: inline-block; width: 14px; height: 11px; border-block: 2px solid; position: relative; }
.menu-glyph::after { content: ""; position: absolute; top: 3px; inset-inline: 0; border-top: 2px solid; }

.sidebar { grid-area: sidebar; min-width: 0; padding: 22px 12px; background: var(--ink); }
.sidebar nav { display: grid; gap: 4px; }
.sidebar a {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--background);
    text-decoration: none;
    font-weight: 600;
}
.sidebar a[aria-current] { color: var(--gold-soft); background: var(--ink-hover); box-shadow: inset 3px 0 var(--gold); }
.sidebar a:hover { background: var(--ink-hover); }
.sidebar a:focus-visible { outline-color: var(--gold); }
.sidebar .sidebar-account { margin-top: 24px; color: #d8cdbd; font-size: .9rem; font-weight: 500; }
.nav-icon { display: inline-block; width: 16px; height: 16px; flex-shrink: 0; position: relative; }
.icon-home::before { content: ""; position: absolute; inset: 2px 3px auto; height: 10px; border: solid currentColor; border-width: 1.5px 0 0 1.5px; transform: rotate(45deg); }
.icon-home::after { content: ""; position: absolute; inset: 6px 3px 1px; border: solid currentColor; border-width: 0 1.5px 1.5px; }
.icon-users::before { content: ""; position: absolute; top: 0; left: 5px; width: 7px; height: 7px; border: 1.5px solid; border-radius: 50%; }
.icon-users::after { content: ""; position: absolute; inset: 8px 1px 1px; border: 1.5px solid; border-radius: 8px 8px 2px 2px; }
.icon-audit::before { content: ""; position: absolute; inset: 1px 2px; border: 1.5px solid; border-radius: 2px; }
.icon-audit::after { content: ""; position: absolute; inset: 5px 5px; border-block: 1.5px solid; }

.content {
    grid-area: main;
    width: min(100%, 1400px);
    padding: clamp(18px, 4vw, 38px);
    margin-inline: auto;
}
.page-heading { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.page-heading h1 { font-size: clamp(1.65rem, 4vw, 2.2rem); line-height: 1.1; letter-spacing: -.025em; }
.footer { grid-area: footer; padding: 16px clamp(18px, 4vw, 38px); border-top: 1px solid var(--line); color: var(--muted); background: var(--paper); font-size: .875rem; }
.footer span { margin-inline: .25em; color: var(--gold-dark); }
.surface, .summary-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.surface-heading { padding: 17px 19px; border-bottom: 1px solid var(--line); }
.surface-heading h2 { font-size: 1.05rem; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.summary-card { display: grid; align-content: start; gap: 6px; padding: 17px 19px; color: var(--ink); text-decoration: none; }
.summary-card:hover { border-color: var(--gold-dark); }
.summary-card > span { color: var(--muted); font-weight: 650; }
.summary-card small, .activity-list small, .user-identity small, .audit-action small { color: var(--muted); font-size: .9rem; }
.summary-card > strong { font-size: 2.1rem; letter-spacing: -.04em; }
.summary-card > .summary-label { font-size: 1.25rem; letter-spacing: -.025em; }
.summary-highlight { border-color: var(--gold); background: var(--gold-soft); }
.activity-list, .user-list { list-style: none; padding: 0; }
.activity-list li { display: flex; justify-content: space-between; align-items: center; gap: 9px 16px; padding: 14px 19px; }
.activity-list li + li, .user-row + .user-row, .audit-event + .audit-event { border-top: 1px solid var(--line); }
.activity-list strong, .activity-list small, .user-identity strong, .user-identity small, .audit-action strong, .audit-action small { display: block; overflow-wrap: anywhere; }
time { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.empty { padding: 18px; color: var(--muted); }
.form-surface { max-width: 540px; padding: clamp(16px, 3vw, 24px); }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 4px; }

.user-row { display: grid; grid-template-columns: minmax(140px, 1fr) auto minmax(0, 1.3fr); align-items: center; gap: 10px 14px; padding: 13px 16px; }
.user-identity { min-width: 0; display: flex; align-items: center; gap: 9px; }
.user-initial { flex: 0 0 34px; display: grid; place-items: center; height: 34px; border-radius: 6px; color: var(--gold-dark); background: var(--gold-soft); font-size: .9rem; font-weight: 750; }
.badge { justify-self: start; padding: 4px 8px; border-radius: 20px; background: var(--background); color: var(--muted); font-size: .82rem; font-weight: 650; }
.badge-active { background: #e8f6ee; color: #205a3e; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: end; align-items: center; gap: 0 10px; }
.row-actions a, .text-button { display: inline-flex; align-items: center; min-height: 40px; padding: 0; color: var(--gold-dark); font-size: .9rem; font-weight: 600; text-decoration: none; }
.text-button { border: 0; background: transparent; }
.row-actions a:hover, .text-button:hover { text-decoration: underline; }
.text-button.danger { color: #9d2729; }

.audit-event summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; cursor: pointer; list-style: none; padding: 13px 18px; }
.audit-event summary::-webkit-details-marker { display: none; }
.audit-event summary::after { content: "+"; grid-column: 3; grid-row: 1; font-size: 1.12rem; color: var(--gold-dark); }
.audit-event[open] summary::after { content: "−"; }
.audit-event summary:hover, .audit-event[open] summary { background: var(--background); }
.audit-event:first-child summary { border-radius: var(--radius) var(--radius) 0 0; }
.audit-detail { padding: 14px 18px; border-top: 1px solid var(--line); }
.audit-meta { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.audit-meta > div { min-width: 0; }
.audit-meta dt { font-weight: 650; font-size: .84rem; }
.audit-meta dd { color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.audit-states { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 8px 14px; margin-top: 12px; }
.audit-states h2 { font-size: .9rem; }
.audit-states pre { padding: 10px; border-radius: 6px; background: var(--background); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .82rem; }
.pager { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

@media (max-width: 1020px) {
    .user-row { grid-template-columns: minmax(140px, 1fr) auto; }
    .row-actions { grid-column: 1 / -1; justify-content: start; }
}

@media (max-width: 760px) {
    .workspace { grid-template: auto auto 1fr auto / minmax(0, 1fr); grid-template-areas: "header" "sidebar" "main" "footer"; }
    .nav-ready .nav-toggle { display: inline-flex; align-items: center; gap: 7px; }
    .nav-ready .sidebar:not(.is-open) { display: none; }
    .sidebar { padding: 10px 12px; }
    .sidebar .sidebar-account { margin-top: 8px; }
    .content { padding-block-start: 20px; }
}

@media (max-width: 480px) {
    .account-name { display: none; }
    .topbar { gap: 10px; }
    .summary-grid { grid-template-columns: minmax(0, 1fr); }
    .activity-list li { flex-wrap: wrap; }
    .audit-event summary { grid-template-columns: minmax(0, 1fr) auto; }
    .audit-event summary::after { grid-column: 2; }
    .audit-event time { grid-row: 2; }
}

@media (max-width: 360px) {
    .topbar { padding-inline: 10px; gap: 7px; }
    .wordmark { font-size: 1rem; gap: 5px; }
    .wordmark img { width: 30px; height: 30px; }
    .nav-toggle, .sign-out { padding-inline: 7px; }
}
