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

:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

/* ── LOGIN ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}
.login-container {
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-logo { font-size: 56px; margin-bottom: 12px; }
.login-title { font-size: 28px; font-weight: 700; }
.login-sub { color: var(--text2); margin: 6px 0 32px; }
.login-form { text-align: left; }

/* ── CAMPOS ── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.field input:focus, .field select:focus { border-color: var(--primary); }
.field select option { background: var(--bg2); }

/* ── BOTONES ── */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-full { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
}
.btn-danger {
  background: transparent;
  color: var(--red);
  border: none;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
}

.error-msg { color: var(--red); font-size: 13px; margin-bottom: 10px; min-height: 18px; }

/* ── LAYOUT PRINCIPAL ── */
.app { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-user { font-size: 13px; color: var(--text2); }
.topbar-logout { color: var(--text2); font-size: 13px; text-decoration: none; }

.main-content {
  flex: 1;
  padding: 16px;
  padding-bottom: 90px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* ── BOTTOM NAV ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  cursor: pointer;
  color: var(--text2);
  font-size: 11px;
  gap: 3px;
  border: none;
  background: transparent;
  transition: color 0.2s;
}
.nav-item .nav-icon { font-size: 22px; line-height: 1; }
.nav-item.active { color: var(--primary); }
.nav-item.nav-add {
  color: #fff;
}
.nav-item.nav-add .nav-icon {
  background: var(--primary);
  border-radius: 50%;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  box-shadow: 0 4px 16px rgba(99,102,241,0.5);
}

/* ── SECCIONES ── */
.section { display: none; }
.section.active { display: block; }

/* ── DASHBOARD ── */
.month-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
}
.month-selector button {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.month-label { font-size: 16px; font-weight: 600; min-width: 130px; text-align: center; }

.summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.summary-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
}
.summary-card.full { grid-column: 1 / -1; }
.card-label { font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.card-amount { font-size: 22px; font-weight: 700; }
.card-amount.green { color: var(--green); }
.card-amount.red { color: var(--red); }
.card-amount.yellow { color: var(--yellow); }

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text2);
  margin: 20px 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── LISTA TRANSACCIONES ── */
.tx-list { display: flex; flex-direction: column; gap: 2px; }
.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.tx-icon {
  font-size: 24px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--bg3);
  flex-shrink: 0;
}
.tx-info { flex: 1; min-width: 0; }
.tx-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12px; color: var(--text2); }
.tx-amount { font-size: 15px; font-weight: 700; flex-shrink: 0; }
.tx-amount.green { color: var(--green); }
.tx-amount.red { color: var(--red); }
.tx-delete { color: var(--text2); font-size: 16px; cursor: pointer; padding: 4px; opacity: 0.5; }
.tx-delete:hover { opacity: 1; color: var(--red); }

.date-header {
  font-size: 12px;
  color: var(--text2);
  padding: 12px 0 4px;
  font-weight: 600;
}

/* ── CATEGORÍAS CHIPS ── */
.cat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}
.cat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.cat-chip.selected {
  border-color: var(--primary);
  background: rgba(99,102,241,0.15);
}

/* ── TIPO TOGGLE ── */
.type-toggle {
  display: flex;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 16px;
  gap: 4px;
}
.type-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.type-btn.active.gasto { background: var(--red); color: #fff; }
.type-btn.active.ingreso { background: var(--green); color: #fff; }
.type-btn.active.transferencia { background: var(--primary); color: #fff; }

/* ── CUENTAS ── */
.accounts-list { display: flex; flex-direction: column; gap: 10px; }
.account-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.account-icon { font-size: 28px; }
.account-info { flex: 1; }
.account-name { font-size: 15px; font-weight: 600; }
.account-type { font-size: 12px; color: var(--text2); text-transform: capitalize; }
.account-balance { font-size: 18px; font-weight: 700; }
.account-balance.neg { color: var(--red); }

/* ── DEUDAS ── */
.debt-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.debt-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.debt-desc { font-size: 15px; font-weight: 600; }
.debt-person { font-size: 12px; color: var(--text2); }
.debt-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
}
.debt-badge.debo { background: rgba(239,68,68,0.15); color: var(--red); }
.debt-badge.me_deben { background: rgba(34,197,94,0.15); color: var(--green); }
.debt-progress { height: 6px; background: var(--bg3); border-radius: 3px; margin-bottom: 8px; overflow: hidden; }
.debt-progress-bar { height: 100%; border-radius: 3px; background: var(--primary); }
.debt-amounts { display: flex; justify-content: space-between; font-size: 12px; color: var(--text2); }
.debt-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 600px;
  max-height: 92dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(.32,.72,0,1);
}
.modal-overlay.open .modal {
  transform: translateY(0);
}
.modal-handle {
  width: 36px; height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  margin: 0 auto 18px;
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; }

/* ── CATEGORÍAS POR TIPO ── */
.cat-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}
.cat-bar-item { display: flex; align-items: center; gap: 10px; }
.cat-bar-label { font-size: 13px; width: 110px; display: flex; align-items: center; gap-6px; gap: 6px; }
.cat-bar-track { flex: 1; height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 4px; }
.cat-bar-amount { font-size: 13px; font-weight: 600; min-width: 80px; text-align: right; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text2);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg3);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s;
  z-index: 300;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── PERFIL ── */
.perfil-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 0 20px;
}
.perfil-avatar {
  width: 90px; height: 90px;
  border-radius: 50%;
  background: var(--bg3);
  border: 3px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.perfil-avatar img { width: 100%; height: 100%; object-fit: cover; }
.perfil-avatar-edit {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.55);
  font-size: 11px;
  text-align: center;
  padding: 4px 0;
  color: #fff;
  font-weight: 600;
}
.perfil-name { font-size: 20px; font-weight: 700; margin-top: 12px; }
.perfil-email { font-size: 13px; color: var(--text2); margin-top: 3px; }
.perfil-badge {
  font-size: 11px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
  margin-top: 8px;
}
.perfil-badge.admin { background: rgba(99,102,241,0.2); color: var(--primary); }
.perfil-badge.user  { background: rgba(148,163,184,0.15); color: var(--text2); }

.perfil-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
}
.perfil-card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text2);
  margin-bottom: 14px;
}

/* ── PROGRAMADOS ── */
.programado-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.programado-card.inactivo { opacity: 0.45; }
.programado-icon {
  font-size: 22px;
  width: 42px; height: 42px;
  background: var(--bg3);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.programado-info { flex: 1; min-width: 0; }
.programado-nombre { font-size: 14px; font-weight: 600; }
.programado-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.programado-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.programado-monto { font-size: 15px; font-weight: 700; }
.programado-actions { display: flex; gap: 6px; }

.freq-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(99,102,241,0.15);
  color: var(--primary);
}
.freq-badge.mensual {
  background: rgba(245,158,11,0.15);
  color: var(--yellow);
}

/* Pendiente item */
.pendiente-item {
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.pendiente-nombre { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.pendiente-detalle { font-size: 13px; color: var(--text2); }
.pendiente-fechas { font-size: 12px; color: var(--primary); margin-top: 4px; }

/* ── UTILS ── */
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-16 { margin-top: 16px; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--text2); }
