/* ═══════════════════════════════════════════════════════════
   My Budget App — Main Stylesheet
   ═══════════════════════════════════════════════════════════ */
:root {
  --primary:     #6366f1;
  --primary-d:   #4f46e5;
  --success:     #22c55e;
  --danger:      #ef4444;
  --warning:     #f59e0b;
  --info:        #06b6d4;
  --bg:          #0f172a;
  --bg2:         #1e293b;
  --bg3:         #334155;
  --surface:     #1e293b;
  --surface2:    #273548;
  --border:      #334155;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --sidebar-w:   260px;
  --topbar-h:    56px;
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html { -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.app-title { font-weight: 700; font-size: 1.1rem; color: var(--primary); }
.menu-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text); padding: 4px; border-radius: 8px;
  display: flex; align-items: center;
}
.menu-toggle:hover { background: var(--bg3); }
.month-badge {
  background: var(--primary); color: #fff;
  padding: 4px 12px; border-radius: 20px;
  font-size: .8rem; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.month-badge:hover { background: var(--primary-d); }

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: -280px; bottom: 0; z-index: 200;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: left .25s ease;
  overflow-y: auto;
}
.sidebar.open { left: 0; }
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 16px 16px;
  font-weight: 700; font-size: 1.1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-close {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 1.2rem; padding: 4px;
}
.nav-list { list-style: none; padding: 12px 8px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--text-muted);
  font-size: .95rem; font-weight: 500;
  margin-bottom: 2px; transition: all .15s;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 199;
  background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ── Content ────────────────────────────────────────────── */
.content {
  margin-top: var(--topbar-h);
  padding: 20px 16px;
  min-height: calc(100vh - var(--topbar-h));
  max-width: 600px; margin-left: auto; margin-right: auto;
  margin-top: calc(var(--topbar-h) + 0px);
}

/* ── Page sections ─────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-title { font-size: 1.3rem; font-weight: 700; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); margin-bottom: 6px;
}
.card-value {
  font-size: 1.8rem; font-weight: 800; line-height: 1.1;
}
.card-value.positive { color: var(--success); }
.card-value.negative { color: var(--danger); }
.card-value.neutral  { color: var(--text); }

.stat-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.stat-value { font-size: 1.4rem; font-weight: 800; }

/* ── Progress bar ───────────────────────────────────────── */
.progress-wrap { margin: 8px 0; }
.progress-bar {
  height: 8px; background: var(--bg3); border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 99px;
  transition: width .4s ease;
  background: var(--success);
}
.progress-fill.warn { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }
.progress-labels {
  display: flex; justify-content: space-between;
  font-size: .72rem; color: var(--text-muted); margin-top: 4px;
}

/* ── Category row ───────────────────────────────────────── */
.cat-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s;
}
.cat-row:hover { border-color: var(--primary); }
.cat-row-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
}
.cat-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}
.cat-icon svg { width: 18px; height: 18px; }
.cat-name { font-weight: 600; font-size: .95rem; flex: 1; }
.cat-amounts {
  display: flex; justify-content: space-between;
  font-size: .8rem; color: var(--text-muted); margin-top: 4px;
}
.cat-amounts .overspent { color: var(--danger); font-weight: 600; }
.cat-amounts .saved { color: var(--success); font-weight: 600; }

