/* ═══════════════════════════════════════════════════════════
   Ahorro Pro — Global Styles
   Design: Dark glassmorphism, purple-blue gradient
   ════════════════════════════════════════════════════════════ */

/* ── Variables ──────────────────────────────────────────── */
:root {
  --bg-base:        #0d0d1a;
  --bg-layer1:      #12122a;
  --bg-layer2:      #1a1a35;

  --accent:         #7c3aed;
  --accent-2:       #2563eb;
  --accent-grad:    linear-gradient(135deg, #7c3aed 0%, #2563eb 100%);
  --accent-glow:    rgba(124, 58, 237, 0.35);

  --income-color:   #10b981;
  --expense-color:  #f43f5e;
  --balance-color:  #f59e0b;

  --text-primary:   #f0f0ff;
  --text-secondary: #9494b8;
  --text-muted:     #5a5a80;

  --glass-bg:       rgba(255,255,255,0.05);
  --glass-border:   rgba(255,255,255,0.08);
  --glass-blur:     16px;

  --radius-sm:      8px;
  --radius-md:      14px;
  --radius-lg:      20px;
  --radius-xl:      28px;

  --nav-height:     68px;
  --topbar-height:  56px;

  --transition:     all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
input, button { font-family: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }
input { outline: none; }

/* ── Background Gradient Orbs ──────────────────────────── */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(124,58,237,0.18) 0%, transparent 70%),
    radial-gradient(ellipse 50% 35% at 80% 80%, rgba(37,99,235,0.15) 0%, transparent 70%);
}

/* ── App Shell ───────────────────────────────────────────── */
#app {
  position: relative; z-index: 1;
  max-width: 480px; margin: 0 auto;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--topbar-height);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: rgba(13,13,26,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.app-logo {
  font-size: 22px;
  background: var(--accent-grad);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.app-name { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.topbar-right { display: flex; align-items: center; gap: 4px; }

/* ── Icon Button ────────────────────────────────────────── */
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--glass-bg); }
.icon-btn:active { transform: scale(0.9); }

/* ── Search Bar ─────────────────────────────────────────── */
.search-bar-wrap {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.35s cubic-bezier(0.4,0,0.2,1),
              opacity 0.25s ease;
  opacity: 0;
  background: rgba(13,13,26,0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
}
.search-bar-wrap.open {
  max-height: 120px;
  opacity: 1;
}
.search-bar-inner {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 0;
}
.search-icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--text-secondary); }
.search-input {
  flex: 1; background: none; border: none;
  color: var(--text-primary); font-size: 15px;
}
.search-input::placeholder { color: var(--text-muted); }
.search-filters { display: flex; gap: 6px; flex-shrink: 0; }
.filter-chip {
  padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--glass-border); color: var(--text-secondary);
  transition: var(--transition);
}
.filter-chip.active {
  background: var(--accent-grad); color: #fff; border-color: transparent;
}

.date-filter-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
}
.date-input {
  flex: 1; background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--text-primary); border-radius: var(--radius-sm);
  padding: 5px 8px; font-size: 12px;
}
.date-sep { color: var(--text-muted); font-size: 12px; }
.text-btn {
  font-size: 13px; font-weight: 500; color: var(--accent);
  padding: 4px 8px; border-radius: var(--radius-sm);
  transition: var(--transition);
}
.text-btn:hover { background: var(--accent-glow); }

/* ── Page Content ───────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(var(--nav-height) + 24px);
  scroll-behavior: smooth;
}
.page { display: none; animation: fadeSlide 0.3s ease; }
.page.active { display: block; }
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Glass Card ─────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
}

/* ── Month Selector ─────────────────────────────────────── */
.month-selector {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin-bottom: 16px; padding-top: 4px;
}
.month-nav {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  transition: var(--transition);
}
.month-nav svg { width: 18px; height: 18px; }
.month-nav:hover { background: var(--accent-glow); border-color: var(--accent); }
.month-label { font-size: 16px; font-weight: 600; min-width: 100px; text-align: center; }

