:root {
    --primary: #4f6ef7;
    --primary-dark: #3d5ae0;
    --primary-soft: #eef1fe;
    --success: #22a06b;
    --danger: #d64545;
    --warn: #c98a1b;
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1f2430;
    --muted: #767c8b;
    --border: #e5e8f0;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(20, 30, 60, .06), 0 6px 18px rgba(20, 30, 60, .05);
    --mono: #0ac28e;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
/* 固定滚动条槽位，避免内容超过一屏时滚动条占宽导致页面挤压/跳动 */
html { scrollbar-gutter: stable; }

/* 统一、美观的滚动条样式（Webkit 内核，含移动端） */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(118, 124, 139, .4);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(118, 124, 139, .6); border: 2px solid transparent; background-clip: padding-box; }

body {
    font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { opacity: .85; }

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---------- 顶部导航 ---------- */
.navbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
    box-shadow: 0 1px 2px rgba(20,30,60,.04);
}
.navbar-inner { display: flex; align-items: center; gap: 16px; height: 60px; }
.brand { font-weight: 800; font-size: 18px; color: var(--text); letter-spacing: .5px; }
.brand::before { content: "💰"; margin-right: 6px; }
.nav-toggle { display: none; }
.nav-collapse { display: flex; align-items: center; flex: 1; gap: 16px; }
.nav-links { display: flex; gap: 2px; flex: 1; }
.nav-link { padding: 7px 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.nav-link:hover { color: var(--text); background: #f2f4fb; opacity: 1; }
.nav-link.is-active { color: var(--primary); background: var(--primary-soft); }
.nav-dropdown { position: relative; }
.nav-dropdown .nav-link { display: inline-flex; align-items: center; }
.nav-dropdown .caret { font-size: 11px; margin-left: 4px; }
/* 按钮与下拉菜单之间留一条不可见的“桥”，避免移动鼠标瞬间丢失 hover 导致菜单闪没 */
.nav-dropdown::before {
    content: ""; position: absolute; top: 100%; left: 0; right: 0; height: 6px;
}
.nav-dropdown .dropdown-menu {
    display: none; position: absolute; top: 100%; left: 0; min-width: 170px;
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow); padding: 6px; z-index: 30; margin-top: 6px;
}
.nav-dropdown:hover .dropdown-menu { display: block; }
.dropdown-item {
    display: block; padding: 8px 12px; border-radius: 6px; color: var(--text);
    font-size: 14px; font-weight: 600;
}
.dropdown-item:hover { background: var(--primary-soft); color: var(--primary); }
.nav-user { display: flex; align-items: center; gap: 10px; }
.nav-username { color: var(--muted); font-size: 14px; padding: 6px 10px; border-radius: 8px; transition: background .15s; }
.nav-username:hover { opacity: 1; color: var(--text); background: #f2f4fb; }

/* 导航移动端自适应：较窄屏收为汉堡菜单 */
@media (max-width: 1080px) {
    .navbar-inner { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: 0; position: relative; }
    .brand { margin-right: auto; font-size: 17px; }
    .nav-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        width: 44px; height: 44px; border: 0; border-radius: 8px;
        background: none; color: var(--text); font-size: 26px; line-height: 1; cursor: pointer;
        transition: background .15s;
    }
    .nav-toggle:hover { background: #f2f4fb; }
    .nav-toggle:active { background: #e7eaf3; }
    .navbar.menu-open .brand { display: none; }
    .nav-collapse {
        display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 2px;
        padding: 10px 0 4px; margin-top: 8px; border-top: 1px solid var(--border);
        max-height: calc(100vh - 96px); overflow-y: auto;
    }
    .nav-collapse.is-open { display: flex; }
    .nav-links { flex-direction: column; align-items: stretch; gap: 2px; }
    .nav-link { display: block; padding: 11px 12px; }
    .nav-dropdown { margin-bottom: 2px; }
    .nav-dropdown .dropdown-menu {
        display: block; position: static; min-width: 0; border: 0; box-shadow: none;
        margin: 2px 0 0 12px; padding: 0;
    }
    .nav-dropdown .dropdown-item { padding: 9px 12px; }
    .nav-user { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 0 4px; }
    .nav-username { padding: 10px 12px; }
    .nav-user .btn { justify-content: center; }
}

/* ---------- 布局 ---------- */
.page { padding-top: 28px; padding-bottom: 40px; }
.page-head, .dash-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 24px; margin: 0; font-weight: 800; }
.dash-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
.category-hint { padding: 8px 10px; border-radius: 8px; font-size: 12.5px; margin: 0; }
.category-hint-allowance { background: var(--primary-soft); color: var(--primary); }
.category-hint-rec { background: #f2f4f8; color: var(--muted); }
.nowrap { white-space: nowrap; }
.ta-r { text-align: right; }
.ltd { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 一键发放条 ---------- */
.payout-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    background: linear-gradient(90deg, var(--primary-soft), #f7f4ff);
    border: 1px solid #e3e6ff; border-radius: var(--radius);
    padding: 14px 18px; margin-bottom: 20px;
}
.payout-text strong { display: block; font-size: 15px; color: var(--primary); }
.payout-text span { font-size: 13px; color: var(--muted); }

/* ---------- 卡片 ---------- */
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.card-narrow { max-width: 520px; margin: 0 auto; }
.card-title { font-size: 17px; margin: 0 0 16px; font-weight: 800; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 16px; }
.per-form { flex: none; }
.input-sm { width: auto; padding: 6px 10px; font-size: 13px; }

/* 明细筛选栏 */
.filter-bar {
    border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 14px;
    background: var(--bg);
}
.filter-grid { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: flex-end; }
.filter-item { display: flex; flex-direction: column; gap: 5px; }
.filter-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.filter-range { display: flex; align-items: center; gap: 6px; }
.filter-range .input-sm { width: 132px; }
.filter-keyword .input-sm { width: 160px; }
.filter-actions { display: flex; gap: 8px; flex: 1; justify-content: flex-end; }
.filter-presets { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; font-size: 13px; }
.filter-presets a { color: var(--primary); text-decoration: none; }
.filter-presets a:hover { text-decoration: underline; }
@media (max-width: 720px) {
    .filter-grid { flex-direction: column; align-items: stretch; }
    .filter-range .input-sm, .filter-keyword .input-sm { width: 100%; flex: 1; }
    .filter-actions { justify-content: flex-start; }
}
.two-col-eq { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: stretch; margin-top: 24px; }
.two-col-eq .card { height: 100%; display: flex; flex-direction: column; }
@media (max-width: 820px) { .two-col-eq { grid-template-columns: 1fr; } }
.two-col { display: grid; grid-template-columns: minmax(0,1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- 统计条 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
@media (max-width: 720px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-label { display: block; font-size: 12.5px; color: var(--muted); }
.stat-value { display: block; font-size: 22px; font-weight: 800; margin-top: 2px; }
.stat-value-sm { font-size: 15px; }
.stat-income .stat-value { color: var(--success); }
.stat-expense .stat-value { color: var(--danger); }
.stat-link a { color: var(--primary); font-weight: 700; font-size: 15px; text-decoration: none; }
.stat-link a:hover { text-decoration: underline; }

/* 统计图表 */
.chart { width: 100%; height: auto; display: block; }
.chart-axis { stroke: var(--border); stroke-width: 1.5; }
.chart-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-grid.light { opacity: .45; }
.chart-y { fill: var(--muted); font-size: 11px; text-anchor: end; }
.chart-label { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.chart-legend { display: flex; gap: 16px; margin: 0 0 8px; font-size: 13px; color: var(--text); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot-income { background: var(--success); }
.dot-expense { background: var(--danger); }
.row-total td { font-weight: 800; border-top: 1px solid var(--border); }

/* 分类占比 */
.table-shares { margin-top: 4px; }
.cat-share { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.bar-track {
    flex: 1; height: 8px; border-radius: 6px; background: var(--bg);
    min-width: 40px; overflow: hidden;
}
.cat-share .bar { height: 8px; min-width: 0; border-radius: 6px; display: block; }
.cat-pct { font-size: 12px; color: var(--muted); flex: none; width: 38px; text-align: right; }

/* ---------- 孩子卡片 ---------- */
.children-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.child-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.child-head { display: flex; align-items: center; gap: 12px; }
.child-name { margin: 0; font-size: 17px; font-weight: 800; }
.child-id { display: flex; flex-direction: column; gap: 4px; }
.avatar {
    width: 48px; height: 48px; border-radius: 50%; color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 800; flex: none; user-select: none;
}
.avatar-sm { width: 38px; height: 38px; font-size: 16px; }
.badge {
    display: inline-block; background: var(--primary-soft); color: var(--primary);
    font-size: 11.5px; padding: 1px 8px; border-radius: 20px; font-weight: 600;
    align-self: flex-start; white-space: nowrap;
}
.badge-success { background: rgba(34,160,107,.12); color: var(--success); }
.badge-danger { background: rgba(214,69,69,.12); color: var(--danger); }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }

/* 键值对信息（账号记录页） */
.kv { margin: 0; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.kv-row:last-child { border-bottom: 0; }
.kv-row dt { color: var(--muted); font-size: 14px; }
.kv-row dd { margin: 0; font-weight: 600; font-size: 14px; word-break: break-all; text-align: right; }
.child-balance { border-top: 1px dashed var(--border); border-bottom: 1px dashed var(--border); padding: 8px 0; }
.balance-label { font-size: 12px; color: var(--muted); margin-right: 8px; }
.balance-value { font-size: 22px; font-weight: 800; color: var(--primary); }
.child-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.child-meta b { color: var(--text); }
.child-actions { display: flex; gap: 8px; }

/* 分类管理 */
/* 新增分类卡片：放在页面最上方，表单横向紧凑排布 */
.cat-add { margin-bottom: 20px; }
.cat-add-form {
    display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap;
}
.cat-add-form .field { flex: 1; min-width: 150px; }
.cat-add-form .field-check { align-self: flex-end; margin-bottom: 11px; }
.cat-add-form .btn { white-space: nowrap; margin-top: auto; }
@media (max-width: 560px) {
    .cat-add-form { flex-direction: column; align-items: stretch; }
    .cat-add-form .field-check { align-self: flex-start; }
}

/* 收入/支出两个面板：上下排列，高度随内容自动调整 */
.cat-panels {
    display: flex; flex-direction: column; gap: 20px; align-items: stretch;
}
.cat-panels .card { margin: 0; min-width: 0; box-sizing: border-box; }
.cat-panel-income { background: #f3faf7; border-color: #d7ece2; }
.cat-panel-income .card-title { color: #16794e; }
.cat-panel-expense { background: #fdf5f5; border-color: #efd9d9; }
.cat-panel-expense .card-title { color: #b33434; }
.hidden-form { display: none; }
.field-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; }
.field-check input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.cat-list { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cat-name { flex: 1; min-width: 90px; }
.cat-toggle {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
    flex: none; min-width: 96px;
    font-size: 13px; padding: 5px 12px; border-radius: 20px;
    background: #eef1f6; color: var(--muted); border: 1px solid var(--border);
    transition: all .15s; user-select: none; font-family: inherit; font-weight: 600; line-height: 1.3;
}
.cat-toggle.is-on { background: rgba(34,160,107,.12); color: var(--success); border-color: rgba(34,160,107,.3); }
.cat-toggle:hover { filter: brightness(.97); }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid transparent; border-radius: 9px; padding: 9px 16px;
    font-size: 14px; font-weight: 600; cursor: pointer; background: transparent;
    transition: filter .15s, background .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { opacity: 1; filter: brightness(.96); }
.btn:disabled, .is-disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 3px 10px rgba(79,110,247,.28); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { border-color: var(--primary); color: var(--primary); background: #fff; }
.btn-outline:hover { background: var(--primary-soft); }
.btn-ghost { color: var(--text); background: #eef1f6; }
.btn-ghost:hover { background: #e2e6ef; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #bb3a3a; }
.btn-link { padding: 4px 6px; background: none; box-shadow: none; font-size: 13px; }
.btn-danger-text { color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---------- 登录/注册 ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
    width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--border);
    border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.auth-title { margin: 0 0 6px; text-align: center; font-size: 26px; font-weight: 800; }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 22px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-switch { text-align: center; margin: 18px 0 0; color: var(--muted); font-size: 14px; }

/* 验证码 */
.captcha-box { display: flex; align-items: center; gap: 8px; }
.captcha-img {
    flex: none; width: 130px; height: 44px; border-radius: 9px;
    border: 1px solid var(--border); cursor: pointer; background: var(--bg);
}
.captcha-input { flex: 1; min-width: 0; text-align: center; letter-spacing: 4px; text-transform: uppercase; font-family: ui-monospace, Consolas, monospace; }
.captcha-refresh {
    flex: none; width: 40px; height: 44px; border-radius: 9px; border: 1px solid var(--border);
    background: #fff; color: var(--primary); font-size: 18px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s;
}
.captcha-refresh:hover { background: var(--primary-soft); }

/* ---------- 表单 ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field-label em { color: var(--danger); font-style: normal; }
.field-inline { flex-direction: row; align-items: center; gap: 12px; }
.input {
    border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px;
    font-size: 14px; width: 100%; background: #fff; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,247,.15); }
.input-static {
    display: inline-block; border: 1px dashed var(--border); border-radius: 9px;
    padding: 10px 12px; font-size: 14px; background: var(--bg); color: var(--text);
}
select.input { appearance: auto; }
.color-pick { width: 44px; height: 36px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }

/* 收支方向切换 */
.direction-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.direction-switch input { display: none; }
.direction-switch label {
    text-align: center; padding: 9px; border-radius: 8px; font-weight: 700; cursor: pointer;
    color: var(--muted); font-size: 14px;
}
.direction-switch input#dir-income:checked + label { background: var(--success); color: #fff; }
.direction-switch input#dir-expense:checked + label { background: var(--danger); color: #fff; }

/* 批量记账行 */
.batch-rows { display: flex; flex-direction: column; gap: 10px; }
.batch-row { display: grid; grid-template-columns: 168px 86px 1fr 108px 1fr auto; gap: 8px; align-items: center; }
.batch-row .input { padding: 8px 10px; }
.batch-time { min-width: 0; }
.batch-del { white-space: nowrap; }
.batch-head { padding: 0 2px; }
.batch-head span { font-size: 12px; color: var(--muted); font-weight: 600; }
@media (max-width: 720px) {
    .batch-row { grid-template-columns: 1fr 1fr; }
    .batch-time, .batch-dir, .batch-cat { grid-column: auto; }
    .batch-time { grid-column: 1 / -1; }
    .batch-del { grid-column: 1 / -1; justify-self: end; }
}

/* ---------- 提示条（侧滑 toast） ---------- */
.flash-container {
    position: fixed; top: 16px; right: 16px; z-index: 999;
    display: flex; flex-direction: column; gap: 10px;
    pointer-events: none;
}
.flash {
    width: 260px; padding: 12px 36px 12px 14px; border-radius: 10px;
    font-size: 14px; border: 1px solid; position: relative;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .12);
    animation: flash-slide 0.3s ease-out;
}
@keyframes flash-slide {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}
.flash-success { background: #e9f9f1; color: #16794e; border-color: #b7e6cf; }
.flash-error { background: #fdecec; color: #a33; border-color: #f2c4c4; }
.flash-warn { background: #fdf5e6; color: #8a5a12; border-color: #f0dcb0; }
.flash-close { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 18px; cursor: pointer; color: inherit; pointer-events: auto; }

/* ---------- 列表 ---------- */
.child-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.child-list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.child-list-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.child-list-name { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.child-list-actions { display: flex; gap: 6px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.table thead th { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.tx-table thead th { text-align: center; }
.tx-table thead th.ta-r { text-align: right; }
.note-trunc {
    max-width: 5.2em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.table tbody tr:hover { background: #fafbff; }
.tag { display: inline-block; font-size: 12px; padding: 1px 9px; border-radius: 20px; font-weight: 700; }
.tag-income { background: #e6f6ef; color: #16794e; }
.tag-expense { background: #fdecec; color: #a33; }
.money-in { color: var(--success); font-weight: 700; }
.money-out { color: var(--danger); font-weight: 700; }

.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.page-info { color: var(--muted); font-size: 13px; }

/* ---------- 分类统计 ---------- */
.aside-title { font-size: 13px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.aside-sub { font-size: 12px; color: var(--muted); margin: 10px 0 6px; font-weight: 600; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bar-label { width: 46px; font-size: 13px; flex: none; }
.bar { height: 8px; border-radius: 6px; min-width: 2px; }
.bar-income { background: var(--success); }
.bar-expense { background: var(--danger); }
.bar-val { font-size: 12px; color: var(--muted); flex: none; }
.totals { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.totals li { display: flex; justify-content: space-between; }

/* ---------- 空状态 / 页脚 ---------- */
.empty-state { text-align: center; padding: 56px 16px; color: var(--muted); background: #fff; border: 1px dashed var(--border); border-radius: var(--radius); }
.empty-icon { font-size: 40px; }
.footer { text-align: center; color: #b6bcc9; font-size: 13px; padding: 24px 0 10px; }