:root {
    --bg: #f3f6fb;
    --panel: #ffffff;
    --panel-muted: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --line: #dbe3ef;
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.12);
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 22px;
}

body[data-resolved-theme="dark"] {
    --bg: #0a1628;
    --panel: #132437;
    --panel-muted: #1a2d45;
    --text: #f3f8ff;
    --muted: #d0dced;
    --line: #2a3d52;
    --accent: #7ab7ff;
    --accent-soft: rgba(96, 165, 250, 0.2);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    overflow-x: hidden;
}

body {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.2s ease, color 0.2s ease;
    --bs-body-bg: var(--bg);
    --bs-body-color: var(--text);
    --bs-border-color: var(--line);
    --bs-secondary-color: var(--muted);
    --bs-secondary-bg: var(--panel-muted);
    --bs-tertiary-bg: var(--panel);
    --bs-emphasis-color: var(--text);
}

.text-muted,
.text-body-secondary,
.small.text-muted {
    color: var(--muted) !important;
}

body, button, input, select, textarea {
    font-size: 14px;
}

body.compact-mode, body.compact-mode button, body.compact-mode input, body.compact-mode select, body.compact-mode textarea {
    font-size: 13px;
}

.hidden {
    display: none !important;
}

.app-shell, .login-shell {
    width: 100%;
    max-width: 100%;
    margin: 0;
    min-height: 100vh;
    position: relative;
}

.login-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 18px;
}

.login-card {
    width: 100%;
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,255,255,0.9));
    border: 1px solid var(--line);
    border-radius: 28px;
    padding: 26px 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

body[data-resolved-theme="dark"] .login-card {
    background: linear-gradient(180deg, rgba(19, 36, 55, 0.98), rgba(26, 45, 69, 0.95));
}

.brand-badge {
    width: 58px;
    height: 58px;
    margin: 0 auto 14px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 24px;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #60a5fa);
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 24px;
    font-weight: 800;
}

.login-card p, .hint-text {
    color: var(--muted);
    margin: 0 0 18px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px clamp(16px, 3vw, 28px) 12px;
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    backdrop-filter: blur(14px);
}

.header-title {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.1;
}

.header-subtitle {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.icon-button {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    box-shadow: var(--shadow);
}

.text-icon-button {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.app-main {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 6px clamp(14px, 3vw, 24px) 104px;
}

.app-view {
    display: none;
}

.app-view.is-active {
    display: block;
}

.kpi-grid, .summary-grid, .grid-two, .grid-three, .chips-grid {
    display: grid;
    gap: 10px;
}

.kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 10px;
}

.grid-two, .grid-three {
    grid-template-columns: 1fr;
}

.panel-card, .kpi-card, .txn-card, .empty-card, .category-chip {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel-card {
    padding: 12px;
    margin-bottom: 12px;
}

.sticky-panel {
    position: sticky;
    top: 74px;
    z-index: 15;
}

.panel-head, .tight-head, .category-header, .txn-header, .txn-footer, .txn-actions, .type-switch, .bottom-nav, .compact-filter-group {
    display: flex;
    align-items: center;
}

.panel-head, .category-header, .txn-header, .txn-footer {
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.panel-title {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
}

.panel-subtitle, .field-label, .meta-text, .txn-meta, .note-text, .text-button, .existing-receipt, .remove-receipt-check, .small-muted {
    color: var(--muted);
}

.panel-subtitle, .field-label, .txn-meta, .note-text, .existing-receipt, .remove-receipt-check {
    font-size: 12px;
}

.text-button {
    border: 0;
    background: transparent;
    font-weight: 700;
    color: var(--accent);
}

.kpi-card {
    padding: 10px 9px;
    text-align: left;
}

.kpi-card .label {
    color: var(--muted);
    font-size: 11px;
    margin-bottom: 6px;
}

.kpi-card .value {
    font-size: clamp(13px, 2.8vw, 16px);
    font-weight: 800;
}

.kpi-card.income .value, .summary-item.income .value, .type-income, .amount-income {
    color: var(--success);
}

.kpi-card.expense .value, .summary-item.expense .value, .type-expense, .amount-expense {
    color: var(--danger);
}

.kpi-card.balance .value, .summary-item.balance .value {
    color: var(--accent);
}

body[data-resolved-theme="dark"] .kpi-card.balance .value,
body[data-resolved-theme="dark"] .summary-item.balance .value,
body[data-resolved-theme="dark"] .balance-value,
body[data-resolved-theme="dark"] .inline-link,
body[data-resolved-theme="dark"] .text-button {
    color: #9fc9ff;
}

.summary-item {
    padding: 10px;
    border-radius: 16px;
    background: var(--panel-muted);
    border: 1px solid var(--line);
}

.summary-item .label {
    font-size: 11px;
    color: var(--muted);
}

.summary-item .value {
    font-size: clamp(12px, 2.6vw, 15px);
    font-weight: 800;
    margin-top: 4px;
    color: var(--text);
}

.form-block {
    width: 100%;
}

.stack-form, .filter-stack, .details-body {
    display: grid;
    gap: 12px;
}

.compact-stack {
    gap: 10px;
}

.compact-filter-group {
    gap: 6px;
    flex-wrap: wrap;
}

.form-control, .form-select, .form-control-color {
    min-height: 42px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel-muted);
    color: var(--text);
}

.form-control::placeholder {
    color: var(--muted);
}

.form-control:focus, .form-select:focus, .form-control-color:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 0.22rem var(--accent-soft);
    background: var(--panel);
}

.form-control-color {
    padding: 6px;
}

.form-select option {
    background: var(--panel);
    color: var(--text);
}

.btn {
    border-radius: 14px;
    min-height: 40px;
    font-weight: 700;
}

.btn-sm {
    min-height: 32px;
    border-radius: 10px;
}

.btn-outline-primary, .btn-outline-secondary, .btn-outline-success, .btn-outline-danger {
    background: var(--panel);
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100%;
    justify-content: space-around;
    gap: 6px;
    padding: 10px clamp(10px, 3vw, 28px) calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
    z-index: 40;
}

.nav-item {
    flex: 1;
    display: grid;
    justify-items: center;
    gap: 4px;
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 2px 6px;
    font-size: 11px;
}

.nav-symbol {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    min-height: 24px;
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--panel-muted);
    border: 1px solid var(--line);
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
}