/* ── Summary Cards ──────────────────────────────────────── */
.summary-cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-bottom: 16px;
}
.summary-card { padding: 16px; transition: var(--transition); }
.summary-card:hover { transform: translateY(-2px); }
.span-full { grid-column: 1 / -1; }
.card-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin-bottom: 8px; }
.card-amount { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.card-amount.income  { color: var(--income-color); }
.card-amount.expense { color: var(--expense-color); }
.card-amount.balance { color: var(--balance-color); font-size: 26px; }

/* ── Chart Section ──────────────────────────────────────── */
.chart-section { padding: 16px; margin-bottom: 16px; }
.chart-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.chart-tab {
  padding: 6px 16px; border-radius: 99px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--glass-border); color: var(--text-secondary);
  transition: var(--transition);
}
.chart-tab.active { background: var(--accent-grad); color: #fff; border-color: transparent; }
.chart-wrap { position: relative; }
.chart-wrap.hidden { display: none; }
.chart-wrap canvas { max-width: 100%; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-secondary); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Section Header ─────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.tx-count { font-size: 13px; color: var(--text-muted); }

/* ── Transaction List ───────────────────────────────────── */
.tx-list { display: flex; flex-direction: column; gap: 8px; }
.tx-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  cursor: pointer; transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.tx-item:hover { background: rgba(255,255,255,0.08); transform: translateX(2px); }
.tx-item:active { transform: scale(0.98); }

.tx-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
  background: rgba(255,255,255,0.06);
}
.tx-info { flex: 1; min-width: 0; }
.tx-note { font-size: 14px; font-weight: 500; truncate: ellipsis; white-space: nowrap; overflow: hidden; }
.tx-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.tx-amount {
  font-size: 15px; font-weight: 700; flex-shrink: 0;
  letter-spacing: -0.3px;
}
.tx-amount.income  { color: var(--income-color); }
.tx-amount.expense { color: var(--expense-color); }

/* ── Empty State ────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.5; }

/* ── Bottom Nav ─────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: var(--nav-height);
  display: grid; grid-template-columns: 1fr 1fr 72px 1fr 1fr;
  align-items: center;
  background: rgba(13,13,26,0.92);
  backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 200;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px; border-radius: var(--radius-md);
  color: var(--text-muted); font-size: 10px; font-weight: 500;
  transition: var(--transition);
}
.nav-item svg { width: 22px; height: 22px; transition: var(--transition); }
.nav-item:hover { color: var(--text-secondary); }
.nav-item.active { color: var(--accent); }
.nav-item.active svg { filter: drop-shadow(0 0 6px var(--accent)); }

/* FAB */
.nav-fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: var(--transition);
  justify-self: center;
}
.nav-fab svg { width: 24px; height: 24px; color: #fff; }
.nav-fab:hover { transform: scale(1.1); box-shadow: 0 6px 28px var(--accent-glow); }
.nav-fab:active { transform: scale(0.95); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay.open {
  opacity: 1; pointer-events: auto;
}
.modal {
  width: 100%; max-width: 480px;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1);
  max-height: 92vh; overflow-y: auto;
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-size: 17px; font-weight: 700; }

/* Type Toggle */
.type-toggle {
  display: flex; gap: 0;
  background: var(--bg-layer1); border-radius: 10px; padding: 3px;
  margin-bottom: 20px;
}
.type-btn {
  flex: 1; padding: 8px; border-radius: 8px; font-size: 14px; font-weight: 600;
  transition: var(--transition); color: var(--text-muted);
}
.type-btn.active.expense { background: rgba(244,63,94,0.2); color: var(--expense-color); }
.type-btn.active.income  { background: rgba(16,185,129,0.2); color: var(--income-color); }

/* Form */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-input {
  width: 100%; padding: 11px 13px;
  background: var(--bg-layer1); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); color: var(--text-primary); font-size: 15px;
  transition: var(--transition);
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-input::placeholder { color: var(--text-muted); }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input-with-prefix { display: flex; align-items: center; background: var(--bg-layer1); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); transition: var(--transition); }
.input-with-prefix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.input-prefix { padding: 11px 10px 11px 13px; color: var(--text-secondary); font-weight: 600; }
.input-with-prefix .form-input { border: none; background: none; box-shadow: none; padding-left: 0; }
.input-with-prefix .form-input:focus { box-shadow: none; }

