:root {
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;

  --color-bg: #000000;
  --color-bg-alt: #0A0A0A;
  --color-card: #141414;
  --color-card-soft: #101010;
  --color-card-border: rgba(255, 255, 255, 0.06);
  --color-text: #F5F5F1;
  --color-text-muted: #94948C;
  --color-text-faint: #5C5C55;

  --color-accent: #2BD9CC;
  --color-accent-dim: #1B8F87;
  --color-accent-2: #57E6DB;
  --color-accent-soft: rgba(43, 217, 204, 0.12);
  --color-accent-glow: rgba(43, 217, 204, 0.28);
  --color-on-accent: #04211E;

  --color-good: #4ADE80;
  --color-good-bg: rgba(74, 222, 128, 0.10);
  --color-warn: #E3B15C;
  --color-warn-bg: rgba(227, 177, 92, 0.10);
  --color-bad: #F0708A;
  --color-bad-bg: rgba(240, 112, 138, 0.10);

  --color-ring: #22D3C6;
  --radius-lg: 30px;
  --radius-md: 20px;
  --radius-sm: 14px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
}

body {
  font-family: var(--font);
  font-size: 17px;
  font-weight: 450;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  background: var(--color-bg);
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

button {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
}

a { color: var(--color-accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

:focus-visible {
  outline: 3px solid var(--color-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.86);
  backdrop-filter: blur(14px) saturate(1.1);
  padding: calc(env(safe-area-inset-top) + var(--space-3)) var(--space-5) var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.topbar-action {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: #17171A;
  border: none;
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-action svg { width: 19px; height: 19px; }

/* Main content */
#app {
  padding: var(--space-5) var(--space-4) calc(96px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}

.view { display: flex; flex-direction: column; gap: var(--space-5); }

/* Tab bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: rgba(6, 6, 6, 0.92);
  border-top: 1px solid var(--color-card-border);
  padding: var(--space-2) var(--space-2) calc(env(safe-area-inset-bottom) + var(--space-2));
  backdrop-filter: saturate(1.2) blur(16px);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-2) 2px;
  min-height: 54px;
  border-radius: var(--radius-sm);
  color: var(--color-text-faint);
  font-size: 11px;
  font-weight: 550;
  transition: color 150ms ease, transform 150ms ease;
}

.tab-icon-wrap {
  width: 34px;
  height: 26px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease;
}

.tab-icon { width: 22px; height: 22px; }

.tab[aria-current="page"] {
  color: var(--color-text);
}
.tab[aria-current="page"] .tab-icon-wrap {
  background: rgba(255, 255, 255, 0.08);
}

.tab:active { transform: scale(0.94); }

/* Cards */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-card);
}

.card-tap {
  width: 100%;
  text-align: left;
  display: block;
}

.card-tap:active { transform: scale(0.98); }

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-3) 4px;
}

.section-sub {
  font-size: 13px;
  color: var(--color-text-faint);
  margin: -14px 0 var(--space-2) 4px;
}

/* Hero savings card */
.hero-card {
  position: relative;
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-5);
  color: var(--color-text);
  background: radial-gradient(120% 100% at 30% 0%, #0F2A1C 0%, #06120C 55%, #000000 100%);
  border: 1px solid rgba(74, 222, 128, 0.18);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.hero-bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: block;
}

.hero-scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.32) 0%, rgba(0,0,0,0.42) 45%, rgba(0,0,0,0.62) 100%);
  pointer-events: none;
}

.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  position: relative;
}

.hero-label {
  font-size: 15px;
  font-weight: 450;
  color: rgba(245, 245, 241, 0.6);
  margin: 0 0 2px;
}

.greet-name-wrap {
  position: relative;
  display: block;
  margin-top: 2px;
  height: auto;
}
.greet-name-sizer {
  visibility: hidden;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.25;
}
.greet-name {
  position: absolute;
  inset: 0;
  left: 0;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--color-text);
  opacity: 1;
  transition: opacity 480ms ease;
}
.greet-name.fade-out { opacity: 0; }

.hero-amount {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: var(--space-4) 0 var(--space-3);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
  position: relative;
}
.hero-amount::first-letter { font-weight: 400; opacity: 0.6; }
.hero-amount.good { color: var(--color-good); }
.hero-amount.bad { color: var(--color-bad); }
.hero-amount.warn { color: var(--color-warn); }

.meta-edit-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  position: relative;
}
.meta-edit-btn svg { width: 17px; height: 17px; }

.semaforo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 550;
  background: rgba(255,255,255,0.07);
  color: var(--color-text);
  position: relative;
}

