/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --morado: #7c3aed;
  --morado-claro: #a855f7;
  --morado-bg: #f5f0ff;
  --rosa: #ec4899;
  --verde: #10b981;
  --rojo: #ef4444;
  --amarillo: #f59e0b;
  --gris-claro: #f8f7ff;
  --gris: #6b7280;
  --gris-borde: #e5e7eb;
  --texto: #1f2937;
  --blanco: #ffffff;
  --sombra: 0 2px 12px rgba(124,58,237,0.10);
  --radio: 14px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--gris-claro);
  color: var(--texto);
  min-height: 100vh;
}

/* ===== PANTALLAS ===== */
.pantalla { display: none; }
.pantalla.activa { display: block; }

/* ===== LOGIN ===== */
#pantalla-login {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4c1d95 0%, #7c3aed 50%, #a855f7 100%);
}

#pantalla-login.activa {
  display: flex;
}

.login-box {
  background: white;
  border-radius: 24px;
  padding: 48px 36px;
  width: 90%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.logo-login { font-size: 56px; margin-bottom: 12px; }
.login-box h1 { font-size: 26px; color: var(--morado); margin-bottom: 6px; }
.subtitulo { color: var(--gris); font-size: 14px; margin-bottom: 28px; }

.login-box input {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--gris-borde);
  border-radius: var(--radio);
  font-size: 18px;
  text-align: center;
  letter-spacing: 6px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.login-box input:focus { border-color: var(--morado); }

.login-box button {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--morado), var(--morado-claro));
  color: white;
  border: none;
  border-radius: var(--radio);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}
.login-box button:hover { opacity: 0.9; }
.error-msg { color: var(--rojo); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ===== HEADER ===== */
header {
  background: linear-gradient(135deg, #4c1d95, #7c3aed);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(124,58,237,0.3);
}

.header-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 26px; }
.titulo-header { font-size: 20px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 14px; }

.btn-icon {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.2s;
}
.btn-icon:hover { background: rgba(255,255,255,0.25); }

/* ===== NAV TABS ===== */
.nav-tabs {
  display: flex;
  background: white;
  border-bottom: 2px solid var(--gris-borde);
  position: sticky;
  top: 66px;
  z-index: 99;
  overflow-x: auto;
}

.tab {
  flex: 1;
  padding: 14px 8px;
  border: none;
  background: none;
  color: var(--gris);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: color 0.2s;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.tab i { font-size: 18px; }
.tab.activa { color: var(--morado); border-bottom-color: var(--morado); }
.tab:hover:not(.activa) { color: var(--morado-claro); }

/* ===== MAIN ===== */
main { padding: 16px; max-width: 600px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.activa { display: block; }

/* ===== SEMANA NAV ===== */
.semana-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  border-radius: var(--radio);
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: var(--sombra);
}
.semana-nav button {
  background: var(--morado-bg);
  border: none;
  color: var(--morado);
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}
.semana-nav button:hover { background: var(--morado); color: white; }
#label-semana { font-weight: 700; color: var(--texto); font-size: 15px; }

/* ===== STAT CARDS ===== */
.tarjetas-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: white;
  border-radius: var(--radio);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--sombra);
}

