:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f9fbfd;
    --text: #182538;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --positive: #15803d;
    --negative: #dc2626;
    --neutral: #374151;
    --purple: #7c3aed;
    --orange: #ea580c;
    --green: #16a34a;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
    color: var(--text);
}

.app-shell {
    max-width: 1420px;
    margin: 0 auto;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
}

.eyebrow {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: var(--primary);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

h1 {
    margin: 0;
    font-size: 38px;
    line-height: 1.1;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.sync-compact {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
    font-size: 13px;
    color: var(--muted);
}

.sync-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sync-dot.ok { background: #22c55e; }
.sync-dot.warn { background: #f59e0b; }
.sync-dot.error { background: #ef4444; }

.primary-button,
.ghost-button {
    border: 0;
    cursor: pointer;
    border-radius: 12px;
    font-weight: bold;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.primary-button {
    background: var(--primary);
    color: white;
    font-size: 15px;
    padding: 14px 18px;
    box-shadow: var(--shadow);
}

.primary-button:hover {
    background: var(--primary-hover);
}

.ghost-button {
    background: #eef2ff;
    color: #1e3a8a;
    padding: 10px 12px;
}

.logout-link {
    min-height: 42px;
}

.cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

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

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

.card-white {
    background: linear-gradient(135deg, #ffffff 0%, #f8fbff 100%);
}

.card-accent-blue { border-top: 5px solid var(--primary); }
.card-accent-green { border-top: 5px solid var(--green); }
.card-accent-purple { border-top: 5px solid var(--purple); }
.card-accent-orange { border-top: 5px solid var(--orange); }

.clickable {
    cursor: pointer;
}

.card-label {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: bold;
    margin-bottom: 12px;
}

.big-value {
    font-size: 40px;
    font-weight: bold;
    line-height: 1.05;
    margin-bottom: 10px;
}

.card-subtext {
    color: var(--muted);
    font-size: 14px;
}

.compact-card {
    padding-top: 18px;
    padding-bottom: 18px;
}

.month-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.compact-summary .amount {
    font-size: 24px;
}

.mini-label {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.amount {
    font-size: 28px;
    font-weight: bold;
}

.amount.positive { color: var(--positive); }
.amount.negative { color: var(--negative); }
.amount.neutral { color: var(--neutral); }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.section-header h2 {
    margin: 0;
    font-size: 26px;
}

.section-note {
    color: var(--muted);
    font-size: 14px;
}

.inline-controls,
.history-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.small-select {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: white;
}

.chart-card canvas {
    width: 100% !important;
    height: 320px !important;
}

.insights-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.insight-box {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    background: var(--surface-2);
}

.insight-main {
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 8px;
}

.insight-sub {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.4;
}

.list-block {
    display: grid;
    gap: 12px;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-2);
}

.list-item-main {
    font-weight: bold;
}

.list-item-sub {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.list-item-value {
    font-weight: bold;
    white-space: nowrap;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    font-size: 13px;
    color: var(--muted);
    font-weight: bold;
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

tbody td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

tbody tr:hover {
    background: #fafcff;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 24px;
}

.tx-description {
    font-weight: bold;
    margin-bottom: 4px;
}

.tx-subtext {
    color: var(--muted);
    font-size: 13px;
}

.badge {
    display: inline-block;
    font-size: 12px;
    font-weight: bold;
    padding: 6px 10px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
}

.value-positive {
    color: var(--positive);
    font-weight: bold;
}

.value-negative {
    color: var(--negative);
    font-weight: bold;
}

.value-neutral {
    color: var(--neutral);
    font-weight: bold;
}

.modal.hidden {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
}

.modal-content {
    position: relative;
    z-index: 1001;
    max-width: 640px;
    margin: 60px auto;
    background: white;
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.settings-form {
    display: grid;
    gap: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row {
    display: grid;
    gap: 8px;
}

.form-row label {
    font-size: 14px;
    color: var(--muted);
    font-weight: bold;
}

.form-row input,
.form-row textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 15px;
    background: white;
}

.form-row input:focus,
.form-row textarea:focus,
.small-select:focus {
    outline: 2px solid rgba(37, 99, 235, 0.15);
    border-color: var(--primary);
}

.form-actions {
    display: flex;
    justify-content: flex-start;
}

.form-feedback {
    font-size: 14px;
    color: var(--muted);
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
}

.login-card {
    width: 100%;
    max-width: 460px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 32px;
}

.login-title {
    margin: 0 0 10px 0;
    font-size: 34px;
}

.login-subtitle {
    margin: 0 0 22px 0;
    color: var(--muted);
}

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

.login-button {
    width: 100%;
    margin-top: 8px;
}

.login-error {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.login-success {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.auth-switch {
    margin-top: 18px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

.auth-switch a {
    color: var(--primary);
    font-weight: bold;
    text-decoration: none;
}

@media (max-width: 1200px) {
    .cards-grid-4 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 1024px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }

    .big-value {
        font-size: 34px;
    }
}

@media (max-width: 720px) {
    .app-shell {
        padding: 16px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-right {
        justify-content: space-between;
        flex-wrap: wrap;
    }

    h1 {
        font-size: 30px;
    }

    .month-summary,
    .insights-grid,
    .form-grid,
    .cards-grid-4 {
        grid-template-columns: 1fr;
    }

    .primary-button {
        width: 100%;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .list-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .modal-content {
        margin: 20px;
    }
}
