:root {
    --ink-950: #172034;
    --ink-900: #202b42;
    --ink-800: #2c3952;
    --ink-700: #46536a;
    --ink-600: #657087;
    --ink-500: #838da0;
    --line: #dfe4ec;
    --line-strong: #c9d0dc;
    --surface: #ffffff;
    --surface-soft: #f6f7fa;
    --surface-tint: #eef2ff;
    --primary: #3e5bc7;
    --primary-dark: #3048a0;
    --primary-soft: #e9edff;
    --success: #23795d;
    --success-soft: #e7f6ef;
    --warning: #9a650f;
    --warning-soft: #fff5da;
    --danger: #b54444;
    --danger-soft: #fff0f0;
    --sidebar: #182238;
    --sidebar-muted: #91a0bb;
    --shadow-sm: 0 1px 2px rgba(23, 32, 52, .06), 0 8px 24px rgba(23, 32, 52, .04);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 248px;
    color-scheme: light;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
    margin: 0;
    color: var(--ink-900);
    background: var(--surface-soft);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    line-height: 1.55;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, label, select { cursor: pointer; }
img { max-width: 100%; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

:focus-visible { outline: 3px solid rgba(62, 91, 199, .28); outline-offset: 2px; }
.muted { color: var(--ink-600); }
.eyebrow { margin-bottom: .45rem; color: var(--primary); font-size: .72rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.text-link { color: var(--primary); font-weight: 700; }
.text-link:hover { text-decoration: underline; }
.text-link--danger { color: var(--danger); }
.numeric { font-variant-numeric: tabular-nums; }

.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    display: flex;
    width: var(--sidebar-width);
    flex-direction: column;
    color: #fff;
    background: var(--sidebar);
}
.sidebar__brand { display: flex; min-height: 76px; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand { display: inline-flex; align-items: center; gap: 11px; font-weight: 700; }
.brand__mark { display: inline-grid; width: 36px; height: 36px; place-items: center; border-radius: 10px; color: #fff; background: var(--primary); font-size: .78rem; font-weight: 900; letter-spacing: .05em; }
.brand small { display: block; color: var(--sidebar-muted); font-size: .68rem; font-weight: 600; letter-spacing: .08em; }
.sidebar__close { display: none; color: #fff; font-size: 1.7rem; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
.nav-group + .nav-group { margin-top: 17px; }
.nav-group__label { margin: 0 10px 6px; color: var(--sidebar-muted); font-size: .66rem; font-weight: 800; letter-spacing: .11em; }
.nav-link { display: flex; min-height: 41px; align-items: center; gap: 10px; margin: 2px 0; padding: 8px 10px; border-radius: 8px; color: #c9d2e2; font-size: .88rem; font-weight: 650; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-link.is-active { color: #fff; background: rgba(111, 137, 236, .22); box-shadow: inset 3px 0 #8ea4ff; }
.nav-link.is-disabled { cursor: default; opacity: .55; }
.nav-link.is-disabled:hover { color: #c9d2e2; background: transparent; }
.nav-link__mark { display: inline-grid; width: 25px; height: 25px; flex: 0 0 25px; place-items: center; border: 1px solid rgba(255,255,255,.15); border-radius: 7px; font-size: .68rem; }
.nav-link small { margin-left: 4px; color: var(--sidebar-muted); font-size: .62rem; }
.sidebar__note { margin: 12px; padding: 12px; border: 1px solid rgba(255,255,255,.09); border-radius: 9px; color: var(--sidebar-muted); background: rgba(255,255,255,.04); font-size: .72rem; }
.sidebar__note strong, .sidebar__note span { display: block; }
.sidebar__note strong { margin-bottom: 3px; color: #e8edfa; }

.workspace { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; min-height: 76px; align-items: center; justify-content: space-between; gap: 20px; padding: 13px 28px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(12px); }
.topbar__start { display: flex; min-width: 0; align-items: center; gap: 14px; }
.topbar h1 { overflow: hidden; margin: 0; font-size: 1.24rem; text-overflow: ellipsis; white-space: nowrap; }
.topbar p { margin: 2px 0 0; color: var(--ink-600); font-size: .76rem; }
.topbar__menu { display: none; width: 38px; height: 38px; place-content: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; }
.topbar__menu span { display: block; width: 18px; height: 2px; background: var(--ink-700); }
.topbar__user { display: flex; align-items: center; gap: 10px; font-size: .76rem; }
.topbar__identity strong, .topbar__identity span { display: block; }
.topbar__identity span { color: var(--ink-600); }
.avatar { display: inline-grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; border-radius: 50%; color: var(--primary-dark); background: var(--primary-soft); font-weight: 800; }
.main-content { width: min(100%, 1500px); margin: 0 auto; padding: 26px 28px 48px; }
.content-narrow { max-width: 720px; }
.nav-toggle, .nav-backdrop { display: none; }

.page-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-actions__copy h2 { margin-bottom: 3px; }
.page-actions__copy p { margin-bottom: 0; color: var(--ink-600); font-size: .83rem; }
.page-actions__buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.panel + .panel { margin-top: 18px; }
.panel__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 19px 20px 15px; border-bottom: 1px solid var(--line); }
.panel__header h2, .panel__header p { margin-bottom: 0; }
.panel__header p { margin-top: 4px; color: var(--ink-600); font-size: .8rem; }
.panel__body { padding: 20px; }
.panel__footer { padding: 14px 20px; border-top: 1px solid var(--line); background: #fbfcfd; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { min-height: 128px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.stat-card__label { color: var(--ink-600); font-size: .78rem; font-weight: 700; }
.stat-card__value { margin: 13px 0 6px; font-size: 1.8rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-card__meta { color: var(--ink-500); font-size: .72rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr); gap: 18px; }
.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 18px; }
.quick-action { padding: 15px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.quick-action strong, .quick-action span { display: block; }
.quick-action span { margin-top: 4px; color: var(--ink-600); font-size: .74rem; }
.quick-action:hover { border-color: #b7c2ee; background: var(--surface-tint); }

.button { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--ink-800); background: var(--surface); font-size: .82rem; font-weight: 750; line-height: 1.2; }
.button:hover { border-color: #aeb7c7; background: var(--surface-soft); }
.button--primary { border-color: var(--primary); color: #fff; background: var(--primary); }
.button--primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.button--danger { border-color: #d9a2a2; color: var(--danger); background: #fff; }
.button--ghost { background: transparent; }
.button--small { min-height: 32px; padding: 6px 10px; font-size: .74rem; }
.button--block { width: 100%; }
.button[disabled] { cursor: not-allowed; opacity: .5; }

.alert { margin-bottom: 16px; padding: 12px 14px; border: 1px solid; border-radius: 9px; font-size: .83rem; }
.alert ul { margin: 7px 0 0; padding-left: 20px; }
.alert--success { border-color: #b4dfd0; color: #165d47; background: var(--success-soft); }
.alert--warning { border-color: #ead59e; color: #77500f; background: var(--warning-soft); }
.alert--danger { border-color: #e8baba; color: #8c3030; background: var(--danger-soft); }
.alert--info { border-color: #bfcaef; color: #314a9f; background: var(--primary-soft); }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.filter-bar .field { min-width: 150px; flex: 0 1 210px; }
.filter-bar .field--search { min-width: 230px; flex-grow: 1; }
.filter-check { align-self: center; padding: 7px 4px; }
.filter-bar .filter-check { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
.filter-bar label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.filter-bar input, .filter-bar select { min-height: 38px; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.data-table th { padding: 10px 14px; color: var(--ink-600); background: #fafbfc; font-size: .69rem; font-weight: 800; letter-spacing: .03em; text-align: left; white-space: nowrap; }
.data-table td { padding: 13px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:hover { background: #fafbfe; }
.table-primary { font-weight: 750; }
.table-secondary { display: block; margin-top: 2px; color: var(--ink-600); font-size: .7rem; }
.table-actions { display: flex; justify-content: flex-end; gap: 10px; white-space: nowrap; }
.table-empty { padding: 35px 18px !important; color: var(--ink-600); text-align: center; }
.pagination { display: flex; justify-content: space-between; padding: 14px 16px; border-top: 1px solid var(--line); }

.status-pill { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px; font-size: .67rem; font-weight: 800; white-space: nowrap; }
.status-pill--success { color: var(--success); background: var(--success-soft); }
.status-pill--warning { color: var(--warning); background: var(--warning-soft); }
.status-pill--danger { color: var(--danger); background: var(--danger-soft); }
.status-pill--info { color: var(--primary-dark); background: var(--primary-soft); }
.status-pill--muted { color: var(--ink-600); background: #eef0f4; }

.form-stack { display: grid; gap: 18px; padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px 18px; }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { min-width: 0; }
.field--full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; color: var(--ink-800); font-size: .76rem; font-weight: 750; }
.field label .required { color: var(--danger); }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--ink-900); background: #fff; }
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); outline: 3px solid rgba(62,91,199,.11); }
.field input[readonly], .field select[disabled] { color: var(--ink-600); background: var(--surface-soft); }
.field-help { margin: 5px 0 0; color: var(--ink-600); font-size: .7rem; }
.field-error { margin: 5px 0 0; color: var(--danger); font-size: .72rem; font-weight: 650; }
.check-row { display: flex; align-items: flex-start; gap: 8px; font-size: .8rem; }
.check-row input { margin-top: 3px; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; padding-top: 16px; border-top: 1px solid var(--line); }
.auth-form .form-actions { border: 0; }
.sticky-actions { position: sticky; bottom: 0; z-index: 20; display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; padding: 13px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.96); box-shadow: 0 -8px 30px rgba(23,32,52,.08); backdrop-filter: blur(10px); }
.document-lines { display: grid; gap: 0; }
.document-line { padding: 18px 20px 20px; border-bottom: 1px solid var(--line); }
.document-line:last-child { border-bottom: 0; }
.document-line__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.document-line__head button, .table-actions button { padding: 0; border: 0; background: transparent; }
.reversal-panel summary { padding: 18px 20px; cursor: pointer; font-size: .85rem; font-weight: 800; }
.reversal-form { padding: 0; }
.field--span-2 { grid-column: span 2; }
.allocation-groups { display: grid; }
.allocation-group { border-bottom: 1px solid var(--line); }
.allocation-group:last-child { border-bottom: 0; }
.allocation-group__header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px 20px 14px; background: #fafbfc; }
.allocation-group__header h3, .allocation-group__header p, .allocation-group__header .eyebrow { margin-bottom: 0; }
.allocation-group__header p { margin-top: 5px; color: var(--ink-600); font-size: .73rem; }
.allocation-required { min-width: 118px; text-align: right; }
.allocation-required span, .allocation-required small { display: block; color: var(--ink-600); font-size: .68rem; }
.allocation-required strong { margin-right: 4px; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.allocation-list { display: grid; }
.allocation-row { display: grid; grid-template-columns: minmax(180px, .8fr) minmax(220px, 1.4fr) minmax(130px, .55fr) auto; align-items: end; gap: 12px; padding: 15px 20px; border-top: 1px solid var(--line); }
.allocation-row__remove { align-self: center; min-height: 36px; padding: 0 4px; border: 0; background: transparent; }
.allocation-group__footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px 16px; border-top: 1px dashed var(--line); }
.allocation-sum { padding: 4px 9px; border-radius: 999px; color: var(--warning); background: var(--warning-soft); font-size: .7rem; }
.allocation-sum.is-complete { color: var(--success); background: var(--success-soft); }
.allocation-sum.is-over { color: var(--danger); background: var(--danger-soft); }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; }
.detail-item { min-height: 75px; padding: 14px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-item:nth-child(3n) { border-right: 0; }
.detail-item dt { margin-bottom: 4px; color: var(--ink-600); font-size: .68rem; font-weight: 750; }
.detail-item dd { margin: 0; font-size: .83rem; font-weight: 650; }
.summary-strip { display: flex; flex-wrap: wrap; gap: 20px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.summary-strip span { color: var(--ink-600); font-size: .72rem; }
.summary-strip strong { display: block; margin-top: 2px; color: var(--ink-900); font-size: .9rem; }

.empty-state { padding: 48px 20px; color: var(--ink-600); text-align: center; }
.empty-state__icon { display: grid; width: 46px; height: 46px; margin: 0 auto 13px; place-items: center; border-radius: 50%; color: var(--primary); background: var(--primary-soft); font-size: 1.5rem; }
.empty-state h3 { margin-bottom: 6px; color: var(--ink-900); }
.empty-state p { max-width: 430px; margin: 0 auto 16px; font-size: .8rem; }

.auth-body { min-height: 100vh; background: #eef1f7; }
.auth-shell { display: grid; min-height: 100vh; grid-template-columns: minmax(320px, .85fr) minmax(460px, 1.15fr); }
.auth-intro { display: flex; padding: 42px clamp(32px, 6vw, 80px); flex-direction: column; justify-content: space-between; color: #dce4f5; background: radial-gradient(circle at 18% 15%, #344870 0, var(--sidebar) 45%, #11182a 100%); }
.auth-intro h1 { margin-bottom: 18px; color: #fff; font-size: clamp(2rem, 3.5vw, 3.5rem); letter-spacing: -.045em; }
.auth-intro p { color: #aab7ce; }
.auth-intro .eyebrow { color: #9fb2ff; }
.auth-intro__foot { margin: 0; font-size: .74rem; }
.auth-panel { display: grid; place-items: center; padding: 28px; }
.auth-card { width: min(100%, 430px); padding: 34px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: 0 24px 60px rgba(23,32,52,.1); }
.auth-card h2 { margin-bottom: 6px; font-size: 1.45rem; }
.auth-card__mobile-brand { display: none; margin-bottom: 28px; align-items: center; gap: 10px; font-weight: 800; }
.auth-form { padding: 18px 0 0; }

@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .topbar__identity { display: none; }
    .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .detail-item:nth-child(3n) { border-right: 1px solid var(--line); }
    .detail-item:nth-child(2n) { border-right: 0; }
}

@media (max-width: 820px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    .sidebar__close { display: block; }
    .workspace { margin-left: 0; }
    .topbar { padding: 11px 16px; }
    .topbar__menu { display: grid; }
    .main-content { padding: 20px 16px 42px; }
    .nav-backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(12,18,31,.52); }
    .nav-toggle:checked ~ .app-shell .sidebar { transform: translateX(0); }
    .nav-toggle:checked ~ .app-shell .nav-backdrop { display: block; }
    .auth-shell { grid-template-columns: 1fr; }
    .auth-intro { display: none; }
    .auth-card__mobile-brand { display: flex; }
    .allocation-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .allocation-row__remove { justify-self: start; }
}

@media (max-width: 620px) {
    .topbar__user .text-link, .avatar { display: none; }
    .topbar p { display: none; }
    .stats-grid, .quick-actions, .form-grid, .form-grid--3, .detail-grid { grid-template-columns: 1fr; }
    .stat-card { min-height: 106px; }
    .detail-item, .detail-item:nth-child(3n) { border-right: 0; }
    .page-actions { align-items: stretch; }
    .page-actions__buttons, .page-actions__buttons .button { width: 100%; }
    .form-stack, .panel__body { padding: 16px; }
    .form-actions { position: sticky; bottom: 0; z-index: 5; margin: 0 -16px -16px; padding: 12px 16px; background: rgba(255,255,255,.96); }
    .sticky-actions { margin-right: -8px; margin-left: -8px; }
    .filter-bar .field { min-width: 100%; flex-basis: 100%; }
    .auth-panel { padding: 16px; }
    .auth-card { padding: 25px 20px; }
    .field--span-2 { grid-column: 1; }
    .allocation-group__header { align-items: flex-start; padding: 16px; }
    .allocation-row { grid-template-columns: 1fr; padding: 14px 16px; }
    .allocation-group__footer { align-items: stretch; padding: 12px 16px 16px; flex-direction: column; }
    .allocation-sum { text-align: center; }
}
