/* ===== 全局样式 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --income: #10b981;
    --income-light: #d1fae5;
    --expense: #ef4444;
    --expense-light: #fee2e2;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    min-height: 100vh;
}

/* ===== 侧边栏 ===== */
.sidebar {
    width: 240px;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.logo-icon {
    font-size: 28px;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.2s;
    text-align: left;
    width: 100%;
}

.nav-item:hover {
    background: var(--bg);
    color: var(--text);
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

.nav-icon {
    font-size: 18px;
}

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

.btn-add-record {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-add-record:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-add-record span {
    font-size: 18px;
}

/* ===== 主内容区 ===== */
.main {
    flex: 1;
    margin-left: 240px;
    padding: 32px 40px;
    max-width: calc(100% - 240px);
}

.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

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

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
}

.month-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.month-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    font-size: 18px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.month-btn:hover {
    background: var(--bg);
    color: var(--primary);
}

.month-text {
    font-weight: 600;
    min-width: 100px;
    text-align: center;
}

/* ===== 概览卡片 ===== */
.overview-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.card-value {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 8px;
}

.card-sub {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
}

.card-sub b {
    font-weight: 600;
}

.card-balance .card-value { color: var(--primary); }
.card-income .card-value { color: var(--income); }
.card-expense .card-value { color: var(--expense); }
.card-total .card-value { color: var(--text); }

.card-income { border-left: 3px solid var(--income); }
.card-expense { border-left: 3px solid var(--expense); }
.card-balance { border-left: 3px solid var(--primary); }
.card-total { border-left: 3px solid var(--text); }

/* ===== 面板 ===== */
.panel {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

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

.panel-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.panel-desc {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 12px;
}

.link-btn {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 13px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.link-btn:hover {
    background: var(--primary-light);
    color: white;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 16px;
}

/* ===== 记录列表 ===== */
.record-list {
    max-height: 400px;
    overflow-y: auto;
}

.record-item {
    display: flex;
    align-items: center;
    padding: 12px 8px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
    gap: 12px;
}

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

.record-item:hover {
    background: var(--bg);
}

.record-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.record-icon.income { background: var(--income-light); }
.record-icon.expense { background: var(--expense-light); }

.record-info {
    flex: 1;
    min-width: 0;
}

.record-category {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.record-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 8px;
}

.record-note {
    color: var(--text-secondary);
}

.record-amount {
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.record-amount.income { color: var(--income); }
.record-amount.expense { color: var(--expense); }

.record-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.record-item:hover .record-actions {
    opacity: 1;
}

.record-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.record-action-btn:hover {
    background: var(--bg);
}

.record-action-btn.delete:hover {
    background: var(--expense-light);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ===== 图表 ===== */
.chart-container {
    display: flex;
    align-items: center;
    gap: 20px;
    min-height: 220px;
}

.chart-container canvas {
    max-width: 200px;
    max-height: 200px;
}

.chart-legend {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-label {
    flex: 1;
    color: var(--text-secondary);
}

.legend-value {
    font-weight: 600;
}

.legend-percent {
    color: var(--text-muted);
    font-size: 12px;
    width: 40px;
    text-align: right;
}

/* ===== 筛选栏 ===== */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.filter-group select,
.filter-group input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--card-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.filter-group select:focus,
.filter-group input:focus {
    border-color: var(--primary);
}

.btn-reset {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.2s;
    height: 36px;
}

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

/* ===== 统计页面 ===== */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-item {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    text-align: center;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
}

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

.stats-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 16px;
}

.stats-grid canvas {
    width: 100% !important;
    max-height: 280px;
}

.category-ranking {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rank-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rank-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.rank-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.rank-amount {
    font-weight: 600;
    color: var(--text-secondary);
}

.rank-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.rank-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ===== 设置页面 ===== */
.category-manager {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.category-section h4 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.category-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    min-height: 40px;
}

.category-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg);
    border-radius: 20px;
    font-size: 13px;
    border: 1px solid var(--border);
}

.category-tag .remove {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
}

.category-tag .remove:hover {
    color: var(--expense);
}

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

.add-category input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
}

.add-category input:focus {
    border-color: var(--primary);
}

.btn-small {
    padding: 8px 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.btn-small:hover {
    background: var(--primary-dark);
}

.data-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-secondary {
    padding: 10px 18px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

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

.btn-danger {
    padding: 10px 18px;
    background: var(--expense-light);
    color: var(--expense);
    border: 1px solid var(--expense);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-danger:hover {
    background: var(--expense);
    color: white;
}

/* ===== 弹窗 ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--card-bg);
    border-radius: 16px;
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.25s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    font-size: 16px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

#recordForm {
    padding: 24px;
}

.type-tabs {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
}

.type-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.type-tab.active {
    background: var(--card-bg);
    box-shadow: var(--shadow);
}

.type-tab.active[data-type="expense"] { color: var(--expense); }
.type-tab.active[data-type="income"] { color: var(--income); }

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.amount-input {
    display: flex;
    align-items: center;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    transition: border-color 0.2s;
}

.amount-input:focus-within {
    border-color: var(--primary);
}

.currency {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 4px;
}

.amount-input input {
    flex: 1;
    border: none;
    outline: none;
    padding: 12px 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    background: transparent;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-row input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-row input:focus {
    border-color: var(--primary);
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-height: 160px;
    overflow-y: auto;
}

.cat-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    background: var(--card-bg);
}

.cat-option:hover {
    border-color: var(--primary-light);
}

.cat-option.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.cat-option .cat-emoji {
    font-size: 20px;
}

.cat-option .cat-name {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.btn-cancel, .btn-submit {
    flex: 1;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-cancel {
    background: var(--bg);
    color: var(--text-secondary);
}

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

.btn-submit {
    background: var(--primary);
    color: white;
}

.btn-submit:hover {
    background: var(--primary-dark);
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== 响应式 ===== */
@media (max-width: 1024px) {
    .overview-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    .stats-summary {
        grid-template-columns: repeat(2, 1fr);
    }
    .dashboard-grid, .stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 64px;
        padding: 16px 8px;
    }
    .logo-text, .nav-item span:not(.nav-icon), .sidebar-footer .btn-add-record span:not(:first-child) {
        display: none;
    }
    .logo { justify-content: center; padding: 0 0 16px; }
    .nav-item { justify-content: center; }
    .btn-add-record { padding: 10px; }
    .main {
        margin-left: 64px;
        padding: 20px;
        max-width: calc(100% - 64px);
    }
    .overview-cards, .stats-summary {
        grid-template-columns: 1fr;
    }
    .category-manager {
        grid-template-columns: 1fr;
    }
    .category-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
/* ===== 用户昵称框（侧边栏底部） ===== */
.user-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin-top: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.user-box:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}
.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}
.user-name {
    flex: 1;
    font-size: 13px;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-edit {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* ===== 记录编辑者标签 ===== */
.record-editor {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    color: var(--primary-color);
    background: var(--primary-light);
    padding: 1px 8px;
    border-radius: 10px;
    margin-left: 6px;
    white-space: nowrap;
}
