/* ============================================================
   FinanzasFam — Estilos principales
   Autor: generado con IA | Versión: 1.0
   Fuentes: DM Serif Display (títulos) + DM Sans (cuerpo)
   Paleta: Verde oscuro (#2E7D52) acento, fondo crema (#FAF8F4)
   ============================================================ */

/* ── VARIABLES ─────────────────────────────────────────────── */
:root {
  /* Colores base */
  --cream:       #FAF8F4;
  --white:       #FFFFFF;
  --ink:         #1A1A18;
  --ink-muted:   #6B6B66;
  --ink-light:   #A8A8A0;
  --border:      rgba(0,0,0,0.08);
  --border-md:   rgba(0,0,0,0.14);

  /* Acento principal: verde */
  --green-900:   #1A3D2B;
  --green-700:   #2E7D52;
  --green-500:   #4CAF80;
  --green-100:   #E8F5EE;
  --green-50:    #F2FBF5;

  /* Rojo / peligro */
  --red-700:     #B83232;
  --red-500:     #E24B4A;
  --red-100:     #FDEAEA;
  --red-50:      #FEF5F5;

  /* Amarillo / advertencia */
  --amber-700:   #92600A;
  --amber-500:   #E09020;
  --amber-100:   #FEF0D4;

  /* Azul / info / ahorro */
  --blue-700:    #1A6999;
  --blue-500:    #378ADD;
  --blue-100:    #E3F0FB;

  /* Sección colores */
  --col-s1:      #1A6999;   /* Ahorro */
  --col-s2:      #92600A;   /* Deudas */
  --col-s3:      #7C3D6F;   /* Gastos generales */
  --col-ss1:     #534AB7;   /* Servicios */
  --col-ss2:     #0F6E56;   /* Casa */
  --col-ss3:     #993556;   /* Personal */
  --col-ss4:     #BA7517;   /* Entret. */
  --col-ss5:     #3C3489;   /* Educ. */
  --col-ss6:     #1D9E75;   /* Médico */
  --col-ss7:     #5F5E5A;   /* Auto */

  /* Layout */
  --nav-height:  62px;
  --header-height: 56px;
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   20px;

  /* Sombras */
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 8px rgba(0,0,0,0.04);
  --shadow-nav:  0 -1px 0 rgba(0,0,0,0.07);

  /* Tipografía */
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
}

/* ── RESET ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  padding-top: var(--header-height);
  padding-bottom: calc(var(--nav-height) + 16px);
  line-height: 1.5;
}

/* ── HEADER ─────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--green-900);
  z-index: 100;
  display: flex;
  align-items: center;
}
.header-inner {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  width: 32px; height: 32px;
  background: var(--green-500);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--white);
  font-weight: 400;
}
.brand-name {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--white);
  letter-spacing: -0.02em;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.month-select {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--white);
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  cursor: pointer;
  appearance: none;
}
.month-select option { color: var(--ink); background: var(--white); }
.year-label {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  font-weight: 300;
}

/* ── BOTTOM NAV ─────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--white);
  box-shadow: var(--shadow-nav);
  display: flex;
  z-index: 100;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--ink-light);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 4px;
  transition: color 0.15s;
}
.nav-btn.active {
  color: var(--green-700);
}
.nav-btn.active svg { stroke: var(--green-700); }
.nav-btn svg { stroke: var(--ink-light); transition: stroke 0.15s; }

/* ── MAIN CONTENT ───────────────────────────────────────────── */
.main-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 1rem;
}

/* ── VIEWS ──────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ── SECTION TITLE BAR ──────────────────────────────────────── */
.section-title-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1rem;
}
.section-title {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--ink);
  font-weight: 400;
  letter-spacing: -0.02em;
}
.section-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.03em;
}
.badge-income { background: var(--green-100); color: var(--green-900); }
.badge-expense { background: var(--red-100); color: var(--red-700); }
.badge-save   { background: var(--blue-100); color: var(--blue-700); }
.badge-debt   { background: var(--amber-100); color: var(--amber-700); }

/* ── CARDS ──────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1rem;
  border: 1px solid var(--border);
}
.mt-1 { margin-top: 12px; }
.card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.85rem;
}

/* ── ALERT BANNER ───────────────────────────────────────────── */
.alert-banner {
  border-radius: var(--radius-md);
  padding: 0.7rem 1rem;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 1rem;
  display: none;
}
.alert-banner.show { display: block; }
.alert-banner.ok     { background: var(--green-50);  color: var(--green-900); border: 1px solid rgba(46,125,82,0.15); }
.alert-banner.warn   { background: var(--amber-100); color: var(--amber-700); border: 1px solid rgba(146,96,10,0.15); }
.alert-banner.danger { background: var(--red-50);    color: var(--red-700);   border: 1px solid rgba(184,50,50,0.15); }

