/* ============================================================
   MoneyMind – Hoja de estilos principal
   Paleta: Verde (#2E7D32), Blanco, Gris claro
   Tipografía: Inter (Google Fonts)
   ============================================================ */

/* ---------- Variables de color (tema claro) ---------- */
:root {
  --green-dark:   #2E7D32;
  --green-mid:    #388E3C;
  --green-light:  #A5D6A7;
  --green-pale:   #E8F5E9;
  --teal:         #00897B;
  --blue:         #1565C0;
  --orange:       #E65100;
  --red:          #C62828;

  --bg:           #F4F6F8;
  --surface:      #FFFFFF;
  --surface-2:    #F0F4F0;
  --border:       #E0E0E0;

  --text-primary:   #1A1A2E;
  --text-secondary: #546E7A;
  --text-muted:     #90A4AE;

  --shadow-sm: 0 2px 8px rgba(0,0,0,.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,.12);

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

  --nav-height: 68px;
  --topbar-height: 56px;
  --transition: .25s ease;
}

/* ---------- Tema oscuro ---------- */
body.dark-mode {
  --bg:           #0F1923;
  --surface:      #1A2535;
  --surface-2:    #243040;
  --border:       #2E3D50;
  --text-primary:   #E8F0FE;
  --text-secondary: #90A4AE;
  --text-muted:     #546E7A;
  --green-pale:   #1B2E1C;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,.4);
}

/* ---------- Reset y base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

ul { list-style: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }
a { text-decoration: none; color: inherit; }

/* ============================================================
   PANTALLAS (login / app)
   ============================================================ */
.screen { display: none; }
.screen.active { display: block; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--teal) 100%);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
  animation: slideUp .4s ease;
}

