:root {
  --bg: #F9F6F0;
  --card: #FFFFFF;
  --ink: #2E2E2E;
  --text-secondary: #4A4A4A;
  --muted: #5C5C5C;
  --chevron: #C6CEEF;
  --border: #E5DFD2;
  /* 3 escalones de redondeo — antes habia 7+ valores distintos (8/10/11/12/14/16/18/20/24px)
     repartidos entre estilo.css y los <style> locales de cada pantalla, sin ningun criterio. */
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --primary: #2E5077;
  --primary-dark: #223C5C;
  --primary-tint: #E6ECF1;
  --success: #16A34A;
  --success-tint: #E7F8EC;
  --success-ink: #2E7D32;
  --warning: #F5A524;
  --warning-tint: #FEF3DA;
  --warning-ink: #8a5a00;
  --danger: #F2545B;
  --danger-tint: #FDE7E8;
  --danger-ink: #a4222c;
  --shadow: 0 10px 30px rgba(30, 40, 90, 0.08);
}
:root[data-theme="dark"] {
  --bg: #14161c;
  --card: #1e2027;
  --ink: #EAEAEC;
  --text-secondary: #c7c7c9;
  --muted: #9096A3;
  --chevron: #4b5877;
  --border: #2c2f38;
  --primary: #6FA3D1;
  --primary-dark: #17314a;
  --primary-tint: #1f3145;
  --success: #22C55E;
  --success-tint: #123821;
  --success-ink: #4ADE80;
  --warning: #FBBF24;
  --warning-tint: #3a2c0f;
  --warning-ink: #FFC670;
  --danger: #FB7185;
  --danger-tint: #3a1b1f;
  --danger-ink: #ff9aa2;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}
/* El toggle de tema oscuro/claro cambiaba toda la paleta de golpe, sin transicion —
   se sentia como un parpadeo en vez de un cambio suave. */
.card, .field input, .field textarea, .chip, .doc-ico, .quick-action, .sheet-option {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.wrap {
  max-width: 460px;
  margin: 0 auto;
  padding: 28px 20px 90px;
  min-height: 100vh;
}

/* ---------- barra de navegacion inferior ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(30,40,90,0.06);
}
.tabbar-inner {
  width: 100%; max-width: 460px; display: flex;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
}
.tab-item {
  position: relative;
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-decoration: none; padding: 4px 0; border: none; background: none; font-family: inherit; cursor: pointer;
}
.tab-item i { font-size: 18px; }
.tab-item.active { color: var(--primary); }
.tab-badge {
  /* Relativo al centro del propio tab-item (siempre centrado por flex), no a un ancho de
     tab asumido — antes se rompia si el numero de tabs cambiaba. */
  position: absolute; top: -2px; left: 50%; margin-left: 6px; min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 8px; background: #E4574C; color: #fff; border: 2px solid var(--card);
  font-size: 9px; font-weight: 800; font-family: 'Poppins', sans-serif;
  display: flex; align-items: center; justify-content: center;
}

.word {
  font-family: 'Poppins', sans-serif;
  font-weight: 800;
  font-size: 1.6rem;
  color: var(--primary);
}
.word-logo { height: 34px; display: block; margin: 0 auto; }
.login-mascot { width: 96px; height: 96px; object-fit: contain; display: block; margin: 14px auto 0; }

/* login */
.login-shell {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 30px;
}
.login-card .word { display: block; text-align: center; margin-bottom: 6px; }
.h1 { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 1.5rem; margin: 22px 0 4px; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.field input {
  width: 100%; height: 50px; border-radius: var(--radius-md); border: 1.5px solid var(--border);
  background: var(--card); padding: 0 18px; font-family: inherit; font-size: 14.5px; color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #2E507722; }
.field-password { position: relative; }
.field-password input { padding-right: 46px; }
.field-password .toggle-pass {
  position: absolute; right: 4px; top: 32px; width: 42px; height: 42px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.field-password .toggle-pass:active { opacity: 0.6; }
.field textarea {
  width: 100%; min-height: 64px; border-radius: var(--radius-md); border: 1.5px solid var(--border);
  background: var(--card); padding: 12px 18px; font-family: inherit; font-size: 14.5px; color: var(--ink); resize: vertical;
}
.field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #2E507722; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 52px; border-radius: var(--radius-md); border: none;
  font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 15.5px; cursor: pointer;
  transition: transform 0.1s ease, opacity 0.1s ease;
}
.btn:active { transform: scale(0.97); opacity: 0.88; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 10px 20px rgba(61,90,239,0.28); }
.btn-primary:disabled { opacity: 0.6; cursor: default; box-shadow: none; }
.btn-primary:disabled:active { transform: none; }
.btn-white { background: #fff; color: var(--primary); }
.btn-ghost { background: transparent; color: var(--primary); font-weight: 700; height: auto; padding: 0; }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 10px 20px rgba(242,84,91,0.28); }
.btn-danger:disabled { opacity: 0.6; cursor: default; box-shadow: none; }

.link-row { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; margin: 14px 0 22px; color: var(--muted); }
.link-row a { color: var(--primary); text-decoration: none; font-weight: 600; }

.error-box {
  background: var(--danger-tint); color: var(--danger-ink); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 13px; margin-bottom: 14px; display: none;
}
.error-box.show { display: block; }

/* inicio */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.avatar-blob {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(145deg, var(--primary), #5B8AB0);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 1rem; cursor: pointer; border: none;
  transition: transform 0.1s ease;
}
.avatar-blob:active { transform: scale(0.94); }
.greet { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 1.5rem; margin: 18px 0 2px; }
.greet-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }
.cat-chip { font-weight: 700; background: var(--primary-tint); color: var(--primary); border-radius: var(--radius-sm); padding: 2px 9px; font-size: 13px; }

.quick-actions { display: flex; align-items: stretch; gap: 10px; margin: 4px 0 16px; }
.quick-action {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius-md);
  padding: 16px 6px; text-decoration: none; color: var(--ink); font-size: 12px; font-weight: 600;
  text-align: center; line-height: 1.25; min-height: 84px;
  transition: transform 0.1s ease, opacity 0.1s ease, border-color 0.2s ease, background-color 0.2s ease;
}
.quick-action:active { transform: scale(0.97); opacity: 0.85; }
.quick-action i { font-size: 22px; color: var(--primary); flex-shrink: 0; }
.unread-dot {
  position: absolute; top: 8px; right: 10px; width: 9px; height: 9px;
  border-radius: 50%; background: #E4574C; border: 1.5px solid var(--card);
}
.unread-count {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: #E4574C; color: #fff; border: 2px solid var(--card);
  font-size: 11px; font-weight: 800; font-family: 'Poppins', sans-serif;
  display: flex; align-items: center; justify-content: center;
}

.vep-card {
  background: linear-gradient(145deg, var(--primary), #4A7CA8); color: #fff;
  border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 12px;
  box-shadow: 0 10px 22px rgba(61,90,239,0.25);
}
.vep-card .lbl { font-size: 11px; opacity: 0.85; font-weight: 600; margin: 0 0 4px; }
.vep-card .amt { font-family: 'Poppins', sans-serif; font-size: 1.7rem; font-weight: 800; line-height: 1.15; }
.vep-card .due { font-size: 12px; opacity: 0.85; margin: 3px 0 0; }
.vep-card .btn { margin-top: 12px; }

.card { background: var(--card); border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 14px; box-shadow: 0 6px 18px rgba(30,40,90,0.06); }
.card h3 { font-family: 'Poppins', sans-serif; font-size: 1.05rem; font-weight: 700; margin: 0 0 12px; }

.progress-track { height: 10px; border-radius: 999px; background: var(--primary-tint); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #5B8AB0); }
.progress-fill.over { background: linear-gradient(90deg, var(--danger), #c73a41); }
.progress-note.over { color: var(--danger); font-weight: 600; }
.progress-amt { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.progress-note { font-size: 12.5px; color: var(--text-secondary); margin-top: 10px; }

.evo-chart-svg { display: block; width: 100%; height: auto; }
.evo-chart-svg .evo-callout { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 13px; fill: var(--primary); }
.evo-chart-svg .evo-label { font-family: inherit; font-size: 9px; fill: var(--muted); text-transform: uppercase; }

.doc-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; text-decoration: none; color: inherit; transition: opacity 0.1s ease; }
.doc-row:active { opacity: 0.6; }
.doc-left { display: flex; align-items: center; gap: 10px; font-size: 13.5px; font-weight: 600; }
.doc-ico { width: 34px; height: 34px; border-radius: var(--radius-sm); background: var(--primary-tint); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.doc-borrar { background: none; border: none; padding: 10px; margin: -10px; color: var(--muted); font-size: 13px; cursor: pointer; }
.doc-borrar:hover { color: var(--danger); }
.empty-note { color: var(--muted); font-size: 13px; padding: 8px 0; }

.state-msg { text-align: center; color: var(--muted); font-size: 14px; padding: 60px 0; }

/* ---------- skeleton (placeholder con la forma del contenido final, no un "Cargando..."
   suelto que despues salta a un layout totalmente distinto) ---------- */
@keyframes skeleton-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.skeleton-card {
  border-radius: var(--radius-lg); background: var(--card); border: 1.5px solid var(--border);
  margin-bottom: 14px; animation: skeleton-pulse 1.3s ease-in-out infinite;
}

/* ---------- mascota ---------- */
.empty-mascot { text-align: center; padding: 10px 0 4px; }
.empty-mascot img { width: 84px; height: 84px; object-fit: contain; margin: 0 auto 10px; display: block; }
.empty-mascot p { margin: 0; }

.success-overlay { position: fixed; inset: 0; background: rgba(249,246,240,0.96); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 300; gap: 14px; }
:root[data-theme="dark"] .success-overlay { background: rgba(20,22,28,0.96); }
.success-overlay img { width: 140px; height: 140px; object-fit: contain; }
.success-overlay p { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 1.3rem; color: var(--primary); margin: 0; }

/* ---------- bottom sheet (elegir tipo de documento) ---------- */
.sheet-overlay { position: fixed; inset: 0; background: rgba(27,33,64,0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 200; }
.sheet-overlay.hidden { display: none; }
.sheet-card { width: 100%; max-width: 460px; background: var(--card); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 22px 22px 28px; }
.sheet-card h3 { font-family: 'Poppins', sans-serif; font-size: 1.05rem; margin: 0 0 4px; }
.sheet-card .sheet-sub { font-size: 12.5px; color: var(--muted); margin: 0 0 16px; }
.sheet-option {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 14px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: var(--card); margin-bottom: 9px; font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--ink); cursor: pointer; text-align: left;
  transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.sheet-option:hover { background: var(--primary-tint); border-color: var(--primary); }
.sheet-option:active { transform: scale(0.98); }
.sheet-option i { color: var(--primary); width: 18px; text-align: center; }
.sheet-cancel { width: 100%; text-align: center; padding: 10px; color: var(--muted); font-size: 13.5px; background: none; border: none; margin-top: 4px; font-family: inherit; cursor: pointer; }
.doc-type-tag { font-size: 11px; color: var(--muted); }

/* ---------- filtro de chips + agrupado por periodo ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; margin: -2px -2px 0; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--card); color: var(--ink-soft, var(--ink)); cursor: pointer; white-space: nowrap;
  transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.chip:active { transform: scale(0.96); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(46,80,119,0.25); }

.period-group { margin-bottom: 18px; }
.period-label {
  font-family: 'Poppins', sans-serif; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 8px 4px;
}

/* ---------- toast (avisos flotantes, reemplaza alert() nativo) ---------- */
.toast {
  position: fixed; top: 14px; left: 50%; transform: translate(-50%, -140%);
  max-width: 420px; width: calc(100% - 32px); z-index: 400;
  border-radius: 14px; padding: 12px 16px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow); text-align: center;
  transition: transform 0.25s ease;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); }
.toast-error { background: var(--danger-tint); color: var(--danger-ink); }
.toast-success { background: var(--success-tint); color: var(--success-ink); }