/* ── METRICS GRID ───────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.metric-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
}
.metric-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}
.metric-value {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.metric-value.ok  { color: var(--green-700); }
.metric-value.bad { color: var(--red-700); }
.metric-sub {
  font-size: 10px;
  color: var(--ink-light);
  margin-top: 3px;
}

/* ── FLOW BARS ──────────────────────────────────────────────── */
.flow-item { margin-bottom: 0.9rem; }
.flow-item:last-child { margin-bottom: 0; }
.flow-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  margin-bottom: 4px;
}
.flow-name { color: var(--ink); font-weight: 500; }
.flow-vals { color: var(--ink-muted); }
.flow-var  { font-size: 11px; font-weight: 600; }
.flow-var.ok  { color: var(--green-700); }
.flow-var.bad { color: var(--red-700); }
.bar-bg {
  height: 7px;
  background: var(--cream);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* ── BALANCE SUMMARY TABLE ──────────────────────────────────── */
.bal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.bal-table th {
  text-align: right;
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.bal-table th:first-child { text-align: left; }
.bal-table td {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  text-align: right;
  color: var(--ink);
}
.bal-table td:first-child { text-align: left; color: var(--ink-muted); }
.bal-table tr:last-child td { border-bottom: none; font-weight: 600; color: var(--ink); }
.td-ok  { color: var(--green-700) !important; }
.td-bad { color: var(--red-700)   !important; }

/* ── ITEMS TABLE (ingresos / salidas) ───────────────────────── */
.items-table {
  width: 100%;
  border-collapse: collapse;
}
.items-table .th-row th {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  padding: 4px 4px 8px;
  border-bottom: 1px solid var(--border-md);
  text-align: right;
}
.items-table .th-row th:first-child { text-align: left; }
.item-tr td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.item-tr:last-child td { border-bottom: none; }
.item-name-cell {
  font-size: 13px;
  color: var(--ink);
  text-align: left;
}
.num-field {
  width: 80px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  text-align: right;
  -moz-appearance: textfield;
}
.num-field::-webkit-outer-spin-button,
.num-field::-webkit-inner-spin-button { -webkit-appearance: none; }
.num-field:focus {
  outline: none;
  border-color: var(--green-700);
  background: var(--white);
}
.var-td {
  font-size: 11px;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}
.var-ok  { color: var(--green-700); }
.var-bad { color: var(--red-700); }
.var-neu { color: var(--ink-light); }
.del-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-md);
  background: transparent;
  color: var(--ink-light);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.del-btn:hover { background: var(--red-100); color: var(--red-700); border-color: rgba(184,50,50,0.2); }

/* ── TOTALS ROW ─────────────────────────────────────────────── */
.totals-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.tot-pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--cream);
  color: var(--ink-muted);
  border: 1px solid var(--border);
}
.tot-pill b { color: var(--ink); }
.tot-pill.ok b { color: var(--green-700); }
.tot-pill.bad b { color: var(--red-700); }

/* ── ADD ITEM ROW ───────────────────────────────────────────── */
.add-item-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 0.85rem;
  padding: 8px 12px;
  background: var(--cream);
  border: 1px dashed var(--border-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-muted);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.add-item-btn:hover { background: var(--green-50); color: var(--green-700); border-color: rgba(46,125,82,0.3); }
.add-icon {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--green-700);
  color: var(--white);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── SUBSECTION ─────────────────────────────────────────────── */
.subsection {
  margin: 0.5rem 0 1rem 0;
  border-left: 3px solid var(--border-md);
  padding-left: 0.85rem;
  border-radius: 0;
}
.subsection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.subsection-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}
.subsection-total {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
}
.subsection-bar {
  height: 4px;
  background: var(--cream);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}
.subsection-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ── CATEGORY CARD ──────────────────────────────────────────── */
.cat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  overflow: hidden;
}
.cat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.cat-card-title {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--ink);
  font-weight: 400;
}
.cat-card-body { padding: 0.75rem 1rem 1rem; }

/* ── CHARTS ─────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  width: 100%;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--ink-muted);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── TOP GASTOS ─────────────────────────────────────────────── */
.top-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.top-item:last-child { border-bottom: none; }
.top-rank {
  width: 24px; height: 24px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.rank-1 { background: #FEF0D4; color: #92600A; }
.rank-2 { background: #E8E8E4; color: #5F5E5A; }
.rank-3 { background: #FAECE7; color: #993C1D; }
.top-name { flex: 1; font-size: 13px; color: var(--ink); }
.top-amount { font-size: 13px; font-weight: 600; color: var(--ink); }
.top-pct { font-size: 11px; color: var(--ink-light); margin-left: 4px; }

/* ── MODAL ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,26,24,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--nav-height);
}
.modal-box {
  background: var(--white);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 500px;
  padding: 0 0 1rem;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.85rem;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  font-weight: 400;
}
.modal-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--cream);
  color: var(--ink-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-body { padding: 1rem 1.25rem; }
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 5px;
  margin-top: 0.85rem;
}
.field-label:first-child { margin-top: 0; }
.field-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.field-input:focus { outline: none; border-color: var(--green-700); background: var(--white); }
.modal-footer {
  display: flex;
  gap: 10px;
  padding: 0 1.25rem;
}
.btn-cancel {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-md);
  background: var(--cream);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
}
.btn-confirm {
  flex: 2;
  padding: 12px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--green-700);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
  cursor: pointer;
}
.btn-confirm:hover { background: var(--green-900); }

/* ── DESKTOP ADJUSTMENTS ────────────────────────────────────── */
@media (min-width: 600px) {
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .modal-overlay { align-items: center; padding-bottom: 0; }
  .modal-box { border-radius: var(--radius-xl); max-width: 440px; }
  .bottom-nav { justify-content: center; gap: 0; }
  .nav-btn { max-width: 120px; }
  .num-field { width: 90px; }
}
@media (min-width: 768px) {
  .main-content { padding: 1.25rem 1.5rem; }
  .metrics-grid { grid-template-columns: repeat(4, 1fr); }
}
