/* ─────────────────────────────────────────────
   SpendWise — UI v2
   ───────────────────────────────────────────── */

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

:root {
    --sidebar-w: 256px;
    --topbar-h: 64px;

    /* Money Theme — Green × Gold × Navy */
    --violet:    #16A34A;   /* money green — primary */
    --violet-d:  #15803D;   /* deep green */
    --violet-l:  #DCFCE7;   /* light green tint */
    --gold:      #D97706;   /* gold accent */
    --gold-l:    #FEF3C7;
    --pink:      #ec4899;
    --emerald:   #10b981;
    --amber:     #f59e0b;
    --sky:       #0ea5e9;
    --rose:      #ef4444;

    /* Surface */
    --bg:        #F1F5F9;
    --card:      #ffffff;
    --border:    #E2E8F0;
    --sidebar-bg:#071020;   /* deep navy */
    --topbar-bg: #ffffff;

    /* Text */
    --text:      #1E293B;
    --muted:     #64748B;
    --subtle:    #94A3B8;

    /* Misc */
    --radius:    14px;
    --radius-sm: 8px;
    --shadow:    0 1px 3px rgba(0,0,0,.05), 0 4px 16px rgba(22,163,74,.07);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.14);
    --transition: .2s ease;
}

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── App Shell ──────────────────────────────── */
.app { display: flex; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(170deg, #0D1F35 0%, #071020 100%);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    transition: transform var(--transition);
    overflow-y: auto;
    scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.4rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-icon {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--violet), var(--gold));
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.brand-name {
    font-size: 1.1rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: -.3px;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem .75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .7rem 1rem;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,.55);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    position: relative;
    transition: background var(--transition), color var(--transition);
}
.nav-item:hover {
    background: rgba(255,255,255,.07);
    color: rgba(255,255,255,.9);
}
.nav-item.active {
    background: rgba(22,163,74,.18);
    color: #86EFAC;
}
.nav-active-bar {
    position: absolute;
    right: 0; top: 20%; bottom: 20%;
    width: 3px;
    border-radius: 2px;
    background: var(--violet);
}
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-icon svg { width: 100%; height: 100%; }

.sidebar-footer {
    padding: 1rem 1.25rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,.06);
}
.month-badge {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .78rem;
    font-weight: 600;
    color: rgba(255,255,255,.4);
    letter-spacing: .3px;
    text-transform: uppercase;
}
.month-badge svg { opacity: .6; }

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 190;
    backdrop-filter: blur(2px);
}

