/* ============================================================
   存钱计划工作台 - 全局样式 (桌面优先 + 全面移动端适配 v1.2)
   ============================================================ */
:root {
    --primary: #00C896;
    --primary-light: #E6F8F2;
    --warning: #F59E0B;
    --error:   #EF4444;
    --purple:  #5046E5;
    --text:    #0F172A;
    --text-2:  #64748B;
    --text-3:  #94A3B8;
    --border:  #E5E7EB;
    --bg:      #F8F9FA;
    --card:    #FFFFFF;
    --shadow:  0 1px 2px rgba(15,20,25,0.04), 0 4px 12px rgba(15,20,25,0.06);
    --radius:  12px;
    --radius-sm: 8px;
    --topbar-h: 56px;
    --bottomnav-h: 60px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { text-decoration: none; color: inherit; -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    background: var(--card);
    border-right: 1px solid var(--border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 30;
}
.logo {
    display: flex; align-items: center; gap: 10px;
    padding: 8px;
    margin-bottom: 24px;
}
.logo-icon {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 8px;
    flex-shrink: 0;
}
.logo-text {
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
}
.nav-label {
    font-size: 11px;
    color: var(--text-2);
    font-weight: 600;
    padding: 0 12px 8px;
    letter-spacing: 0.04em;
}
nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    transition: background .15s;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}
.nav-icon {
    width: 20px; height: 20px;
    display: inline-flex;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,0.04);
    border-radius: 4px;
    font-size: 13px;
    flex-shrink: 0;
}
.nav-item.active .nav-icon { background: var(--primary); color: #fff; }
.sidebar-footer { padding-top: 16px; border-top: 1px solid var(--border); }
.user-box {
    display: flex; align-items: center; gap: 10px;
    padding: 12px;
}
.avatar {
    width: 36px; height: 36px;
    background: var(--purple);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-weight: 600;
    flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-meta { font-size: 11px; color: var(--text-2); }
.logout-link {
    display: block;
    text-align: center;
    padding: 10px;
    font-size: 13px;
    color: var(--text-2);
    border-radius: 6px;
}
.logout-link:hover { background: var(--bg); color: var(--error); }

/* Admin */
.nav-divider { height: 1px; background: var(--border); margin: 8px 0; }
.nav-badge {
    margin-left: auto; background: var(--purple); color: #fff; font-size: 9px;
    padding: 1px 6px; border-radius: 99px; font-weight: 600;
}
.admin-tag {
    display: inline-block; padding: 2px 8px; border-radius: 99px;
    background: var(--primary); color: #fff; font-size: 10px;
    font-weight: 600; margin-left: 4px; vertical-align: middle;
    line-height: 1.6;
    white-space: nowrap;
    flex-shrink: 0;
}

/* 移动顶栏(仅移动端显示) */
.mobile-topbar {
    display: none;
}
/* 抽屉遮罩 */
.drawer-overlay {
    display: none;
}

/* 底部导航(仅移动端显示) */
.bottom-nav { display: none; }

/* Main */
.main {
    flex: 1;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 100%;
    min-width: 0;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.page-header > div:first-child { min-width: 0; }
.page-title { font-size: 24px; font-weight: 700; line-height: 1.3; word-break: break-word; }
.page-subtitle { font-size: 13px; color: var(--text-2); margin-top: 4px; }

/* Stat Cards */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}
.stat-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stat-label { font-size: 13px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.stat-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.stat-value {
    font-size: 32px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1.1;
    overflow-wrap: anywhere;
}
.stat-sub { font-size: 12px; color: var(--text-2); }
.stat-sub-row { display: flex; gap: 8px; align-items: center; font-size: 12px; flex-wrap: wrap; }

/* Card */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border);
    min-width: 0;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.card-title { font-size: 16px; font-weight: 600; }
.card-link { color: var(--primary); font-size: 13px; font-weight: 500; }

/* Content layout */
.content-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
}

/* Quick add */
.cat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.cat-card {
    padding: 12px 6px;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    border: 1px solid transparent;
    transition: border-color .15s, transform .1s;
    user-select: none;
}
.cat-card:hover { border-color: var(--primary); }
.cat-card.active { border-color: var(--primary); background: var(--primary-light); }
.cat-emoji { font-size: 28px; line-height: 1; }
.cat-name { font-size: 12px; font-weight: 500; margin-top: 6px; }

/* Toggle */
.toggle {
    display: inline-flex;
    background: #F1F5F9;
    padding: 4px;
    border-radius: 8px;
    gap: 4px;
    flex-wrap: wrap;
}
.toggle-item {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-2);
    border: none;
    background: none;
    display: inline-block;
    white-space: nowrap;
}
.toggle-item.active {
    background: var(--card);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow);
}

