@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Reset ───────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ── Design Tokens ───────────────────────── */
:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #f0f1f6;
    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.16);

    --text-primary: #0e1117;
    --text-secondary: #5a6072;
    --text-muted: #9aa0b4;

    --emerald: #059669;
    --emerald-light: #d1fae5;
    --emerald-dark: #047857;

    --rose: #e11d48;
    --rose-light: #ffe4e6;
    --rose-dark: #be123c;

    --navy: #1e2a45;
    --blue: #3b82f6;
    --blue-light: #eff6ff;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.10), 0 4px 8px rgba(0, 0, 0, 0.04);

    --font-body: 'Inter', system-ui, sans-serif;
    --font-mono: 'DM Mono', 'Courier New', monospace;
}

/* ── Dark Mode ───────────────────────────── */
body.dark {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2230;
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.16);

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;

    --emerald: #34d399;
    --emerald-light: rgba(52, 211, 153, 0.12);
    --emerald-dark: #6ee7b7;

    --rose: #fb7185;
    --rose-light: rgba(251, 113, 133, 0.12);
    --rose-dark: #fda4af;

    --navy: #e6edf3;
    --blue: #60a5fa;
    --blue-light: rgba(96, 165, 250, 0.12);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* ── Base ────────────────────────────────── */
html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.25s ease, color 0.25s ease;
    padding-bottom: 60px;
}

/* ── Header ──────────────────────────────── */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

header h1 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#darkToggle {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#darkToggle:hover {
    border-color: var(--border-hover);
    background: var(--surface);
    transform: rotate(12deg);
}

/* ── Page Layout ─────────────────────────── */
.summary,
.form-section,
.transactions-section {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ── Summary Cards ───────────────────────── */
.summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding-top: 28px;
    padding-bottom: 4px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px 18px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* Subtle top accent bar */
.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.income-card::before {
    background: var(--emerald);
}

.expense-card::before {
    background: var(--rose);
}

.balance-card::before {
    background: var(--blue);
}

.card-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.card-amount {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 500;
    letter-spacing: -0.5px;
    line-height: 1;
}

.income-card .card-amount {
    color: var(--emerald);
}

.expense-card .card-amount {
    color: var(--rose);
}

.balance-card .card-amount {
    color: var(--text-primary);
}

/* ── Form Section ────────────────────────── */
.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 24px 26px 22px;
    box-shadow: var(--shadow-sm);
    margin-top: 20px;
}

.form-section h2 {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-size: 11px;
    margin-bottom: 18px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 18px;
}

/* ── Field Labels ────────────────────────── */
.field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.2px;
}

/* ── Inputs ──────────────────────────────── */
.field input,
.field select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
}

.field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

.field input:hover,
.field select:hover {
    border-color: var(--border-hover);
}

.field input:focus,
.field select:focus {
    border-color: var(--blue);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--blue-light);
}

.field input::placeholder {
    color: var(--text-muted);
}

/* ── Error state ─────────────────────────── */
.field input.error {
    border-color: var(--rose);
    background: var(--rose-light);
    box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.08);
}

.error-msg {
    font-size: 11px;
    color: var(--rose);
    margin-top: 5px;
    display: none;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}

.error-msg.show {
    display: flex;
    animation: slideIn 0.3s ease forwards;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Type Toggle Buttons ─────────────────── */
.type-btns {
    display: flex;
    gap: 8px;
    height: 40px;
}

.type-btn {
    flex: 1;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.18s ease;
    letter-spacing: 0.1px;
}

.type-btn:hover {
    border-color: var(--border-hover);
    background: var(--surface);
}

.type-btn.active[data-type="income"] {
    background: var(--emerald-light);
    border-color: var(--emerald);
    color: var(--emerald-dark);
    font-weight: 600;
}

.type-btn.active[data-type="expense"] {
    background: var(--rose-light);
    border-color: var(--rose);
    color: var(--rose-dark);
    font-weight: 600;
}

/* ── Add Button ──────────────────────────── */
.add-btn {
    width: 100%;
    height: 44px;
    background: var(--navy);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.2px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

body.dark .add-btn {
    background: #e6edf3;
    color: #0d1117;
}

.add-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.add-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

/* ── Transactions Section ────────────────── */
.transactions-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 22px 26px;
    box-shadow: var(--shadow-sm);
    margin-top: 16px;
}

.transactions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 12px;
}

.transactions-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

/* ── Filters ─────────────────────────────── */
.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.filters select {
    height: 34px;
    padding: 0 28px 0 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.2s ease;
}

.filters select:hover {
    border-color: var(--border-hover);
}

.filters select:focus {
    border-color: var(--blue);
    outline: none;
}

#clearAllBtn {
    height: 34px;
    padding: 0 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 500;
    color: var(--rose);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

#clearAllBtn:hover {
    background: var(--rose-light);
    border-color: var(--rose);
}

/* ── Transaction Item ────────────────────── */
#transactionList {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.transaction-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: all 0.18s ease;
    cursor: default;
}

.transaction-item:hover {
    border-color: var(--border-hover);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transform: translateX(2px);
}

.transaction-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

/* Category icon pill */
.transaction-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--border);
}

.transaction-item.income .transaction-icon {
    background: var(--emerald-light);
    border-color: transparent;
}

.transaction-item.expense .transaction-icon {
    background: var(--rose-light);
    border-color: transparent;
}

.transaction-desc {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
    letter-spacing: -0.1px;
}

.transaction-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
    font-weight: 400;
}

.transaction-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.transaction-amount {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -0.3px;
}

.transaction-item.income .transaction-amount {
    color: var(--emerald);
}

.transaction-item.expense .transaction-amount {
    color: var(--rose);
}

.delete-btn {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    cursor: pointer;
    opacity: 0;
    color: var(--text-muted);
    transition: all 0.15s ease;
}

.transaction-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: var(--rose-light);
    color: var(--rose);
    opacity: 1;
}

/* ── Empty State ─────────────────────────── */
.empty-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    gap: 6px;
}

.empty-state p:first-child {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
}

.empty-state p:last-child {
    font-size: 13px;
    color: var(--text-muted);
}

/* ── Scrollbar ───────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* ── Responsive ──────────────────────────── */
@media (max-width: 640px) {
    header {
        padding: 0 16px;
    }

    .summary,
    .form-section,
    .transactions-section {
        padding: 0 12px;
    }

    .summary {
        grid-template-columns: 1fr;
        padding-top: 16px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-section,
    .transactions-section {
        border-radius: var(--radius-lg);
        padding: 18px 16px;
    }

    .card-amount {
        font-size: 22px;
    }

    .transaction-desc {
        max-width: 160px;
    }

    .transactions-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .filters {
        width: 100%;
    }

    .filters select {
        flex: 1;
    }
}

/* ── Focus Accessibility ─────────────────── */
*:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}