:root {
    --bg: #f8fafc;
    --bg-elevated: #ffffff;
    --text: #0f172a;
    --text-secondary: #475569;
    --muted: #64748b;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --expense: #16a34a;
    --expense-bg: #f0fdf4;
    --income: #dc2626;
    --income-bg: #fef2f2;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-bg: #eff6ff;
    --info: #0891b2;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-btn: 999px;
    --sidebar-width: 240px;
    --transition: 0.2s ease;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* App shell */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    background: #0f172a;
    color: #fff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
}

.sidebar-title {
    font-weight: 700;
    font-size: 16px;
}

.sidebar-subtitle {
    font-size: 12px;
    color: var(--muted);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-link {
    display: block;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
}

.sidebar-link:hover {
    background: var(--border-light);
    color: var(--text);
}

.sidebar-link.active {
    background: var(--accent-bg);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-footer {
    padding: 16px 20px 24px;
    border-top: 1px solid var(--border-light);
}

.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout {
    font-size: 12px;
    color: var(--muted);
    text-decoration: none;
    flex-shrink: 0;
}

.sidebar-logout:hover {
    color: var(--danger);
}

.sidebar-db-label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

.sidebar-db-select {
    width: 100%;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
}

.mobile-header {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-header-title {
    font-weight: 600;
    font-size: 16px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 90;
}

.page-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 32px 32px 48px;
}

/* Typography */
h1 {
    margin: 0 0 8px;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sub {
    color: var(--muted);
    margin: 0 0 24px;
    font-size: 14px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.page-header-actions .btn,
.page-header-actions button {
    height: 36px;
    min-height: 36px;
    padding: 0 16px;
}

.page-header-actions-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.page-header-actions--desktop,
.page-header-actions--record {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.card .label {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
    font-weight: 500;
}

.card .value {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.card.expense .value { color: var(--expense); }
.card.income .value { color: var(--income); }

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.toolbar label,
.form-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    display: block;
    margin-bottom: 4px;
}

.form-group {
    display: flex;
    flex-direction: column;
    min-width: 140px;
}

.form-group-wide {
    flex: 1;
    min-width: 200px;
}

/* Form controls */
select, input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="datetime-local"], textarea {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    font-family: inherit;
}

select:focus, input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

select:disabled {
    background: #f1f5f9;
    color: var(--muted);
    cursor: not-allowed;
}

select.filter-select { min-width: 160px; max-width: 260px; }
select.category-select,
#txn-category {
    min-width: 220px;
    max-width: 360px;
    font-variant-numeric: tabular-nums;
}

#txn-category option:disabled {
    color: var(--muted);
    font-weight: 600;
    background: var(--border-light);
}

textarea {
    resize: vertical;
    min-height: 72px;
}

/* Buttons */
button, .btn {
    background: var(--text);
    color: #fff;
    border: 1px solid var(--text);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--radius-btn);
    padding: 8px 16px;
    min-height: 36px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.25;
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
    transition: background var(--transition), border-color var(--transition);
    white-space: nowrap;
}

button:hover, .btn:hover {
    background: #1e293b;
    border-color: #1e293b;
}

.btn-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
    border-color: var(--border);
}

.btn-dark {
    background: var(--text);
    border-color: var(--text);
    color: #fff;
}

.btn-dark:hover {
    background: #1e293b;
    border-color: #1e293b;
}

.btn-sm {
    padding: 4px 12px;
    min-height: 28px;
    font-size: 12px;
}

.btn-expense {
    background: var(--expense);
    border-color: var(--expense);
    color: #fff;
}

.btn-expense:hover {
    background: #15803d;
    border-color: #15803d;
}

.btn-income {
    background: var(--income);
    border-color: var(--income);
    color: #fff;
}

.btn-income:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.field-with-action {
    display: flex;
    gap: 8px;
    align-items: center;
}

.field-with-action select {
    flex: 1;
    min-width: 0;
}

.inline-form-panel {
    margin-top: 10px;
    padding: 12px;
    background: var(--border-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.inline-form-target {
    margin: 0 0 8px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
}

.inline-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.inline-form-row input,
.inline-form-row select {
    flex: 1;
    min-width: 120px;
}

.inline-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.txn-type-tag {
    display: inline-flex;
    margin-top: 4px;
}

.field-hint {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: var(--radius-btn);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

.icon-btn:hover {
    background: var(--border-light);
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-elevated);
}

th, td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
    vertical-align: middle;
    font-size: 14px;
}

th {
    background: #f8fafc;
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
}

tbody tr:hover td {
    background: #f8fafc;
}

tbody tr:last-child td { border-bottom: none; }

.col-actions {
    white-space: nowrap;
    width: 1%;
}

.col-actions .btn-sm {
    margin-right: 4px;
}

.amount-expense { color: var(--expense); font-weight: 700; }
.amount-income { color: var(--income); font-weight: 700; }

.tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.tag.expense { background: var(--expense-bg); color: var(--expense); }
.tag.income { background: var(--income-bg); color: var(--income); }
.tag.transfer { background: #e0e7ff; color: #4338ca; }

.muted { color: var(--muted); }
.category-main { font-weight: 600; }

.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    color: var(--muted);
    font-size: 14px;
}

.pager a {
    color: var(--accent);
    text-decoration: none;
    margin-left: 12px;
    font-weight: 500;
}

.pager a:hover { text-decoration: underline; }

.empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--muted);
}

