:root {
    color-scheme: light;
    --page: #f4f6f9;
    --surface: #fff;
    --ink: #152438;
    --muted: #52637a;
    --line: #dce3ed;
    --navy: #142540;
    --navy-deep: #101e33;
    --blue: #1d4dba;
    --blue-dark: #163d96;
    --primary: var(--blue);
    --primary-hover: var(--blue-dark);
    --focus: #2863dc;
    --error: #a12634;
    --header-background: #edf1f5;
    --header-border: #dbe3ec;
    --header-control-border: #c8d3e0;
    --header-hover: #f5f8fc;
    --header-active-border: #7892b8;
    --header-popover-shadow: 0 10px 30px #14254022;
    --radius: 12px;
    --shadow: 0 2px 5px #14254008;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --page: #0f1828;
    --surface: #172338;
    --ink: #eff5ff;
    --muted: #b4c3da;
    --line: #3b4d68;
    --navy: #13213a;
    --navy-deep: #0d192d;
    --blue: #a8caff;
    --blue-dark: #ccdeff;
    --primary: #2959b2;
    --primary-hover: #355fb0;
    --focus: #a8caff;
    --error: #ffb6c2;
    --control: #111c2e;
    --control-border: #7389a9;
    --control-hover: #253957;
    --header-background: #1d2b40;
    --header-border: #3b4d68;
    --header-control-border: var(--control-border);
    --header-hover: var(--control-hover);
    --header-active-border: #91aad1;
    --header-popover-shadow: 0 10px 30px #080d1890;
    --shadow: 0 2px 5px #080d1880;
}

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

body {
    min-width: 0;
    margin: 0;
    background: var(--page);
    color: var(--ink);
}

a { color: var(--blue); text-underline-offset: .16em; }
a:hover { color: var(--blue-dark); }

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

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .65; }

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: clamp(1.75rem, 4vw, 2.25rem); letter-spacing: -.035em; }
h2 { font-size: 1.2rem; letter-spacing: -.015em; }
h3 { font-size: 1rem; }

.layout {
    --header-row: 4.5rem;
    display: grid;
    grid-template-columns: minmax(13rem, 15rem) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 100vh;
}

.app-header {
    display: flex;
    grid-column: 1 / -1;
    align-items: center;
    justify-content: space-between;
    align-self: start;
    gap: .75rem;
    position: sticky;
    z-index: 3;
    top: .5rem;
    min-width: 0;
    min-height: calc(var(--header-row) - 1rem);
    margin: .5rem .75rem;
    padding: .4rem .55rem;
    border: 1px solid var(--header-border);
    border-radius: var(--radius);
    background: var(--header-background);
}

.header-start, .header-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
}

.header-start { flex: 1 1 auto; }
.header-actions { justify-content: flex-end; }

.header-logo {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: .5rem;
    padding: .15rem .35rem;
    color: var(--ink);
    font-size: 1rem;
    font-weight: 750;
    letter-spacing: -.025em;
    text-decoration: none;
    white-space: nowrap;
}

.header-logo:hover { color: var(--blue-dark); }
.header-logo .brand-mark { min-height: 2rem; flex-basis: 2rem; }

.header-menu { position: relative; min-width: 0; }
.company-menu { max-width: 21rem; }
.account-menu { max-width: 16rem; }
.settings-menu, .header-signout { flex: none; }

.header-menu > summary { list-style: none; cursor: pointer; }
.header-menu > summary::-webkit-details-marker { display: none; }

.header-trigger, .icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    min-height: 2.5rem;
    max-width: 100%;
    padding: .35rem .65rem;
    border: 1px solid var(--header-control-border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: .875rem;
    font-weight: 650;
    line-height: 1.2;
}

.icon-button { width: 2.5rem; padding: 0; }

.header-trigger:hover, .icon-button:hover, .header-menu[open] > summary {
    border-color: var(--header-active-border);
    background: var(--header-hover);
}