/* Amount input */
.amount-input-wrap { display: flex; align-items: center; background: var(--bg-layer1); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); transition: var(--transition); }
.amount-input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.currency-symbol { padding: 11px 8px 11px 13px; color: var(--text-secondary); font-weight: 600; font-size: 16px; }
.amount-input { border: none; background: none; font-size: 24px; font-weight: 700; padding-left: 0; }
.amount-input:focus { box-shadow: none; }

/* Category chips in modal */
.category-select { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-chip {
  padding: 6px 12px; border-radius: 99px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--glass-border); color: var(--text-secondary);
  transition: var(--transition); cursor: pointer;
}
.cat-chip.selected { background: var(--accent-grad); color: #fff; border-color: transparent; }

.modal-actions { display: flex; gap: 10px; margin-top: 24px; }
.modal-actions .btn-primary { flex: 1; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
  padding: 13px 20px; border-radius: var(--radius-md);
  background: var(--accent-grad); color: #fff; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: var(--transition);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary.full-width { width: 100%; }
.btn-primary svg { width: 18px; height: 18px; }

.btn-secondary {
  padding: 9px 16px; border-radius: var(--radius-sm);
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--text-primary); font-size: 13px; font-weight: 500;
  transition: var(--transition);
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); }

.btn-danger {
  padding: 9px 16px; border-radius: var(--radius-sm);
  background: rgba(244,63,94,0.15); border: 1px solid rgba(244,63,94,0.3);
  color: var(--expense-color); font-size: 13px; font-weight: 500;
  transition: var(--transition);
}
.btn-danger:hover { background: rgba(244,63,94,0.25); }

.btn-danger-outline {
  padding: 13px 16px; border-radius: var(--radius-md);
  background: transparent; border: 1px solid rgba(244,63,94,0.4);
  color: var(--expense-color); font-size: 14px; font-weight: 500;
  transition: var(--transition);
}
.btn-danger-outline:hover { background: rgba(244,63,94,0.1); }

/* ── Invoice Page ────────────────────────────────────────── */
.invoice-hero { padding: 24px; text-align: center; margin-bottom: 16px; }
.invoice-hero-icon { font-size: 40px; margin-bottom: 12px; }
.invoice-hero h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.invoice-hero p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.invoice-form { padding: 20px; margin-bottom: 16px; }

.invoice-card {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-md); padding: 14px; margin-bottom: 8px;
}
.invoice-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.invoice-num { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.invoice-amount { font-size: 16px; font-weight: 700; color: var(--expense-color); }
.invoice-date { font-size: 12px; color: var(--text-muted); }
.invoice-items { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.invoice-item { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-secondary); padding: 3px 0; border-top: 1px solid var(--glass-border); }
.invoice-import-check { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.invoice-import-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.invoice-import-check label { font-size: 13px; color: var(--text-secondary); }

/* ── Loading ─────────────────────────────────────────────── */
.loading-overlay { text-align: center; padding: 40px; color: var(--text-secondary); }
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--glass-border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Settings ────────────────────────────────────────────── */
.settings-card { padding: 16px; margin-bottom: 12px; }
.settings-card-header { display: flex; align-items: center; gap: 12px; }
.settings-icon { font-size: 24px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: var(--glass-bg); border-radius: 12px; flex-shrink: 0; }
.drive-icon { color: #4285f4; }
.settings-title { font-size: 14px; font-weight: 600; }
.settings-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.settings-card-header .btn-secondary { margin-left: auto; flex-shrink: 0; }
.settings-actions { display: flex; gap: 8px; margin-top: 12px; }
.settings-btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.category-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.category-tag {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; border-radius: 99px; font-size: 12px;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
}
.category-tag button { color: var(--text-muted); font-size: 14px; padding: 0 2px; }
.add-category-row { display: flex; gap: 8px; }
.add-category-row .form-input { flex: 1; }
.version-text { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 24px; padding-bottom: 8px; }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-height) + 16px); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,60,0.95); color: #fff;
  padding: 10px 20px; border-radius: 99px; font-size: 14px; font-weight: 500;
  white-space: nowrap; z-index: 999;
  opacity: 0; pointer-events: none;
  transition: all 0.3s ease;
  border: 1px solid var(--glass-border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  backdrop-filter: blur(12px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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

/* ── Search result highlight ─────────────────────────────── */
mark { background: rgba(124,58,237,0.3); color: inherit; border-radius: 2px; padding: 0 1px; }