/* Branding en login */
.brand { text-align: center; margin-bottom: 28px; }
.brand-icon { font-size: 3rem; display: block; margin-bottom: 8px; }
.brand-name {
  font-size: 2rem;
  font-weight: 800;
  color: var(--green-dark);
  letter-spacing: -1px;
}
.brand-slogan {
  font-size: .875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Tabs auth */
.auth-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.tab-btn {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.tab-btn.active {
  background: var(--green-dark);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* Formularios auth */
.auth-form { display: none; }
.auth-form.active { display: block; }

.auth-error {
  font-size: .8rem;
  color: var(--red);
  min-height: 18px;
  margin-bottom: 8px;
}

/* ============================================================
   CAMPOS DE FORMULARIO (reutilizable)
   ============================================================ */
.field-group {
  margin-bottom: 16px;
}
.field-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.field-group input,
.field-group select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  font-size: .95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.field-group input:focus,
.field-group select:focus {
  border-color: var(--green-dark);
  box-shadow: 0 0 0 3px rgba(46,125,50,.15);
}
.field-group select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23546E7A' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

/* ============================================================
   BOTONES
   ============================================================ */
.btn-primary {
  background: linear-gradient(135deg, var(--green-dark), var(--green-mid));
  color: #fff;
  padding: 13px 24px;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 600;
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
  box-shadow: 0 4px 14px rgba(46,125,50,.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(46,125,50,.45); }
.btn-primary:active { transform: translateY(0); }
.btn-primary.full-width { width: 100%; }

.btn-danger {
  background: var(--red);
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
  transition: opacity var(--transition);
}
.btn-danger:hover { opacity: .85; }

.icon-btn {
  font-size: 1.2rem;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--surface-2); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.brand-icon-sm { font-size: 1.4rem; }
.topbar-title { font-size: 1.1rem; font-weight: 700; color: var(--green-dark); }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.topbar-user {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 4px 10px;
  background: var(--green-pale);
  border-radius: 20px;
}

/* ============================================================
   NAVEGACIÓN INFERIOR
   ============================================================ */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  transition: background var(--transition);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  transition: color var(--transition);
  padding: 8px 0;
}
.nav-btn.active { color: var(--green-dark); }
.nav-btn.active .nav-icon { transform: scale(1.15); }
.nav-icon { font-size: 1.3rem; transition: transform var(--transition); }
.nav-label { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }

/* ============================================================
   CONTENIDO PRINCIPAL
   ============================================================ */
.main-content {
  padding-top: calc(var(--topbar-height) + 16px);
  padding-bottom: calc(var(--nav-height) + 16px);
  padding-left: 16px;
  padding-right: 16px;
  max-width: 680px;
  margin: 0 auto;
}

/* Vistas */
.view { display: none; animation: fadeIn .3s ease; }
.view.active { display: block; }

.view-header { margin-bottom: 20px; }
.view-header h2 { font-size: 1.4rem; font-weight: 700; }
.subtitle { font-size: .875rem; color: var(--text-secondary); margin-top: 4px; }

/* ============================================================
   DASHBOARD – TARJETAS
   ============================================================ */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}
.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
  border-left: 4px solid transparent;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card-green  { border-left-color: var(--green-dark); }
.card-blue   { border-left-color: var(--blue); }
.card-teal   { border-left-color: var(--teal); }
.card-orange { border-left-color: var(--orange); }

.card-icon { font-size: 1.6rem; flex-shrink: 0; }
.card-info { display: flex; flex-direction: column; min-width: 0; }
.card-label { font-size: .7rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; }
.card-value { font-size: 1rem; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================================================
   GRÁFICO DE BARRAS (CSS puro)
   ============================================================ */
.chart-section {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.chart-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }

.bar-chart { display: flex; flex-direction: column; gap: 10px; }

.bar-row {
  display: grid;
  grid-template-columns: 100px 1fr 60px;
  align-items: center;
  gap: 10px;
}
.bar-label { font-size: .8rem; color: var(--text-secondary); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track {
  background: var(--surface-2);
  border-radius: 20px;
  height: 10px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 20px;
  background: linear-gradient(90deg, var(--green-dark), var(--green-light));
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.bar-amount { font-size: .78rem; font-weight: 600; color: var(--text-primary); text-align: right; }

/* ============================================================
   ÚLTIMOS GASTOS (dashboard)
   ============================================================ */
.recent-section {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.recent-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 14px; }
.recent-list { display: flex; flex-direction: column; gap: 8px; }

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  animation: slideUp .25s ease;
}
.recent-item-left { display: flex; align-items: center; gap: 10px; }
.recent-cat-icon { font-size: 1.2rem; }
.recent-desc { font-size: .85rem; font-weight: 500; }
.recent-cat  { font-size: .75rem; color: var(--text-secondary); }
.recent-amount { font-size: .9rem; font-weight: 700; color: var(--green-dark); }

/* ============================================================
   FORMULARIO DE GASTO
   ============================================================ */
.expense-form {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

/* Toast de confirmación */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--green-dark);
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: .875rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  z-index: 200;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   HISTORIAL
   ============================================================ */
.history-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.sort-group { display: flex; align-items: center; gap: 8px; }
.sort-group label { font-size: .8rem; font-weight: 600; color: var(--text-secondary); }
.sort-group select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  font-size: .85rem;
  outline: none;
}

.expense-list { display: flex; flex-direction: column; gap: 10px; }

.expense-item {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  animation: slideUp .25s ease;
  transition: transform var(--transition);
}
.expense-item:hover { transform: translateX(3px); }

.expense-item-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.expense-emoji { font-size: 1.5rem; flex-shrink: 0; }
.expense-info { min-width: 0; }
.expense-desc { font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: .75rem; color: var(--text-secondary); margin-top: 2px; }

.expense-item-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.expense-amount { font-size: 1rem; font-weight: 700; color: var(--green-dark); }
.btn-delete {
  font-size: 1rem;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: color var(--transition), background var(--transition);
}
.btn-delete:hover { color: var(--red); background: rgba(198,40,40,.1); }

/* ============================================================
   ANÁLISIS
   ============================================================ */
.analysis-alert {
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 20px;
  font-size: .95rem;
  font-weight: 500;
  line-height: 1.5;
  background: var(--green-pale);
  border-left: 4px solid var(--green-dark);
  color: var(--text-primary);
  transition: background var(--transition);
}
.analysis-alert.warning {
  background: #FFF3E0;
  border-left-color: var(--orange);
}
body.dark-mode .analysis-alert.warning {
  background: #2E1A00;
}

.analysis-breakdown {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.analysis-breakdown h3 { font-size: 1rem; font-weight: 600; margin-bottom: 14px; }

.breakdown-list { display: flex; flex-direction: column; gap: 10px; }
.breakdown-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}
.breakdown-bar-wrap { display: flex; align-items: center; gap: 8px; }
.breakdown-cat { font-size: .85rem; font-weight: 500; min-width: 110px; }
.breakdown-track {
  flex: 1;
  background: var(--surface-2);
  border-radius: 20px;
  height: 8px;
  overflow: hidden;
}
.breakdown-fill {
  height: 100%;
  border-radius: 20px;
  background: linear-gradient(90deg, var(--green-dark), var(--teal));
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.breakdown-pct { font-size: .8rem; font-weight: 700; color: var(--text-secondary); }

.suggestions-section {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.suggestions-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 14px; }
.suggestions-list { display: flex; flex-direction: column; gap: 10px; }
.suggestion-item {
  padding: 12px 14px;
  background: var(--green-pale);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  line-height: 1.5;
  border-left: 3px solid var(--green-dark);
  animation: slideUp .25s ease;
}

/* ============================================================
   UTILIDADES
   ============================================================ */
.empty-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
  padding: 24px 0;
}

/* ============================================================
   ANIMACIONES
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   RESPONSIVE – pantallas más grandes
   ============================================================ */
@media (min-width: 600px) {
  .cards-grid { grid-template-columns: repeat(4, 1fr); }
  .main-content { padding-left: 24px; padding-right: 24px; }
}

@media (min-width: 900px) {
  /* En desktop la nav va al lado izquierdo */
  .bottom-nav {
    top: var(--topbar-height);
    bottom: 0;
    left: 0;
    right: auto;
    width: 80px;
    height: auto;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 12px rgba(0,0,0,.06);
  }
  .nav-btn { padding: 16px 0; }
  .main-content {
    margin-left: 80px;
    padding-top: calc(var(--topbar-height) + 24px);
    padding-bottom: 24px;
  }
}

/* ============================================================
   GRÁFICO DE TORTA (SVG)
   ============================================================ */
.charts-row {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}
@media (min-width: 600px) {
  .charts-row { flex-direction: row; }
  .charts-row .chart-section { flex: 1; margin-bottom: 0; }
}

.chart-pie-section { margin-bottom: 0; }

.pie-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
@media (min-width: 400px) {
  .pie-wrapper { flex-direction: row; align-items: center; }
}

/* Segmentos SVG */
.pie-slice { transition: opacity .2s; cursor: default; }
.pie-slice:hover { opacity: .8; }

/* Leyenda de torta */
.pie-legend { display: flex; flex-direction: column; gap: 6px; }
.pie-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.pie-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ============================================================
   VISTA FINANZAS
   ============================================================ */
.finance-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.finance-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }

.income-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 400px) { .income-grid { grid-template-columns: 1fr; } }

.field-hint {
  font-size: .78rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

/* Resumen ingreso vs gasto */
.income-summary { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.income-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .9rem;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.income-row-total {
  font-weight: 700;
  font-size: .95rem;
  background: var(--green-pale);
  border: 1px solid var(--green-light);
}
.val-green { color: var(--green-dark); font-weight: 700; }
.val-red   { color: var(--red);        font-weight: 700; }

/* Barra de progreso gasto/ingreso */
.spend-bar-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.spend-bar-track {
  flex: 1;
  background: var(--surface-2);
  border-radius: 20px;
  height: 12px;
  overflow: hidden;
}
.spend-bar-fill {
  height: 100%;
  border-radius: 20px;
  background: linear-gradient(90deg, var(--green-dark), var(--green-light));
  transition: width .6s cubic-bezier(.4,0,.2,1), background .3s;
}
.spend-bar-fill.danger { background: linear-gradient(90deg, var(--red), #EF9A9A); }
.spend-bar-fill.warning { background: linear-gradient(90deg, var(--orange), #FFCC80); }
.spend-bar-pct { font-size: .8rem; font-weight: 700; min-width: 36px; text-align: right; }
.spend-bar-msg { font-size: .8rem; color: var(--text-secondary); }

/* Regla 50/30/20 */
.rule-breakdown { display: flex; flex-direction: column; gap: 10px; }
.rule-item {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  align-items: center;
  gap: 10px;
}
.rule-label { font-size: .82rem; font-weight: 600; }
.rule-track {
  background: var(--surface-2);
  border-radius: 20px;
  height: 10px;
  overflow: hidden;
}
.rule-fill {
  height: 100%;
  border-radius: 20px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.rule-fill-needs   { background: var(--green-dark); }
.rule-fill-wants   { background: var(--blue); }
.rule-fill-savings { background: var(--teal); }
.rule-amount { font-size: .8rem; font-weight: 700; color: var(--text-primary); min-width: 70px; text-align: right; }

/* Meta de ahorro */
.goal-progress {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.goal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.goal-title { font-size: .95rem; font-weight: 700; }
.goal-pct-label { font-size: .85rem; font-weight: 700; color: var(--green-dark); }
.goal-track {
  background: var(--surface-2);
  border-radius: 20px;
  height: 14px;
  overflow: hidden;
  margin-bottom: 8px;
}
.goal-fill {
  height: 100%;
  border-radius: 20px;
  background: linear-gradient(90deg, var(--green-dark), var(--teal));
  transition: width .7s cubic-bezier(.4,0,.2,1);
}
.goal-amounts { display: flex; justify-content: space-between; font-size: .78rem; color: var(--text-secondary); margin-bottom: 8px; }
.goal-months-msg { font-size: .82rem; color: var(--text-secondary); font-style: italic; }

/* ============================================================
   ANÁLISIS – filtro de consejos
   ============================================================ */
.tips-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.tips-filter label { font-size: .82rem; font-weight: 600; color: var(--text-secondary); }
.tips-filter select {
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  font-size: .85rem;
  outline: none;
}