.semaforo-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.semaforo.good .semaforo-dot { background: var(--color-good); }
.semaforo.warn .semaforo-dot { background: var(--color-warn); }
.semaforo.bad .semaforo-dot { background: var(--color-bad); }

.meta-line {
  margin-top: var(--space-4);
  font-size: 13px;
  color: rgba(245, 245, 241, 0.55);
  position: relative;
}
.meta-line strong { color: var(--color-text); font-variant-numeric: tabular-nums; font-weight: 600; }

/* Chart cards */
.chart-card .chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.chart-card .chart-head .chart-legend {
  display: flex;
  gap: var(--space-3);
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 550;
}
.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* Line chart (trading-style) */
.linechart-wrap {
  position: relative;
}
.linechart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}
.linechart-xlabels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 2px;
}
.linechart-xlabels span {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-faint);
}
.linechart-xlabels span.current { color: var(--color-text); }

.chart-point.good { fill: var(--color-good); }
.chart-point.bad { fill: var(--color-bad); }
.chart-point-ring {
  fill: none;
  stroke: var(--color-card);
  stroke-width: 3;
}
.chart-value-label {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  fill: var(--color-text);
}
.chart-value-label.good { fill: var(--color-good); }
.chart-value-label.bad { fill: var(--color-bad); }
.chart-ref-line {
  stroke: var(--color-card-border);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}
.chart-ref-line.zero { stroke: var(--color-bad); opacity: 0.45; }
.chart-ref-line.meta { stroke: var(--color-good); opacity: 0.4; }
.chart-ref-label {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.chart-ref-label.zero { fill: var(--color-bad); opacity: 0.7; }
.chart-ref-label.meta { fill: var(--color-good); opacity: 0.7; }

/* Metric card toggle (Ahorro / Gastos) */
.metric-toggle {
  display: inline-flex;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  margin-bottom: var(--space-4);
}
.metric-toggle-btn {
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
}
.metric-toggle-btn.active { background: var(--color-text); color: #000; }

.metric-big-value {
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  margin: 0 0 2px;
}
.metric-big-value.good { color: var(--color-good); }
.metric-big-value.bad { color: var(--color-bad); }

.metric-delta {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 var(--space-4);
}
.metric-delta.good { color: var(--color-good); }
.metric-delta.bad { color: var(--color-bad); }
.metric-delta.neutral { color: var(--color-text-faint); }

/* Quick stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
.stat-tile {
  background: var(--color-card);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.stat-tile .stat-label {
  font-size: 12px;
  font-weight: 550;
  color: var(--color-text-muted);
  margin: 0 0 6px;
}
.stat-tile .stat-value {
  font-size: 19px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* Plan comida card */
.plan-card {
  background: var(--color-card);
  border: 1px solid var(--color-card-border);
}
.plan-range {
  font-size: 25px;
  font-weight: 650;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  margin: var(--space-2) 0;
}
.plan-note {
  font-size: 13px;
  color: var(--color-text-muted);
}

/* Item cards (ingresos/gastos) */
.item-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
}

.item-name {
  font-size: 17px;
  font-weight: 600;
}

.item-range {
  font-size: 23px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

.item-meta {
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 500;
}

.pct-pill {
  background: rgba(255,255,255,0.06);
  color: var(--color-text-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.edit-fab {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.edit-fab svg { width: 19px; height: 19px; }

.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 52px;
  border-radius: var(--radius-md);
  border: 1.5px dashed var(--color-card-border);
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 15px;
}
.add-btn svg { width: 20px; height: 20px; }

/* Chips (income quick-fill) */
.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: -4px 0 var(--space-3); }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  min-height: 36px;
}
.chip.active { background: var(--color-text); color: #000; }

/* Debts */
.debt-progress-track {
  height: 18px;
  border-radius: 999px;
  background: var(--color-bg-alt);
  overflow: hidden;
  margin: var(--space-2) 0;
}
.debt-progress-fill {
  width: 100%;
  height: 100%;
  background: var(--color-good);
  border-radius: 999px;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 400ms ease;
}

.sparkline { width: 100%; height: 56px; display: block; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 52px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 16px;
}
.btn svg { width: 20px; height: 20px; flex: none; }

.btn-primary { background: var(--color-text); color: #000; width: 100%; }
.btn-primary:active { filter: brightness(0.9); }

.btn-ghost { background: rgba(255,255,255,0.06); color: var(--color-text); width: 100%; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field label { font-size: 14px; font-weight: 600; color: var(--color-text-muted); }
.field input, .field select {
  min-height: 52px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--color-card-border);
  background: var(--color-bg-alt);
  padding: 0 var(--space-4);
  font-size: 17px;
  color: var(--color-text);
}
.field input:focus, .field select:focus {
  border-color: var(--color-text-muted);
  outline: none;
}
.field-row { display: flex; gap: var(--space-3); }
.field-row .field { flex: 1; }
.field-help { font-size: 12px; color: var(--color-text-faint); }

/* Sheet (bottom modal) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 40;
  opacity: 0;
  transition: opacity 200ms ease;
}
.sheet-backdrop.open { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: #101012;
  border: 1px solid var(--color-card-border);
  border-bottom: none;
  border-radius: 28px 28px 0 0;
  padding: var(--space-3) var(--space-5) calc(env(safe-area-inset-bottom) + var(--space-5));
  max-height: 86dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 260ms cubic-bezier(0.32, 0.72, 0, 1);
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,0.16);
  margin: 0 auto var(--space-4);
}

.sheet-title {
  font-size: 20px;
  font-weight: 650;
  margin: 0 0 var(--space-4);
}

/* Empty / helper states */
.empty-hint {
  font-size: 14px;
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-3);
}

.projection-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-card-border);
}
.projection-row:last-child { border-bottom: none; }
.projection-month { font-weight: 600; font-size: 15px; }
.projection-amount { font-weight: 650; font-size: 17px; font-variant-numeric: tabular-nums; }

.food-entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-card-border);
}
.food-entry-row:last-child { border-bottom: none; }
.food-entry-date { font-size: 13px; color: var(--color-text-muted); font-weight: 500; }
.food-entry-amount { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.food-entry-del {
  width: 32px; height: 32px; border-radius: 999px;
  color: var(--color-text-faint);
  display: flex; align-items: center; justify-content: center;
}
.food-entry-del svg { width: 16px; height: 16px; }

/* Quick actions row */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}
.qa-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--color-card);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  min-height: 88px;
}
.qa-btn:active { transform: scale(0.96); }
.qa-icon {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.2);
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.qa-icon.accent { border-color: rgba(255,255,255,0.2); color: var(--color-text); }
.qa-icon svg { width: 14px; height: 14px; }
.qa-text {
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
}
.qa-sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-faint);
}

