:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-soft: #d1fae5;
    --bg: #ffffff;
    --surface: #ffffff;
    --muted-surface: #f7f9f8;
    --text: #17201b;
    --muted: #717b76;
    --border: #e8eeee;
    --danger: #ef4444;
    --danger-soft: #fee2e2;
    --warning: #f59e0b;
    --shadow: 0 10px 24px rgba(15, 23, 42, .10);
    --shadow-soft: 0 4px 14px rgba(15, 23, 42, .06);
    --bottom-nav-height: 66px;
}

body.dark {
    --bg: #0f1713;
    --surface: #16201b;
    --muted-surface: #1c2923;
    --text: #edf7f2;
    --muted: #9aaaa2;
    --border: #26352e;
    --shadow: 0 10px 24px rgba(0, 0, 0, .35);
    --shadow-soft: 0 4px 14px rgba(0, 0, 0, .22);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
}

body {
    overflow-x: hidden;
    font-size: 13px;
}

button, input {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

.hidden {
    display: none !important;
}

#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: grid;
    place-items: center;
    z-index: 10000;
}

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid rgba(16, 185, 129, .18);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin .85s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--bottom-nav-height) + 20px);
    transform: translateX(-50%);
    z-index: 10001;
    min-width: 220px;
    max-width: calc(100vw - 32px);
    padding: 10px 15px;
    border-radius: 999px;
    background: #17201b;
    color: #fff;
    text-align: center;
    font-weight: 600;
    font-size: .82rem;
    box-shadow: var(--shadow);
    transition: .25s ease;
}

.toast.success { background: var(--primary-dark); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.hidden {
    display: block !important;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 10px);
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(180deg, var(--primary) 0 30%, var(--bg) 30% 100%);
}

.login-card {
    width: min(390px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 30px 22px;
    text-align: center;
    box-shadow: var(--shadow);
}

.login-logo {
    width: 58px;
    height: 58px;
    margin: 0 auto 14px;
    border-radius: 20px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    display: grid;
    place-items: center;
    font-size: 26px;
}

.login-card h1 {
    font-size: 1.55rem;
    margin-bottom: 6px;
}

.login-card p {
    color: var(--muted);
    margin-bottom: 20px;
}

.btn-primary, .btn-secondary, .btn-danger {
    width: 100%;
    min-height: 46px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    font-weight: 700;
}

.login-form {
    display: grid;
    gap: 12px;
    text-align: left;
}

.login-form label {
    display: grid;
    gap: 7px;
}

.login-form span {
    color: var(--muted);
    font-size: .76rem;
    font-weight: 700;
}

.login-form input {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--border);
    border-radius: 14px;
    outline: 0;
    padding: 0 13px;
    background: var(--surface);
    color: var(--text);
}

.login-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--muted-surface); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }

.error-message {
    color: var(--danger) !important;
    min-height: 18px;
    margin-top: 14px !important;
    margin-bottom: 0 !important;
}

.app-shell {
    min-height: 100vh;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    background: var(--bg);
}

.app-shell.hidden .bottom-nav,
.app-shell.hidden .fab {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.hero-header {
    background: var(--primary);
    color: #fff;
    padding: 14px 18px 20px;
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;
    box-shadow: 0 10px 22px rgba(16, 185, 129, .20);
    touch-action: pan-y;
    transition: transform .22s ease, opacity .22s ease;
}

.hero-header.swiping-left { transform: translateX(-8px); opacity: .94; }
.hero-header.swiping-right { transform: translateX(8px); opacity: .94; }

.top-actions, .month-selector, .status-grid, .section-heading, .settings-item, .sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.eyebrow {
    display: block;
    font-size: .68rem;
    opacity: .78;
    font-weight: 600;
}

.top-actions h1 {
    font-size: 1.18rem;
    letter-spacing: -.03em;
}

.header-buttons {
    display: flex;
    gap: 8px;
}

.icon-button, .month-button, .small-icon-btn, .close-sheet-btn, .details-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,.16);
    color: #fff;
}

