/* ──────────────────────────────────────────────────────────────
   Medio Pulmón — Light Fintech Theme
   Solo estética. Clases y semántica mantienen el contrato del JS.
   Optimizado para legibilidad bajo el sol.
   ────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Surfaces — gris cálido */
  --bg:        #F0F2F0;
  --surface:   #FFFFFF;
  --surface-2: #F7F8F7;
  --card:      #FFFFFF;     /* alias legacy */
  --border:    #E4E7E4;
  --border-strong: #C9CFC9;

  /* Texto */
  --text:    #0A0E1A;
  --text-2:  #2D3340;
  --muted:   #6B7280;

  /* Marca / accents */
  --primary:  #0066FF;      /* azul eléctrico */
  --primary-600: #0052CC;
  --primary-50:  #E6F0FF;
  --primary-glow: rgba(0,102,255,.15);

  --accent:   #0066FF;      /* alias legacy */
  --info:     #0066FF;
  --info-glow: rgba(0,102,255,.15);

  --success:  #10B981;
  --success-50: #ECFDF5;
  --warning:  #F59E0B;
  --warning-50: #FFFBEB;
  --danger:   #EF4444;
  --danger-50: #FEF2F2;

  /* Sombras suaves para light */
  --shadow-card: 0 1px 2px rgba(15,23,42,.04), 0 4px 16px -8px rgba(15,23,42,.08);
  --shadow-pop:  0 24px 48px -16px rgba(15,23,42,.18), 0 4px 12px -2px rgba(15,23,42,.08);
  --shadow-btn:  0 1px 2px rgba(0,102,255,.18), 0 4px 12px -4px rgba(0,102,255,.35);

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
}

html, body { background: var(--bg); }
body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-feature-settings: 'cv11', 'ss01', 'tnum';
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

/* ── Layout ── */
#app { display: flex; flex-direction: column; min-height: 100dvh; position: relative; }

#header {
  background: var(--surface);
  color: var(--text);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--border);
}

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 40px; height: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px;
  color: var(--primary);
  letter-spacing: .02em;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(15,23,42,.06);
}
.logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.logo-text h1 {
  font-size: 15px; font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.logo-text p {
  font-size: 11px; color: var(--muted);
  font-weight: 500;
  margin-top: 1px;
}

#main { flex: 1; padding: 16px 16px 110px; overflow-y: auto; }

/* ── Bottom Nav ── */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 40;
  padding: 6px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px -16px rgba(15,23,42,.08);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 4px 7px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  border-radius: 12px;
  transition: color .15s, background .2s;
  position: relative;
  font-family: inherit;
}
.nav-btn svg { width: 22px; height: 22px; stroke-width: 2; }
.nav-btn.active {
  color: var(--primary);
  background: var(--primary-50);
}
.nav-btn.active svg { stroke-width: 2.4; }
.nav-dot {
  position: absolute;
  top: 4px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--primary);
  display: none;
}
.nav-btn.active .nav-dot { display: block; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}
.card-p { padding: 16px; }
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ── Badges ── */
.badge {
  font-size: 10.5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: .01em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  flex-shrink: 0;
}
.badge-debe    { background: var(--danger-50);  color: #B91C1C; border-color: rgba(239,68,68,.25); }
.badge-parcial { background: var(--warning-50); color: #92400E; border-color: rgba(245,158,11,.3); }
.badge-pago    { background: var(--success-50); color: #047857; border-color: rgba(16,185,129,.3); }
.badge-info    { background: var(--primary-50); color: #1E40AF; border-color: rgba(0,102,255,.25); }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-input {
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-input::placeholder { color: var(--muted); opacity: .8; }
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'><path d='M3 4.5L6 7.5L9 4.5' stroke='%236B7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* ── Buttons (chunky con borde) ── */
.btn {
  border: 2px solid transparent;
  border-radius: var(--r-md);
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: transform .08s, opacity .15s, background .15s, border-color .15s, box-shadow .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(.98); opacity: .9; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-btn);
}
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-accent {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-outline {
  background: var(--surface);
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-50); }
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  box-shadow: 0 1px 2px rgba(239,68,68,.18), 0 4px 12px -4px rgba(239,68,68,.4);
}
.btn-del {
  background: var(--surface);
  color: var(--danger);
  border: 2px solid var(--danger);
}
.btn-del:hover { background: var(--danger-50); }
.btn-full { width: 100%; }
.btn-sm {
  padding: 6px 14px;
  font-size: 12.5px;
  border-radius: 9px;
  border-width: 2px;
}

/* ── KPI Grid ── */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 500;
}

/* KPI destacado: azul vibrante con saldo en blanco */
.kpi-dark {
  grid-column: span 2;
  background: linear-gradient(135deg, var(--primary) 0%, #0052CC 100%);
  border: 1px solid var(--primary);
  padding: 18px;
  color: #fff;
  box-shadow:
    0 1px 0 rgba(255,255,255,.15) inset,
    0 8px 24px -8px rgba(0,102,255,.4);
}
.kpi-dark .kpi-label { color: rgba(255,255,255,.75); }
.kpi-dark .kpi-value { font-size: 30px; color: #fff; }
.kpi-dark .kpi-sub   { color: rgba(255,255,255,.7); }

/* ── List rows ── */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
  gap: 12px;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover  { background: var(--surface-2); }
.list-row:active { background: var(--primary-50); }
.list-row-name {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
.list-row-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-sheet {
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.32,.72,0,1);
  box-shadow: var(--shadow-pop);
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-handle {
  width: 40px; height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto 18px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 18px;
  letter-spacing: -0.015em;
  color: var(--text);
}

/* ── Tabs ── */
.tab-bar {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 4px;
  gap: 2px;
  box-shadow: var(--shadow-card);
}
.tab-btn {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 9px;
  background: transparent;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.tab-btn:hover { color: var(--text-2); }
.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px -2px rgba(0,102,255,.4);
}

/* ── Progress bar ── */
.progress-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success) 0%, #34D399 100%);
  border-radius: 999px;
  transition: width .5s cubic-bezier(.4,0,.2,1);
}

/* ── Tramo pill ── */
.tramo-pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--primary-50);
  color: var(--primary);
  border: 1px solid rgba(0,102,255,.25);
  font-variant-numeric: tabular-nums;
}

