:root {
    --bg: #f3f6fb;
    --panel: #ffffff;
    --panel-muted: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --line: #dbe3ef;
    --accent: #2563eb;
    --accent-2: #60a5fa;
    --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;
    /* Design tokens */
    --space-xxs: 4px;
    --space-xs: 6px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --card-radius: 12px;
    --card-padding: 14px;
    --card-padding-mobile: 12px;
    --card-padding-compact: 8px;
    --txn-gap: 12px;
    --txn-right-max: 220px;
    --txn-right-max-mobile: 160px;
    --txn-meta-first-max: 110px;
    --txn-meta-second-max: 120px;
}

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

* {
    box-sizing: border-box;
}

/* Utility classes (design-system helpers) */
.u-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.u-flex { display: flex; }
.u-flex-center { display: flex; align-items: center; justify-content: center; }
.u-grid { display: grid; }
.u-gap-sm { gap: var(--space-sm); }
.u-gap-md { gap: var(--space-md); }
.u-p-sm { padding: var(--space-sm); }
.u-p-md { padding: var(--space-md); }
.u-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--card-radius);
    padding: var(--card-padding);
    box-shadow: var(--shadow);
}
body.compact-mode .u-card { padding: var(--card-padding-compact); }

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), var(--accent-2));
}

/* Logo image inside brand badge */
.brand-badge .brand-logo,
.brand-logo {
    width: 56%;
    height: auto;
    display: block;
    object-fit: contain;
}

/* When the badge should show only the logo (no surrounding box) */
.brand-badge.no-box {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
}
.brand-badge.no-box .brand-logo,
.brand-logo.only {
    width: 72px;
    height: auto;
    display: block;
    margin: 0 auto 10px;
}

.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: calc(14px + env(safe-area-inset-top)) 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: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    box-shadow: var(--shadow);
}

.icon-svg {
    display: block;
    width: 20px;
    height: 20px;
    max-width: 100%;
    color: inherit;
}

.fab-icon {
    width: 24px;
    height: 24px;
}

.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-template-columns: repeat(2, minmax(0, 1fr));
}

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

.panel-card, .kpi-card, .empty-card {
    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, .txn-header, .txn-footer, .txn-actions, .type-switch, .bottom-nav, .compact-filter-group {
    display: flex;
    align-items: center;
}

.panel-head, .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: var(--accent);
}

.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;
}

/* Ensure compact filters (month/year) sit inline and are compact */
.compact-filter-group .form-select {
    width: auto !important;
    min-width: 96px;
}

.compact-filter-group .form-select.form-select-sm {
    padding-top: .25rem;
    padding-bottom: .25rem;
    padding-left: .5rem;
    padding-right: .75rem;
    font-size: .88rem;
    min-height: 34px;
    border-radius: 10px;
}

/* Compact mode adjustments for denser UI */
body.compact-mode .form-control,
body.compact-mode .form-select {
    min-height: 36px;
    font-size: 13px;
    border-radius: 10px;
}

.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: 6px;
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 6px 8px;
    font-size: 12px;
    min-height: 56px;
}

.nav-symbol {
    display: inline-grid;
    place-items: center;
    min-width: 36px;
    min-height: 36px;
    padding: 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 {
    /* FAB removed from markup; keep hidden in case legacy markup remains */
    display: none !important;
}

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

.card-list {
    display: grid;
    gap: var(--space-md);
    /* Responsive columns: single column on narrow screens, multiple on wider */
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

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

/* Transaction presentation consolidated into assets/app.txn.css.
   Canonical grid-based txn styles live in `assets/app.txn.css` and
   should be loaded after this file. Removed duplicate fallbacks
   to keep styles centralized. */

.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;
}

.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 {
        /* Use two columns on small screens for better readability */
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    /* Keep month/year compact filters side-by-side on small screens */
    .compact-filter-group {
        display: flex;
        gap: 8px;
        align-items: center;
        flex-wrap: nowrap;
    }
    .compact-filter-group .form-select {
        flex: 1 1 auto;
        min-width: 0;
    }
    .compact-filter-group .form-select.form-select-sm:first-child {
        max-width: 120px;
        flex: 0 0 120px;
    }
    .compact-filter-group .form-select.form-select-sm:last-child {
        max-width: 92px;
        flex: 0 0 92px;
    }

    .card-list {
        gap: 12px;
    }

    /* Transaction card layout is fully managed in assets/app.txn.css */
}

/* Compact mode: denser paddings, smaller controls, compact footer */
body.compact-mode .app-header {
    padding: calc(10px + env(safe-area-inset-top)) clamp(10px, 3vw, 20px) 8px;
}
body.compact-mode .panel-card {
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 12px;
}
body.compact-mode .app-main {
    padding: 6px clamp(10px, 3vw, 18px) 84px;
}
body.compact-mode .kpi-card .value { font-size: clamp(12px, 2.2vw, 14px); }
body.compact-mode .nav-item { font-size: 11px; min-height: 48px; padding: 4px 6px; }
body.compact-mode .nav-symbol { min-width: 30px; min-height: 30px; padding: 4px; }
body.compact-mode .bottom-nav { padding: 6px 10px calc(8px + env(safe-area-inset-bottom)); gap: 4px; }
body.compact-mode .btn, body.compact-mode .btn-sm { min-height: 36px; }
body.compact-mode .form-control, body.compact-mode .form-select { min-height: 36px; padding: 6px; }
/* Compact-mode txn rules moved to assets/app.txn.css */

/* Transaction layout and presentation now live in assets/app.txn.css */
/* Removed duplicated flex-based txn rules here. See assets/app.txn.css for canonical styles. */
/* Dark theme small tweaks for better contrast */
body[data-resolved-theme="dark"] .panel-card,
body[data-resolved-theme="dark"] .summary-item,
body[data-resolved-theme="dark"] .more-details {
    border-color: color-mix(in srgb, var(--line) 60%, transparent);
}

body[data-resolved-theme="dark"] .app-toast.success { border-color: rgba(26, 128, 55, 0.22); }
body[data-resolved-theme="dark"] .app-toast.error { border-color: rgba(180, 40, 40, 0.22); }

/* Improve Add Transaction modal layout: centered on larger screens, bottom-sheet on small screens */ 
.sheet-modal .modal-dialog {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
}

@media (min-width: 641px) {
    .sheet-modal .modal-dialog {
        margin: 1.5rem auto;
        max-width: 720px;
    }
    .sheet-modal .modal-dialog.modal-bottom-sheet {
        display: block;
        min-height: 0;
    }
    .sheet-modal .modal-content {
        border-radius: 14px;
        overflow: hidden;
    }
    .sheet-modal .modal-header, .sheet-modal .modal-body {
        padding-left: 18px;
        padding-right: 18px;
    }
    .sheet-modal .modal-title {
        font-size: 18px;
    }
}

/* Extra narrow-screen txn rules moved to assets/app.txn.css. */


