/* =====================================================
   TARJETAPP v2 — Estilos
   ===================================================== */

/* ── 1. CSS RESET ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { line-height: 1.5; -webkit-font-smoothing: antialiased; }
img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; }
button { cursor: pointer; border: none; background: none; }
ul, ol { list-style: none; }
a { text-decoration: none; color: inherit; }

/* ── 2. VARIABLES ───────────────────────────────── */
:root {
  --bg:       #080808;
  --surface:  #111111;
  --surface2: #1a1a1a;
  --surface3: #222222;
  --border:   rgba(255,255,255,0.07);
  --border2:  rgba(255,255,255,0.13);
  --border3:  rgba(255,255,255,0.22);
  --text:     #f2f2f2;
  --text2:    #888;
  --text3:    #444;
  --accent:       #4ade80;
  --accent-dim:   rgba(74,222,128,0.10);
  --accent-glow:  rgba(74,222,128,0.25);
  --red:      #f87171; --red-dim:    rgba(248,113,113,0.10);
  --amber:    #fbbf24; --amber-dim:  rgba(251,191,36,0.10);
  --blue:     #60a5fa; --blue-dim:   rgba(96,165,250,0.10);
  --purple:   #a78bfa; --purple-dim: rgba(167,139,250,0.10);
  --radius: 16px; --radius-sm: 10px; --radius-xs: 6px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── 3. BASE ────────────────────────────────────── */
html { background: var(--bg); }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  padding-bottom: calc(88px + var(--safe-bottom));
  -webkit-tap-highlight-color: transparent;
}