.month-selector {
    margin: 16px 0 12px;
}

.month-selector strong {
    text-transform: capitalize;
    font-size: .86rem;
    letter-spacing: -.02em;
}

.total-card span, .status-grid span {
    display: block;
    font-size: .72rem;
    opacity: .84;
}

.total-card strong {
    display: block;
    font-size: 1.82rem;
    line-height: 1.05;
    letter-spacing: -.055em;
    margin-top: 4px;
}

.status-grid {
    margin-top: 14px;
    gap: 10px;
}

.status-grid > div {
    flex: 1;
    padding: 10px 12px;
    border-radius: 15px;
    background: rgba(255,255,255,.14);
    backdrop-filter: blur(8px);
    min-width: 0;
}

.status-grid strong {
    display: block;
    margin-top: 4px;
    font-size: .86rem;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.content-view {
    width: min(620px, 100%);
    margin: 0 auto;
    padding: 16px 14px 14px;
    touch-action: pan-y;
}

.view {
    display: none;
    animation: fadeUp .22s ease;
}

.view.active { display: block; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.limit-box, .chart-card, .settings-list, .expense-item, .details-card {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
}

.limit-box {
    padding: 12px 14px;
    border-radius: 17px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.limit-box span, .section-heading span, .details-card span, .settings-item span {
    color: var(--muted);
    font-size: .74rem;
}

.limit-box strong {
    display: block;
    margin-top: 2px;
    font-size: .93rem;
}

.limit-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.limit-input-wrap {
    display: flex;
    width: 122px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--muted-surface);
}

.limit-input-wrap input {
    width: 78px;
    border: 0;
    outline: 0;
    background: transparent;
    padding-left: 10px;
    color: var(--text);
}

.limit-input-wrap button {
    flex: 1;
    color: #fff;
    background: var(--primary);
}

.small-icon-btn {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.notification {
    margin-top: 9px;
    border-radius: 13px;
    padding: 9px 11px;
    font-size: .78rem;
    font-weight: 600;
}

.notification.warning { background: #fef3c7; color: #92400e; }
.notification.danger { background: var(--danger-soft); color: #991b1b; }
.limit-exceeded { border-color: rgba(239, 68, 68, .5); }
.limit-value-exceeded { color: var(--danger); }

.section-heading {
    margin: 17px 0 11px;
}

.section-heading h2 {
    font-size: 1rem;
    letter-spacing: -.02em;
}

.expense-list {
    display: grid;
    gap: 9px;
}

.expense-date-header {
    margin: 7px 4px 0;
    color: var(--muted);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.expense-item {
    width: 100%;
    min-height: 58px;
    padding: 9px 10px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    overflow: hidden;
}

.expense-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.expense-day {
    display: none !important;
}

.expense-icon {
    width: 34px;
    min-width: 34px;
    height: 34px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: .82rem;
}

.expense-text {
    min-width: 0;
    flex: 1;
}

.expense-text strong {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    font-size: .82rem;
    line-height: 1.12;
    letter-spacing: -.01em;
}

.expense-text span {
    color: var(--muted);
    font-size: .66rem;
}

.expense-right {
    text-align: right;
    font-weight: 800;
    white-space: nowrap;
    font-size: .78rem;
    max-width: 86px;
    min-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    margin-top: 3px;
    border-radius: 50%;
    font-size: .46rem;
}

.status-indicator.unpaid { background: var(--danger); }
.status-indicator.paid { color: #fff; background: var(--primary); }

.empty-state {
    min-height: 170px;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 18px;
    color: var(--muted);
}

.empty-illustration {
    width: 86px;
    height: 86px;
    margin: 0 auto 12px;
    border-radius: 28px;
    background: linear-gradient(135deg, var(--primary-soft), rgba(16, 185, 129, .08));
    display: grid;
    place-items: center;
    color: var(--primary-dark);
    font-size: 32px;
}

.empty-state h3 {
    color: var(--text);
    margin-bottom: 4px;
    font-size: .95rem;
}

.empty-state p { font-size: .82rem; }

.chart-card {
    border-radius: 19px;
    padding: 14px;
    min-height: 250px;
}

.chart-card-large { min-height: 300px; }

.breakdown-list {
    margin-top: 12px;
    display: grid;
    gap: 9px;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--muted-surface);
}

.settings-list {
    border-radius: 19px;
    overflow: hidden;
}

.settings-item {
    width: 100%;
    min-height: 62px;
    padding: 12px 14px;
    background: var(--surface);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    text-align: left;
    gap: 10px;
}

.settings-item:last-child { border-bottom: 0; }
.settings-item strong, .settings-item span { display: block; }
.settings-item strong { font-size: .88rem; }
.button-item i { color: var(--primary); }
.file-item { cursor: pointer; }

.switch-input {
    position: absolute;
    opacity: 0;
}

.switch {
    width: 42px;
    min-width: 42px;
    height: 26px;
    border-radius: 999px;
    background: #d7dedb;
    position: relative;
    transition: .2s ease;
}

.switch::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 7px rgba(0,0,0,.18);
    transition: .2s ease;
}

.switch-input:checked + .switch { background: var(--primary); }
.switch-input:checked + .switch::after { transform: translateX(16px); }

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: min(620px, 100%);
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding: 5px 10px calc(5px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 1fr 1fr 56px 1fr 1fr;
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 20px rgba(15, 23, 42, .07);
    z-index: 50;
}

.nav-item {
    color: var(--muted);
    background: transparent;
    display: grid;
    gap: 2px;
    justify-items: center;
    font-size: .61rem;
    font-weight: 700;
}

.nav-item i { font-size: .9rem; }
.nav-item.active { color: var(--primary); }

.fab {
    position: fixed;
    left: 50%;
    bottom: calc(30px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 1.3rem;
    box-shadow: 0 12px 26px rgba(16, 185, 129, .30);
    z-index: 70;
}

.sheet-backdrop, .dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .42);
    z-index: 100;
    opacity: 1;
    transition: .22s ease;
}

.sheet-backdrop.hidden, .dialog-backdrop.hidden {
    display: block !important;
    opacity: 0;
    pointer-events: none;
}

.bottom-sheet {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translate(-50%, 105%);
    width: min(620px, 100%);
    max-height: min(88vh, 720px);
    overflow-y: auto;
    background: var(--surface);
    border-top-left-radius: 23px;
    border-top-right-radius: 23px;
    padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow);
    z-index: 120;
    transition: transform .28s cubic-bezier(.2,.9,.25,1);
}

.bottom-sheet.open { transform: translate(-50%, 0); }
.compact-sheet { max-height: 70vh; }

.sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 99px;
    background: var(--border);
    margin: 2px auto 13px;
}

.sheet-header {
    gap: 12px;
    margin-bottom: 13px;
}

.sheet-header h2 { font-size: 1rem; }
.sheet-header p { color: var(--muted); font-size: .75rem; }
.close-sheet-btn { background: var(--muted-surface); color: var(--text); }

.sheet-header > div:first-child {
    min-width: 0;
}

.details-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.details-icon-btn {
    background: var(--muted-surface);
    color: var(--primary-dark);
}

.details-icon-btn.danger-action {
    color: var(--danger);
}

.expense-form {
    display: grid;
    gap: 13px;
}

.amount-field {
    display: grid;
    gap: 7px;
    padding: 14px;
    border-radius: 19px;
    background: var(--muted-surface);
}

.amount-field span, .input-group span {
    color: var(--muted);
    font-size: .74rem;
    font-weight: 600;
}

.amount-field input {
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -.04em;
    width: 100%;
}

.form-grid, .input-group {
    display: grid;
    gap: 8px;
}

.input-group input, .category-form input {
    width: 100%;
    border: 1px solid var(--border);
    outline: 0;
    min-height: 46px;
    border-radius: 13px;
    padding: 0 12px;
    background: var(--surface);
    color: var(--text);
}

.category-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.category-chip {
    min-height: 58px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 14px;
    display: grid;
    gap: 4px;
    justify-items: center;
    align-content: center;
    font-size: .64rem;
    font-weight: 700;
}

.category-chip i {
    font-size: .95rem;
    color: var(--primary);
}

.category-chip.active {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.repeat-option {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
}

.repeat-option input { display: none; }

.fake-radio {
    width: 19px;
    height: 19px;
    border-radius: 50%;
    border: 2px solid var(--border);
    position: relative;
}

.repeat-option input:checked + .fake-radio { border-color: var(--primary); }
.repeat-option input:checked + .fake-radio::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: var(--primary);
}

.radio-group {
    display: grid;
    gap: 9px;
    padding: 10px;
    border-radius: 14px;
    background: var(--muted-surface);
}

.details-card {
    border-radius: 17px;
    padding: 13px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 11px;
    margin-bottom: 11px;
}

.details-card strong {
    display: block;
    margin-top: 3px;
    font-size: .9rem;
}

.sheet-actions {
    display: grid;
    gap: 8px;
}

.sheet-actions button {
    min-height: 46px;
    border-radius: 14px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.sheet-actions .paid-action {
    background: var(--primary);
    color: #fff;
}

.sheet-actions .unpaid-action {
    background: var(--danger);
    color: #fff;
}

.dialog-backdrop {
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 150;
}

.dialog-box {
    width: min(390px, 100%);
    background: var(--surface);
    border-radius: 21px;
    padding: 19px;
    box-shadow: var(--shadow);
}

.dialog-box h2 {
    margin-bottom: 8px;
    font-size: 1.05rem;
}

.dialog-box p {
    color: var(--muted);
    margin-bottom: 16px;
}

.dialog-actions {
    display: grid;
    gap: 8px;
}

.category-form {
    display: grid;
    grid-template-columns: 1fr 112px;
    gap: 8px;
    margin-bottom: 13px;
}

.managed-categories-list {
    display: grid;
    gap: 8px;
}

.managed-category {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 11px;
    border-radius: 14px;
    background: var(--muted-surface);
}

.managed-category button {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    color: var(--danger);
    background: var(--danger-soft);
}

@media (min-width: 720px) {
    body { background: var(--muted-surface); }

    .app-shell, .bottom-nav, .bottom-sheet {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }

    .app-shell {
        width: min(620px, 100%);
        margin: 0 auto;
        background: var(--bg);
    }
}

@media (max-width: 380px) {
    body { font-size: 12.5px; }

    .hero-header {
        padding: 13px 14px 18px;
        border-bottom-left-radius: 23px;
        border-bottom-right-radius: 23px;
    }

    .content-view { padding: 14px 10px 12px; }
    .top-actions h1 { font-size: 1.1rem; }
    .month-selector strong { font-size: .82rem; }
    .total-card strong { font-size: 1.62rem; }
    .status-grid > div { padding: 9px 10px; }
    .status-grid strong { font-size: .78rem; }

    .expense-item {
        min-height: 54px;
        padding: 8px 9px;
        border-radius: 15px;
    }

    .expense-icon {
        width: 32px;
        min-width: 32px;
        height: 32px;
        border-radius: 11px;
    }

    .expense-left { gap: 7px; }
    .expense-text strong { font-size: .76rem; }
    .expense-text span { font-size: .62rem; }

    .expense-right {
        font-size: .72rem;
        max-width: 76px;
        min-width: 62px;
    }

    .category-picker { grid-template-columns: repeat(2, 1fr); }

    .bottom-nav { grid-template-columns: 1fr 1fr 52px 1fr 1fr; }

    .fab {
        width: 52px;
        height: 52px;
        bottom: calc(29px + env(safe-area-inset-bottom));
    }
}