/* Savings goals (metas) */
.goal-add-card {
  background: var(--color-card);
  border: 1px solid var(--color-card-border);
}
.goal-card { display: flex; flex-direction: column; gap: 2px; }
.goal-detail-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: 6px 0;
}
.goal-progress-label {
  font-size: 12px;
  color: var(--color-text-faint);
  font-weight: 550;
  margin: var(--space-2) 0 4px;
}
.goal-progress-track {
  height: 12px;
  border-radius: 999px;
  background: var(--color-bg-alt);
  overflow: hidden;
}
.goal-progress-fill {
  width: 100%;
  height: 100%;
  background: var(--color-text);
  border-radius: 999px;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 400ms ease;
}
.goal-progress-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--color-text-faint);
  font-weight: 600;
  margin: 4px 0 var(--space-3);
}
.goal-stats-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-card-border);
}
.goal-stats-row .label {
  font-size: 11px;
  color: var(--color-text-faint);
  font-weight: 550;
  margin: 0 0 2px;
}
.goal-stats-row .value {
  font-size: 14px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 480px) {
  .hero-amount { font-size: 50px; }
}

/* Animated green tap glow on interactive surfaces */
.card-tap,
.qa-btn,
.btn,
.add-btn,
.chip,
.edit-fab,
.meta-edit-btn,
.goal-detail-btn,
.metric-toggle-btn,
.food-entry-del,
.btn-mini {
  transition: box-shadow 220ms ease, transform 120ms ease;
}
.card-tap:active,
.qa-btn:active,
.btn:active,
.add-btn:active,
.chip:active,
.edit-fab:active,
.meta-edit-btn:active,
.goal-detail-btn:active,
.metric-toggle-btn:active,
.food-entry-del:active,
.btn-mini:active {
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.65), 0 0 18px rgba(74, 222, 128, 0.4);
  transition: box-shadow 60ms ease, transform 120ms ease;
}

/* Pending fixed-bill reminders */
.pending-bills-card {
  border: 1px solid rgba(227, 177, 92, 0.3);
  margin-bottom: var(--space-4);
}
.pending-bill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-card-border);
}
.pending-bill-row:last-child { border-bottom: none; }
.pending-bill-actions {
  display: flex;
  gap: 8px;
  flex: none;
}
.btn-mini {
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.btn-mini.primary { background: var(--color-text); color: #000; }
