:root {
    --ink: #132c47;
    --ink-2: #1d4266;
    --muted: #64748b;
    --line: #e1e9f2;
    --bg: #f3f7fb;
    --card: #ffffff;
    --accent: #2d5a87;
    --green: #23875f;
    --red: #b13b3b;
    --amber: #a5721e;
    --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { background: var(--bg); }

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font: 15px/1.55 "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
    outline: 3px solid rgba(45, 90, 135, .35);
    outline-offset: 2px;
}

[hidden] { display: none !important; }

.eyebrow {
    margin: 0 0 3px;
    color: #9fb4c9;
    font-size: 10.5px;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.muted { color: var(--muted); }

/* Login */
.login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100svh;
    padding: 24px 18px;
    background: #eef4fa;
}

.login-card {
    width: 100%;
    max-width: 390px;
    padding: 30px 22px 22px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--card);
}

.login-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-bottom: 18px;
    border-radius: 14px;
    background: var(--ink);
    color: #fff;
    font-size: 24px;
    font-weight: 700;
}

.login-card h1 {
    margin: 0 0 3px;
    font-size: 25px;
    line-height: 1.2;
    letter-spacing: -.02em;
}

.login-card > .muted { margin: 0 0 24px; font-size: 13px; }

.login-card form { display: grid; gap: 9px; }
.login-card label { color: var(--muted); font-size: 12px; }
.login-card input {
    width: 100%;
    height: 48px;
    padding: 0 13px;
    border: 1px solid #d7e2ee;
    border-radius: 9px;
    background: #fbfdff;
    color: var(--ink);
    font-size: 18px;
    letter-spacing: .08em;
}

.login-note { margin: 18px 0 0; color: var(--muted); font-size: 11.5px; line-height: 1.6; }

/* App shell */
.app-view { min-height: 100svh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: calc(16px + env(safe-area-inset-top)) 18px 15px;
    background: var(--ink);
    color: #fff;
}

.topbar h1 { margin: 0; color: #fff; font-size: 21px; line-height: 1.2; }
.topbar .eyebrow { color: #a9bfd2; font-size: 10px; }
.icon-btn {
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: 8px;
    background: transparent;
    color: #d9e6f1;
    font-size: 12px;
}

.monthbar {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    font-size: 12px;
}

.monthbar label { flex: 0 0 auto; }
.monthbar input {
    min-width: 0;
    height: 34px;
    padding: 0 7px;
    border: 1px solid #d7e2ee;
    border-radius: 7px;
    background: #fbfdff;
    color: var(--ink);
    font-size: 12px;
}

.text-btn {
    min-height: 34px;
    padding: 0 7px;
    border: 0;
    background: transparent;
    color: var(--accent);
    font-size: 12px;
}

.sync-state { margin-left: auto; color: #8494a6; font-size: 10.5px; }

.main { padding: 14px 14px 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 13px; }
.stat {
    min-width: 0;
    padding: 13px 13px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
}
.stat-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.stat-value { display: block; overflow: hidden; color: var(--ink); font-size: 20px; font-weight: 700; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.stat-value.good { color: var(--green); }
.stat-value.bad { color: var(--red); }
.stat-note { display: block; margin-top: 3px; color: var(--muted); font-size: 10.5px; }

/* Panels and rows */
.panel {
    margin: 0 0 12px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 11px; }
.panel-head h2 { margin: 0 0 2px; font-size: 15px; line-height: 1.3; }
.panel-head p { margin: 0; color: var(--muted); font-size: 10.5px; }

.list { border-top: 1px solid #eef3f8; }
.row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 0;
    border-bottom: 1px solid #eef3f8;
}
.row:last-child { border-bottom: 0; }
.row-main { min-width: 0; flex: 1; }
.row-title { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; font-weight: 600; }
.row-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { margin-top: 3px; color: var(--muted); font-size: 10.5px; line-height: 1.4; overflow-wrap: anywhere; }
.row-side { flex: 0 0 auto; text-align: right; }
.row-amount { color: var(--ink); font-size: 13px; font-weight: 700; white-space: nowrap; }
.row-sub { margin-top: 2px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; height: 19px; padding: 0 6px; border-radius: 5px; background: #edf4fb; color: #3e688f; font-size: 10px; font-weight: 500; white-space: nowrap; }
.badge.green { background: #e9f6ef; color: #287a58; }
.badge.red { background: #fdeeee; color: #a33c3c; }
.empty { padding: 18px 0; color: var(--muted); font-size: 12px; text-align: center; }

/* Quick actions */
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.quick-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-height: 98px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    text-align: left;
}
.quick-card strong { margin-top: 7px; font-size: 14px; }
.quick-card > span:last-child { margin-top: 2px; color: var(--muted); font-size: 10.5px; }
.quick-icon { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 6px; background: #edf4fb; color: var(--accent); font-size: 15px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 11px; }
.form-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.form-grid label.span-2 { grid-column: 1 / -1; }
.form-grid input, .form-grid select {
    width: 100%;
    min-width: 0;
    height: 43px;
    padding: 0 10px;
    border: 1px solid #d7e2ee;
    border-radius: 8px;
    background: #fbfdff;
    color: var(--ink);
    font-size: 15px;
}
.form-grid input::placeholder { color: #97a6b7; }
.form-error { min-height: 17px; margin: 0; color: var(--red); font-size: 11px; }
.btn {
    min-height: 45px;
    padding: 0 15px;
    border: 0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { opacity: .55; }
.span-2 { grid-column: 1 / -1; }

/* Bottom nav */
.tabbar {
    position: fixed;
    z-index: 20;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 -4px 14px rgba(19, 44, 71, .04);
}
.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-height: 50px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #8190a3;
    font-size: 10.5px;
}
.tab span { font-size: 16px; line-height: 1; }
.tab.active { background: #edf4fb; color: var(--accent); font-weight: 600; }

/* Toast */
.toast {
    position: fixed;
    z-index: 30;
    right: 18px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    left: 18px;
    padding: 11px 14px;
    border-radius: 9px;
    background: var(--ink);
    color: #fff;
    font-size: 12px;
    line-height: 1.45;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #7e3030; }

@media (min-width: 720px) {
    .main { max-width: 720px; margin: 0 auto; padding: 18px 20px 24px; }
    .monthbar { justify-content: center; }
    .topbar { padding-right: max(20px, calc((100% - 720px) / 2)); padding-left: max(20px, calc((100% - 720px) / 2)); }
    .tabbar { right: 50%; left: 50%; width: 720px; transform: translateX(-50%); border-radius: 12px 12px 0 0; }
}