.stat-icon {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--morado), var(--morado-claro));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-icon.cat { background: linear-gradient(135deg, var(--rosa), #f472b6); }

.stat-valor { font-size: 20px; font-weight: 800; color: var(--texto); }
.stat-label { font-size: 12px; color: var(--gris); margin-top: 2px; }

/* ===== CARDS ===== */
.card {
  background: white;
  border-radius: var(--radio);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--sombra);
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; color: var(--texto); }

/* ===== LISTA RESUMEN CATEGORÍAS ===== */
.resumen-cat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gris-borde);
}
.resumen-cat-item:last-child { border-bottom: none; }
.resumen-cat-icono {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.resumen-cat-info { flex: 1; }
.resumen-cat-nombre { font-size: 14px; font-weight: 600; }
.resumen-cat-barra-wrap { height: 6px; background: var(--gris-borde); border-radius: 3px; margin-top: 4px; }
.resumen-cat-barra { height: 100%; border-radius: 3px; transition: width 0.4s; }
.resumen-cat-monto { font-size: 15px; font-weight: 700; color: var(--morado); }

/* ===== TARJETAS DE CRÉDITO ===== */
.tarjeta-credito {
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  color: white;
  position: relative;
  overflow: hidden;
}
.tarjeta-credito::before {
  content: '';
  position: absolute;
  top: -20px; right: -20px;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
}
.tarjeta-nombre { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.tarjeta-deuda-label { font-size: 12px; opacity: 0.8; }
.tarjeta-deuda-monto { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.tarjeta-barra-wrap { height: 8px; background: rgba(255,255,255,0.3); border-radius: 4px; margin-bottom: 8px; }
.tarjeta-barra-fill { height: 100%; border-radius: 4px; background: rgba(255,255,255,0.85); }
.tarjeta-footer { display: flex; justify-content: space-between; font-size: 12px; opacity: 0.85; }
.tarjeta-acciones { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }
.tarjeta-acciones button {
  background: rgba(255,255,255,0.2);
  border: none; color: white;
  width: 28px; height: 28px;
  border-radius: 50%; cursor: pointer; font-size: 12px;
}
.tarjeta-acciones button:hover { background: rgba(255,255,255,0.35); }

/* ===== BOTONES ===== */
.btn-primario {
  background: linear-gradient(135deg, var(--morado), var(--morado-claro));
  color: white;
  border: none;
  border-radius: var(--radio);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.2s;
}
.btn-primario:hover { opacity: 0.9; }
.btn-primario.full { width: 100%; justify-content: center; margin-top: 6px; }

.btn-secundario {
  background: var(--morado-bg);
  color: var(--morado);
  border: 2px dashed var(--morado-claro);
  border-radius: var(--radio);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: center;
  margin-top: 8px;
  transition: background 0.2s;
}
.btn-secundario:hover { background: #ede9fe; }

.btn-danger {
  background: linear-gradient(135deg, var(--rojo), #f87171);
  color: white;
  border: none;
  border-radius: var(--radio);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.btn-danger.full { width: 100%; margin-top: 10px; }

/* ===== ACCIONES TOP ===== */
.acciones-top {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.acciones-top select {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--gris-borde);
  border-radius: var(--radio);
  font-size: 13px;
  background: white;
  color: var(--texto);
  min-width: 140px;
}

/* ===== LISTA GASTOS ===== */
.lista-gastos { display: flex; flex-direction: column; gap: 10px; }

.gasto-item {
  background: white;
  border-radius: var(--radio);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--sombra);
  cursor: pointer;
  transition: transform 0.15s;
}
.gasto-item:hover { transform: translateY(-1px); }

.gasto-icono {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.gasto-info { flex: 1; }
.gasto-desc { font-size: 15px; font-weight: 600; }
.gasto-meta { font-size: 12px; color: var(--gris); margin-top: 2px; }
.gasto-monto { font-size: 17px; font-weight: 800; color: var(--rojo); }

/* ===== GRID CATEGORÍAS ===== */
.grid-categorias {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.cat-card {
  background: white;
  border-radius: var(--radio);
  padding: 16px;
  box-shadow: var(--sombra);
  cursor: pointer;
  transition: transform 0.15s;
}
.cat-card:hover { transform: translateY(-2px); }
.cat-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.cat-card-icono { font-size: 30px; }
.cat-card-acciones { display: flex; gap: 6px; }
.cat-card-acciones button {
  background: var(--gris-borde);
  border: none; color: var(--gris);
  width: 28px; height: 28px;
  border-radius: 8px; cursor: pointer; font-size: 12px;
}
.cat-card-nombre { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.cat-card-presupuesto { font-size: 12px; color: var(--gris); }
.cat-card-barra { height: 4px; border-radius: 2px; margin-top: 8px; }

/* ===== GALERÍA RECIBOS ===== */
.galeria-recibos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.recibo-thumb {
  border-radius: var(--radio);
  overflow: hidden;
  aspect-ratio: 3/4;
  cursor: pointer;
  box-shadow: var(--sombra);
  transition: transform 0.15s;
  position: relative;
}
.recibo-thumb:hover { transform: scale(1.02); }
.recibo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.recibo-fecha {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  color: white;
  font-size: 11px;
  padding: 20px 8px 6px;
}

/* ===== MODALES ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-overlay.abierto {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: white;
  border-radius: 24px 24px 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-recibo { border-radius: 24px; max-height: 95vh; }
.modal-recibo img { width: 100%; border-radius: 12px; margin: 12px 0; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 18px; font-weight: 800; }

.btn-cerrar {
  background: var(--gris-borde);
  border: none;
  color: var(--gris);
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
}

.modal label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gris);
  margin: 12px 0 6px;
}

.modal input[type="text"],
.modal input[type="number"],
.modal input[type="date"],
.modal input[type="password"],
.modal select,
.modal textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--gris-borde);
  border-radius: var(--radio);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  background: white;
}
.modal input:focus,
.modal select:focus,
.modal textarea:focus { border-color: var(--morado); }
.modal textarea { min-height: 80px; resize: vertical; }
.modal input[type="color"] { height: 44px; cursor: pointer; padding: 4px; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1f2937;
  color: white;
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  z-index: 999;
  transition: transform 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}
.toast.visible { transform: translateX(-50%) translateY(0); }

/* ===== VACÍO ===== */
.vacio {
  text-align: center;
  padding: 40px 20px;
  color: var(--gris);
}
.vacio i { font-size: 40px; margin-bottom: 12px; opacity: 0.3; }
.vacio p { font-size: 15px; }

/* ===== RESPONSIVE ===== */
@media (min-width: 480px) {
  .modal { border-radius: 24px; margin: auto; }
  .modal-overlay { align-items: center; padding: 20px; }
}