/* Category tree */
.category-sections {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    align-items: start;
}

.category-section {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.category-section--0 {
    border-top: 3px solid var(--expense);
}

.category-section--1 {
    border-top: 3px solid var(--income);
}

.category-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.category-section h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.category-section--0 h2 { color: var(--expense); }
.category-section--1 h2 { color: var(--income); }

.category-section-count {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.category-tabs-wrap {
    display: none;
}

.category-tabs {
    display: flex;
    gap: 8px;
}

.category-tab {
    flex: 1;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.category-tab.active {
    color: #fff;
    border-color: transparent;
}

.category-tab.expense-tab.active {
    background: var(--expense);
}

.category-tab.income-tab.active {
    background: var(--income);
}

.tree-toggle {
    display: none;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font-size: 0;
    line-height: 0;
    box-shadow: none;
    cursor: pointer;
}

.tree-toggle:hover {
    background: var(--border-light);
    border-color: transparent;
}

.tree-toggle-icon {
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform var(--transition);
}

.tree-node--branch.is-expanded > .tree-item .tree-toggle-icon {
    transform: rotate(45deg);
    margin-top: -2px;
}

.tree-root, .tree-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tree-children {
    margin-left: 10px;
    padding-left: 14px;
    border-left: 2px solid var(--border);
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: var(--radius-sm);
    flex-wrap: wrap;
}

.tree-item:hover {
    background: var(--border-light);
}

.tree-item--depth-0 {
    margin-top: 2px;
}

.tree-item--depth-0 > .tree-link {
    font-size: 15px;
}

.tree-item--parent > .tree-link {
    font-weight: 700;
}

.tree-prefix {
    color: var(--muted);
    font-size: 13px;
    line-height: 1;
    flex-shrink: 0;
    user-select: none;
}

.tree-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}

.tree-item--depth-1 .tree-link {
    font-weight: 500;
    color: var(--text-secondary);
}

.tree-link:hover { color: var(--accent); }

.tree-meta {
    color: var(--muted);
    font-size: 12px;
}

.tree-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
}

.account-link {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.account-link:hover {
    color: var(--accent);
}

.account-table-wrap td:nth-child(3) {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* Reports */
.report-page .page-content { max-width: 1600px; }

.report-toolbar {
    padding: 14px 18px;
    margin-bottom: 16px;
    align-items: stretch;
}

.report-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 14px;
    width: 100%;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
}

.filter-group-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
    line-height: 1;
}

.filter-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    flex-shrink: 0;
}

.filter-group--actions {
    margin-left: auto;
    gap: 8px;
}

.segmented-control {
    display: inline-flex;
    align-items: center;
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.segmented-item {
    position: relative;
    margin: 0;
}

.segmented-item input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.segmented-item span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 30px;
    padding: 0 12px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.segmented-item input:checked + span {
    background: #fff;
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.segmented-item input:focus-visible + span {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    outline-offset: 1px;
}

.date-range-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.date-range-sep {
    font-size: 13px;
    color: var(--muted);
    line-height: 1;
}

.report-toolbar input[type="date"] {
    height: 36px;
    padding: 0 10px;
    min-width: 138px;
}

.report-toolbar .filter-group--actions .btn,
.report-toolbar .filter-group--actions button {
    height: 36px;
    padding: 0 14px;
}

.report-head-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.report-tabs-wrap {
    display: flex;
    justify-content: center;
}

.report-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 0;
}

.report-head-spacer {
    min-width: 0;
}

.report-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
}

.report-stat-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    line-height: 1;
    letter-spacing: 0.02em;
}

