/* ============================================
   Personal Finance Tracker — Redesign
   Playful pastel style (mockup v2)
============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Surface */
    --bg: #F4F4F8;
    --surface: #FFFFFF;
    --border: #ECECF2;

    /* Text */
    --text: #0F172A;
    --text-2: #475569;
    --text-3: #94A3B8;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 8px 24px -8px rgba(15, 23, 42, 0.12), 0 2px 6px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.16), 0 4px 12px -4px rgba(15, 23, 42, 0.05);

    /* Radius */
    --r-sm: 10px;
    --r: 16px;
    --r-lg: 22px;
    --r-xl: 28px;

    /* Category palette */
    --purple-1: #A78BFA;
    --purple-2: #7C3AED;
    --blue-1: #60A5FA;
    --blue-2: #2563EB;
    --green-1: #4ADE80;
    --green-2: #16A34A;
    --orange-1: #FB923C;
    --orange-2: #EA580C;

    --nav-bg: #0F0F12;
}

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background:
        radial-gradient(ellipse at 15% 0%, rgba(139, 92, 246, 0.08), transparent 50%),
        radial-gradient(ellipse at 85% 100%, rgba(251, 146, 60, 0.06), transparent 50%),
        var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    line-height: 1.5;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}
button { background: none; border: none; cursor: pointer; }
input, select { outline: none; }
svg { width: 1em; height: 1em; flex-shrink: 0; }

/* ---------- Layout ---------- */
.app {
    max-width: 1080px;
    margin: 0 auto;
    padding: 32px 24px 56px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ---------- Header ---------- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

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

.brand-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--purple-1) 0%, var(--purple-2) 100%);
    color: white;
    display: grid;
    place-items: center;
    font-size: 22px;
    box-shadow: 0 8px 18px -6px rgba(124, 58, 237, 0.45);
}

.brand h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.brand-sub {
    font-size: 12.5px;
    color: var(--text-2);
    margin-top: 2px;
}

.date-display {
    font-size: 13px;
    color: var(--text-2);
    background: var(--surface);
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-weight: 500;
}

/* ---------- Balance hero ---------- */
.balance-hero {
    background: var(--surface);
    border-radius: var(--r-xl);
    padding: 24px 24px 22px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    position: relative;
    overflow: hidden;
}

.balance-hero::before {
    content: '';
    position: absolute;
    top: -60%;
    right: -10%;
    width: 220px;
    height: 220px;
    background: radial-gradient(circle, rgba(167, 139, 250, 0.15), transparent 70%);
    pointer-events: none;
}

.balance-content { flex: 1; min-width: 0; position: relative; z-index: 1; }

.balance-label {
    font-size: 13px;
    color: var(--text-2);
    font-weight: 500;
    display: block;
    margin-bottom: 4px;
}

.balance-value {
    font-size: 38px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.05;
    color: var(--text);
    margin-bottom: 18px;
}

.balance-stats {
    display: flex;
    gap: 22px;
    flex-wrap: wrap;
}

.stat { display: flex; flex-direction: column; gap: 2px; }

.stat-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-2);
    font-weight: 500;
}