.nav-item.is-active {
    color: var(--accent);
    font-weight: 700;
}

.fab-button {
    position: fixed;
    right: clamp(16px, 3vw, 28px);
    bottom: 84px;
    width: 58px;
    height: 58px;
    border-radius: 20px;
    border: 0;
    background: linear-gradient(135deg, var(--accent), #60a5fa);
    color: #fff;
    box-shadow: 0 14px 30px rgba(96, 165, 250, 0.35);
    z-index: 41;
    font-size: 28px;
    font-weight: 300;
    line-height: 1;
}

#view-dashboard.is-active, #view-settings.is-active {
    gap: 16px;
}

.card-list {
    display: grid;
    gap: 10px;
}

.card-list-spaced {
    margin-bottom: 12px;
}

.txn-card {
    padding: 14px;
}

.txn-title {
    font-size: 15px;
    font-weight: 800;
    margin: 0;
}

.txn-amount {
    font-size: 16px;
    font-weight: 800;
}

.txn-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.meta-pill, .type-pill, .category-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 6px 10px;
    background: var(--panel-muted);
    border: 1px solid var(--line);
}

.type-pill {
    font-weight: 800;
    font-size: 11px;
}

.txn-note {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--panel-muted);
    color: var(--text);
}

.txn-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--line);
}

.balance-block {
    font-size: 12px;
}

.balance-value {
    display: block;
    margin-top: 4px;
    color: var(--accent);
    font-weight: 800;
    font-size: 14px;
}

.txn-actions {
    gap: 8px;
}

.inline-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
}

.empty-card {
    padding: 18px 14px;
    text-align: center;
    color: var(--muted);
}

.sheet-modal .modal-content {
    border-radius: 28px 28px 0 0;
    border: 0;
    background: var(--panel);
    color: var(--text);
}

.modal-bottom-sheet {
    margin: 0;
    align-items: flex-end;
    min-height: 100%;
}

.modal-header, .modal-body {
    padding-left: 16px;
    padding-right: 16px;
}

.modal-header {
    border-bottom-color: var(--line);
}

.modal-title {
    font-size: 18px;
    font-weight: 800;
}

body[data-resolved-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(190%);
}

.type-switch {
    gap: 8px;
}

.type-chip {
    flex: 1;
    min-height: 46px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--panel-muted);
    color: var(--muted);
    font-weight: 800;
}

.type-chip.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.more-details {
    background: var(--panel-muted);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 10px 12px;
}

.more-details summary {
    cursor: pointer;
    list-style: none;
    font-weight: 700;
}

.more-details summary::-webkit-details-marker {
    display: none;
}

.details-body {
    margin-top: 12px;
}

.existing-receipt {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.category-section + .category-section {
    margin-top: 16px;
}

.category-add-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
}

.chips-grid {
    grid-template-columns: 1fr;
    margin-top: 12px;
}

.category-chip {
    justify-content: space-between;
    width: 100%;
}

.category-actions {
    display: inline-flex;
    gap: 6px;
}

.category-actions button {
    width: 28px;
    height: 28px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--muted);
}

.bulk-delete-box {
    padding: 12px;
    background: var(--panel-muted);
    border: 1px solid var(--line);
    border-radius: 18px;
}

.toast-host {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 150px;
    width: min(100% - 24px, 430px);
    z-index: 1060;
    display: grid;
    gap: 8px;
}

.app-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.toast-mark {
    min-width: 26px;
    text-align: center;
}

.app-toast.success {
    border-color: rgba(22, 163, 74, 0.28);
}

.app-toast.error {
    border-color: rgba(220, 38, 38, 0.28);
}

body.app-busy, body.app-busy button {
    cursor: progress;
}

body.app-busy .fab-button, body.app-busy .btn, body.app-busy .icon-button, body.app-busy .nav-item {
    opacity: 0.85;
}

/* Mobile-first compact layout */
@media (max-width: 640px) {
    .app-main {
        padding-bottom: calc(156px + env(safe-area-inset-bottom));
    }

    .grid-three, .chips-grid {
        grid-template-columns: 1fr;
    }

    .kpi-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .summary-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .grid-two, .compact-filter-group, .category-header, .category-add-form {
        grid-template-columns: 1fr;
        display: grid;
    }

    .card-list {
        gap: 12px;
    }

    .txn-card {
        padding: 14px 12px;
    }

    .txn-header {
        align-items: flex-start;
        gap: 10px;
    }

    .txn-amount {
        margin-left: auto;
        text-align: right;
        white-space: nowrap;
        max-width: 40%;
    }

    .txn-actions {
        justify-content: flex-end;
    }

    .fab-button {
        right: 14px;
        bottom: calc(96px + env(safe-area-inset-bottom));
        width: 56px;
        height: 56px;
    }
}
