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

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ========== 导航栏 ========== */
.navbar {
    background: var(--card-bg);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    padding: 15px 0;
}

.nav-links {
    display: flex;
    gap: 5px;
}

.nav-btn {
    background: transparent;
    border: none;
    padding: 15px 20px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-secondary);
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

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

.nav-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ========== 主容器 ========== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ========== 页面切换 ========== */
.page {
    display: none;
}

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

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

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

h2 {
    margin-bottom: 20px;
    color: var(--text);
}

h3 {
    margin-bottom: 15px;
    color: var(--text);
}

/* ========== 统计卡片 ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.total-assets .stat-value { color: var(--success); }
.total-debt .stat-value { color: var(--danger); }
.net-worth .stat-value { color: var(--primary); }
.income .stat-value { color: var(--success); }
.expense .stat-value { color: var(--danger); }
.balance .stat-value { color: var(--primary); }
.interest .stat-value { color: var(--danger); }
.debt-payment .stat-value { color: var(--warning); }
.credit-available .stat-value { color: var(--primary); }

/* ========== 账户列表 ========== */
.dashboard-section {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-top: 20px;
}

.accounts-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.account-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--bg);
    border-radius: 8px;
    transition: transform 0.2s;
}

.account-item:hover {
    transform: translateX(5px);
}

.account-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.account-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.account-icon.bank { background: #dbeafe; }
.account-icon.credit { background: #fce7f3; }
.account-icon.debt { background: #fee2e2; }
.account-icon.cash { background: #dcfce7; }
.account-icon.investment { background: #fef3c7; }

.account-name {
    font-weight: 600;
}

.account-type {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.account-extra {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ========== 负债汇总 ========== */
.debt-summary-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.debt-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--bg);
    border-radius: 8px;
    border-left: 4px solid var(--danger);
}

.debt-item-info {
    display: flex;
    flex-direction: column;
}

.debt-item-name {
    font-weight: 600;
}

.debt-item-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.debt-item-amount {
    font-weight: 700;
    color: var(--danger);
    font-size: 1.1rem;
}

.debt-item-right {
    text-align: right;
}

.debt-item-due {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 600;
    margin: 4px 0;
}

.btn-paid {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 6px;
    min-height: 36px;
}

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

.btn-paid.done {
    background: #d1fae5;
    color: #065f46;
    cursor: default;
    font-size: 0.75rem;
}

.debt-item-monthly {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.debt-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-top: 10px;
    background: #fef2f2;
    border-radius: 8px;
    font-weight: 600;
    border-left: 4px solid #ef4444;
}

.debt-total-value {
    font-size: 1.2rem;
    color: var(--danger);
}

/* 还款提醒样式 */
.repayment-urgent {
    color: var(--danger);
    font-weight: 600;
    font-size: 0.8rem;
    margin-left: 8px;
}

.repayment-soon {
    color: var(--warning);
    font-weight: 500;
    font-size: 0.8rem;
    margin-left: 8px;
}

.repayment-normal {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-left: 8px;
}

.account-balance {
    font-weight: 700;
    font-size: 1.1rem;
}

.account-balance.positive { color: var(--success); }
.account-balance.negative { color: var(--danger); }

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

/* ========== 交易列表 ========== */
.transactions-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.transaction-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.transaction-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.transaction-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.transaction-icon.income { background: #d1fae5; color: var(--success); }
.transaction-icon.expense { background: #fee2e2; color: var(--danger); }

.transaction-details {
    display: flex;
    flex-direction: column;
}

.transaction-category {
    font-weight: 600;
}

.transaction-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.transaction-right {
    text-align: right;
}

.transaction-amount {
    font-weight: 700;
    font-size: 1.1rem;
}

.transaction-amount.income { color: var(--success); }
.transaction-amount.expense { color: var(--danger); }

.transaction-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ========== 筛选栏 ========== */
.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input {
    padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--card-bg);
}

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

/* ========== 按钮 ========== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
}

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

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

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

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

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-icon:hover {
    opacity: 1;
    background: var(--bg);
}

/* ========== 模态框 ========== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-small {
    max-width: 350px;
}

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

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

.modal-header h3 {
    margin: 0;
}

.modal-close {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

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

/* ========== 表单 ========== */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

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

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* ========== 图表 ========== */
.chart-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.chart-box {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.chart-box canvas {
    max-height: 300px;
}

/* ========== Toast 提示 ========== */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 2000;
}

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

/* ========== 空状态 ========== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    /* 导航栏 */
    .navbar {
        flex-direction: column;
        padding: 10px;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .nav-brand {
        font-size: 1.1rem;
        padding: 8px 0;
    }

    .nav-links {
        width: 100%;
        display: flex;
        justify-content: space-around;
        border-top: 1px solid var(--border);
        margin-top: 5px;
        padding-top: 5px;
    }

    .nav-btn {
        padding: 12px 8px;
        font-size: 0.8rem;
        flex: 1;
        text-align: center;
        white-space: nowrap;
    }

    .nav-btn.active {
        border-bottom: none;
        border-top: 3px solid var(--primary);
        background: rgba(79, 70, 229, 0.05);
    }

    .container {
        padding: 12px;
    }

    h2 {
        font-size: 1.3rem;
        margin-bottom: 15px;
    }

    h3 {
        font-size: 1.1rem;
    }

    /* 统计卡片 - 2列 */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 15px 12px;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    /* 卡片区块 */
    .dashboard-section {
        padding: 15px;
    }

    /* 账户/交易列表 */
    .account-item,
    .transaction-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px;
    }

    .account-info,
    .transaction-left {
        width: 100%;
    }

    .account-actions,
    .transaction-right {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 5px;
    }

    .account-icon,
    .transaction-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .account-name,
    .transaction-category {
        font-size: 0.95rem;
    }

    .account-type,
    .transaction-desc {
        font-size: 0.75rem;
    }

    .account-balance,
    .transaction-amount {
        font-size: 1rem;
    }

    /* 按钮 */
    .btn {
        padding: 12px 20px;
        font-size: 0.95rem;
        min-height: 44px;
        touch-action: manipulation;
    }

    .btn-primary {
        width: 100%;
    }

    .btn-small {
        padding: 8px 14px;
        font-size: 0.85rem;
        min-height: 36px;
    }

    .btn-icon {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 筛选栏 */
    .filter-bar {
        flex-direction: column;
        gap: 8px;
    }

    .filter-bar select,
    .filter-bar input {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
        min-height: 44px;
    }

    .filter-bar button {
        width: 100%;
        min-height: 44px;
    }

    /* 分页/页面头部 */
    .page-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .page-header h2 {
        margin-bottom: 0;
    }

    /* 图表 */
    .chart-container {
        grid-template-columns: 1fr;
    }

    .chart-box {
        padding: 15px;
    }

    .chart-box h3 {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    /* 模态框 - 全屏手机体验 */
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        padding: 20px;
        display: flex;
        flex-direction: column;
    }

    .modal-header {
        padding-bottom: 15px;
        border-bottom: 1px solid var(--border);
        margin-bottom: 15px;
        flex-shrink: 0;
    }

    .modal-header h3 {
        margin: 0;
    }

    .modal-close {
        padding: 10px;
        margin: -10px;
    }

    .modal-content form {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

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

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 8px;
    }

    .form-group input,
    .form-group select {
        padding: 14px;
        font-size: 1rem;
        min-height: 48px;
        border-radius: 10px;
    }

    .form-actions {
        position: sticky;
        bottom: 0;
        background: var(--card-bg);
        padding: 15px 0;
        margin: 0 -20px -20px;
        padding: 15px 20px;
        border-top: 1px solid var(--border);
        flex-shrink: 0;
    }

    .form-actions .btn {
        min-height: 48px;
    }

    /* Toast */
    .toast {
        left: 10px;
        right: 10px;
        transform: translateX(0) translateY(100px);
        text-align: center;
    }

    .toast.show {
        transform: translateX(0) translateY(0);
    }

    /* 确认删除弹窗 */
    .modal-small {
        max-width: 100%;
        width: calc(100% - 40px);
    }

    #confirmMessage {
        font-size: 1rem;
        padding: 10px 0;
    }

    /* 负债汇总 */
    .debt-item {
        padding: 12px;
    }

    .debt-item-name {
        font-size: 0.95rem;
    }

    .debt-item-detail {
        font-size: 0.75rem;
    }

    .debt-item-amount {
        font-size: 1rem;
    }

    .debt-total-row {
        padding: 12px;
    }

    .debt-total-value {
        font-size: 1.1rem;
    }

    /* 空状态 */
    .empty-state {
        padding: 30px 15px;
    }

    .empty-state-icon {
        font-size: 2.5rem;
    }
}

/* 更大屏幕的手机 */
@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .stat-label {
        margin-bottom: 0;
    }

    .stat-value {
        font-size: 1.2rem;
    }
}

/* ========== 数据状态条 ========== */
.data-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    position: sticky;
    top: 0;
    z-index: 99;
    transition: background 0.3s;
}

.data-status-bar.connecting { background: #fff3cd; color: #856404; }
.data-status-bar.connected { background: #d1fae5; color: #065f46; }
.data-status-bar.error { background: #fee2e2; color: #991b1b; }

.data-status-retry {
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}

.data-status-retry:hover { background: rgba(0,0,0,0.08); }

/* ========== 分期明细行 ========== */
.installment-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    margin-top: 5px;
}

.installment-row {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr 32px;
    gap: 6px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.installment-row .ir-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 3px;
}

.installment-row input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
}

.installment-row input:focus {
    outline: none;
    border-color: var(--primary);
}

.installment-row .ir-remove {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 1.1rem;
    cursor: pointer;
    align-self: end;
    height: 36px;
}

.installment-row .ir-remove:hover {
    background: #fee2e2;
    border-radius: 6px;
}

.installment-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 5px;
    padding: 5px 8px;
    background: var(--bg);
    border-radius: 6px;
}

/* 删除确认 */
#confirmMessage {
    margin: 20px 0;
    text-align: center;
    font-size: 1.1rem;
}
