:root {
    --bg: #f5f7f6;
    --surface: #ffffff;
    --surface-muted: #eef3f1;
    --text: #17211f;
    --muted: #66736f;
    --border: #dce5e2;
    --accent: #146c5f;
    --accent-soft: #dcefeb;
    --income: #18794e;
    --expense: #b42318;
    --saving: #2264a5;
    --warning: #b76e00;
    --danger-soft: #fde8e5;
    --radius: 8px;
    --shadow: 0 16px 40px rgba(22, 40, 35, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

body {
    margin: 0;
    min-width: 320px;
}

a {
    color: inherit;
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    display: none;
}

.main-shell {
    min-width: 0;
}

.content {
    width: min(100%, 1320px);
    margin: 0 auto;
    padding: 16px 16px 88px;
}

.topbar {
    display: grid;
    gap: 12px;
    padding: 18px 16px 12px;
    background: rgba(245, 247, 246, 0.94);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(12px);
}

.topbar h1,
.page-title {
    margin: 0;
    font-size: clamp(1.45rem, 2vw, 2.1rem);
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 3px;
    color: var(--muted);
    font-size: 0.82rem;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 22px 18px;
}

.brand small {
    display: block;
    color: var(--muted);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    font-weight: 800;
}

.nav-menu {
    display: grid;
    gap: 4px;
    padding: 8px;
}

.nav-menu a,
.bottom-nav a {
    text-decoration: none;
    color: var(--muted);
    border-radius: var(--radius);
}

.nav-menu a {
    padding: 11px 12px;
}

.nav-menu a.active,
.nav-menu a:hover {
    color: var(--text);
    background: var(--accent-soft);
}

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--border);
    z-index: 20;
}

.bottom-nav a {
    text-align: center;
    padding: 10px 4px;
    font-size: 0.82rem;
}

.bottom-nav a.active {
    color: var(--accent);
    background: var(--accent-soft);
    font-weight: 700;
}

.grid {
    display: grid;
    gap: 14px;
}

.dashboard-grid {
    display: grid;
    gap: 14px;
}

.two-col,
.three-col,
.four-col {
    display: grid;
    gap: 14px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-pad {
    padding: 16px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin: 22px 0 10px;
}

.section-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.muted {
    color: var(--muted);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.summary-value {
    margin: 0;
    font-size: clamp(1.5rem, 4vw, 2.2rem);
}

.chart-bars {
    display: grid;
    gap: 10px;
}

.chart-row {
    display: grid;
    grid-template-columns: 88px 1fr auto;
    gap: 10px;
    align-items: center;
}

.bar {
    height: 12px;
    border-radius: 999px;
    background: var(--surface-muted);
    overflow: hidden;
}

.bar span {
    display: block;
    height: 100%;
    width: min(var(--value), 100%);
    background: var(--accent);
}

.danger-panel {
    background: var(--danger-soft);
    border-color: #fac5bd;
}

.money {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.money.income {
    color: var(--income);
}

.money.expense {
    color: var(--expense);
}

.amount-cell {
    text-align: right;
}

.status-pill,
.sync-pill,
.category-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 999px;
    padding: 6px 10px;
    background: var(--surface-muted);
    color: var(--text);
    font-size: 0.86rem;
}

.category-button {
    border: 0;
    background: transparent;
    padding: 0;
    cursor: pointer;
}

.category-editor {
    display: grid;
    gap: 8px;
    min-width: 260px;
}

.category-editor select,
.category-editor input[type="text"],
.category-editor input:not([type]) {
    width: 100%;
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 7px 9px;
    background: white;
    color: var(--text);
}

.checkbox-line,
.category-editor-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.category-editor-actions {
    flex-wrap: wrap;
}

.status-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--muted);
}

.status-updated {
    background: var(--income);
}

.status-syncing {
    background: var(--saving);
}

.status-error,
.status-expired,
.status-disconnected {
    background: var(--expense);
}

.button,
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    padding: 8px 12px;
    text-decoration: none;
    cursor: pointer;
}

.button.primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.button.danger {
    background: var(--danger-soft);
    color: var(--expense);
    border-color: #fac5bd;
}

.icon-button {
    width: 42px;
}

.filters {
    display: grid;
    gap: 10px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.field {
    display: grid;
    gap: 5px;
}

.field label {
    font-size: 0.82rem;
    color: var(--muted);
}

.field input,
.field select,
.field input[type="file"] {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    background: white;
    color: var(--text);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.82rem;
}

.mobile-list {
    display: grid;
    gap: 10px;
}

.desktop-table {
    display: none;
}

.progress-track {
    height: 10px;
    background: var(--surface-muted);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: min(var(--value), 100%);
    background: var(--accent);
}

.progress-fill.warning {
    background: var(--warning);
}

.progress-fill.danger {
    background: var(--expense);
}

.skeleton {
    min-height: 92px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, #edf2f0, #f8faf9, #edf2f0);
    background-size: 220% 100%;
    animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
    to {
        background-position: -220% 0;
    }
}

@media (min-width: 720px) {
    .content {
        padding: 22px 24px 96px;
    }

    .topbar {
        grid-template-columns: 1fr auto;
        align-items: center;
        padding: 18px 24px 14px;
    }

    .two-col,
    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filters {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .app-shell {
        display: grid;
        grid-template-columns: 260px minmax(0, 1fr);
    }

    .sidebar {
        display: block;
        min-height: 100vh;
        background: #ffffff;
        border-right: 1px solid var(--border);
        position: sticky;
        top: 0;
    }

    .bottom-nav {
        display: none;
    }

    .content {
        padding: 26px 32px 48px;
    }

    .three-col {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .four-col {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .dashboard-grid {
        grid-template-columns: 1.5fr 1fr;
    }

    .filters {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .desktop-table {
        display: block;
    }

    .mobile-list {
        display: none;
    }
}

.login-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background: var(--bg);
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2.5rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.login-card .brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
}

.login-card .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
}

.login-card h1 {
    font-size: 1.25rem;
    margin: 0 0 0.25rem;
}

.auth-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 5px;
    margin: 1.5rem 0;
    background: var(--surface-muted);
    border-radius: var(--radius);
}

.auth-tab {
    min-height: 38px;
    border: 0;
    border-radius: calc(var(--radius) - 2px);
    background: transparent;
    color: var(--muted);
    font-weight: 700;
    cursor: pointer;
}

.auth-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(18, 35, 31, 0.08);
}

.auth-form {
    display: grid;
    gap: 1rem;
    text-align: left;
}

.auth-submit {
    width: 100%;
    margin-top: 0.25rem;
}

.validation-errors {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem 0.75rem 2rem;
    border-radius: var(--radius);
    background: var(--danger-soft);
    color: var(--expense);
    text-align: left;
    font-size: 0.875rem;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: var(--danger-soft);
    color: var(--expense);
}

.alert-info {
    background: var(--surface-muted);
    color: var(--text);
}

.bank-results {
    display: grid;
    gap: 8px;
    max-height: 420px;
    overflow: auto;
}

.bank-result {
    display: grid;
    grid-template-columns: 32px 1fr;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.bank-result img {
    max-width: 32px;
    max-height: 32px;
    object-fit: contain;
}

.import-panel {
    display: grid;
    gap: 14px;
}

.import-panel h3,
.import-panel p {
    margin: 0;
}

.import-grid {
    display: grid;
    gap: 10px;
}

.import-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0;
}

.button.small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.actions-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 1rem;
}

.user-badge {
    font-size: 0.8125rem;
    color: var(--muted);
    padding: 0.25rem 0.5rem;
    background: var(--surface-muted);
    border-radius: var(--radius);
}