/* Buttons */
.btn {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #00B387; }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-ghost:hover { background: #EDF1F4; }
.btn-danger { background: var(--error); color: #fff; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-lg { padding: 14px 24px; font-size: 15px; }

/* Form */
.form-field { display: flex; flex-direction: column; gap: 8px; }
.form-label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.form-input {
    padding: 14px;
    background: var(--bg);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 14px;
    width: 100%;
    font-family: inherit;
    color: var(--text);
    transition: border-color .15s;
    min-width: 0;
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--card);
}
.form-input::placeholder { color: var(--text-3); }
select.form-input { appearance: auto; }

/* Record list */
.record {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    background: var(--bg);
    margin-bottom: 8px;
    min-width: 0;
}
.record:last-child { margin-bottom: 0; }
.record-icon {
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.record-info { flex: 1; min-width: 0; }
.record-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.record-amount {
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}
.record-amount.expense { color: var(--error); }
.record-amount.income { color: var(--primary); }

/* Goal */
.goal-card {
    padding: 16px;
    background: var(--bg);
    border-radius: 8px;
    margin-bottom: 12px;
}
.goal-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.goal-icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    background: var(--primary);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
}
.goal-title { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.goal-pct { font-size: 14px; font-weight: 700; flex-shrink: 0; }
.progress {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width .3s;
}
.goal-meta { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }

/* Progress bar list (categories) */
.cat-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.cat-row:last-child { margin-bottom: 0; }
.cat-row-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.cat-row-label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; min-width: 0; }
.cat-row-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cat-row-value { font-size: 12px; color: var(--text-2); }

/* Summary card (dark) */
.summary-dark {
    background: var(--text);
    color: #fff;
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.summary-dark .stat-label { color: var(--text-3); }
.summary-dark .stat-value { color: #fff; }
.summary-dark .stat-value.accent { color: var(--primary); }

/* 表格滚动容器 */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-wrap table { width: 100%; border-collapse: collapse; min-width: 0; }

/* Auth pages */
.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
.auth-brand {
    background: var(--text);
    color: #fff;
    padding: 80px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 40px;
}
.auth-brand-hero { font-size: 56px; font-weight: 800; line-height: 1.15; letter-spacing: -0.02em; }
.auth-brand-sub { color: var(--text-3); font-size: 16px; margin-top: 16px; max-width: 480px; }
.auth-brand-stats {
    display: flex;
    gap: 40px;
    flex-wrap: wrap;
}
.auth-stat-value { font-size: 36px; font-weight: 800; color: var(--primary); }
.auth-stat-label { font-size: 13px; color: var(--text-3); margin-top: 4px; }
.auth-brand-footer { color: var(--text-3); font-size: 12px; }

.auth-form-wrap {
    background: var(--card);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    min-width: 0;
}
.auth-form {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.auth-title { font-size: 32px; font-weight: 700; }
.auth-subtitle { color: var(--text-2); font-size: 14px; margin-bottom: 8px; }
.auth-error {
    background: #FEF2F2;
    color: var(--error);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}
.auth-success {
    background: var(--primary-light);
    color: var(--primary);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* ============================================================
   平板 (≤1024)
   ============================================================ */
@media (max-width: 1024px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .content-row { grid-template-columns: 1fr; }
    .auth-page { grid-template-columns: 1fr; }
    .auth-brand { padding: 48px; }
    .auth-brand-hero { font-size: 44px; }
}

/* ============================================================
   移动端 (≤900): 顶栏 + 抽屉 + 底部导航 + 内容适配
   ============================================================ */
@media (max-width: 900px) {

    /* ---- 移动顶栏 ---- */
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        position: sticky;
        top: 0;
        z-index: 40;
        height: var(--topbar-h);
        padding: 0 12px;
        background: var(--card);
        border-bottom: 1px solid var(--border);
    }
    .topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
    .burger-btn {
        width: 40px; height: 40px;
        border-radius: 8px;
        display: inline-flex; align-items: center; justify-content: center;
        font-size: 22px; color: var(--text);
        flex-shrink: 0;
        background: transparent;
    }
    .burger-btn:active { background: var(--bg); }
    .topbar-logo { display: flex; align-items: center; gap: 8px; min-width: 0; }
    .topbar-logo .logo-icon { width: 26px; height: 26px; border-radius: 7px; }
    .topbar-logo .logo-text { font-size: 16px; }
    .topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
    .topbar-btn {
        width: 40px; height: 40px;
        border-radius: 50%;
        display: inline-flex; align-items: center; justify-content: center;
        background: var(--primary-light); color: var(--primary);
        font-weight: 700; font-size: 20px;
    }
    .topbar-btn:active { opacity: .8; }

    /* ---- 侧栏变抽屉 ---- */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 280px;
        max-width: 84vw;
        height: 100vh;
        height: 100dvh;
        border-right: 1px solid var(--border);
        transform: translateX(-105%);
        transition: transform .25s ease;
        box-shadow: none;
        padding-bottom: 24px;
    }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.18); }
    .sidebar .logo { margin-bottom: 12px; padding: 8px 8px 4px; }
    .sidebar-footer { padding-bottom: 8px; }
    .drawer-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,.45);
        z-index: 29;
        opacity: 0;
        visibility: hidden;
        transition: opacity .25s ease, visibility .25s;
    }
    .drawer-overlay.show { opacity: 1; visibility: visible; }
    body.drawer-open { overflow: hidden; }

    /* ---- 底部导航 ---- */
    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--card);
        border-top: 1px solid var(--border);
        z-index: 40;
        align-items: stretch;
    }
    .bn-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        color: var(--text-3);
        font-size: 10px;
        font-weight: 500;
        min-height: var(--bottomnav-h);
        -webkit-tap-highlight-color: transparent;
        position: relative;
        z-index: 1;
    }
    .bn-item .bn-ico {
        font-size: 20px; line-height: 1;
        display: flex; align-items: center; justify-content: center;
        height: 24px;
    }
    .bn-item.active { color: var(--primary); }
    .bn-item.active .bn-ico { color: var(--primary); }
    /* 中部凸起记一笔(绝对定位,4 项均分宽度) */
    .bn-fab {
        position: absolute;
        left: 50%;
        bottom: 14px;
        transform: translateX(-50%);
        width: 56px; height: 56px;
        border-radius: 50%;
        background: var(--primary);
        color: #fff;
        font-size: 28px;
        font-weight: 300;
        display: flex; align-items: center; justify-content: center;
        box-shadow: 0 6px 16px rgba(0,200,150,.45);
        border: 4px solid var(--card);
        z-index: 5;
    }
    .bn-fab:active { transform: translateX(-50%) scale(.94); }
    .bn-fab.active { color: #fff; }

    /* ---- 主区 ---- */
    .main {
        padding: 16px 16px calc(calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px)) + 16px);
        gap: 16px;
        width: 100%;
    }
    .page-title { font-size: 20px; }
    .page-subtitle { font-size: 12px; }

    /* 卡片内边距压缩 */
    .card, .stat-card, .summary-dark { padding: 14px; }
    .stat-card { gap: 6px; }
    .stats-row { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .stat-value { font-size: 15px; line-height: 1.15; }
    .stat-icon { width: 20px; height: 20px; font-size: 11px; border-radius: 5px; }
    .stat-label { font-size: 10px; }
    .stat-sub { font-size: 9px; }
    .stat-header { margin-bottom: 0; gap: 4px; }

    /* 表格在移动端横向滚动,保持可读 */
    .table-wrap table { min-width: 560px; }

    .record { padding: 10px 8px; }

    /* 表单按钮/触控目标加大 */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 36px; padding: 6px 12px; }
    /* 卡片标题、分类网格、记录项进一步收紧 */
    .card-title { font-size: 14px; }
    .card-header { margin-bottom: 12px; }
    .cat-grid { gap: 8px; }
    .cat-card { padding: 10px 4px; }
    .cat-emoji { font-size: 22px; }
    .cat-name { font-size: 11px; margin-top: 4px; }
    .record { padding: 10px; gap: 10px; }
    .record-icon { width: 36px; height: 36px; font-size: 16px; }
    .record-title { font-size: 13px; }
    .record-amount { font-size: 15px; }
    .summary-dark { gap: 12px; }
    .summary-dark .stat-value { font-size: 22px; }
}