.stat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.stat-dot.income { background: var(--green-2); }
.stat-dot.expense { background: #EF4444; }
.stat-dot.count { background: #F59E0B; }

.stat-label { font-size: 12px; }

.stat-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.balance-trend {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #F3EEFF 0%, #E8DEFF 100%);
    color: var(--purple-2);
    display: grid;
    place-items: center;
    font-size: 20px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    box-shadow: 0 4px 12px -4px rgba(124, 58, 237, 0.25);
}

/* ---------- Pill row ---------- */
.pill-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 6px;
    background: var(--surface);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.pill:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.pill-icon {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    background: var(--bg);
    color: var(--text);
    border-radius: 10px;
    font-size: 15px;
}

.pill-name {
    font-size: 12px;
    color: var(--text-2);
    font-weight: 500;
}

/* ---------- Section head ---------- */
.sec-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.sec-head h2 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sec-action {
    font-size: 12px;
    color: var(--text-3);
    font-weight: 500;
    cursor: pointer;
}

/* ---------- Category grid ---------- */
.cat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.cat-card {
    position: relative;
    border-radius: var(--r-lg);
    padding: 16px;
    min-height: 110px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    color: white;
    overflow: hidden;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 8px 18px -8px rgba(15, 23, 42, 0.2);
}

.cat-card:hover { transform: translateY(-2px); box-shadow: 0 12px 24px -8px rgba(15, 23, 42, 0.25); }

.cat-card::before {
    content: '';
    position: absolute;
    top: -35%;
    right: -25%;
    width: 110px;
    height: 110px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    pointer-events: none;
}

.cat-card.purple { background: linear-gradient(135deg, var(--purple-1) 0%, var(--purple-2) 100%); }
.cat-card.blue { background: linear-gradient(135deg, var(--blue-1) 0%, var(--blue-2) 100%); }
.cat-card.green { background: linear-gradient(135deg, var(--green-1) 0%, var(--green-2) 100%); }
.cat-card.orange { background: linear-gradient(135deg, var(--orange-1) 0%, var(--orange-2) 100%); }

.cat-icon {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.22);
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-size: 17px;
    backdrop-filter: blur(6px);
    position: relative;
    z-index: 1;
}

.cat-icon svg { color: white; }

.cat-meta { position: relative; z-index: 1; }

.cat-name {
    font-size: 12px;
    font-weight: 500;
    opacity: 0.95;
}

.cat-amount {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-top: 2px;
}

/* ---------- Main grid ---------- */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1.1fr;
    gap: 20px;
}

/* ---------- Card ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px;
    box-shadow: var(--shadow-sm);
}

.card-header { margin-bottom: 18px; }

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.card-header p {
    font-size: 12.5px;
    color: var(--text-2);
    margin-top: 2px;
}

/* ---------- Form ---------- */
.transaction-form { display: flex; flex-direction: column; gap: 14px; }

.type-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: var(--bg);
    padding: 4px;
    border-radius: var(--r-sm);
}

.type-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    transition: all 0.15s ease;
}

.type-btn svg { font-size: 13px; }
.type-btn:hover { color: var(--text); }

.type-btn.active[data-type="expense"] {
    background: #EF4444;
    color: white;
    box-shadow: 0 4px 8px -2px rgba(239, 68, 68, 0.35);
}

.type-btn.active[data-type="income"] {
    background: var(--green-2);
    color: white;
    box-shadow: 0 4px 8px -2px rgba(22, 163, 74, 0.35);
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input::placeholder { color: var(--text-3); }

.form-group input:focus,
.form-group select:focus {
    border-color: var(--purple-2);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

.form-group input:hover,
.form-group select:hover { border-color: #CFD3E0; }

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

.input-prefix { position: relative; }

.input-prefix span {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-2);
    font-weight: 500;
    pointer-events: none;
}

.input-prefix input { padding-left: 28px !important; }

select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3e%3cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 14px center !important;
    padding-right: 36px !important;
    cursor: pointer;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--purple-1) 0%, var(--purple-2) 100%);
    color: white;
    padding: 12px 20px;
    border-radius: var(--r-sm);
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 6px 14px -4px rgba(124, 58, 237, 0.4);
    transition: all 0.15s ease;
    margin-top: 2px;
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 18px -4px rgba(124, 58, 237, 0.5); }
.btn-primary:active { transform: translateY(0); }
.btn-primary svg { font-size: 16px; }

/* ---------- Chart ---------- */
.chart-container {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    height: 200px;
    padding: 16px 0 8px;
    overflow-x: auto;
}

.chart-bar-group {
    flex: 1;
    min-width: 38px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    height: 100%;
}

.chart-bars {
    display: flex;
    gap: 5px;
    align-items: flex-end;
    flex: 1;
    width: 100%;
    justify-content: center;
    padding-bottom: 4px;
}

.chart-bar {
    width: 14px;
    border-radius: 6px 6px 0 0;
    min-height: 3px;
    transition: opacity 0.2s, transform 0.2s;
    cursor: default;
}

.chart-bar:hover { transform: scaleY(1.04); transform-origin: bottom; }