/* ── Main area ──────────────────────────────── */
.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Topbar ─────────────────────────────────── */
.topbar {
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    height: var(--topbar-h);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-title { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.topbar-sub   { font-size: .8rem; color: var(--muted); margin-top: 1px; }
.hamburger {
    display: none;
    background: none; border: none; cursor: pointer;
    color: var(--text); padding: .3rem;
    border-radius: 6px;
}
.hamburger:hover { background: var(--border); }
.hamburger svg { width: 22px; height: 22px; }

.topbar-right { display: flex; align-items: center; gap: .75rem; }

/* ── Page content ───────────────────────────── */
.content { flex: 1; padding: 2rem; }

/* ── Stat Cards ─────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    border-radius: var(--radius);
    padding: 1.5rem;
    color: #fff;
    position: relative;
    overflow: hidden;
    cursor: default;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-card::after {
    content: '';
    position: absolute;
    top: -30%; right: -10%;
    width: 120px; height: 120px;
    background: rgba(255,255,255,.1);
    border-radius: 50%;
}
.stat-card::before {
    content: '';
    position: absolute;
    bottom: -40%; right: 15%;
    width: 80px; height: 80px;
    background: rgba(255,255,255,.07);
    border-radius: 50%;
}

.stat-card.violet  { background: linear-gradient(135deg, #15803D, #16A34A); }
.stat-card.rose    { background: linear-gradient(135deg, #ec4899, #f472b6); }
.stat-card.emerald { background: linear-gradient(135deg, #10b981, #34d399); }
.stat-card.amber   { background: linear-gradient(135deg, #f59e0b, #fbbf24); }

.stat-icon { font-size: 1.6rem; margin-bottom: .6rem; display: block; position: relative; z-index: 1; }
.stat-value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
    margin-bottom: .3rem;
    position: relative; z-index: 1;
}
.stat-label { font-size: .75rem; font-weight: 600; opacity: .8; text-transform: uppercase; letter-spacing: .5px; position: relative; z-index: 1; }
.stat-sub   { font-size: .78rem; opacity: .7; margin-top: .25rem; position: relative; z-index: 1; }

/* ── Grid Layouts ───────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
.grid-3-1 { display: grid; grid-template-columns: 1fr 340px; gap: 1.5rem; margin-bottom: 1.5rem; }

/* ── Panel / Card ───────────────────────────── */
.panel {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-header {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.panel-title { font-size: .95rem; font-weight: 700; }
.panel-body { padding: 1.5rem; }

/* ── Charts ─────────────────────────────────── */
.chart-wrap { position: relative; height: 240px; }

.donut-center {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}
.donut-center .dc-value { font-size: 1.4rem; font-weight: 800; color: var(--text); }
.donut-center .dc-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }

.chart-legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem .75rem;
    padding: 1rem 1.5rem 1.5rem;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .8rem;
    color: var(--text);
}
.legend-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.legend-name { flex: 1; color: var(--muted); font-size: .78rem; }
.legend-val  { font-weight: 700; font-size: .78rem; }

/* ── Table ──────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
    padding: .85rem 1.25rem;
    text-align: left;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
    background: #f8fafc;
    white-space: nowrap;
}
tbody tr {
    border-top: 1px solid var(--border);
    transition: background var(--transition);
}
tbody tr:hover { background: #fafbff; }
tbody td { padding: .9rem 1.25rem; vertical-align: middle; }

.expense-title { font-weight: 600; color: var(--text); }
.expense-sub   { font-size: .75rem; color: var(--muted); margin-top: 1px; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .3rem .75rem;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 700;
    white-space: nowrap;
}

.pay-badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .2rem .6rem;
    border-radius: 6px;
    font-size: .72rem;
    font-weight: 600;
    background: var(--bg);
    color: var(--muted);
    white-space: nowrap;
}

.amount-neg { color: var(--rose); font-weight: 700; font-size: .95rem; }

.action-btn {
    width: 32px; height: 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: .85rem;
    transition: background var(--transition), transform var(--transition);
}
.action-btn:active { transform: scale(.92); }
.btn-edit-sm  { background: #eff6ff; color: #2563eb; }
.btn-edit-sm:hover  { background: #dbeafe; }
.btn-del-sm   { background: #fff1f2; color: #e11d48; }
.btn-del-sm:hover   { background: #ffe4e6; }

/* ── Buttons ─────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .55rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
    font-family: inherit;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:hover  { opacity: .88; }

.btn-primary {
    background: linear-gradient(135deg, var(--violet), var(--violet-d));
    color: #fff;
    box-shadow: 0 4px 12px rgba(22,163,74,.3);
}
.btn-primary:hover { opacity: 1; box-shadow: 0 6px 20px rgba(22,163,74,.4); }

.btn-ghost   { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger  { background: #fee2e2; color: var(--rose); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: .35rem .8rem; font-size: .8rem; }
.btn svg { width: 16px; height: 16px; }

/* ── Fab (floating action) ──────────────────── */
.fab {
    position: fixed;
    bottom: 2rem; right: 2rem;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--violet), var(--gold));
    color: #fff;
    font-size: 1.5rem;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none;
    box-shadow: 0 8px 24px rgba(22,163,74,.4);
    transition: transform .2s, box-shadow .2s;
    z-index: 50;
}
.fab:hover { transform: scale(1.1) rotate(10deg); box-shadow: 0 12px 32px rgba(22,163,74,.5); }