/* ── Utility ── */
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.space-y > * + * { margin-top: 10px; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-muted   { color: var(--muted); }
.text-sm      { font-size: 13px; }
.text-xs      { font-size: 11.5px; }
.font-bold    { font-weight: 700; }
.text-right   { text-align: right; }
.w-full       { width: 100%; }
.hidden       { display: none !important; }

.kpi-value, .badge, .tramo-pill, .sponsor-spot-monto,
.sim-result .amount {
  font-variant-numeric: tabular-nums;
}

/* ── Login container overlay ── */
#login-container:not(:empty) {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow-y: auto;
}

/* ── Login screen ── */
#login-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  background:
    radial-gradient(50% 40% at 50% 10%, rgba(0,102,255,.08), transparent 70%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-pop);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon {
  width: 72px; height: 72px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  display: grid; place-items: center;
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  margin: 0 auto 16px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.login-logo .icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.login-logo h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.login-logo p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ── Offline banner ── */
#offline-banner {
  background: var(--warning);
  color: #1A1108;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding: 7px;
  display: none;
  position: relative;
  z-index: 50;
}
body.offline #offline-banner { display: block; }

/* ── Spinner ── */
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
}

/* ── Sponsor spot ── */
.sponsor-spot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin-bottom: 8px;
  transition: border-color .15s, background .15s;
}
.sponsor-spot:hover { border-color: var(--primary); background: var(--surface); }
.sponsor-spot:last-child { margin-bottom: 0; }
.sponsor-spot-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.sponsor-spot-name {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 500;
}
.sponsor-spot-monto {
  font-size: 14px;
  font-weight: 700;
  color: var(--success);
}
.sponsor-spot.libre {
  border-style: dashed;
  border-color: var(--border-strong);
  background: transparent;
}
.sponsor-spot.libre .sponsor-spot-monto {
  color: var(--muted);
  font-weight: 500;
  font-style: normal;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .08em;
}

/* ── Simulador ── */
.sim-result {
  background: linear-gradient(135deg, var(--primary) 0%, #0052CC 100%);
  color: #fff;
  border-radius: var(--r-lg);
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 8px 24px -8px rgba(0,102,255,.4);
}
.sim-result > div:first-child {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.75);
  font-weight: 700;
}
.sim-result .amount {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-top: 6px;
  color: #fff;
}
.sim-result .detail {
  font-size: 12px;
  color: rgba(255,255,255,.75);
  margin-top: 10px;
  font-weight: 500;
}

/* ── Selects nativos ── */
select.form-input option {
  background: var(--surface);
  color: var(--text);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

::selection { background: var(--primary-glow); color: var(--text); }