.chart-bar.income { background: linear-gradient(180deg, var(--green-1) 0%, var(--green-2) 100%); }
.chart-bar.expense { background: linear-gradient(180deg, #FCA5A5 0%, #EF4444 100%); }

.chart-label {
    font-size: 11px;
    color: var(--text-2);
    font-weight: 500;
}

.chart-legend {
    display: flex;
    gap: 20px;
    justify-content: center;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--text-2);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.income-dot { background: linear-gradient(135deg, var(--green-1), var(--green-2)); }
.expense-dot { background: linear-gradient(135deg, #FCA5A5, #EF4444); }

/* ---------- List ---------- */
.list-card { padding: 0; overflow: hidden; }

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 22px 22px 14px;
    margin-bottom: 0;
    flex-wrap: wrap;
    gap: 14px;
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; }

.search-box { position: relative; display: flex; align-items: center; }

.search-box svg {
    position: absolute;
    left: 12px;
    color: var(--text-3);
    font-size: 14px;
    pointer-events: none;
}

.search-box input {
    padding: 9px 12px 9px 34px;
    border: 1.5px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 13px;
    width: 180px;
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-box input:focus {
    border-color: var(--purple-2);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

.filter-select {
    padding: 9px 32px 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 13px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s;
}

.filter-select:hover { border-color: #CFD3E0; }
.filter-select:focus {
    border-color: var(--purple-2);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

.transactions-list {
    max-height: 480px;
    overflow-y: auto;
}

.transactions-list::-webkit-scrollbar { width: 8px; }
.transactions-list::-webkit-scrollbar-track { background: var(--bg); }
.transactions-list::-webkit-scrollbar-thumb { background: #CFD3E0; border-radius: 4px; }
.transactions-list::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

.transaction-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 22px;
    border-top: 1px solid var(--border);
    transition: background 0.15s;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.transaction-item:hover { background: #FAFAFD; }

.transaction-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-size: 19px;
    flex-shrink: 0;
    background: var(--bg);
}

.transaction-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.transaction-description {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transaction-meta {
    font-size: 12px;
    color: var(--text-3);
    display: flex;
    gap: 8px;
    align-items: center;
}

.transaction-meta .dot {
    width: 3px;
    height: 3px;
    background: var(--text-3);
    border-radius: 50%;
}

.transaction-amount {
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.transaction-item.income .transaction-amount { color: var(--green-2); }
.transaction-item.expense .transaction-amount { color: #DC2626; }

.transaction-delete {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-3);
    display: grid;
    place-items: center;
    transition: all 0.15s;
    opacity: 0;
}

.transaction-item:hover .transaction-delete { opacity: 1; }

.transaction-delete:hover {
    background: #FEE2E2;
    color: #DC2626;
}

.transaction-delete svg { font-size: 15px; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 56px 24px;
    display: none;
}

.empty-state.show { display: block; }

.empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    background: var(--bg);
    border-radius: 18px;
    display: grid;
    place-items: center;
    color: var(--text-3);
    font-size: 26px;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 13.5px;
    color: var(--text-2);
    max-width: 320px;
    margin: 0 auto;
}

/* ---------- Footer ---------- */
.app-footer {
    text-align: center;
    font-size: 12.5px;
    color: var(--text-3);
    padding-top: 8px;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    background: var(--nav-bg);
    color: white;
    padding: 12px 20px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast svg { color: var(--green-1); font-size: 16px; }

.toast.error { background: #B91C1C; }
.toast.error svg { color: #FCA5A5; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .main-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .app { padding: 20px 14px 40px; gap: 16px; }
    .brand h1 { font-size: 19px; }
    .brand-sub { font-size: 12px; }
    .brand-icon { width: 42px; height: 42px; font-size: 19px; }

    .balance-hero { padding: 20px; border-radius: var(--r-lg); }
    .balance-value { font-size: 30px; }
    .balance-stats { gap: 16px; }

    .pill { padding: 10px 4px; }
    .pill-icon { width: 28px; height: 28px; font-size: 13px; }
    .pill-name { font-size: 11px; }

    .cat-card { padding: 14px; min-height: 96px; }
    .cat-icon { width: 32px; height: 32px; font-size: 15px; }
    .cat-amount { font-size: 17px; }

    .list-header { flex-direction: column; align-items: stretch; padding: 18px 18px 12px; }
    .filters { width: 100%; }
    .search-box input { flex: 1; width: auto; }

    .form-row { grid-template-columns: 1fr; }
    .transaction-item { padding: 11px 18px; }
    .transaction-delete { opacity: 1; }
    .chart-container { height: 170px; }
}