/* ── Form ────────────────────────────────────── */
.form-page  { max-width: 680px; margin: 0 auto; }
.form-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.form-grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: .45rem; }
.field label { font-size: .8rem; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: .4px; }

.field input,
.field select,
.field textarea {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .7rem 1rem;
    font-size: .9rem;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: border var(--transition), box-shadow var(--transition);
    font-family: inherit;
    width: 100%;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--violet);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}
.field textarea { resize: vertical; min-height: 90px; }
.field .hint { font-size: .75rem; color: var(--muted); }
.field .error-msg { font-size: .75rem; color: var(--rose); font-weight: 500; }

.input-icon-wrap { position: relative; }
.input-icon-wrap .icon-prefix {
    position: absolute; left: .85rem; top: 50%; transform: translateY(-50%);
    color: var(--muted); font-size: .95rem; pointer-events: none;
}
.input-icon-wrap input { padding-left: 2.2rem; }

.form-section-title {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
    padding: 1.25rem 0 .5rem;
    border-top: 1px solid var(--border);
    margin-top: .5rem;
}
.form-section-title:first-child { padding-top: 0; border-top: none; margin-top: 0; }

.form-actions { display: flex; gap: .75rem; padding-top: 1.5rem; border-top: 1px solid var(--border); margin-top: 1.5rem; }

/* ── Category selector ─────────────────────── */
.cat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
}
.cat-opt { display: none; }
.cat-opt + label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .3rem;
    padding: .75rem .5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: center;
    font-size: .72rem;
    font-weight: 600;
    color: var(--muted);
    transition: all var(--transition);
}
.cat-opt + label .cat-emoji { font-size: 1.4rem; }
.cat-opt:checked + label {
    border-color: var(--violet);
    background: var(--violet-l);
    color: var(--violet-d);
}
.cat-opt + label:hover { border-color: var(--violet); background: var(--violet-l); }