/* 更小屏幕 (≤480) */
@media (max-width: 480px) {
    .stats-row { gap: 4px; }
    .stat-value { font-size: 13px; }
    .cat-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .cat-emoji { font-size: 22px; }
    .cat-name { font-size: 11px; }
    .cat-card { padding: 10px 2px; }
    .page-header .toggle { max-width: 100%; }
    .toggle { width: 100%; display: flex; }
    .toggle-item { flex: 1; text-align: center; padding: 10px 8px; }
    .record-title { font-size: 13px; }
    .goal-header { flex-wrap: wrap; }
    .goal-actions { width: 100%; display: flex; gap: 8px; }
    .goal-actions .btn { flex: 1; }
    /* 目标详情: 图标+文字换行,操作放下一行 */
    .goal-detail { flex-wrap: wrap; }
    .goal-detail-main { flex-basis: calc(100% - 80px); }
    .goal-detail-actions,
    .goal-detail .goal-actions { width: 100%; flex-direction: row !important; }
    .goal-detail .goal-actions .btn { flex: 1; }
    /* 摘要区纵向排 */
    .summary-dark > div[style*="display:flex"] { flex-direction: column; }
    .btn-lg { width: 100%; }
}

/* 通用两列栅格(移动端收为一列) */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
/* 目标新建表单(桌面 2fr 1fr 1fr auto) */
.goal-form-grid { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 12px; align-items: end; }
@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .goal-form-grid { grid-template-columns: 1fr 1fr; }
    .goal-form-grid > .form-field:nth-child(1) { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
    .goal-form-grid { grid-template-columns: 1fr; }
    .goal-form-grid .btn { width: 100%; }
}

