:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #fbfbfc;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #f97316;
    --accent-strong: #ea580c;
    --accent-soft: #fff1e6;
    --success: #16a34a;
    --success-soft: #ecfdf3;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    --radius: 18px;
    --radius-sm: 12px;
    --nav-height: 62px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #0f1115;
        --surface: #171a21;
        --surface-2: #1d212a;
        --text: #e5e7eb;
        --muted: #9ca3af;
        --border: #2a2f3a;
        --accent: #fb923c;
        --accent-strong: #f97316;
        --accent-soft: #2a1c12;
        --success: #4ade80;
        --success-soft: #10231a;
        --danger: #f87171;
        --danger-soft: #2a1416;
        --shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

h1,
h2,
h3,
p {
    margin: 0;
}

.app-shell {
    min-height: 100vh;
    max-width: 720px;
    margin: 0 auto;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 22px);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(10px + var(--safe-top)) 16px 10px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    box-shadow: 0 6px 14px rgba(249, 115, 22, 0.28);
}

.brand-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.topbar-user {
    max-width: 40%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 13px;
}

.content {
    padding: 16px 16px 8px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

.card-title {
    font-size: 15px;
    font-weight: 650;
    margin-bottom: 10px;
}

.hero {
    background:
        radial-gradient(circle at 92% 8%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 42%),
        linear-gradient(145deg, var(--accent-soft), var(--surface) 70%);
    border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
}

.hero-title {
    font-size: 26px;
    font-weight: 750;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.hero-sub {
    margin-top: 6px;
    color: var(--muted);
    font-size: 14px;
}

.eyebrow {
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 650;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 13px;
}

.accent-text {
    color: var(--accent-strong);
}

.danger-text {
    color: var(--danger);
}

.success-text {
    color: var(--success);
}

.row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Stats */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 13px 14px;
}

.stat-label {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 3px;
}

.stat-value {
    font-size: 21px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.stat-value.accent {
    color: var(--accent-strong);
}

/* Entry */
.entry-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 14px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
}

.entry-input {
    display: block;
    width: 100%;
    min-height: 92px;
    resize: none;
    border: 1.5px solid transparent;
    border-radius: 16px;
    background: var(--surface-2);
    padding: 13px 15px;
    font-size: 17px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.entry-input:focus {
    border-color: var(--accent);
    background: var(--surface);
}

.entry-input::placeholder {
    color: var(--muted);
}

.entry-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
}

.entry-hint {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.entry-hint strong {
    color: var(--accent-strong);
    font-weight: 600;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    transition: transform 0.08s ease, background 0.15s ease;
}

.icon-btn:active {
    transform: scale(0.96);
}

.icon-btn.accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.icon-btn.recording {
    background: var(--danger-soft);
    border-color: color-mix(in srgb, var(--danger) 35%, transparent);
    color: var(--danger);
}

.icon-btn svg,
.nav-item svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 46px;
    padding: 0 16px;
    border-radius: 13px;
    border: 1px solid transparent;
    font-size: 15px;
    font-weight: 600;
    transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:active {
    transform: scale(0.985);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 8px 18px rgba(249, 115, 22, 0.24);
}

.btn-primary:hover {
    background: var(--accent-strong);
}

.btn-ghost {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

.btn-danger {
    background: var(--danger-soft);
    border-color: color-mix(in srgb, var(--danger) 30%, transparent);
    color: var(--danger);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    min-height: 44px;
    padding: 0 12px;
    font-size: 13px;
    border-radius: 10px;
}

/* Lists */
.day-group {
    margin-bottom: 14px;
}

.day-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 2px 8px;
}

.day-label {
    font-size: 13px;
    font-weight: 650;
    color: var(--muted);
}

.day-total {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.entry-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.entry-row {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    min-height: 60px;
    background: var(--surface);
    text-align: left;
    width: 100%;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    cursor: pointer;
    appearance: none;
}

.entry-row:last-child {
    border-bottom: 0;
}

.entry-row:active {
    background: var(--surface-2);
}

.entry-emoji {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--accent-soft);
    font-size: 19px;
}

.entry-main {
    min-width: 0;
    flex: 1;
}

.entry-note {
    display: block;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entry-meta {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entry-amount {
    flex: 0 0 auto;
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

/* Empty */
.empty {
    text-align: center;
    padding: 34px 18px;
}

.empty-icon {
    font-size: 38px;
    line-height: 1;
    margin-bottom: 10px;
}

.empty-title {
    font-size: 15px;
    font-weight: 650;
    margin-bottom: 4px;
}

.empty-text {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

/* Toast */
.toast-root {
    position: fixed;
    top: calc(12px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 28px);
    max-width: 520px;
    z-index: 120;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
    font-size: 14px;
    pointer-events: auto;
    animation: toast-in 0.2s ease both;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast-message {
    flex: 1;
    min-width: 0;
}

.toast-action {
    flex: 0 0 auto;
    border: 0;
    background: none;
    color: var(--accent-strong);
    font-weight: 650;
    font-size: 14px;
    padding: 6px;
    min-height: 44px;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Bottom sheet */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(15, 23, 42, 0.46);
    backdrop-filter: blur(2px);
}

.sheet {
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: 24px 24px 0 0;
    padding: 12px 18px calc(18px + var(--safe-bottom));
    box-shadow: 0 -16px 40px rgba(15, 23, 42, 0.22);
    animation: sheet-in 0.22s ease both;
}

.sheet-handle {
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    margin: 0 auto 12px;
}

.sheet-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 14px;
}

.sheet-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.sheet-actions .btn {
    flex: 1;
}

@keyframes sheet-in {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Forms */
.field {
    margin-bottom: 12px;
}

.field label {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 46px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 16px;
    outline: none;
    transition: border-color 0.15s ease;
}

.field textarea {
    min-height: 82px;
    resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--accent);
}

.field-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.field-error {
    color: var(--danger);
    font-size: 12px;
    margin-top: 4px;
}

.form-message {
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 12px;
}

.form-message.error {
    background: var(--danger-soft);
    color: var(--danger);
}

.form-message.success {
    background: var(--success-soft);
    color: var(--success);
}

/* Segmented */
.segmented {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    margin-bottom: 14px;
}

.segment {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 999px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}

.segment.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

/* Filters */
.filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.filters select,
.filters input {
    min-height: 44px;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-2);
    font-size: 15px;
}

.chip-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}

.chip-row::-webkit-scrollbar {
    display: none;
}

.chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.chip.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-strong);
}

/* Reports */
.report-grid {
    display: grid;
    gap: 12px;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}

.chart-title {
    font-size: 14px;
    font-weight: 650;
    margin-bottom: 10px;
}

.chart-wrap {
    position: relative;
    width: 100%;
    height: 220px;
}

.chart-wrap canvas {
    max-width: 100%;
}

.rank-list {
    margin-top: 4px;
}

.rank-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.rank-row:last-child {
    border-bottom: 0;
}

.rank-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.rank-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-amount {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.rank-pct {
    width: 46px;
    text-align: right;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

/* Login */
.login-wrap {
    min-height: calc(100vh - 120px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 24px 20px;
}

.login-logo {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 18px;
    box-shadow: 0 12px 26px rgba(249, 115, 22, 0.28);
}

.login-title {
    font-size: 24px;
    font-weight: 750;
    letter-spacing: -0.02em;
}

.login-sub {
    color: var(--muted);
    font-size: 14px;
    margin: 6px 0 20px;
}

/* Settings */
.settings-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 54px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    width: 100%;
    text-align: left;
    border-left: 0;
    border-right: 0;
    border-top: 0;
}

.settings-row:last-child {
    border-bottom: 0;
}

.settings-row-main {
    min-width: 0;
}

.settings-row-title {
    font-size: 15px;
    font-weight: 600;
}

.settings-row-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.settings-row-value {
    color: var(--muted);
    font-size: 14px;
    flex: 0 0 auto;
}

.category-row {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.category-row:last-child {
    border-bottom: 0;
}

.category-emoji {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--accent-soft);
    font-size: 19px;
    flex: 0 0 auto;
}

.category-main {
    flex: 1;
    min-width: 0;
}

.category-name {
    font-size: 15px;
    font-weight: 600;
}

.category-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 1px;
}

.category-actions {
    display: flex;
    gap: 6px;
    flex: 0 0 auto;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.badge.accent {
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 25%, transparent);
    color: var(--accent-strong);
}

.badge.success {
    background: var(--success-soft);
    border-color: color-mix(in srgb, var(--success) 25%, transparent);
    color: var(--success);
}

/* Bottom nav */
.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    max-width: 720px;
    padding: 6px 8px calc(6px + var(--safe-bottom));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(16px);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 50px;
    border-radius: 12px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.nav-item.active {
    color: var(--accent-strong);
}

.nav-item.active svg {
    stroke-width: 2.2;
}

/* Utility */
.spin {
    animation: spin 0.9s linear infinite;
}

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.htmx-request .send-icon {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-flex;
}

.htmx-request .send-label {
    opacity: 0.6;
}

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-flex;
}

@media (min-width: 720px) {
    .content {
        padding: 24px 24px 8px;
    }

    .card {
        padding: 20px;
    }

    .hero-title {
        font-size: 30px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}