:root {
  color-scheme: light;
  --ink: #191b1e;
  --muted: #6b7078;
  --line: #e2e4e7;
  --soft: #f5f6f7;
  --paper: #ffffff;
  --sidebar: #171a1f;
  --sidebar-muted: #989fa8;
  --accent: #e4552d;
  --accent-dark: #bf3f1d;
  --green: #217a56;
  --green-soft: #e7f4ed;
  --red: #b73d42;
  --red-soft: #fae9e8;
  --amber: #986411;
  --amber-soft: #fff2d8;
  --blue: #326c96;
  --shadow: 0 18px 46px rgba(25, 27, 30, 0.12);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--soft); letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 232px; padding: 24px 14px 18px; display: flex; flex-direction: column; color: white; background: var(--sidebar); z-index: 10; }
.brand { display: flex; gap: 11px; align-items: center; padding: 0 10px 30px; }
.brand-mark { width: 37px; aspect-ratio: 1; display: grid; place-items: center; background: var(--accent); font-size: 18px; font-weight: 700; }
.brand div, .storage-state div { display: grid; gap: 3px; }
.brand strong { font-size: 15px; }
.brand small, .storage-state small { color: var(--sidebar-muted); font-size: 11px; }
nav { display: grid; gap: 4px; }
.nav-item { height: 42px; padding: 0 12px; display: flex; align-items: center; gap: 11px; border: 0; border-radius: 5px; color: #c6cbd1; background: transparent; text-align: left; font-size: 13px; }
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: #24282e; color: white; }
.nav-item.active { color: white; background: #2a2e34; box-shadow: inset 3px 0 var(--accent); }
.storage-state { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid #2d3137; display: flex; gap: 9px; align-items: center; }
.storage-state strong { font-size: 12px; font-weight: 500; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #50bd83; box-shadow: 0 0 0 4px rgba(80, 189, 131, .1); }
.main { grid-column: 2; min-width: 0; }
.topbar { height: 96px; padding: 0 34px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--paper); }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 10px; line-height: 1; font-weight: 700; letter-spacing: 1.6px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 22px; line-height: 1.2; }
h2 { margin-bottom: 0; font-size: 19px; }
h3 { margin-bottom: 4px; font-size: 14px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.month-control { height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: white; }
.month-control svg { width: 16px; }
.month-control input { width: 122px; border: 0; outline: 0; color: var(--ink); font-size: 13px; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: white; }
.icon-button:hover { border-color: #bdc1c6; background: var(--soft); }
.icon-button svg { width: 17px; height: 17px; }
.content { padding: 28px 34px 46px; max-width: 1440px; margin: 0 auto; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); background: white; }
.metric { min-height: 126px; padding: 22px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.metric-icon { width: 30px; aspect-ratio: 1; display: grid; place-items: center; border-radius: 5px; background: var(--soft); }
.metric-icon svg { width: 15px; }
.metric strong { display: block; margin-top: 13px; font-size: 25px; line-height: 1; }
.metric small { display: block; margin-top: 9px; color: var(--muted); font-size: 11px; }
.metric.positive strong { color: var(--green); }
.metric.negative strong { color: var(--red); }
.dashboard-grid { margin-top: 18px; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr); gap: 18px; }
.panel { border: 1px solid var(--line); background: white; }
.panel-head { min-height: 66px; padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.chart { height: 282px; padding: 26px 22px 18px; display: flex; gap: 16px; align-items: end; }
.chart-group { min-width: 0; height: 100%; flex: 1; display: grid; grid-template-rows: 1fr auto; gap: 10px; }
.bars { min-height: 0; display: flex; gap: 5px; align-items: end; justify-content: center; border-bottom: 1px solid var(--line); }
.bar { width: min(25%, 18px); min-height: 3px; transition: height .25s ease; }
.bar.income { background: var(--green); }
.bar.expense { background: #dc8d74; }
.chart-label { overflow: hidden; color: var(--muted); font-size: 10px; text-align: center; white-space: nowrap; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; display: inline-block; }
.list { padding: 0; }
.list-row { min-height: 54px; padding: 10px 18px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.list-row small { color: var(--muted); font-size: 10px; }
.list-row > strong { font-size: 13px; }
.page-tools { margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.search { width: min(360px, 100%); height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid var(--line); background: white; }
.search svg { width: 16px; color: var(--muted); }
.search input { min-width: 0; flex: 1; border: 0; outline: 0; }
.button { height: 38px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 5px; font-size: 12px; font-weight: 600; }
.button svg { width: 16px; height: 16px; }
.button.primary { color: white; background: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { border-color: var(--line); color: var(--ink); background: white; }
.button.danger { border-color: #efcaca; color: var(--red); background: white; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); background: white; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { height: 42px; padding: 0 16px; color: var(--muted); background: #fafafa; font-size: 10px; font-weight: 600; text-align: left; white-space: nowrap; }
td { height: 56px; padding: 8px 16px; border-top: 1px solid var(--line); white-space: nowrap; }
td.primary-cell { font-weight: 600; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.income { color: var(--green); }
.amount.expense { color: var(--red); }
.badge { display: inline-flex; min-height: 22px; align-items: center; padding: 0 8px; border-radius: 11px; font-size: 10px; font-weight: 600; }
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.red { color: var(--red); background: var(--red-soft); }
.badge.amber { color: var(--amber); background: var(--amber-soft); }
.badge.gray { color: #5f646b; background: #edf0f2; }
.badge.blue { color: var(--blue); background: #e7f1f7; }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.row-actions button { width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 4px; color: var(--muted); background: transparent; }
.row-actions button:hover { color: var(--ink); background: var(--soft); }
.row-actions svg { width: 15px; }
.empty { padding: 54px 20px; color: var(--muted); text-align: center; }
.empty svg { width: 30px; height: 30px; margin-bottom: 10px; }
.empty strong { display: block; margin-bottom: 5px; color: var(--ink); }
.import-layout, .settings-layout { display: grid; grid-template-columns: minmax(300px, .75fr) minmax(0, 1.25fr); gap: 18px; }
.upload-zone { min-height: 260px; padding: 30px; display: grid; place-items: center; border: 1px dashed #c7cbd0; background: white; text-align: center; }
.upload-zone.dragging { border-color: var(--accent); background: #fff8f5; }
.upload-zone svg { width: 34px; height: 34px; color: var(--accent); }
.upload-zone p { margin: 10px 0 5px; font-size: 13px; font-weight: 600; }
.upload-zone small { display: block; margin-bottom: 18px; color: var(--muted); font-size: 11px; }
.upload-controls { width: min(280px, 100%); display: grid; gap: 10px; }
.upload-controls select { height: 38px; border: 1px solid var(--line); padding: 0 10px; background: white; }
.settings-section { min-height: 240px; padding: 26px; border: 1px solid var(--line); background: white; }
.settings-section > svg { width: 28px; height: 28px; color: var(--accent); }
.settings-section p { max-width: 520px; margin: 12px 0 20px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.settings-section input[type=file] { width: 100%; margin-bottom: 14px; padding: 10px; border: 1px solid var(--line); font-size: 11px; }
.notice { margin-top: 16px; padding: 12px 14px; border-left: 3px solid var(--amber); color: #6f5220; background: var(--amber-soft); font-size: 11px; line-height: 1.6; }
dialog { width: min(620px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 6px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(20, 22, 25, .56); }
.dialog-head { padding: 21px 24px 17px; display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); }
.form-grid { padding: 22px 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { color: #45494f; font-size: 11px; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 4px; outline: 0; background: white; }
.field input, .field select { height: 39px; padding: 0 10px; }
.field textarea { min-height: 76px; padding: 10px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(228, 85, 45, .1); }
.dialog-actions { padding: 15px 24px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); background: #fafafa; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 340px; padding: 12px 16px; border-radius: 5px; color: white; background: var(--ink); box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; z-index: 30; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }
.mobile-only { display: none; }
.loading { min-height: 320px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.spinner { width: 25px; height: 25px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 980px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .dashboard-grid, .import-layout, .settings-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main { min-height: 100vh; }
  .mobile-only { display: grid; }
  .topbar { height: 80px; padding: 0 16px; gap: 12px; justify-content: flex-start; }
  .topbar h1 { font-size: 18px; }
  .topbar-actions { margin-left: auto; }
  .month-control { padding: 0 8px; }
  .month-control svg { display: none; }
  .month-control input { width: 108px; }
  .content { padding: 18px 14px 34px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 112px; padding: 16px; }
  .metric strong { font-size: 20px; }
  .page-tools { align-items: stretch; flex-direction: column; }
  .search { width: 100%; }
  .page-tools .button { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .chart { gap: 7px; padding-inline: 12px; }
}

.logout-form { margin: 0; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--sidebar); }
.login-card { width: min(420px, 100%); padding: 30px; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); }
.login-brand { padding: 0 0 24px; }
.login-brand small { color: var(--muted); }
.login-form { display: grid; gap: 10px; }
.login-form label { color: var(--muted); font-size: 12px; font-weight: 600; }
.login-form input { height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; outline: 0; background: white; }
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(228, 85, 45, .1); }
.login-form .button { margin-top: 8px; height: 42px; }
.login-error { margin: 0 0 16px; padding: 10px 12px; border: 1px solid #efcaca; color: var(--red); background: var(--red-soft); font-size: 13px; }
.login-hint { margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
