:root {
  color-scheme: light;
  --ink: #202c2a;
  --muted: #71807b;
  --line: #dfe6e2;
  --paper: #ffffff;
  --canvas: #f4f6f4;
  --green: #176b55;
  --green-dark: #105440;
  --green-soft: #e6f3ed;
  --blue: #286b8b;
  --blue-soft: #e8f1f5;
  --amber: #99601a;
  --amber-soft: #fbf0dc;
  --red: #a43e36;
  --red-soft: #faeae7;
  --shadow: 0 8px 24px rgba(26, 53, 45, 0.07);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--canvas); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.5; }
a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); }
button, input { font: inherit; }
button, a, input { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 238px; display: flex; flex-direction: column; padding: 24px 16px 16px; background: #fff; border-right: 1px solid var(--line); z-index: 5; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 750; font-size: 17px; }
.brand:hover { color: var(--ink); }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: #fff; background: var(--green); font-size: 16px; font-weight: 700; }
.sidebar-label { margin: 36px 10px 10px; color: #8b9692; font-size: 11px; font-weight: 700; }
.primary-nav { display: grid; gap: 4px; }
.primary-nav a, .settings-link { display: flex; align-items: center; min-height: 42px; padding: 0 12px; border-radius: 6px; color: #52615d; font-weight: 600; }
.primary-nav a:hover, .settings-link:hover { color: var(--ink); background: #f2f6f3; }
.primary-nav a.active, .settings-link.active { color: var(--green-dark); background: var(--green-soft); }
.sidebar-footer { margin-top: auto; }
.settings-link { margin-bottom: 14px; }
.user-chip { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 9px; padding: 12px 4px 4px; border-top: 1px solid var(--line); }
.user-avatar, .account-avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: var(--green-dark); background: var(--green-soft); font-weight: 700; }
.user-name { overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 650; }
.user-chip form { margin: 0; }
.text-button { border: 0; padding: 4px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.text-button:hover { color: var(--green); }
.text-danger { color: var(--red); }
.main-content { width: min(1120px, calc(100% - 238px)); margin-left: 238px; padding: 40px 44px 72px; }
.mobile-header, .mobile-nav { display: none; }
.page-header { margin-bottom: 28px; }
.page-header-row { display: flex; justify-content: space-between; align-items: end; gap: 24px; }
.eyebrow, .auth-kicker { margin-bottom: 6px; color: var(--green); font-size: 11px; font-weight: 750; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 28px; line-height: 1.2; font-weight: 750; }
h2 { margin: 0; font-size: 17px; font-weight: 720; }
h3 { margin-bottom: 8px; font-size: 18px; }
.muted { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.date-picker { display: flex; align-items: center; gap: 10px; }
.date-picker label { color: var(--muted); font-size: 13px; }
input { min-width: 0; height: 42px; padding: 0 11px; border: 1px solid #cfd9d4; border-radius: 5px; outline: none; color: var(--ink); background: #fff; }
input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 107, 85, 0.12); }
textarea { width: 100%; min-height: 88px; resize: vertical; padding: 10px 11px; border: 1px solid #cfd9d4; border-radius: 5px; outline: none; color: var(--ink); background: #fff; font: inherit; }
textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 107, 85, 0.12); }
input:disabled { color: #83908b; background: #f5f7f5; }
input::placeholder { color: #a3aeaa; }
.date-picker input { height: 40px; }
.date-picker .button { min-height: 40px; }
.metric-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 32px; }
.metric { min-height: 120px; display: flex; flex-direction: column; align-items: flex-start; padding: 16px 18px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); }
.metric > span { color: #697873; font-size: 12px; font-weight: 650; }
.metric strong { margin: 8px 0 4px; font-size: 24px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.metric small { margin-top: auto; color: var(--muted); font-size: 11px; }
.metric-primary { border-color: #c9e1d5; background: var(--green-soft); }
.metric-primary > span { color: var(--green-dark); }
.metric-due strong { color: var(--amber); }
.metric-late strong { color: var(--red); }
.metric-next strong { color: var(--blue); }
.section-block { margin: 0 0 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading > div p { margin: 5px 0 0; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 16px; border: 1px solid transparent; border-radius: 5px; cursor: pointer; font-weight: 680; white-space: nowrap; transition: background-color .15s, border-color .15s; }
.button-primary { color: white; background: var(--green); }
.button-primary:hover { color: white; background: var(--green-dark); }
.button-secondary { color: #34433f; background: white; border-color: #cfd9d4; }
.button-secondary:hover { background: #f7f9f7; border-color: #aab9b1; }
.button-small { min-height: 34px; padding: 0 11px; font-size: 12px; }
.button-wide { width: 100%; }
.button-link { text-decoration: none; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: white; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { height: 42px; padding: 0 16px; color: #77847f; background: #f8faf8; font-size: 11px; font-weight: 700; }
td { height: 62px; padding: 9px 16px; border-top: 1px solid #edf0ee; vertical-align: middle; font-size: 13px; }
.ledger-table th:nth-child(2), .ledger-table td:nth-child(2) { width: 230px; }
.ledger-table th:nth-child(3), .ledger-table td:nth-child(3) { width: 200px; }
.ledger-table th:nth-child(4), .ledger-table td:nth-child(4) { width: 112px; }
.account-cell { display: grid; gap: 2px; }
.account-cell strong { font-size: 14px; }
.account-cell span { color: var(--muted); font-size: 11px; }
.money-input { display: flex; align-items: center; gap: 6px; color: #71807b; }
.money-input input { width: 145px; height: 38px; font-variant-numeric: tabular-nums; }
.date-input { width: 160px; height: 38px; }
.status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 4px; color: #596763; background: #eef2ef; font-size: 11px; font-weight: 680; white-space: nowrap; }
.status-open { color: #47655c; background: #e9f1ec; }
.status-paid { color: #176447; background: #e2f3e9; }
.status-due { color: #805113; background: var(--amber-soft); }
.status-late { color: #9c3d34; background: var(--red-soft); }
.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding-top: 14px; }
.form-actions .muted { font-size: 12px; }
.empty-state { padding: 44px 16px; text-align: center; border: 1px dashed #cbd6d0; border-radius: 6px; background: rgba(255,255,255,.6); }
.empty-state p { margin-bottom: 18px; color: var(--muted); }
.empty-inline { padding: 14px 0; margin: 0; color: var(--muted); font-size: 13px; }
.count-label { color: var(--muted); font-size: 12px; }
.reminder-section { padding-top: 20px; }
.section-danger { border-color: #e7c6c0; }
.section-danger h2 { color: var(--red); }
.section-today h2 { color: var(--amber); }
.reminder-list, .account-list { border-top: 1px solid var(--line); }
.reminder-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 20px; min-height: 74px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.reminder-main { min-width: 0; }
.reminder-title { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.reminder-title strong { font-size: 14px; }
.reminder-meta { margin-top: 5px; color: var(--muted); font-size: 12px; }
.reminder-amount { min-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.account-add-form { display: grid; grid-template-columns: 1fr 1.3fr auto; align-items: end; gap: 12px; }
.bulk-account-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; max-width: 680px; margin-top: 22px; }
.bulk-account-form label { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: #4e5c58; font-size: 12px; font-weight: 650; }
.account-add-form input { width: 100%; }
.optional { color: #8b9692; font-weight: 400; }
.account-row { display: flex; align-items: center; gap: 16px; min-height: 68px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.account-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.account-main > div { display: grid; gap: 2px; min-width: 0; }
.account-main strong { overflow-wrap: anywhere; }
.account-note { color: var(--muted); font-size: 12px; }
.account-archived { opacity: .7; }
.settings-block { max-width: 720px; }
.settings-form { max-width: 420px; }
.settings-form .button { justify-self: start; margin-top: 4px; }
.settings-status { margin: 0; color: var(--muted); font-size: 13px; }
.flash-stack { display: grid; gap: 8px; margin-bottom: 22px; }
.flash { padding: 10px 13px; border: 1px solid var(--line); border-radius: 5px; font-size: 13px; }
.flash-success { color: #176447; background: #e8f4ec; border-color: #c8e6d3; }
.flash-error { color: #913b33; background: #fbefed; border-color: #efcfca; }
.flash-info { color: #315f73; background: #edf5f8; border-color: #d3e5ec; }

.auth-main { display: grid; align-content: center; justify-items: center; min-height: 100vh; padding: 28px 18px; }
.auth-panel { width: min(100%, 420px); padding: 28px; border: 1px solid var(--line); border-radius: 7px; background: white; box-shadow: var(--shadow); }
.auth-panel-wide { width: min(100%, 460px); }
.auth-brand { margin-bottom: 28px; }
.auth-kicker { margin-bottom: 4px; }
.auth-panel h1 { margin-bottom: 22px; font-size: 24px; }
.form-stack { display: grid; gap: 15px; }
.form-stack input { width: 100%; }
.auth-switch { margin: 22px 0 0; text-align: center; color: var(--muted); font-size: 13px; }
.auth-switch a { font-weight: 700; }
.auth-flashes { width: min(100%, 460px); }

@media (max-width: 1050px) {
  .main-content { padding-right: 28px; padding-left: 28px; }
  .metric-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  body.signed-in { padding-top: 58px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .sidebar { display: none; }
  .mobile-header { position: fixed; inset: 0 0 auto; z-index: 10; height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
  .mobile-header .brand { font-size: 16px; }
  .mobile-header .brand-mark { width: 30px; height: 30px; }
  .mobile-user { max-width: 42%; overflow: hidden; color: var(--muted); text-overflow: ellipsis; font-size: 12px; }
  .mobile-nav { position: fixed; inset: auto 0 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.98); }
  .mobile-nav a { display: grid; place-items: center; min-height: 42px; border-radius: 5px; color: #687771; font-size: 12px; font-weight: 650; }
  .mobile-nav a.active { color: var(--green-dark); background: var(--green-soft); }
  .main-content { width: 100%; margin: 0; padding: 24px 16px 38px; }
  .page-header { margin-bottom: 21px; }
  .page-header-row { align-items: flex-start; flex-direction: column; gap: 14px; }
  h1 { font-size: 24px; }
  .date-picker { width: 100%; justify-content: space-between; }
  .date-picker input { width: min(57%, 230px); }
  .metric-row { gap: 8px; margin-bottom: 24px; }
  .metric { min-height: 106px; padding: 12px; }
  .metric strong { margin-top: 7px; font-size: 20px; }
  .metric small { font-size: 10px; }
  .section-block { margin-bottom: 22px; padding-top: 20px; }
  .section-heading { align-items: flex-start; margin-bottom: 13px; }
  .section-heading .button { min-height: 36px; padding: 0 10px; font-size: 12px; }
  .ledger-table, .ledger-table tbody, .ledger-table tr, .ledger-table td { display: block; width: 100%; }
  .ledger-table thead { display: none; }
  .ledger-table tbody { padding: 0 12px; }
  .ledger-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(116px, .9fr); gap: 10px 12px; padding: 14px 0; border-bottom: 1px solid #e9eeeb; }
  .ledger-table tr:last-child { border-bottom: 0; }
  .ledger-table td { width: auto !important; height: auto; min-height: 0; padding: 0; border: 0; }
  .ledger-table td:first-child { grid-column: 1 / -1; }
  .ledger-table td:nth-child(4) { grid-column: 1 / -1; }
  .ledger-table td[data-label="收到金额"]::before, .ledger-table td[data-label="付款日期"]::before { display: block; margin: 0 0 4px; color: var(--muted); font-size: 10px; }
  .ledger-table td[data-label="收到金额"]::before { content: "收到金额"; }
  .ledger-table td[data-label="付款日期"]::before { content: "付款日期"; }
  .money-input { gap: 3px; }
  .money-input input { width: 100%; height: 40px; padding: 0 7px; font-size: 14px; }
  .date-input { width: 100%; height: 40px; padding: 0 6px; font-size: 12px; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions .muted { order: 2; text-align: center; }
  .form-actions .button { width: 100%; }
  .reminder-row { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; padding: 13px 0; }
  .reminder-main { grid-column: 1 / 2; }
  .reminder-amount { grid-column: 2; grid-row: 1; min-width: auto; font-size: 14px; }
  .reminder-row form { grid-column: 1 / -1; }
  .reminder-row .button { width: 100%; }
  .account-add-form { grid-template-columns: 1fr; }
  .account-add-form .button { width: 100%; }
  .table-wrap table:not(.ledger-table) { min-width: 580px; }
  .auth-main { min-height: 100svh; padding: 18px 14px; }
  .auth-panel { padding: 23px 19px; }
}