.header-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-icon, .header-chevron { flex: none; width: 1.15rem; height: 1.15rem; }
.header-chevron { width: .85rem; height: .85rem; color: var(--muted); }
.header-menu[open] > summary .header-chevron { transform: rotate(180deg); }

.header-popover {
    position: absolute;
    z-index: 1;
    inset-block-start: calc(100% + .55rem);
    inset-inline-end: 0;
    width: max-content;
    min-width: min(13rem, calc(100vw - 2rem));
    max-width: min(23rem, calc(100vw - 2rem));
    max-height: min(25rem, calc(100dvh - 6rem));
    overflow: auto;
    padding: .8rem;
    border: 1px solid var(--header-border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--header-popover-shadow);
    font-size: .875rem;
    overflow-wrap: anywhere;
}

.company-menu .header-popover { inset-inline-start: 0; inset-inline-end: auto; }
.header-popover > * + * { margin-block-start: .45rem; }
.header-popover-title { color: var(--ink); font-weight: 750; }

.company-options { display: grid; gap: .25rem; }

.company-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    min-height: 2.5rem;
    width: 100%;
    padding: .4rem .55rem;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--ink);
    line-height: 1.35;
    text-align: start;
}

.company-option:hover { background: var(--header-hover); }

.company-option[aria-current="true"] {
    border-color: var(--header-active-border);
    background: var(--header-hover);
    color: var(--blue-dark);
    font-weight: 700;
}

.company-option span { min-width: 0; }

.header-account-details {
    display: grid;
    grid-template-columns: minmax(4.5rem, max-content) minmax(0, 1fr);
    gap: .3rem .7rem;
    margin: .45rem 0;
}

.header-account-details dt { color: var(--muted); }
.header-account-details dd { margin: 0; }

.header-popover .preferences { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.header-popover .preferences button { grid-column: 1 / -1; justify-self: start; }

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    position: sticky;
    top: var(--header-row);
    height: calc(100vh - var(--header-row));
    padding: 1.5rem 1rem 1rem;
    overflow: auto;
    background: linear-gradient(160deg, var(--navy), var(--navy-deep));
    color: #f5f7fc;
}

.sidebar :focus-visible { outline-color: #a8c9ff; }

.brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .15rem .5rem;
    color: #fff;
    font-size: 1.15rem;
    font-weight: 750;
    letter-spacing: -.025em;
    text-decoration: none;
}

.brand:hover { color: #fff; }

.brand-mark {
    display: inline-grid;
    flex: 0 0 2.25rem;
    min-height: 2.25rem;
    place-items: center;
    border-radius: 8px;
    background: #dce8ff;
    color: #193b89;
    font-size: 1rem;
}

.nav { display: grid; gap: .3rem; }

.nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    min-height: 2.7rem;
    padding: .55rem .7rem;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #d5e0f0;
    font-size: .9rem;
    font-weight: 550;
    text-decoration: none;
}

.nav-link:hover, .nav-link.active, .nav-link[aria-current="page"] {
    background: #263e64;
    color: #fff;
}