/* ── Budget page ─────────────────────────────── */
.budget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.budget-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
}
.budget-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.bc-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.bc-cat { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: .9rem; }
.bc-icon { font-size: 1.3rem; }
.bc-status {
    font-size: .7rem; font-weight: 700; padding: .25rem .6rem;
    border-radius: 20px; text-transform: uppercase; letter-spacing: .4px;
}
.bc-status.ok   { background: #ecfdf5; color: #065f46; }
.bc-status.warn { background: #fffbeb; color: #92400e; }
.bc-status.over { background: #fff1f2; color: #be123c; }
.bc-status.none { background: var(--bg); color: var(--muted); }

.bc-amounts { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-bottom: .5rem; }
.bc-spent   { font-weight: 700; color: var(--text); }
.bc-budget  { font-weight: 600; }

.progress-bar {
    height: 8px;
    background: #f1f5f9;
    border-radius: 20px;
    overflow: hidden;
    margin-bottom: .6rem;
}
.progress-fill {
    height: 100%;
    border-radius: 20px;
    transition: width .6s cubic-bezier(.4,0,.2,1);
}
.progress-fill.ok   { background: linear-gradient(90deg, var(--emerald), #34d399); }
.progress-fill.warn { background: linear-gradient(90deg, var(--amber), #fbbf24); }
.progress-fill.over { background: linear-gradient(90deg, var(--rose), #fb7185); }

.bc-pct { font-size: .72rem; font-weight: 700; color: var(--muted); }
.bc-input-row { display: flex; gap: .5rem; margin-top: .85rem; }
.bc-input-row input {
    flex: 1;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    padding: .4rem .7rem;
    font-size: .85rem;
    font-family: inherit;
    outline: none;
    transition: border var(--transition);
}
.bc-input-row input:focus { border-color: var(--violet); }
.bc-input-row button {
    padding: .4rem .8rem;
    border-radius: 6px;
    border: none;
    background: var(--violet);
    color: #fff;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: opacity var(--transition);
}
.bc-input-row button:hover { opacity: .85; }

/* ── Empty state ─────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    gap: .75rem;
}
.empty-state .es-icon { font-size: 3rem; }
.empty-state h3 { font-size: 1rem; font-weight: 700; }
.empty-state p  { font-size: .875rem; color: var(--muted); }

/* ── Filter strip ────────────────────────────── */
.filter-strip {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    align-items: center;
}
.filter-strip input,
.filter-strip select {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .45rem .85rem;
    font-size: .82rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    font-family: inherit;
    transition: border var(--transition);
}
.filter-strip input:focus,
.filter-strip select:focus { border-color: var(--violet); background: #fff; }
.filter-strip input[type="text"] { min-width: 180px; }

/* ── Pagination ──────────────────────────────── */
.pagination {
    display: flex;
    justify-content: center;
    gap: .35rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
}
.pg-btn {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px;
    font-size: .82rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--muted);
    border: 1px solid var(--border);
    background: var(--card);
    transition: all var(--transition);
}
.pg-btn:hover { border-color: var(--violet); color: var(--violet); background: var(--violet-l); }
.pg-btn.active { background: var(--violet); color: #fff; border-color: var(--violet); }

/* ── Modal ──────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15,23,42,.5);
    backdrop-filter: blur(4px);
    z-index: 500;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--card);
    border-radius: 20px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 24px 64px rgba(0,0,0,.25);
    animation: modalIn .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(.9) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-icon { font-size: 2.5rem; margin-bottom: .75rem; display: block; }
.modal h3   { font-size: 1.1rem; font-weight: 800; margin-bottom: .5rem; }
.modal p    { color: var(--muted); font-size: .875rem; margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: .75rem; }

/* ── Toast ───────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 1.5rem; right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.toast {
    min-width: 280px;
    max-width: 380px;
    padding: .85rem 1.2rem;
    border-radius: 12px;
    font-size: .875rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .6rem;
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    transform: translateX(120%);
    transition: transform .35s cubic-bezier(.34,1.56,.64,1);
    color: #fff;
}
.toast.show { transform: translateX(0); }
.toast-success { background: linear-gradient(135deg, #10b981, #059669); }
.toast-danger  { background: linear-gradient(135deg, #ef4444, #dc2626); }
.toast-info    { background: linear-gradient(135deg, #3b82f6, #2563eb); }

/* ── Quick stat in panel header ─────────────── */
.panel-stat {
    font-size: .85rem;
    font-weight: 700;
    color: var(--violet);
    background: var(--violet-l);
    padding: .25rem .7rem;
    border-radius: 20px;
}

/* ── Category breakdown list ─────────────────── */
.cat-breakdown { display: flex; flex-direction: column; gap: .85rem; padding: 1.25rem 1.5rem; }
.cbl-item { display: flex; flex-direction: column; gap: .35rem; }
.cbl-top  { display: flex; align-items: center; justify-content: space-between; }
.cbl-name { font-size: .82rem; font-weight: 600; display: flex; align-items: center; gap: .4rem; }
.cbl-pct  { font-size: .75rem; color: var(--muted); }
.cbl-bar  { height: 6px; background: #f1f5f9; border-radius: 20px; overflow: hidden; }
.cbl-fill { height: 100%; border-radius: 20px; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2     { grid-template-columns: 1fr; }
    .grid-3-1   { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-overlay.open { display: block; }
    .main { margin-left: 0; }
    .hamburger { display: flex; }
    .content { padding: 1rem; }
    .topbar { padding: 0 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }
    .cat-grid { grid-template-columns: repeat(3, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
    .fab { bottom: 1.25rem; right: 1.25rem; }
    /* quick-add: let title take its own row */
    .qa-title { flex: 1 1 100%; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card  { padding: 1.1rem 1rem; }
    .stat-value { font-size: 1.4rem; letter-spacing: -.5px; }
    .stat-icon  { font-size: 1.2rem; margin-bottom: .3rem; }
}

/* ═══════════════════════════════════════════════
   GAMIFICATION + REAL-TIME ADDITIONS
   ═══════════════════════════════════════════════ */

/* ── Sidebar XP bar ──────────────────────────── */
.sidebar-xp {
    padding: .85rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,.06);
    border-bottom: 1px solid rgba(255,255,255,.06);
    margin-bottom: .25rem;
}
.xp-level-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .45rem;
}
.xp-level-badge {
    font-size: .78rem;
    font-weight: 800;
    color: rgba(255,255,255,.75);
    letter-spacing: .1px;
}
.xp-count {
    font-size: .68rem;
    font-weight: 700;
    color: #FCD34D;
    background: rgba(217,119,6,.25);
    padding: .15rem .5rem;
    border-radius: 20px;
}
.xp-track {
    height: 6px;
    background: rgba(255,255,255,.1);
    border-radius: 20px;
    overflow: hidden;
}
.xp-fill {
    height: 100%;
    background: linear-gradient(90deg, #D97706, #F59E0B);
    border-radius: 20px;
    transition: width .7s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 0 8px rgba(217,119,6,.6);
}
.xp-label {
    font-size: .65rem;
    color: rgba(255,255,255,.3);
    margin-top: .3rem;
    font-weight: 600;
}

/* ── Quick-add panel ─────────────────────────── */
.quick-add-panel {
    background: linear-gradient(120deg, #F0FDF4 0%, #DCFCE7 100%);
    border-bottom: 1px solid rgba(22,163,74,.15);
    padding: .85rem 1.25rem;
}
.qa-eyebrow {
    font-size: .65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--violet-d);
    margin-bottom: .5rem;
    display: flex;
    align-items: center;
    gap: .35rem;
}
.qa-form {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
}
.qa-form input,
.qa-form select {
    border: 1.5px solid rgba(22,163,74,.25);
    border-radius: 8px;
    padding: .5rem .75rem;
    font-size: .85rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border var(--transition), box-shadow var(--transition);
}
.qa-form input:focus,
.qa-form select:focus {
    border-color: var(--violet);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}
.qa-form input.qa-error { border-color: var(--rose); animation: shake .3s ease; }
.qa-title  { flex: 2; min-width: 140px; }
.qa-amount { width: 90px; }
.qa-cat    { width: 145px; }
.qa-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .5rem 1rem;
    background: linear-gradient(135deg, var(--violet), var(--violet-d));
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity var(--transition), transform var(--transition);
    white-space: nowrap;
    font-family: inherit;
    box-shadow: 0 3px 10px rgba(22,163,74,.3);
}
.qa-btn:hover  { opacity: .9; transform: translateY(-1px); }
.qa-btn:active { transform: scale(.96); }
.qa-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

@keyframes shake {
    0%,100% { transform: translateX(0); }
    25%      { transform: translateX(-6px); }
    75%      { transform: translateX(6px); }
}

/* ── Optimistic row ──────────────────────────── */
.row-optimistic td { background: #fafbff !important; }
.spinning { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── New row slide-in ────────────────────────── */
tr.row-new {
    animation: rowSlideIn .4s cubic-bezier(.34,1.56,.64,1);
    background: #f0fdf4 !important;
    transition: background 2s ease;
}
@keyframes rowSlideIn {
    from { opacity: 0; transform: translateY(-12px) scale(.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Stat card pulse ─────────────────────────── */
@keyframes statPulse {
    0%,100% { transform: scale(1); }
    50%      { transform: scale(1.04); }
}
.stat-card.pulse { animation: statPulse .4s ease; }

/* ── Floating XP label ───────────────────────── */
.xp-float {
    position: fixed;
    font-size: 1.15rem;
    font-weight: 900;
    color: #F59E0B;
    text-shadow: 0 2px 10px rgba(0,0,0,.3);
    pointer-events: none;
    z-index: 9999;
    transition: transform 1.1s cubic-bezier(.17,.67,.2,1), opacity .9s ease;
    transform-origin: center bottom;
    white-space: nowrap;
}

/* ── Achievement popup ───────────────────────── */
.achievement-popup {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: linear-gradient(135deg, #071020 0%, #0D1F35 60%, #162035 100%);
    border: 1px solid rgba(217,119,6,.45);
    color: #fff;
    border-radius: 18px;
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.1rem;
    min-width: 300px;
    max-width: 380px;
    box-shadow: 0 24px 64px rgba(0,0,0,.55), 0 0 0 1px rgba(217,119,6,.2), inset 0 1px 0 rgba(255,255,255,.06);
    z-index: 2500;
    animation: achieveIn .55s cubic-bezier(.34,1.56,.64,1);
}
@keyframes achieveIn {
    from { transform: translateX(130%) scale(.85); opacity: 0; }
    to   { transform: translateX(0) scale(1); opacity: 1; }
}
.ap-badge { font-size: 2.4rem; flex-shrink: 0; filter: drop-shadow(0 4px 8px rgba(0,0,0,.4)); }
.ap-body  { display: flex; flex-direction: column; gap: .2rem; }
.ap-sup   { font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .7px; color: #FCD34D; }
.ap-title { font-size: 1rem; font-weight: 800; line-height: 1.2; }
.ap-desc  { font-size: .78rem; color: rgba(255,255,255,.6); }
.ap-xp    {
    display: inline-block;
    background: rgba(217,119,6,.2);
    color: #FCD34D;
    border: 1px solid rgba(217,119,6,.35);
    border-radius: 20px;
    padding: .18rem .6rem;
    font-size: .7rem;
    font-weight: 800;
    margin-top: .1rem;
    width: fit-content;
}

/* ── Live indicator ──────────────────────────── */
.live-indicator {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .72rem;
    font-weight: 600;
    color: var(--muted);
}
#liveDot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--muted);
    transition: background .3s;
    flex-shrink: 0;
}
#liveDot.live-active {
    background: var(--emerald);
    box-shadow: 0 0 0 3px rgba(16,185,129,.2);
    animation: livePulse 2s infinite;
}
@keyframes livePulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(16,185,129,.4); }
    50%      { box-shadow: 0 0 0 5px rgba(16,185,129,0); }
}

/* ── Sound toggle ────────────────────────────── */
.sound-btn {
    width: 34px; height: 34px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: var(--card);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: .95rem;
    transition: all var(--transition);
    flex-shrink: 0;
}
.sound-btn:hover { border-color: var(--violet); background: var(--violet-l); }

/* ── Achievements mini-row on dashboard ──────── */
.ach-grid {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    padding: 1rem 1.5rem;
}
.ach-chip {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .35rem .75rem;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 700;
    cursor: default;
}
.ach-chip.earned {
    background: #DCFCE7;
    color: var(--violet-d);
    border: 1px solid #86EFAC;
}
.ach-chip.locked {
    background: #f8fafc;
    color: var(--muted);
    border: 1px solid var(--border);
    opacity: .55;
    filter: grayscale(1);
}
.ach-chip[title]:hover::after {
    content: attr(title);
    position: absolute;
    background: #0f172a;
    color: #fff;
    padding: .3rem .6rem;
    border-radius: 6px;
    font-size: .7rem;
    font-weight: 600;
    white-space: nowrap;
    transform: translateY(-110%);
    left: 50%;
    transform: translateX(-50%) translateY(-110%);
    pointer-events: none;
    z-index: 100;
}
.ach-chip { position: relative; }

/* ── Toast (overrides app.js styles) ────────── */
#toast-container {
    position: fixed;
    top: 1.25rem; right: 1.25rem;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .8rem 1.1rem;
    border-radius: 12px;
    font-size: .85rem;
    font-weight: 600;
    color: #fff;
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
    transform: translateX(120%);
    transition: transform .35s cubic-bezier(.34,1.56,.64,1);
    pointer-events: all;
    min-width: 260px;
}
.toast.show      { transform: translateX(0); }
.toast-success   { background: linear-gradient(135deg, #10b981, #059669); }
.toast-danger    { background: linear-gradient(135deg, #ef4444, #dc2626); }
.toast-info      { background: linear-gradient(135deg, #3b82f6, #2563eb); }

/* ═══════════════════════════════════════════════
   MOBILE — small phones (≤ 640px)
   ═══════════════════════════════════════════════ */
@media (max-width: 640px) {

    /* ── Topbar ──────────────────────────────── */
    .topbar-sub { display: none; }
    .live-indicator span:last-child { display: none; } /* hide "Live" text */

    /* ── Panel header: stack on small screens ─── */
    .panel-header {
        flex-direction: column;
        align-items: flex-start;
        gap: .6rem;
    }
    .panel-header .filter-strip { width: 100%; }

    /* ── Quick-add: stack vertically ────────────*/
    .quick-add-panel { padding: .75rem 1rem; }
    .qa-form {
        flex-direction: column;
        gap: .4rem;
    }
    .qa-form input,
    .qa-form select {
        width: 100% !important;
        min-width: 0 !important;
        flex: none !important;
    }
    .qa-btn {
        width: 100%;
        justify-content: center;
    }

    /* ── Filter strip: stack ─────────────────── */
    .filter-strip {
        flex-direction: column;
        align-items: stretch;
        gap: .4rem;
    }
    .filter-strip input,
    .filter-strip select {
        width: 100%;
        min-width: 0;
    }
    .filter-strip input[type="text"] { min-width: 0; }
    .filter-strip .btn { align-self: flex-start; }

    /* ── Expense table → card rows ───────────── */
    .table-wrap table  { display: block; }
    .table-wrap thead  { display: none; }
    .table-wrap tbody  { display: flex; flex-direction: column; }
    .table-wrap tbody tr {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto;
        column-gap: .6rem;
        row-gap: .15rem;
        padding: .85rem 1rem;
        border: none;
        border-bottom: 1px solid var(--border);
    }
    .table-wrap tbody tr:last-child { border-bottom: none; }
    .table-wrap tbody tr:hover { background: transparent; }
    .table-wrap tbody td { padding: 0; border: none; }

    /* title — row 1 left */
    .table-wrap tbody td:nth-child(1) { grid-column: 1; grid-row: 1; }
    /* category badge — row 2 left */
    .table-wrap tbody td:nth-child(2) { grid-column: 1; grid-row: 2; }
    /* payment — hidden */
    .table-wrap tbody td:nth-child(3) { display: none; }
    /* amount — row 1 right */
    .table-wrap tbody td:nth-child(4) {
        grid-column: 2; grid-row: 1;
        text-align: right;
    }
    .table-wrap tbody td:nth-child(4) .amount-neg { font-size: 1rem; }
    /* date — row 2 right */
    .table-wrap tbody td:nth-child(5) {
        grid-column: 2; grid-row: 2;
        text-align: right;
        font-size: .72rem;
        color: var(--muted);
        white-space: nowrap;
    }
    /* actions — row 3, spans both cols */
    .table-wrap tbody td:nth-child(6) {
        grid-column: 1 / -1; grid-row: 3;
        padding-top: .5rem;
    }
    .table-wrap .action-btn { width: 36px; height: 36px; font-size: .95rem; }

    /* ── Chart legend: single column ────────── */
    .chart-legend { grid-template-columns: 1fr; gap: .4rem; }

    /* ── Category radio tiles ────────────────── */
    .cat-grid { grid-template-columns: repeat(3, 1fr); gap: .3rem; }
    .cat-opt + label { padding: .55rem .25rem; font-size: .66rem; }
    .cat-opt + label .cat-emoji { font-size: 1.2rem; }

    /* ── Form actions: stack ─────────────────── */
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; justify-content: center; }

    /* ── Budget grid: single col ─────────────── */
    .budget-grid { grid-template-columns: 1fr; }

    /* ── Achievement popup: full width ──────── */
    .achievement-popup {
        right: .75rem;
        left: .75rem;
        bottom: .75rem;
        min-width: unset;
        max-width: unset;
    }

    /* ── Pagination: smaller buttons ─────────── */
    .pg-btn { width: 30px; height: 30px; font-size: .78rem; }

    /* ── FAB: smaller on mobile ──────────────── */
    .fab { width: 48px; height: 48px; font-size: 1.3rem; }
}

