:root {
  --ink: #17201c;
  --ink-soft: #4e5a54;
  --canvas: #f3f5f2;
  --surface: #ffffff;
  --surface-muted: #eef1ed;
  --line: #d8ded9;
  --line-strong: #b9c3bc;
  --brand: #154e3d;
  --brand-strong: #0c3a2c;
  --brand-soft: #dcebe4;
  --income: #087947;
  --income-soft: #dff3e8;
  --expense: #b83b35;
  --expense-soft: #fae7e5;
  --warning: #8a5a06;
  --focus: #1677ff;
  --shadow: 0 1px 2px rgb(12 42 31 / 7%), 0 8px 24px rgb(12 42 31 / 5%);
  --radius: 6px;
  --sidebar: 252px;
  --font-body: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-display: "Space Grotesk", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--canvas); color: var(--ink); font-family: var(--font-body); }
body { margin: 0; min-width: 320px; background: var(--canvas); font-size: 15px; line-height: 1.5; letter-spacing: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; padding: 12px 16px; background: var(--ink); color: white; border-radius: var(--radius); }
.skip-link:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.muted { color: var(--ink-soft); }
.text-income { color: var(--income) !important; }
.text-expense { color: var(--expense) !important; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; display: flex; width: var(--sidebar); flex-direction: column; padding: 24px 16px 16px; background: #10261e; color: #edf5f0; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.brand-mark { display: inline-grid; width: 42px; height: 42px; place-items: center; flex: 0 0 auto; border: 1px solid rgb(255 255 255 / 24%); border-radius: var(--radius); background: #edf5f0; color: var(--brand-strong); font-family: var(--font-display); font-weight: 700; }
.brand strong, .brand small, .admin-identity strong, .admin-identity small { display: block; }
.brand strong { font-family: var(--font-display); font-size: 17px; }
.brand small { color: #9fb5aa; font-size: 11px; text-transform: uppercase; }
.nav-list { display: grid; gap: 4px; }
.nav-item { display: flex; min-height: 46px; align-items: center; gap: 12px; padding: 0 14px; border-radius: var(--radius); color: #c5d4cc; text-decoration: none; transition: background 120ms, color 120ms; }
.nav-item > span:first-child { display: grid; width: 20px; place-items: center; font-size: 18px; }
.nav-item:hover { background: rgb(255 255 255 / 7%); color: white; }
.nav-item.is-active { background: #e8f3ed; color: var(--brand-strong); font-weight: 700; }
.sidebar-footer { display: grid; gap: 14px; margin-top: auto; padding-top: 20px; border-top: 1px solid rgb(255 255 255 / 11%); }
.admin-identity, .user-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.admin-identity small, .user-cell small { color: #9fb5aa; }
.avatar-placeholder, .user-cell img { display: inline-grid; width: 38px; height: 38px; place-items: center; flex: 0 0 auto; overflow: hidden; border-radius: 50%; background: var(--brand-soft); color: var(--brand-strong); font-weight: 800; object-fit: cover; }
.user-cell small { display: block; color: var(--ink-soft); }

.content-shell { min-height: 100vh; margin-left: var(--sidebar); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; height: 76px; align-items: center; gap: 18px; padding: 0 32px; border-bottom: 1px solid var(--line); background: rgb(243 245 242 / 94%); backdrop-filter: blur(12px); }
.topbar h1 { margin: 0; font-family: var(--font-display); font-size: 22px; line-height: 1.2; }
.eyebrow { margin: 0 0 3px; color: var(--ink-soft); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.eyebrow-light { color: #a7beb2; }
.topbar-meta { display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--ink-soft); font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--income); box-shadow: 0 0 0 4px var(--income-soft); }
.menu-button { display: none; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-size: 20px; }
.main-content { width: min(1480px, 100%); margin: 0 auto; padding: 28px 32px 56px; }
.nav-scrim { display: none; }

.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius); font-weight: 700; text-decoration: none; cursor: pointer; transition: transform 100ms, background 120ms, border-color 120ms; }
.button:active { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.button-primary { background: var(--brand); color: white; }
.button-primary:hover { background: var(--brand-strong); }
.button-secondary { border-color: var(--line-strong); background: var(--surface); color: var(--ink); }
.button-secondary:hover, .button-quiet:hover { background: var(--surface-muted); }
.button-quiet { border-color: transparent; background: transparent; color: inherit; }
.sidebar .button-quiet { border-color: rgb(255 255 255 / 16%); color: #d7e4dd; }
.button-danger { background: var(--expense); color: white; }
.button-danger-quiet { border-color: #e8b4b0; background: var(--expense-soft); color: #8c2621; }
.button-small { min-height: 38px; padding: 0 12px; font-size: 13px; }
.button-full { width: 100%; }

.flash { display: flex; min-height: 48px; align-items: center; gap: 10px; margin-bottom: 20px; padding: 10px 14px; border: 1px solid; border-radius: var(--radius); }
.flash span { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 50%; font-weight: 900; }
.flash-success { border-color: #a8d8bd; background: var(--income-soft); color: #075b37; }
.flash-success span { background: var(--income); color: white; }
.flash-error { border-color: #e8b4b0; background: var(--expense-soft); color: #842722; }
.flash-error span { background: var(--expense); color: white; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.metric-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 18px; }
.metric { position: relative; min-height: 152px; overflow: hidden; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric::after { position: absolute; inset: auto 0 0; height: 3px; content: ""; background: var(--line-strong); }
.metric-income::after { background: var(--income); }
.metric-expense::after { background: var(--expense); }
.metric-net::after { background: var(--warning); }
.metric-label { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.metric-icon { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 50%; background: var(--surface-muted); color: var(--ink); font-weight: 900; }
.metric strong { display: block; margin-top: 20px; font-family: var(--font-display); font-size: 32px; line-height: 1; overflow-wrap: anywhere; }
.metric small { display: block; margin-top: 12px; color: var(--ink-soft); }

.section-block { margin-top: 30px; }
.compact-top { margin-top: 20px; }
.section-heading { display: flex; min-height: 54px; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; font-family: var(--font-display); font-size: 20px; }
.table-frame { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th { height: 44px; padding: 0 14px; border-bottom: 1px solid var(--line); background: #f7f8f6; color: var(--ink-soft); font-size: 11px; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { min-height: 54px; padding: 12px 14px; border-bottom: 1px solid #e7ebe8; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbf9; }
.direction, .status-badge, .role-badge { display: inline-flex; min-height: 24px; align-items: center; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.direction-income { background: var(--income-soft); color: var(--income); }
.direction-expense { background: var(--expense-soft); color: var(--expense); }
.status-badge { background: var(--surface-muted); color: var(--ink-soft); }
.status-active { background: var(--income-soft); color: var(--income); }
.status-voided { background: #ececeb; color: #6e716f; text-decoration: line-through; }
.role-badge { background: var(--surface-muted); color: var(--ink-soft); }
.role-core { background: #fff0c9; color: #74500c; }
.role-assistant { background: var(--brand-soft); color: var(--brand-strong); }
.amount { font-family: var(--font-display); font-weight: 800; white-space: nowrap; }
.amount-income { color: var(--income); }
.amount-expense { color: var(--expense); }
.amount-block, .cell-note { display: block; margin-top: 4px; }
.cell-note { max-width: 340px; color: var(--ink-soft); font-size: 12px; overflow-wrap: anywhere; }
.actions-cell { width: 1%; text-align: right; }
.empty-state { display: grid; min-height: 160px; place-content: center; gap: 5px; color: var(--ink-soft); text-align: center; }
.empty-state strong { color: var(--ink); font-size: 16px; }

.filter-panel { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 14px; }
.filter-grid-short { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.field { display: grid; gap: 6px; min-width: 0; }
.field label, .compact-form > label { color: var(--ink-soft); font-size: 12px; font-weight: 800; }
.field small { color: var(--ink-soft); }
input, select { width: 100%; min-height: 44px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
input:hover, select:hover { border-color: #87968d; }
.filter-actions { display: flex; align-items: end; gap: 8px; }
.filter-panel-inline { display: flex; }
.inline-form { display: flex; align-items: end; gap: 10px; }
.inline-form .field { min-width: 280px; }
.stack-form { display: grid; gap: 14px; }
.compact-form { gap: 10px; }
.secondary-action { margin-top: 10px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }

.action-menu { position: relative; }
.action-menu > summary { list-style: none; }
.action-menu > summary::-webkit-details-marker { display: none; }
.action-popover { position: fixed; z-index: 40; top: 92px; right: 32px; width: 360px; max-height: calc(100vh - 116px); overflow-y: auto; padding: 16px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); box-shadow: 0 18px 50px rgb(20 42 32 / 18%); text-align: left; }
.action-popover hr { margin: 16px 0; border: 0; border-top: 1px solid var(--line); }

.audit-list { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.audit-item { display: grid; grid-template-columns: 14px 1fr auto; gap: 14px; align-items: start; padding: 18px; border-bottom: 1px solid var(--line); }
.audit-item:last-child { border-bottom: 0; }
.audit-marker { width: 10px; height: 10px; margin-top: 7px; border: 2px solid var(--surface); border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.audit-marker-role { background: var(--warning); box-shadow: 0 0 0 2px #faebc8; }
.audit-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.audit-body p { margin: 5px 0 0; color: var(--ink-soft); }
.audit-item time { color: var(--ink-soft); font-size: 12px; white-space: nowrap; }

.login-body { min-height: 100vh; background: var(--surface); }
.login-shell { display: grid; min-height: 100vh; grid-template-columns: minmax(360px, 1.05fr) minmax(420px, .95fr); }
.login-brand { position: relative; display: grid; place-items: center; overflow: hidden; padding: 56px; background: #10261e; color: white; }
.login-brand::before { position: absolute; inset: 0; content: ""; opacity: .13; background-image: linear-gradient(#fff 1px, transparent 1px), linear-gradient(90deg, #fff 1px, transparent 1px); background-size: 44px 44px; mask-image: linear-gradient(to bottom right, black, transparent 80%); }
.login-brand-inner { position: relative; width: min(560px, 100%); }
.brand-mark-large { width: 58px; height: 58px; margin-bottom: 64px; font-size: 19px; }
.login-brand h1 { max-width: 560px; margin: 10px 0 20px; font-family: var(--font-display); font-size: 56px; line-height: 1.08; }
.login-brand p:not(.eyebrow) { max-width: 540px; color: #c3d2ca; font-size: 17px; }
.trust-row { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 48px; color: #c3d2ca; font-size: 13px; }
.trust-row span { display: flex; align-items: center; gap: 8px; }
.trust-row i { width: 7px; height: 7px; border-radius: 50%; background: #6fd29e; }
.login-panel { display: grid; place-items: center; padding: 48px; }
.login-form-wrap { width: min(420px, 100%); }
.login-form-wrap h2 { margin: 5px 0 8px; font-family: var(--font-display); font-size: 31px; }
.login-form-wrap > .muted { margin: 0 0 28px; }
.security-note { margin-top: 24px; color: var(--ink-soft); font-size: 12px; text-align: center; }
.security-note span { color: var(--income); }

@media (max-width: 1080px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  body { font-size: 16px; }
  .sidebar { transform: translateX(-100%); transition: transform 200ms ease-out; }
  .nav-open .sidebar { transform: translateX(0); }
  .nav-open .nav-scrim { position: fixed; inset: 0; z-index: 25; display: block; background: rgb(10 24 18 / 55%); }
  .content-shell { margin-left: 0; }
  .topbar { height: 68px; padding: 0 16px; }
  .topbar h1 { font-size: 19px; }
  .topbar-meta { display: none; }
  .menu-button { display: inline-grid; place-items: center; }
  .main-content { padding: 20px 14px 40px; }
  .metric-grid, .metric-grid-three { grid-template-columns: 1fr; }
  .metric { min-height: 132px; }
  .metric strong { font-size: 30px; }
  .table-frame { overflow: visible; border: 0; background: transparent; box-shadow: none; }
  .table-frame table, .table-frame tbody { display: block; }
  .table-frame thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  .table-frame tbody { display: grid; gap: 12px; }
  .table-frame tbody tr { display: block; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
  .table-frame tbody td { display: grid; min-height: 48px; grid-template-columns: 104px minmax(0, 1fr); gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid #e7ebe8; text-align: left; white-space: normal; }
  .table-frame tbody td::before { content: attr(data-label); color: var(--ink-soft); font-size: 12px; font-weight: 800; }
  .table-frame tbody td[colspan] { display: block; }
  .table-frame tbody td[colspan]::before { content: none; }
  .table-frame tbody td:last-child { border-bottom: 0; }
  .table-frame .actions-cell { width: auto; }
  .filter-grid, .filter-grid-short { grid-template-columns: 1fr; }
  .filter-actions, .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form .field { min-width: 0; }
  .section-heading { align-items: start; }
  .section-heading > div { min-width: 0; }
  .section-heading h2 { font-size: 18px; overflow-wrap: normal; }
  .section-heading > .muted { max-width: 48%; font-size: 13px; text-align: right; }
  th, td { padding-right: 12px; padding-left: 12px; }
  .action-popover { position: fixed; inset: auto 12px 12px; width: auto; max-height: 76vh; overflow: auto; }
  .audit-item { grid-template-columns: 14px 1fr; }
  .audit-item time { grid-column: 2; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 330px; padding: 34px 24px; }
  .brand-mark-large { margin-bottom: 34px; }
  .login-brand h1 { font-size: 42px; }
  .trust-row { margin-top: 26px; }
  .login-panel { padding: 40px 22px; }
}

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