.report-stat-value {
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.report-stat-value.expense { color: var(--expense); }
.report-stat-value.income { color: var(--income); }

.report-tab {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    padding: 8px 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.report-tab.active { color: #fff; border-color: transparent; }
.report-tab.expense-tab.active { background: var(--expense); }
.report-tab.income-tab.active { background: var(--income); }

.report-tab:not(.active):hover {
    color: var(--text);
    background: var(--border-light);
    border-color: var(--border);
}

.report-tab.active:hover {
    color: #fff;
}

.report-tab.expense-tab.active:hover {
    background: var(--expense);
    border-color: transparent;
}

.report-tab.income-tab.active:hover {
    background: var(--income);
    border-color: transparent;
}

.report-view { display: none; }
.report-view.active { display: block; }

.period-nav {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.period-nav .btn {
    height: 30px;
    min-height: 30px;
    padding: 0 10px;
    font-size: 13px;
    border-radius: var(--radius-btn);
    background: #fff;
}

.period-nav .btn:hover {
    background: var(--border-light);
}

.period-label {
    min-width: 88px;
    padding: 0 6px;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    line-height: 30px;
    color: var(--text);
}

.report-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 1024px) {
    .report-grid:not(.bar-mode) {
        grid-template-columns: 1fr 1fr;
    }

    .report-grid:not(.bar-mode) .report-chart {
        height: clamp(380px, 42vh, 520px);
        min-height: 380px;
    }
}

.report-panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px 24px;
    box-shadow: var(--shadow-sm);
}

.report-panel h2 {
    margin: 0 0 16px;
    font-size: 18px;
    font-weight: 600;
}

.report-panel.expense-panel h2 { color: var(--expense); }
.report-panel.income-panel h2 { color: var(--income); }

.report-chart {
    width: 100%;
    height: clamp(460px, 58vh, 680px);
    min-height: 460px;
    cursor: pointer;
}

/* Trends */
.trends-page .page-content { max-width: 1600px; }

.trends-range-hint {
    font-size: 13px;
    color: var(--muted);
}

.filter-group--hint {
    margin-left: auto;
}

.trends-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
    align-items: stretch;
}

.trends-summary-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.trends-summary-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.trends-summary-value {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.trends-summary-card.income .trends-summary-value { color: var(--income); }
.trends-summary-card.expense .trends-summary-value { color: var(--expense); }
.trends-summary-card.balance .trends-summary-value {
    color: var(--info);
    font-size: 32px;
    letter-spacing: -0.03em;
}
.trends-summary-card.rate .trends-summary-value { color: var(--info); }

.trends-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.trends-panel .panel-desc {
    margin: -8px 0 14px;
    font-size: 13px;
    color: var(--muted);
}

.trends-chart {
    width: 100%;
    height: clamp(320px, 38vh, 420px);
    min-height: 320px;
}

@media (min-width: 1024px) {
    .trends-grid {
        grid-template-columns: 1fr 1fr;
    }

    .trends-panel--wide {
        grid-column: 1 / -1;
    }

    .trends-chart {
        height: clamp(340px, 36vh, 440px);
        min-height: 340px;
    }
}

@media (max-width: 900px) {
    .trends-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

}

@media (max-width: 768px) {
    .filter-group--hint {
        margin-left: 0;
        width: 100%;
    }

    .trends-summary {
        grid-template-columns: 1fr;
    }

    .trends-summary-value {
        font-size: 22px;
    }

    .trends-summary-card.balance .trends-summary-value {
        font-size: 28px;
    }
}

/* Yearly ledger */
.yearly-page .page-content {
    max-width: 960px;
}

.ledger-year-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.ledger-year-summary-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ledger-summary-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.ledger-summary-value {
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.ledger-year-summary-card.balance .ledger-summary-value { color: var(--info); }
.ledger-year-summary-card.income .ledger-summary-value { color: var(--income); }
.ledger-year-summary-card.expense .ledger-summary-value { color: var(--expense); }
.ledger-year-summary-card.muted-card .ledger-summary-value { color: var(--text); }

.ledger-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.ledger-toolbar-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.ledger-toolbar-actions {
    display: flex;
    gap: 8px;
}

.ledger-months {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.ledger-month {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.ledger-month-header {
    width: 100%;
    border: none;
    background: transparent;
    padding: 16px 18px;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 12px 16px;
    align-items: center;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    color: inherit;
    transition: background var(--transition);
}

.ledger-month-header:hover {
    background: #f8fafc;
}

.ledger-month-leading {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 14px 18px;
    min-width: 0;
}

.ledger-month-title {
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.ledger-month-count {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    justify-self: end;
}

.ledger-month-stats {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 18px;
    justify-content: flex-start;
    min-width: 0;
}

.ledger-month-stat {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ledger-month-stat.income { color: var(--income); }
.ledger-month-stat.expense { color: var(--expense); }
.ledger-month-stat.balance { color: var(--info); }

.ledger-month-stat.balance .ledger-month-stat-amount {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.ledger-month-chevron {
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform var(--transition);
    margin-left: 4px;
}

.ledger-month.is-expanded .ledger-month-chevron {
    transform: rotate(-135deg);
    margin-top: 4px;
}

.ledger-month-body {
    border-top: 1px solid var(--border-light);
}

.ledger-month-empty,
.ledger-empty {
    padding: 20px 18px;
    color: var(--muted);
    text-align: center;
}

.ledger-txn-table {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(100px, 2.3fr) 88px 136px;
    column-gap: 12px;
    padding: 0 18px;
    font-size: 14px;
}

.ledger-txn-row {
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

.ledger-txn-row:last-child {
    border-bottom: none;
}

.ledger-txn-row:not(.ledger-txn-row--head) {
    transition: background var(--transition);
}

.ledger-txn-row:not(.ledger-txn-row--head):hover {
    background: #f8fafc;
}

.ledger-txn-row--head {
    padding-top: 12px;
    padding-bottom: 8px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

.ledger-txn-row--head > [class^="ledger-txn-col"] {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    line-height: 1.4;
}

.ledger-txn-row--head .ledger-txn-col-amount {
    text-align: left;
}

.ledger-txn-row--head .ledger-txn-col-actions {
    display: block;
}

.ledger-txn-row--continued .ledger-txn-col-date {
    color: transparent;
    user-select: none;
}

.ledger-txn-col-date,
.ledger-txn-col-type,
.ledger-txn-col-category {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ledger-txn-col-date {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.ledger-txn-weekday {
    margin-left: 2px;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-category {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-memo,
.ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-account {
    font-size: 14px;
    color: var(--text);
}

.ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-memo,
.ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-account {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-memo {
    color: var(--text-secondary);
}

.ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-account {
    color: var(--muted);
}

.ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-amount {
    text-align: left;
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.ledger-txn-col-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.ledger-year-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

.ledger-year-nav--top {
    padding: 4px 0 18px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.ledger-year-nav--bottom {
    padding: 20px 0 8px;
    border-top: 1px solid var(--border);
}

.ledger-year-nav-label {
    min-width: 88px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
}

.ledger-year-nav-current {
    margin-left: 4px;
}

.btn.is-disabled,
.btn.is-disabled:hover {
    opacity: 0.45;
    pointer-events: none;
    cursor: default;
    background: #fff;
    color: var(--muted);
    border-color: var(--border);
}

@media (max-width: 900px) {
    .ledger-year-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ledger-month-header {
        grid-template-columns: 1fr auto;
    }

    .ledger-month-leading {
        grid-column: 1 / -1;
    }

    .ledger-month-count {
        justify-self: start;
    }

}

@media (max-width: 768px) {
    .ledger-txn-table {
        display: block;
        padding: 0;
    }

    .ledger-txn-row--head {
        display: none;
    }
}

.record-panel {
    margin-top: 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px 24px;
    box-shadow: var(--shadow-sm);
}

.record-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.record-panel-header h2 {
    margin: 0 0 6px;
    font-size: 20px;
}

.record-panel-meta {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.record-panel-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.record-panel-loading {
    color: var(--muted);
    padding: 24px 0;
    text-align: center;
}

.record-panel-table-wrap { overflow-x: auto; }
.record-panel .pager { margin-top: 14px; }

/* Modal */
.modal-root {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-root[hidden] { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}

.modal-dialog {
    position: relative;
    background: var(--bg-elevated);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 0;
    gap: 12px;
}

.modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 24px 20px;
}

.modal-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.modal-form-grid .form-group-full {
    grid-column: 1 / -1;
}

/* Back to top */
.back-to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 250;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity var(--transition), visibility var(--transition), transform var(--transition),
        background var(--transition), color var(--transition), border-color var(--transition);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Toast */
.toast-root {
    position: fixed;
    top: 24px;
    left: 0;
    right: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--text);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.25s ease;
    pointer-events: auto;
    max-width: min(360px, calc(100vw - 48px));
    text-align: center;
}

.toast.error { background: var(--danger); }
.toast.success { background: #15803d; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 1279px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
    }

    .sidebar-overlay[hidden] {
        display: none;
    }

    .app-main {
        margin-left: 0;
    }

    .mobile-header {
        display: flex;
    }

    .page-content {
        padding: 20px 16px 40px;
    }
}

@media (max-width: 1100px) {
    .category-sections {
        grid-template-columns: 1fr;
    }

    .filter-group--actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
    }
}

@media (max-width: 768px) {
    h1 { font-size: 22px; }

    .page-header {
        flex-direction: column;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .report-filter-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
    }

    .filter-divider {
        display: none;
    }

    .filter-group,
    .filter-group--dates {
        flex-wrap: wrap;
        width: 100%;
    }

    .filter-group--actions {
        margin-left: 0;
        width: 100%;
    }

    .filter-group--actions .btn,
    .filter-group--actions button {
        flex: 1;
    }

    .date-range-row {
        flex: 1;
        min-width: 0;
    }

    .report-toolbar input[type="date"] {
        flex: 1;
        min-width: 0;
    }

    .period-nav {
        width: 100%;
        justify-content: space-between;
    }

    .period-label {
        flex: 1;
    }

    .report-head-bar {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .report-head-spacer {
        display: none;
    }

    .report-stat {
        align-items: center;
        text-align: center;
        width: 100%;
    }

    .report-stat-value {
        font-size: 30px;
    }

    .report-tabs-wrap {
        width: 100%;
    }

    .report-tabs {
        width: 100%;
        justify-content: center;
    }

    .form-group, .form-group-wide {
        min-width: 0;
        width: 100%;
    }

    select.filter-select,
    select.category-select {
        width: 100%;
        max-width: none;
    }

    .modal-form-grid {
        grid-template-columns: 1fr;
    }

    .report-chart {
        height: clamp(360px, 52vh, 520px);
        min-height: 360px;
    }

    .report-grid:not(.bar-mode) .report-chart {
        height: clamp(360px, 52vh, 520px);
        min-height: 360px;
    }

    .table-wrap:not(.mobile-card-table) table,
    .table-wrap:not(.mobile-card-table) thead,
    .table-wrap:not(.mobile-card-table) tbody,
    .table-wrap:not(.mobile-card-table) th,
    .table-wrap:not(.mobile-card-table) td,
    .table-wrap:not(.mobile-card-table) tr { display: block; }

    .table-wrap:not(.mobile-card-table) thead { display: none; }

    .table-wrap:not(.mobile-card-table) tr {
        border-bottom: 1px solid var(--border);
        padding: 10px 0;
    }

    .table-wrap:not(.mobile-card-table) td {
        border: none;
        padding: 4px 14px;
    }

    .table-wrap:not(.mobile-card-table) td::before {
        content: attr(data-label) ": ";
        color: var(--muted);
        font-weight: 500;
    }

    .col-actions {
        padding-top: 8px;
    }

    .tree-actions {
        width: 100%;
        margin-left: calc(var(--depth) * 20px);
        padding-bottom: 4px;
    }
}

/* Mobile category picker */
.mobile-picker-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}

.mobile-picker-trigger {
    display: none;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.mobile-picker-trigger:disabled {
    background: #f1f5f9;
    color: var(--muted);
    cursor: not-allowed;
}

.mobile-picker-value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.mobile-picker-value.is-placeholder {
    color: var(--muted);
    font-weight: 400;
}

.mobile-picker-chevron {
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg);
    flex-shrink: 0;
    margin-top: -2px;
}

.picker-sheet {
    position: fixed;
    inset: 0;
    z-index: 300;
}

.picker-sheet[hidden] {
    display: none;
}

.picker-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.picker-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(78vh, 640px);
    background: var(--bg-elevated);
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -12px 32px rgba(15, 23, 42, 0.16);
    animation: pickerSheetIn 0.22s ease;
}

@keyframes pickerSheetIn {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.picker-sheet-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.picker-sheet-title {
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.picker-sheet-action {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 15px;
    font-family: inherit;
    padding: 6px 4px;
    cursor: pointer;
}

.picker-sheet-action--primary {
    color: var(--accent);
    font-weight: 600;
}

.picker-sheet-body {
    overflow-y: auto;
    padding: 8px 0 calc(12px + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch;
}

.picker-sheet-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.picker-sheet-group {
    padding: 12px 18px 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: none;
}

.picker-sheet-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border: none;
    border-bottom: 1px solid var(--border-light);
    background: transparent;
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.picker-sheet-item--deep {
    padding-left: 30px;
}

.picker-sheet-item:last-child {
    border-bottom: none;
}

.picker-sheet-item:active {
    background: #f8fafc;
}

.picker-sheet-item.is-selected {
    color: var(--accent);
    font-weight: 600;
}

.picker-sheet-item-check {
    color: var(--accent);
    font-size: 16px;
    font-weight: 700;
    opacity: 0;
}

.picker-sheet-item.is-selected .picker-sheet-item-check {
    opacity: 1;
}

body.picker-sheet-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    .mobile-picker-trigger {
        display: flex;
    }

    .mobile-picker-wrap > select.mobile-picker-native,
    .mobile-picker-wrap > .category-select,
    .mobile-picker-wrap > #txn-category {
        position: absolute;
        width: 1px;
        height: 1px;
        opacity: 0;
        pointer-events: none;
        margin: 0;
        padding: 0;
        border: 0;
    }

    .field-with-action .mobile-picker-wrap {
        flex: 1;
        min-width: 0;
    }
}

/* Mobile app-style UI */
@media (max-width: 768px) {
    .page-content {
        padding: 16px 16px calc(28px + env(safe-area-inset-bottom, 0px));
    }

    .yearly-page .page-content,
    .list-page .page-content {
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    }

    h1 {
        font-size: 20px;
        margin-bottom: 4px;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }

    .page-header .sub {
        margin: 0;
        font-size: 12px;
        line-height: 1.5;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .page-header-actions-wrap {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    .page-header-actions--desktop {
        width: 100%;
        margin-bottom: 0;
    }

    .page-header-actions--desktop .btn {
        width: 100%;
    }

    .page-header-actions--record {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 60;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
        background: rgba(255, 255, 255, 0.96);
        border-top: 1px solid var(--border);
        box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
        backdrop-filter: blur(10px);
    }

    .page-header-actions--record .btn {
        height: 44px;
        min-height: 44px;
        font-size: 15px;
        font-weight: 600;
    }

    .cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        margin-bottom: 16px;
    }

    .card {
        padding: 14px;
        border-radius: 14px;
    }

    .card .label {
        font-size: 12px;
        margin-bottom: 6px;
    }

    .card .value {
        font-size: 18px;
    }

    /* Collapsible filter */
    .filter-panel {
        margin-bottom: 14px;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: 14px;
        box-shadow: var(--shadow-sm);
        overflow: hidden;
    }

    .filter-panel-summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 14px 16px;
        cursor: pointer;
        list-style: none;
        font-weight: 600;
        color: var(--text);
    }

    .filter-panel-summary::-webkit-details-marker {
        display: none;
    }

    .filter-panel-title {
        font-size: 15px;
    }

    .filter-panel-badge {
        font-size: 12px;
        font-weight: 600;
        color: var(--accent);
        background: var(--accent-bg);
        padding: 4px 10px;
        border-radius: 999px;
    }

    .filter-panel .toolbar {
        border: none;
        border-radius: 0;
        box-shadow: none;
        margin: 0;
        padding: 0 16px 16px;
        background: transparent;
    }

    .filter-panel .toolbar button[type="submit"] {
        width: 100%;
        height: 44px;
        min-height: 44px;
        margin-top: 4px;
    }

    /* Card-style data tables */
    .mobile-card-table {
        overflow: visible;
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .mobile-card-table table,
    .mobile-card-table thead,
    .mobile-card-table tbody,
    .mobile-card-table th,
    .mobile-card-table td,
    .mobile-card-table tr {
        display: block;
    }

    .mobile-card-table thead {
        display: none;
    }

    .mobile-card-table tbody tr {
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: 14px;
        box-shadow: var(--shadow-sm);
        margin-bottom: 10px;
        padding: 14px 16px;
    }

    .mobile-card-table tbody tr:last-child {
        margin-bottom: 0;
    }

    .mobile-card-table tbody tr:hover td {
        background: transparent;
    }

    .mobile-card-table td {
        border: none;
        padding: 0;
    }

    .mobile-card-table td::before {
        display: none;
    }

    /* List page transaction cards */
    .list-page .mobile-card-table tbody tr {
        display: grid;
        grid-template-columns: 54px 1fr auto;
        column-gap: 10px;
        row-gap: 2px;
        align-items: start;
        padding: 12px 14px;
    }

    .list-page .mobile-card-table td[data-label="日期"] {
        grid-column: 1;
        grid-row: 1 / span 4;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 2px;
        padding-right: 8px;
        margin-right: 2px;
        border-right: 1px solid var(--border-light);
        font-size: 11px;
        font-weight: 600;
        color: var(--text-secondary);
        line-height: 1.3;
        text-align: center;
        white-space: normal;
        word-break: break-all;
    }

    .list-page .mobile-card-table td[data-label="分类"] {
        grid-column: 2;
        grid-row: 1;
        font-size: 16px;
        font-weight: 600;
        color: var(--text);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.3;
    }

    .list-page .mobile-card-table td[data-label="金额"] {
        grid-column: 3;
        grid-row: 1;
        text-align: right;
        font-size: 18px;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        line-height: 1.2;
    }

    .list-page .mobile-card-table td[data-label="类型"] {
        display: none;
    }

    .list-page .mobile-card-table td[data-label="账户"] {
        grid-column: 2;
        grid-row: 2;
        font-size: 11px;
        color: #94a3b8;
        line-height: 1.4;
    }

    .list-page .mobile-card-table td[data-label="备注"] {
        grid-column: 2 / -1;
        grid-row: 3;
        font-size: 12px;
        color: #94a3b8;
        line-height: 1.4;
        margin-top: 1px;
    }

    .list-page .mobile-card-table td[data-label="操作"] {
        grid-column: 3;
        grid-row: 2;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 2px;
        margin: 0;
        padding: 0;
        border: none;
    }

    /* Accounts cards */
    .accounts-page .mobile-card-table tbody tr {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "name balance"
            "stats stats"
            "memo memo"
            "actions actions";
        gap: 6px 12px;
        align-items: center;
    }

    .accounts-page .mobile-card-table td[data-label="账户名称"] {
        grid-area: name;
        font-size: 16px;
        font-weight: 700;
    }

    .accounts-page .mobile-card-table td[data-label="账户名称"] .account-link {
        color: var(--text);
        text-decoration: none;
    }

    .accounts-page .mobile-card-table td[data-label="余额"] {
        grid-area: balance;
        text-align: right;
        font-size: 18px;
        font-weight: 800;
        font-variant-numeric: tabular-nums;
        color: var(--text);
    }

    .accounts-page .mobile-card-table td[data-label="记账数"] {
        grid-area: stats;
        font-size: 12px;
        color: var(--muted);
    }

    .accounts-page .mobile-card-table td[data-label="记账数"]::after {
        content: " 条记录";
    }

    .accounts-page .mobile-card-table td[data-label="备注"] {
        grid-area: memo;
        font-size: 13px;
        color: var(--text-secondary);
    }

    .accounts-page .mobile-card-table td[data-label="备注"]:empty {
        display: none;
    }

    .accounts-page .mobile-card-table td[data-label="操作"] {
        grid-area: actions;
        display: flex;
        justify-content: flex-end;
        gap: 10px;
        width: auto;
        white-space: normal;
        margin-top: 6px;
        padding-top: 0;
        border-top: none;
    }

    .accounts-page .mobile-card-table td[data-label="操作"] .table-action-btn {
        flex: none;
        width: auto;
        min-width: 0;
        height: auto;
        min-height: 36px;
        margin: 0;
        padding: 8px 16px;
        font-size: 14px;
        font-weight: 500;
        line-height: 1.4;
        white-space: nowrap;
        background: transparent;
        border: none;
        border-radius: 8px;
        box-shadow: none;
        color: var(--muted);
    }

    .accounts-page .mobile-card-table td[data-label="操作"] .table-action-btn:hover {
        background: var(--border-light);
        border: none;
        color: var(--text-secondary);
    }

    .accounts-page .page-header-actions,
    .categories-page .page-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .accounts-page .page-header-actions .btn,
    .categories-page .page-header-actions .btn {
        flex: 1;
        min-width: calc(50% - 4px);
    }

    .categories-page .page-header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    /* Categories mobile */
    .categories-page .category-tabs-wrap {
        display: block;
        margin-bottom: 14px;
    }

    .categories-page .category-tabs {
        width: 100%;
        gap: 0;
        border-bottom: 1px solid var(--border);
    }

    .categories-page .category-tab {
        flex: 1;
        position: relative;
        min-height: 0;
        padding: 10px 12px 12px;
        border: none;
        border-radius: 0;
        background: transparent;
        color: var(--muted);
        font-size: 15px;
        box-shadow: none;
    }

    .categories-page .category-tab::after {
        content: '';
        position: absolute;
        left: 12px;
        right: 12px;
        bottom: 0;
        height: 2px;
        border-radius: 2px 2px 0 0;
        background: transparent;
    }

    .categories-page .category-tab.active {
        background: transparent;
        border-color: transparent;
    }

    .categories-page .category-tab.expense-tab.active {
        color: var(--expense);
        background: transparent;
    }

    .categories-page .category-tab.income-tab.active {
        color: var(--income);
        background: transparent;
    }

    .categories-page .category-tab.expense-tab.active::after {
        background: var(--expense);
    }

    .categories-page .category-tab.income-tab.active::after {
        background: var(--income);
    }

    .categories-page .category-sections {
        gap: 0;
        grid-template-columns: 1fr;
    }

    .categories-page .category-section:not(.active) {
        display: none;
    }

    .categories-page .category-section {
        padding: 14px;
        border-radius: 14px;
    }

    .categories-page .category-tabs-wrap + .category-sections .category-section-header {
        justify-content: flex-end;
        margin-bottom: 8px;
    }

    .categories-page .category-tabs-wrap + .category-sections .category-section-header h2 {
        display: none;
    }

    .categories-page .category-section-header {
        margin-bottom: 10px;
    }

    .categories-page .category-section h2 {
        font-size: 16px;
    }

    .categories-page .tree-toggle {
        display: inline-flex;
    }

    .categories-page .tree-node--branch > .tree-children {
        display: none;
    }

    .categories-page .tree-node--branch.is-expanded > .tree-children {
        display: block;
    }

    .categories-page .tree-children {
        margin-left: 0;
        padding-left: 0;
        border-left: none;
    }

    .categories-page .tree-item {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px 14px;
        margin-bottom: 8px;
        background: #f8fafc;
        border: 1px solid var(--border-light);
        border-radius: 12px;
    }

    .categories-page .tree-item:hover {
        background: #f1f5f9;
    }

    .categories-page .tree-item--parent {
        cursor: pointer;
    }

    .categories-page .tree-item--parent .tree-link {
        pointer-events: none;
        color: inherit;
    }

    .categories-page .tree-item--parent .tree-link:hover {
        color: inherit;
    }

    .categories-page .tree-link {
        flex: 1;
        min-width: 0;
        font-size: 15px;
        line-height: 1.4;
        word-break: break-word;
    }

    .categories-page .tree-item--depth-1 .tree-link {
        font-size: 14px;
    }

    .categories-page .tree-meta {
        font-size: 11px;
    }

    .categories-page .tree-actions {
        width: 100%;
        margin-left: 0 !important;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 8px;
        border-top: 1px solid var(--border-light);
    }

    .categories-page .tree-item--depth-0 .tree-actions {
        width: auto;
        margin-left: auto !important;
        padding-top: 0;
        border-top: none;
    }

    /* Ledger / yearly page */
    .yearly-page .ledger-year-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        margin-bottom: 14px;
    }

    .yearly-page .ledger-year-summary-card {
        padding: 12px 14px;
        border-radius: 14px;
    }

    .yearly-page .ledger-summary-value {
        font-size: 18px;
    }

    .yearly-page .ledger-year-nav--bottom {
        display: none;
    }

    .yearly-page .ledger-year-nav {
        gap: 8px;
        padding: 0;
        margin-bottom: 12px;
        border: none;
    }

    .yearly-page .ledger-year-nav .btn {
        height: 36px;
        min-height: 36px;
        padding: 0 12px;
        font-size: 13px;
    }

    .yearly-page .ledger-year-nav-label {
        font-size: 17px;
        min-width: auto;
        flex: 1;
        text-align: center;
    }

    .yearly-page .ledger-year-nav-current {
        width: 100%;
        margin: 0;
    }

    .yearly-page .ledger-toolbar {
        margin-bottom: 12px;
        padding: 12px 14px;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: 14px;
    }

    .yearly-page .ledger-toolbar-actions {
        width: 100%;
        justify-content: stretch;
    }

    .yearly-page .ledger-toolbar-actions .btn {
        flex: 1;
    }

    .yearly-page .ledger-month {
        border-radius: 14px;
    }

    .yearly-page .ledger-month-header {
        padding: 14px 16px;
        grid-template-columns: 1fr auto;
        gap: 8px 12px;
    }

    .yearly-page .ledger-month-title {
        font-size: 17px;
    }

    .yearly-page .ledger-month-stats {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        width: 100%;
    }

    .yearly-page .ledger-month-stat {
        font-size: 12px;
    }

    .yearly-page .ledger-month-stat.balance .ledger-month-stat-amount {
        font-size: 16px;
    }

    .yearly-page .ledger-month-count {
        font-size: 11px;
        background: var(--border-light);
        padding: 4px 8px;
        border-radius: 999px;
        justify-self: end;
    }

    .yearly-page .ledger-txn-table {
        padding: 0;
    }

    .yearly-page .ledger-txn-row:not(.ledger-txn-row--head) {
        display: grid;
        grid-template-columns: 54px 1fr auto;
        column-gap: 10px;
        row-gap: 2px;
        align-items: start;
        padding: 10px 14px;
        border-bottom: 1px solid var(--border-light);
    }

    .yearly-page .ledger-txn-row--continued {
        padding-top: 6px;
    }

    .yearly-page .ledger-txn-col-date {
        grid-column: 1;
        grid-row: 1 / span 4;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 2px;
        padding-right: 8px;
        margin-right: 2px;
        border-right: 1px solid var(--border-light);
        font-size: 11px;
        font-weight: 600;
        color: var(--text-secondary);
        line-height: 1.3;
        text-align: center;
        white-space: normal;
    }

    .yearly-page .ledger-txn-row--continued .ledger-txn-col-date {
        visibility: hidden;
    }

    .yearly-page .ledger-txn-weekday {
        display: block;
        margin: 0;
        font-size: 10px;
        font-weight: 500;
        color: var(--muted);
    }

    .yearly-page .ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-category {
        grid-column: 2;
        grid-row: 1;
        min-width: 0;
        font-size: 16px;
        font-weight: 600;
        color: var(--text);
        line-height: 1.3;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .yearly-page .ledger-txn-col-amount {
        grid-column: 3;
        grid-row: 1;
        text-align: right !important;
        font-size: 18px !important;
        font-weight: 700 !important;
        margin-top: 0 !important;
        line-height: 1.2;
    }

    .yearly-page .ledger-txn-col-type {
        display: none;
    }

    .yearly-page .ledger-txn-row:not(.ledger-txn-row--head) .ledger-txn-col-account {
        grid-column: 2;
        grid-row: 2;
        font-size: 11px;
        color: #94a3b8;
        line-height: 1.4;
    }

    .yearly-page .ledger-txn-col-memo {
        grid-column: 2 / -1;
        grid-row: 3;
        font-size: 12px;
        color: #94a3b8;
        line-height: 1.4;
        margin-top: 1px;
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
    }

    .yearly-page .ledger-txn-col-memo:empty {
        display: none;
    }

    .yearly-page .ledger-txn-col-actions {
        display: none;
    }

    .yearly-page .ledger-txn-row--editable {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .yearly-page .ledger-txn-row--editable:active {
        background: #f8fafc;
    }

    /* 经典视图：紧凑文字操作 */
    .list-page .mobile-card-table td[data-label="操作"] .btn-sm {
        flex: none;
        height: auto;
        min-height: 0;
        margin: 0;
        padding: 2px 6px;
        font-size: 11px;
        font-weight: 500;
        line-height: 1.4;
        background: transparent;
        border: none;
        border-radius: 4px;
        color: var(--muted);
        box-shadow: none;
    }

    .list-page .mobile-card-table td[data-label="操作"] .btn-secondary {
        color: var(--muted);
    }

    .list-page .mobile-card-table td[data-label="操作"] .btn-secondary:hover {
        background: var(--border-light);
        color: var(--text-secondary);
    }

    /* Pager */
    .pager {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-top: 14px;
        padding: 14px 16px;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: 14px;
    }

    .pager > div {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .pager a {
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 40px;
        border: 1px solid var(--border);
        border-radius: 999px;
        background: #fff;
        font-weight: 600;
    }

    /* Modal bottom sheet */
    .modal-root {
        align-items: flex-end;
        padding: 0;
    }

    .modal-dialog {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 92vh;
    }

    .modal-header {
        padding: 16px 16px 0;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px));
        gap: 10px;
    }

    .modal-footer .btn {
        flex: 1;
        height: 44px;
        min-height: 44px;
    }

    .back-to-top {
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }
}

@media (min-width: 769px) {
    .filter-panel > summary {
        display: none;
    }

    .filter-panel {
        display: block;
    }

    .filter-panel .toolbar {
        display: flex;
        margin-bottom: 20px;
    }

    .page-header-actions--record {
        position: static;
        display: flex;
        padding: 0;
        background: transparent;
        border: none;
        box-shadow: none;
        backdrop-filter: none;
        grid-template-columns: none;
        width: auto;
    }

    .page-header-actions--record .btn {
        height: 36px;
        min-height: 36px;
        font-size: 14px;
        font-weight: 500;
    }
}

/* Import page */
.import-panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.import-toolbar {
    margin-bottom: 16px;
}

.import-actions {
    min-width: auto;
}

.import-action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.import-textarea {
    width: 100%;
    min-height: 220px;
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
}

.import-hint {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.import-preview {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.import-summary {
    margin-bottom: 14px;
    font-size: 14px;
    color: var(--text-secondary);
}

.import-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.import-table th,
.import-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
    vertical-align: top;
}

.import-table th {
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
    background: var(--bg);
}

.import-category-cell {
    min-width: 180px;
}

.import-category-select {
    width: 100%;
    min-width: 160px;
    max-width: 260px;
    font-size: 13px;
}

.import-category-select option {
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.import-memo-cell {
    max-width: 320px;
    word-break: break-all;
}

.import-memo-editable {
    cursor: pointer;
    transition: background var(--transition);
}

.import-memo-editable:hover {
    background: var(--accent-bg);
}

.import-memo-editor {
    width: 100%;
    min-width: 200px;
    min-height: 72px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    font-family: inherit;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.import-row--ok {
    background: var(--expense-bg);
}

.import-row--ok .import-status-cell {
    color: var(--expense);
}

.import-row--warn .import-status-cell {
    color: #ca8a04;
}

.import-row--error .import-status-cell {
    color: var(--danger);
}

.import-row--error {
    background: var(--danger-bg);
}

.import-row--warn {
    background: #fefce8;
}

.default-form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
}

.default-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: var(--radius-btn);
    background: var(--accent-bg);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.default-badge + .default-badge {
    margin-left: 4px;
}

.tree-item .default-badge {
    margin-left: 8px;
    vertical-align: middle;
}

.account-table-wrap .default-badge {
    margin-left: 0;
    margin-right: 4px;
}

/* Legacy compat */
.wrap { max-width: 1600px; margin: 0 auto; padding: 24px 16px 48px; }
.top-nav { display: none; }

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(180deg, #eff6ff 0%, var(--bg) 40%);
}

.login-shell {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 32px 28px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.login-heading {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 700;
}

.login-hint,
.login-note {
    margin: 0 0 20px;
    font-size: 13px;
    color: var(--muted);
}

.login-note {
    margin: 0 0 16px;
}

.login-error {
    margin-bottom: 16px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 14px;
}

.login-form .form-group {
    min-width: 0;
    width: 100%;
    margin-bottom: 16px;
}

.login-form input[type="text"],
.login-form input[type="password"] {
    width: 100%;
}

.login-submit {
    width: 100%;
    margin-top: 4px;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}