.nav-link.active, .nav-link[aria-current="page"] { border-color: #5479b5; }

.sidebar-footer {
    display: grid;
    gap: .55rem;
    margin-top: auto;
    padding: .85rem .5rem 0;
    border-top: 1px solid #51627d;
    color: #d0dcee;
    font-size: .82rem;
    overflow-wrap: anywhere;
}

.sidebar-footer a { color: #e7efff; }
.sidebar .muted { color: #c1cee1; }

.main {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-width: 0;
    width: 100%;
    max-width: 100rem;
    margin-inline: auto;
    padding: 1.75rem clamp(1.25rem, 3.5vw, 3.25rem) 3rem;
}

.topline, .page-heading, .toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem 1rem;
    min-width: 0;
}

.topline { color: var(--muted); font-size: .88rem; }

.preferences {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .45rem .65rem;
    min-width: 0;
    max-width: 100%;
}

.preferences > label {
    display: grid;
    gap: .2rem;
    min-width: 0;
    max-width: 100%;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 650;
}

.preferences select, .preferences button {
    max-width: 100%;
    min-height: 2rem;
    font-size: .8rem;
}

.preferences select { padding: .28rem .5rem; }
.preferences button { padding: .32rem .65rem; }

.page-heading { align-items: flex-end; }
.page-heading p { margin-top: .45rem; color: var(--muted); }

.eyebrow {
    display: block;
    margin-bottom: .4rem;
    color: var(--blue-dark);
    font-size: .72rem;
    font-weight: 750;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.panel {
    min-width: 0;
    padding: clamp(1rem, 2.5vw, 1.5rem);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel > :where(h2, h3):not(:last-child) { margin-bottom: .8rem; }
.panel > .toolbar:not(:last-child) { margin-bottom: 1rem; }
form.toolbar { justify-content: flex-start; align-items: flex-end; gap: .65rem; }
.toolbar > .field:first-of-type { flex: 1 1 14rem; }
.toolbar > .field { max-width: 100%; }
.panel > .badge + p { margin-block: .55rem .9rem; }

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: .4rem;
    min-height: 2.5rem;
    padding: .5rem .85rem;
    border: 1px solid #c9d5e5;
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-size: .875rem;
    font-weight: 650;
    line-height: 1.3;
    text-align: center;
    text-decoration: none;
}

.button:hover { border-color: #7d94b6; background: #f1f5fd; color: var(--ink); }
.button.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.button.primary:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.button.danger { border-color: #e7bac0; color: var(--error); }
.button.danger:hover { border-color: var(--error); background: #fff0f2; color: #842231; }
.button.small { min-height: 2rem; padding: .32rem .65rem; font-size: .8rem; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 1rem;
}

.field { display: grid; align-content: start; gap: .35rem; min-width: 0; }
.field > label, label.field { font-size: .875rem; font-weight: 650; }
.full { grid-column: 1 / -1; }

:where(input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="reset"], [type="hidden"]), select, textarea) {
    min-width: 0;
    min-height: 2.5rem;
    padding: .48rem .65rem;
    border: 1px solid #bdcadd;
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-size: .9rem;
}

:where(input, textarea)::placeholder { color: #5f6d81; }
textarea { min-height: 6rem; resize: vertical; }
input[type="file"] { max-width: 100%; }

input::file-selector-button {
    margin-right: .5rem;
    padding: .25rem .5rem;
    border: 0;
    border-radius: 5px;
    background: #e8eef9;
    color: #173976;
    font: inherit;
    cursor: pointer;
}

.notice {
    padding: .65rem .85rem;
    border: 1px solid #c3d5f5;
    border-radius: 8px;
    background: #edf4ff;
    color: #1b3d79;
    font-size: .9rem;
    overflow-wrap: anywhere;
}

.notice.error { border-color: #edc2c8; background: #fff0f2; color: #861e2d; }
.notice.success { border-color: #a7d6bb; background: #eaf8ef; color: #145735; }

.table-wrap { overflow-x: auto; }
.table-wrap > table { width: 100%; border-collapse: collapse; font-size: .875rem; }

th, td { padding: .8rem .75rem; border-bottom: 1px solid var(--line); text-align: left; }
th { background: #f0f4fa; color: #41516a; font-size: .78rem; font-weight: 700; }
td { vertical-align: middle; }
td a { font-weight: 650; }
tbody tr:hover { background: #f7faff; }
tbody tr:last-child td { border-bottom: 0; }
th:first-child { border-radius: 7px 0 0 0; }
th:last-child { border-radius: 0 7px 0 0; }

.money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.badge {
    display: inline-block;
    padding: .22rem .53rem;
    border: 1px solid #cbd5e2;
    border-radius: 999px;
    background: #eef2f7;
    color: #34465f;
    font-size: .76rem;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
}

.badge.open { border-color: #ead39e; background: #fff3d9; color: #744c0d; }
.badge.approved { border-color: #abd5be; background: #e5f5eb; color: #165637; }
.badge.rejected { border-color: #e9bfc5; background: #fdebef; color: #852535; }

.empty { padding: 2rem .75rem; color: var(--muted); text-align: center; }
.empty p + p { margin-top: .4rem; }

.details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .8rem 1.2rem;
    margin: 0;
}

.details dt { color: var(--muted); font-size: .8rem; font-weight: 600; }
.details dd { margin: .1rem 0 0; overflow-wrap: anywhere; }

.split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    align-items: start;
}

.audit { margin: 0; padding: 0; list-style: none; font-size: .88rem; }
.audit > li { padding: .6rem 0; overflow-wrap: anywhere; }
.audit > li + li { border-top: 1px solid var(--line); }
.muted { color: var(--muted); }
.stack { display: grid; align-content: start; gap: .8rem; min-width: 0; }

.auth {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 1.5rem;
    background: radial-gradient(ellipse at top, #e3edff, transparent 62%), var(--page);
}

.auth-card {
    display: grid;
    gap: 1rem;
    width: min(100%, 27rem);
    padding: clamp(1.25rem, 5vw, 2rem);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 12px 34px #14254014;
}

.auth-card .brand { padding: 0; color: var(--ink); }

.auth-card .preferences {
    padding-top: .75rem;
    border-top: 1px solid var(--line);
}

html[data-theme="dark"] .button:not(.primary) {
    border-color: var(--control-border);
    background: var(--control);
}

html[data-theme="dark"] .button:not(.primary):hover { background: var(--control-hover); }
html[data-theme="dark"] .button.danger { border-color: #a56472; }
html[data-theme="dark"] .button.danger:hover { border-color: var(--error); background: #45242e; color: var(--error); }

html[data-theme="dark"] :where(input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="reset"], [type="hidden"]), select, textarea) {
    border-color: var(--control-border);
    background: var(--control);
}

html[data-theme="dark"] :where(input, textarea)::placeholder { color: var(--muted); }
html[data-theme="dark"] input::file-selector-button { background: var(--control-hover); color: var(--ink); }

html[data-theme="dark"] .notice { border-color: #537bad; background: #1d3457; color: #cbe0ff; }
html[data-theme="dark"] .notice.error { border-color: #a56472; background: #45242e; color: #ffc2ca; }
html[data-theme="dark"] .notice.success { border-color: #5b947d; background: #193b30; color: #bcebd1; }

html[data-theme="dark"] th { background: #23334d; color: var(--muted); }
html[data-theme="dark"] tbody tr:hover { background: #1d2c44; }
html[data-theme="dark"] .badge { border-color: #657e9e; background: #263a57; color: #dae7fc; }
html[data-theme="dark"] .badge.open { border-color: #997946; background: #413218; color: #ffe3a8; }
html[data-theme="dark"] .badge.approved { border-color: #5b947d; background: #193b30; color: #bcebd1; }
html[data-theme="dark"] .badge.rejected { border-color: #a56472; background: #45242e; color: #ffc2ca; }

html[data-theme="dark"] .auth { background: radial-gradient(ellipse at top, #203454, transparent 62%), var(--page); }
html[data-theme="dark"] .auth-card { background: var(--surface); box-shadow: 0 12px 34px #080d1870; }

@media (max-width: 58rem) {
    .layout { grid-template-columns: 12rem minmax(0, 1fr); }
    .split { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 43rem) {
    .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
    .app-header { position: relative; top: auto; flex-wrap: wrap; gap: .45rem; margin: .4rem .5rem; }
    .header-start, .header-actions { flex: 1 1 100%; }
    .header-menu { position: static; }
    .header-menu .header-popover {
        inset-inline: .45rem;
        width: auto;
        min-width: 0;
        max-width: none;
        max-height: min(25rem, calc(100dvh - 8rem));
    }
    .sidebar { position: static; height: auto; gap: .75rem; padding: .85rem 1rem; }
    .nav { display: flex; flex-wrap: wrap; }
    .sidebar-footer { display: flex; flex-wrap: wrap; align-items: center; }
    .main { padding: 1.25rem 1rem 2rem; }
    .form-grid, .details { grid-template-columns: minmax(0, 1fr); }
}
