@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');

/* === RESET === */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Poppins', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
  background: #f4f6f8;
  color: #333;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  padding-bottom: 250px;
}

/* === CONTENEDOR PRINCIPAL === */
.container {
  width: 100%;
  max-width: 800px;
}
.container-white-bg {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
  padding: 20px;
}

/* === HEADER === */
.header-text h1 {
  text-align: center;
  font-size: 1.8rem;
  color: #2c3e50;
}

.header-buttons-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  /* Damos un fondo blanco al header también */
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
  padding: 18px;
  margin-bottom: 20px;
  border: 1px solid #e2e8f0;
}

/* === BOTONES === */
.btn {
  display: inline-block;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 0.75rem;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.25s, transform 0.1s, opacity 0.2s;
  text-decoration: none;
  text-align: center;
  position: relative; /* Para el spinner */
}

.btn:hover { background: #2563eb; }
.btn:active { transform: scale(0.97); }

.btn.small { padding: 6px 12px; font-size: 0.85rem; }
.btn.danger { background: #dc3545; }
.btn.danger:hover { background: #a71d2a; }

.btn.flat { background: #10b981; }
.btn.flat:hover { background: #059669; }

.btn.link {
  background: transparent;
  color: #6b7280;
}
.btn.link:hover { color: #111827; }

/* Botón deshabilitado (para UX de formulario) */
.btn:disabled {
  background: #9ca3af; /* Gris */
  cursor: not-allowed;
  transform: none;
}
.btn:disabled:hover { background: #9ca3af; }


/* --- SPINNER DE CARGA --- */
.btn .spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
  -webkit-animation: spin 1s ease-in-out infinite;
}
.btn.loading .btn-text {
  visibility: hidden;
  opacity: 0;
}
.btn.loading .spinner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-block; /* Asegurar que se muestre */
}
/* Spinner para botones de texto (como Restablecer) */
.btn-restore {
    position: relative; /* Para el spinner */
}
.btn-restore.loading .btn-text {
  visibility: hidden;
  opacity: 0;
}
.btn-restore .spinner { /* Estilo base del spinner */
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  border-top-color: #3b82f6; /* Azul */
  animation: spin 1s ease-in-out infinite;
  -webkit-animation: spin 1s ease-in-out infinite;
  
  /* Posicionamiento */
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}


@keyframes spin {
  to { transform: rotate(360deg); }
}
@-webkit-keyframes spin {
  to { -webkit-transform: rotate(360deg); }
}
/* --- FIN SPINNER --- */


/* === TARJETAS === */
.tarjeta {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  margin-bottom: 20px;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
  overflow: hidden; /* Para que el header se ajuste */
  transition: opacity 0.3s ease-out; /* Para borrado suave */
}

.tarjeta-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px; /* Ajuste de padding */
  color: #333; /* Color por defecto si no es oscuro */
}
/* Clase para texto claro */
.tarjeta-header.text-light {
  color: #ffffff;
}
.tarjeta-header.text-light h2,
.tarjeta-header.text-light small {
  color: #ffffff;
}

.tarjeta-header h2 {
  font-size: 1.2rem;
  color: #333; /* Color por defecto */
  font-weight: 600;
  margin: 0;
}
.tarjeta-header small {
  font-size: 0.9rem;
  color: #555; /* Color por defecto */
  display: block;
}

.titulos {
  flex-grow: 1;
  flex-shrink: 1;
  min-width: 0;
}
/* --- ¡ACTUALIZADO! ---
   Contenedor de botones del header con Flex y Gap */
.tarjeta-buttons {
  display: flex;
  align-items: center;
  gap: 8px; /* Espacio entre botones */
  flex-shrink: 0;
  margin-left: 10px;
}
.tarjeta-buttons form {
  display: inline;
}


/* === Layout de Fechas (Con Títulos Arriba) === */
.fechas {
  font-size: 0.9rem;
  color: #475569;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 15px; /* Padding del contenedor */
  background: #f8fafc; /* Fondo ligeramente gris */
  border-bottom: 1px solid #e2e8f0;
}
.fecha-item {
  display: flex;
  flex-direction: column; /* Apila el título sobre la fecha */
  flex-grow: 1; /* Ocupan espacio */
  min-width: 120px; /* Para que se vean bien */
}
.fecha-item strong {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.fecha-item span {
  font-size: 1.1rem;
  font-weight: 600;
  color: #1e293b;
}
/* === FIN LAYOUT FECHAS === */


/* === BLOQUES (Barras y Monto) === */
.bloque { 
  margin-bottom: 0; 
  padding: 15px; 
  border-bottom: 1px solid #e2e8f0;
}
.tarjeta .bloque:last-child {
  border-bottom: none; /* Quitar último borde */
}

.principal { 
  font-size: 0.95rem; 
  margin-bottom: 8px; /* Más espacio */
  font-weight: 600;
  color: #334155;
}
.principal small {
  display: block; /* Asegura el salto de línea */
  font-size: 0.9rem;
}

.barra {
  background: #e1e4e8;
  border-radius: 10px;
  height: 12px;
  width: 100%;
  overflow: hidden;
}

.progreso {
  background: linear-gradient(90deg, #007bff, #00bcd4);
  height: 100%;
  border-radius: 10px;
  transition: width 0.3s ease;
}

/* === FORMULARIOS DE MONTO === */
.monto-form-container label {
  font-size: 0.9rem;
  display: block;
  margin-bottom: 4px;
}

.monto-form-container input[type="number"] {
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #ccc;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

/* Estilos para el monto-display y estado-ciclo */
.monto-display {
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.monto-display strong {
    flex-grow: 1; /* El texto ocupa el espacio sobrante */
}

/* --- ¡NUEVAS CLASES! --- */
.monto-pagado-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.monto-pagado {
  font-size: 1.1rem;
  font-weight: 600;
  color: #059669; /* Verde */
  text-decoration: line-through; /* Tachado */
  text-decoration-thickness: 2px;
  padding: 5px 0;
  flex-grow: 1;
}
.btn-restore {
  background: none;
  border: none;
  color: #3b82f6; /* Azul */
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  padding: 5px;
  flex-shrink: 0; /* No encoger */
}
.btn-restore:hover {
  text-decoration: underline;
}
/* --- FIN NUEVAS CLASES --- */

.estado-ciclo {
  font-size: 0.9rem;
  color: #6b7280;
  font-style: italic;
}


/* === LOGIN Y FORMULARIOS (agregar.php, editar.php) === */
.form-container {
  background: #fff;
  padding: 2rem;
  border-radius: 1rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  width: 100%; /* Ocupa el 100% del .container */
  text-align: center;
  margin: auto;
  animation: fadeIn 0.5s ease-in-out;
}
.login-container {
  padding: 2rem;
  border-radius: 1rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  width: 90%;
  max-width: 420px;
  text-align: center;
  margin: auto;
  animation: fadeIn 0.5s ease-in-out;
  background: #fff;
}


.form-container h1,
.login-container h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 1.5rem;
}

/* Campos y etiquetas */
.form-container form,
.login-container form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: left;
}

label {
  font-weight: 600;
  color: #374151;
  font-size: 0.95rem;
  display: block; /* ¡Añadido para margin! */
  margin-bottom: 5px; /* Espacio entre label y input */
}

input[type="text"],
input[type="email"],
input[type="number"],
select {
  width: 100%;
  padding: 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid #d1d5db;
  font-size: 1rem;
  outline: none;
  background: #f9fafb;
  transition: all 0.2s ease;
}

input:focus,
select:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
  background: #fff;
}
/* Borde de error para validación JS */
.input-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25) !important;
}


/* === ALERTAS === */
.alert {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 0.75rem;
  border-radius: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

/* === CAMPOS INLINE (Agregar/Editar tarjeta) === */
.inline-fields {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  flex-wrap: wrap;
}
.inline-fields > div {
  display: flex;
  flex-direction: column;
  /* gap: 1rem; <- quitado, label ya tiene margin */
  flex-grow: 1; 
  min-width: 120px; 
}


/* === MODALES (Borrado y Notificación) === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: none; /* Se activa con JS */
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.modal-overlay.visible {
  display: flex;
  opacity: 1;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  transform: scale(0.95);
  transition: transform 0.3s ease;
}
.modal-overlay.visible .modal-content {
  transform: scale(1);
}
.modal-content h3 {
  font-size: 1.4rem;
  margin-top: 0;
  margin-bottom: 10px;
  color: #1f2937;
}
.modal-content p {
  font-size: 1rem;
  color: #4b5563;
  margin-bottom: 20px;
}
.modal-buttons {
  display: flex;
  justify-content: flex-end; /* Botones a la derecha */
  gap: 10px;
}

/* Lista del modal de notificación */
#lista-pagos-proximos {
  list-style-type: none;
  padding: 0;
  margin-bottom: 20px;
  max-height: 200px;
  overflow-y: auto;
}
#lista-pagos-proximos li {
  padding: 10px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.95rem;
}
#lista-pagos-proximos li:last-child {
  border-bottom: none;
}
#lista-pagos-proximos li strong {
  color: #111827;
}
#lista-pagos-proximos li .dias-restantes {
  float: right;
  font-weight: 600;
  color: #ef4444; /* Rojo */
}


/* === RESPONSIVE === */
@media (max-width: 600px) {
  .header-buttons-row { flex-direction: column; gap: 10px; }
  
  /* Regla general para botones en móvil */
  .btn { width: 100%; text-align: center; }

  /* MANTENEMOS ESTA REGLA CRÍTICA: */
  /* Hace que los botones de icono NO ocupen el 100% */
  .tarjeta-buttons .btn,
  .monto-display .btn,
  .monto-display form .btn {
    width: auto !important; 
    flex-grow: 0; /* No crecer */
  }
  .monto-display form {
    display: inline-block; /* Asegurar que no ocupe todo */
    width: auto;
  }
  
  /* Apila los botones de "Actualizar" y "Cancelar" */
  .monto-form-container div {
    flex-direction: column;
  }

  /* Apila los campos de "día corte" y "días pagar" */
  .inline-fields { flex-direction: column; gap: 0; }
  
  .form-container,
  .login-container { padding: 1.5rem; }

  /* Reducir el círculo de color en móvil */
  .color-preview {
    width: 45px;
    height: 45px;
  }
}

/* === ANIMACIONES === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