/* ── 4. HEADER ──────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(8,8,8,0.85);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  padding: calc(var(--safe-top) + 13px) 18px 13px;
  border-bottom: 0.5px solid var(--border2);
  display: flex; align-items: center; gap: 11px;
}
.app-logo-svg { width: 34px; height: 34px; flex-shrink: 0; }
.app-header-text h1 {
  font-size: 17px; font-weight: 700; letter-spacing: -0.4px;
  background: linear-gradient(135deg, #f2f2f2, #888);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.app-header-text p { font-size: 12px; color: var(--text2); margin-top: 1px; }


/* ── 7. BOTTOM NAV ──────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 780px;
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-top: 0.5px solid var(--border2);
  display: flex; padding-bottom: var(--safe-bottom); z-index: 50;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 11px 0 9px;
  color: var(--text3); font-size: 10px; font-weight: 500; letter-spacing: 0.3px;
  transition: color 0.18s var(--ease); position: relative;
}
.nav-btn svg { width: 22px; height: 22px; stroke-width: 1.7; transition: transform 0.18s var(--ease); }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { transform: translateY(-1px); }
.nav-btn.active::after {
  content: ''; position: absolute; bottom: 6px;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 6px var(--accent-glow);
}
.nav-btn:active { opacity: 0.6; }

/* ── 8. SCREENS ─────────────────────────────────── */
.screen { display: none; padding: 18px; animation: fadeIn 0.2s var(--ease); }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ── 9. CARDS ───────────────────────────────────── */
.card {
  background: var(--surface); border: 0.5px solid var(--border2);
  border-radius: var(--radius); padding: 18px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.card-title { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 16px; }

/* ── 10. METRICS ────────────────────────────────── */
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.metric {
  background: var(--surface); border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm); padding: 16px;
  transition: border-color 0.2s var(--ease);
}
.metric:hover { border-color: var(--border3); }
.metric.full { grid-column: 1/-1; }
.metric .mlabel { font-size: 11px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
.metric .mval { font-size: 26px; font-weight: 700; letter-spacing: -1px; }
.metric .mval.green { color: var(--accent); text-shadow: 0 0 20px var(--accent-glow); }
.metric .mval.small { font-size: 18px; }
.metric .mval.amber { color: var(--amber); }

/* ── 11. FORMS ──────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label { font-size: 11px; color: var(--text2); display: block; margin-bottom: 7px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.field input, .field select {
  width: 100%; background: var(--surface2); border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text); font-size: 15px;
  padding: 12px 14px; outline: none; appearance: none; -webkit-appearance: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23555' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; padding-right: 36px;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.field input::placeholder { color: var(--text3); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── 12. PREVIEW PILL ───────────────────────────── */
.preview-pill {
  display: none; background: var(--accent-dim); border: 0.5px solid var(--accent-glow);
  border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13px;
  color: var(--accent); margin-bottom: 14px; font-weight: 500;
}

/* ── 13. BUTTONS ────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 12px 20px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; cursor: pointer;
  border: 0.5px solid var(--border2); background: transparent; color: var(--text);
  transition: all 0.18s var(--ease); white-space: nowrap;
}
.btn:hover { border-color: var(--border3); background: var(--surface2); }
.btn:active { transform: scale(0.97); opacity: 0.8; }
.btn.primary {
  background: var(--accent); color: #080808; border-color: var(--accent);
  font-weight: 700; box-shadow: 0 4px 14px var(--accent-glow);
}
.btn.primary:hover { background: #6ee79a; box-shadow: 0 6px 20px rgba(74,222,128,0.4); }
.btn.full { width: 100%; justify-content: center; }
.btn.danger { color: var(--red); border-color: rgba(248,113,113,0.25); }
.btn.danger:hover { background: var(--red-dim); }
.btn.small { padding: 8px 13px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ── 14. MES SELECTOR ───────────────────────────── */
.mes-selector { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.mes-selector select {
  flex: 1; min-width: 170px; background: var(--surface2); border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
  padding: 10px 36px 10px 13px; outline: none; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23555' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
  transition: border-color 0.18s var(--ease);
}
.mes-selector select:focus { border-color: var(--accent); }

/* ── 15. GASTO ITEMS ────────────────────────────── */
.gasto-item {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 15px; margin-bottom: 8px;
  transition: opacity 0.2s var(--ease), border-color 0.18s var(--ease);
}
.gasto-item:hover { border-color: var(--border2); }
.gasto-item.pagado { opacity: 0.38; }
.gasto-item.pagado .gi-nombre { text-decoration: line-through; }
.gasto-item[data-medio="tarjeta"]  { border-left: 3px solid var(--blue); }
.gasto-item[data-medio="prestamo"] { border-left: 3px solid var(--amber); }
.gasto-item[data-medio="efectivo"] { border-left: 3px solid var(--text3); }
.gasto-item[data-medio="otro"]     { border-left: 3px solid var(--purple); }
.gi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.gi-info { flex: 1; min-width: 0; }
.gi-nombre { font-size: 15px; font-weight: 600; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gi-meta { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.gi-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.gi-monto { font-size: 15px; font-weight: 700; }
.gi-cuota-badge { font-size: 11px; color: var(--text2); }
.gi-actions { display: flex; gap: 7px; margin-top: 12px; padding-top: 12px; border-top: 0.5px solid var(--border); }
.action-btn {
  flex: 1; min-height: 44px; padding: 9px; background: var(--surface2); border: 0.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text2); font-size: 12px; font-weight: 500;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px;
  transition: all 0.18s var(--ease);
}
.action-btn:active { transform: scale(0.96); }
.action-btn.paid { color: var(--accent); border-color: rgba(74,222,128,0.3); background: var(--accent-dim); }
.action-btn.del  { color: var(--red);   border-color: rgba(248,113,113,0.2); }
.action-btn.del:hover { background: var(--red-dim); }

/* ── 16. BADGES ─────────────────────────────────── */
.badge { font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 20px; letter-spacing: 0.04em; white-space: nowrap; }
.badge.cuota    { background: var(--blue-dim);   color: var(--blue);   border: 0.5px solid rgba(96,165,250,0.2); }
.badge.fijo     { background: var(--amber-dim);  color: var(--amber);  border: 0.5px solid rgba(251,191,36,0.2); }
.badge.tarjeta  { background: var(--blue-dim);   color: var(--blue);   border: 0.5px solid rgba(96,165,250,0.2); }
.badge.prestamo { background: var(--amber-dim);  color: var(--amber);  border: 0.5px solid rgba(251,191,36,0.2); }
.badge-alerta   { display:inline-flex;align-items:center;font-size:10px;font-weight:700;color:#fb923c;background:rgba(251,146,60,0.1);border:0.5px solid rgba(251,146,60,0.3);padding:2px 7px;border-radius:20px;white-space:nowrap; }
.alerta-cierre  { margin-top:4px;font-size:11px;font-weight:700;color:#fb923c;display:flex;align-items:center;gap:4px; }


/* ── 17. RESUMEN ITEMS ──────────────────────────── */
.resumen-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 0; border-bottom: 0.5px solid var(--border); gap: 10px;
}
.resumen-item:last-child { border-bottom: none; }
.ri-left { flex: 1; min-width: 0; }
.ri-nombre { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri-sub { font-size: 11px; color: var(--text2); margin-top: 3px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.ri-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ri-monto { font-size: 14px; font-weight: 700; }

/* ── 18. TOTAL ROW ──────────────────────────────── */
.total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px;
  background: linear-gradient(135deg, rgba(74,222,128,0.10), rgba(74,222,128,0.05));
  border: 0.5px solid var(--accent-glow); border-radius: var(--radius-sm); margin-top: 12px;
}
.total-row span:first-child { font-size: 13px; font-weight: 600; color: var(--accent); }
.total-row span:last-child  { font-size: 20px; font-weight: 800; color: var(--accent); letter-spacing: -0.5px; }

/* ── 19. POR PERSONA ────────────────────────────── */
.persona-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 0.5px solid var(--border); font-size: 14px; }
.persona-row:last-child { border-bottom: none; }
.persona-row span:first-child { color: var(--text2); }
.persona-row span:last-child { font-weight: 700; }

/* ── 20. EMPTY STATE ────────────────────────────── */
.empty { text-align: center; padding: 48px 24px; color: var(--text3); font-size: 14px; }
.empty svg { width: 40px; height: 40px; stroke: var(--text3); margin: 0 auto 12px; opacity: 0.5; }

/* ── 21. SECTION LABEL ──────────────────────────── */
.section-label { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.09em; margin: 20px 0 10px; }

/* ── 22. TOAST ──────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(96px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--surface3); border: 0.5px solid var(--border2); color: var(--text);
  padding: 11px 20px; border-radius: 24px; font-size: 13px; font-weight: 600;
  opacity: 0; transition: all 0.28s var(--ease); z-index: 999;
  white-space: nowrap; pointer-events: none; box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── 23. SEGMENTED CONTROL ──────────────────────── */
.seg-control {
  display: flex; background: var(--surface2); border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm); padding: 3px; margin-bottom: 14px; gap: 3px;
}
.seg-btn {
  flex: 1; padding: 9px; border-radius: 7px; font-size: 13px; font-weight: 600;
  color: var(--text2); background: transparent; border: none; cursor: pointer;
  transition: all 0.18s var(--ease);
}
.seg-btn.active { background: var(--surface3); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.3); }

/* ── 24. LOAN CARDS ─────────────────────────────── */
.loan-card {
  background: var(--surface); border: 0.5px solid var(--border2);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.loan-card[data-medio="tarjeta"]  { border-left: 3px solid var(--blue); }
.loan-card[data-medio="prestamo"] { border-left: 3px solid var(--amber); }
.loan-card[data-medio="otro"]     { border-left: 3px solid var(--purple); }
.loan-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.loan-nombre { font-size: 16px; font-weight: 700; }
.loan-monto-restante { font-size: 16px; font-weight: 800; color: var(--amber); }
.loan-meta { font-size: 12px; color: var(--text2); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ── 25. PROGRESS BAR ───────────────────────────── */
.progress-wrap { margin-top: 10px; }
.progress-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text2); margin-bottom: 6px; }
.progress-bar { width: 100%; height: 5px; background: var(--surface3); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), #22d35e); transition: width 0.6s var(--ease); }
.progress-fill.amber { background: linear-gradient(90deg, var(--amber), #f59e0b); }
.loan-actions { display: flex; gap: 7px; margin-top: 12px; padding-top: 12px; border-top: 0.5px solid var(--border); }

/* ── 26. SETTINGS ───────────────────────────────── */
.settings-group { margin-bottom: 24px; }
.settings-group-title { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.09em; margin-bottom: 10px; }

/* ── 27. PROYECCIÓN ANUAL ────────────────────────── */
.proy-card {
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  padding: 20px 20px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.proy-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 18px; padding-bottom: 14px;
  border-bottom: 0.5px solid var(--border);
}
.proy-header__label { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.08em; }
.proy-header__total { font-size: 20px; font-weight: 800; color: var(--accent); letter-spacing: -0.5px; text-shadow: 0 0 20px var(--accent-glow); }
.proy-list { display: flex; flex-direction: column; gap: 10px; }
.proy-row {
  display: grid;
  grid-template-columns: 72px 1fr 88px;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  transition: background 0.15s var(--ease);
}
.proy-row:hover { background: var(--surface2); }
.proy-row--current {
  background: rgba(74,222,128,0.06);
  border: 0.5px solid rgba(74,222,128,0.18);
}
.proy-row__mes {
  font-size: 12px; font-weight: 600; color: var(--text2);
  white-space: nowrap;
}
.proy-row--current .proy-row__mes { color: var(--accent); }
.proy-row__bar-wrap {
  background: var(--surface3);
  border-radius: 6px; height: 6px; overflow: hidden;
}
.proy-row__bar {
  height: 100%; border-radius: 6px; min-width: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, #22d35e 100%);
  transition: width 0.6s var(--ease);
}
.proy-row--current .proy-row__bar {
  box-shadow: 0 0 8px var(--accent-glow);
}
.proy-row__amt {
  font-size: 12px; font-weight: 600; text-align: right;
  color: var(--text2); white-space: nowrap;
}
.proy-row__amt--current { color: var(--accent); font-weight: 700; }
.section-label { display: flex; align-items: center; }


/* ── 28. RESPONSIVE tablet ──────────────────────── */
@media (min-width: 600px) {
  .form-row { grid-template-columns: 1fr 1fr 1fr; }
  .metrics  { grid-template-columns: repeat(4, 1fr); }
  .metric.full { grid-column: auto; }
  .screen { padding: 22px 28px; }
  .bottom-nav { border-radius: 20px 20px 0 0; }
  .app-header { padding-left: 28px; padding-right: 28px; }
}

/* ── 29. MOBILE SMALL (≤390px) iPhone SE, Xiaomi ── */
@media (max-width: 390px) {
  .form-row   { grid-template-columns: 1fr; }
  .gi-actions { flex-wrap: wrap; }
  .action-btn { flex: 1 1 44%; }
  .nav-btn    { font-size: 9px; }
  .nav-btn svg { width: 20px; height: 20px; }
  .metric .mval       { font-size: 22px; }
  .metric .mval.small { font-size: 16px; }
  .screen { padding: 14px; }
  .toast  { font-size: 12px; padding: 9px 16px; white-space: normal; max-width: 88vw; text-align: center; }
  .proyeccion-row { grid-template-columns: 50px 1fr 78px; }
  .gi-nombre { font-size: 14px; }
}