/* ── List items ─────────────────────────────────────────── */
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 500; font-size: .9rem; }
.list-item-sub { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.list-item-amount { font-weight: 700; font-size: .95rem; white-space: nowrap; }
.list-item-actions { display: flex; gap: 6px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  border: none; cursor: pointer; font-size: .9rem; font-weight: 600;
  font-family: var(--font); transition: all .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-warning   { background: var(--warning); color: #000; }
.btn-ghost     { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-sm        { padding: 6px 12px; font-size: .8rem; }
.btn-icon      { padding: 8px; border-radius: 8px; }
.btn-full      { width: 100%; }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

/* ── Forms ──────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: .95rem;
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
}
.field-row { display: flex; align-items: center; }
.input-icon-wrap { position: relative; }
.input-icon-wrap input { padding-right: 42px; }
.toggle-pw {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1rem;
}
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: .9rem; }
.form-row { display: flex; gap: 10px; }
.form-row .field { flex: 1; }
select option { background: var(--bg2); }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: .85rem; margin-bottom: 12px;
}
.alert-error   { background: rgba(239,68,68,.15); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.alert-success { background: rgba(34,197,94,.15);  color: #86efac; border: 1px solid rgba(34,197,94,.3); }
.alert-info    { background: rgba(99,102,241,.15); color: #a5b4fc; border: 1px solid rgba(99,102,241,.3); }
.alert-warn    { background: rgba(245,158,11,.15); color: #fcd34d; border: 1px solid rgba(245,158,11,.3); }

/* ── Modals ─────────────────────────────────────────────── */
.modal {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  align-items: flex-end; justify-content: center;
}
.modal.open { display: flex; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 600px;
  max-height: 90vh; overflow-y: auto;
  animation: slideUp .25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1.2rem; padding: 4px;
}
.modal-body { padding: 20px; }
.modal-footer { padding: 0 20px 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* ── Month picker ───────────────────────────────────────── */
.month-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin-bottom: 16px;
}
.month-btn {
  padding: 10px 4px; border-radius: 8px; text-align: center;
  font-size: .85rem; font-weight: 500; cursor: pointer;
  background: var(--bg3); border: 1px solid transparent;
  color: var(--text); transition: all .15s;
}
.month-btn:hover  { border-color: var(--primary); }
.month-btn.active { background: var(--primary); color: #fff; }
.year-nav {
  display: flex; align-items: center; justify-content: center; gap: 20px;
}

/* ── Toast ──────────────────────────────────────────────── */
#toastContainer {
  position: fixed; bottom: 24px; right: 16px; z-index: 500;
  display: flex; flex-direction: column; gap: 8px; max-width: 320px;
}
.toast {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
  font-size: .85rem; box-shadow: var(--shadow);
  animation: slideInRight .2s ease;
  display: flex; align-items: center; gap: 10px;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ── Login page ─────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-container { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px 24px;
}
.login-logo { text-align: center; font-size: 3rem; margin-bottom: 8px; }
.login-title { text-align: center; font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--text-muted); font-size: .85rem; margin-bottom: 24px; }

/* ── EF log ─────────────────────────────────────────────── */
.ef-log-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.ef-log-item:last-child { border-bottom: none; }
.ef-badge {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; flex-shrink: 0;
}
.ef-badge.credit { background: rgba(34,197,94,.2); color: var(--success); }
.ef-badge.debit  { background: rgba(239,68,68,.2);  color: var(--danger); }
.ef-log-info { flex: 1; min-width: 0; }
.ef-log-reason { font-size: .8rem; font-weight: 600; }
.ef-log-detail { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.ef-log-amount { font-weight: 700; white-space: nowrap; }

/* ── Tabs ───────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; background: var(--bg3); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.tab-btn {
  flex: 1; padding: 8px; border: none; border-radius: 7px; cursor: pointer;
  background: transparent; color: var(--text-muted);
  font-size: .85rem; font-weight: 600; font-family: var(--font); transition: all .15s;
}
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.3); }

/* ── Chips / Tags ───────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 99px;
  font-size: .72rem; font-weight: 600;
}
.chip-success { background: rgba(34,197,94,.15); color: var(--success); }
.chip-danger  { background: rgba(239,68,68,.15);  color: var(--danger); }
.chip-warning { background: rgba(245,158,11,.15); color: var(--warning); }
.chip-info    { background: rgba(6,182,212,.15);  color: var(--info); }

/* ── Color swatch ───────────────────────────────────────── */
.color-swatch {
  width: 28px; height: 28px; border-radius: 6px; border: 2px solid var(--border);
  cursor: pointer; flex-shrink: 0;
}

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 20px; color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: .9rem; }

/* ── Divider ────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ── Section header ─────────────────────────────────────── */
.section-header {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); font-weight: 600; margin: 16px 0 8px;
}

/* ── Utility ────────────────────────────────────────────── */
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted   { color: var(--text-muted); }
.text-right   { text-align: right; }
.fw-bold      { font-weight: 700; }
.mt-4         { margin-top: 4px; }
.mt-8         { margin-top: 8px; }
.mt-16        { margin-top: 16px; }
.mb-8         { margin-bottom: 8px; }
.flex         { display: flex; }
.flex-1       { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8        { gap: 8px; }
.hidden       { display: none !important; }

/* ── Big EF balance ─────────────────────────────────────── */
.ef-hero {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
}
.ef-hero-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.ef-hero-amount { font-size: 2.8rem; font-weight: 900; color: var(--success); }

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Responsive tweaks ──────────────────────────────────── */
@media (max-width: 400px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 14px 12px; }
}