/* 7天趋势图: 窄屏下数值旋转/隐藏防溢出 */
@media (max-width: 480px) {
    .trend-bars { gap: 6px; height: 200px; }
    .trend-val { font-size: 10px; transform: rotate(-30deg); transform-origin: bottom center; }
    .trend-bar > div:nth-child(3) { font-size: 9px; }
}

/* ============================================================
   登录/注册页移动端优化
   ============================================================ */
@media (max-width: 900px) {
    .auth-page { grid-template-columns: 1fr; }
    .auth-brand {
        padding: 24px 20px;
        gap: 16px;
        min-height: auto;
    }
    .auth-brand .logo { margin-bottom: 8px; }
    .auth-brand-hero { font-size: 30px; }
    .auth-brand-sub { font-size: 13px; margin-top: 8px; }
    .auth-brand-stats { gap: 24px; }
    .auth-stat-value { font-size: 24px; }
    .auth-brand-footer { display: none; }
    .auth-form-wrap { padding: 32px 20px; min-height: calc(100vh - 300px); }
    .auth-title { font-size: 26px; }
    .auth-form { gap: 16px; }
    .auth-form .btn { min-height: 50px; }
}
@media (max-width: 480px) {
    .auth-brand-stats { display: none; }
    .auth-brand { padding: 20px 16px 16px; }
    .auth-form-wrap { padding: 28px 16px; }
}