/* =============================================
   BASE
============================================= */
*,
*::before,
*::after {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: #f0f3f8;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* =============================================
   LAYOUT
============================================= */
.page-wrapper {
  padding: 0.5rem 0 4rem;
}

@media (min-width: 768px) {
  .page-wrapper {
    padding-top: 2rem;
  }
}

.container-hist {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 0.5rem;
}

@media (min-width: 576px) {
  .container-hist {
    padding: 0 1.25rem;
  }
}

/* =============================================
   HEADER
============================================= */
.page-header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.page-header h1 {
  font-size: clamp(1.3rem, 5vw, 1.7rem);
  font-weight: 800;
  color: #111827;
  margin-bottom: 0.25rem;
  line-height: 1.2;
}

.page-header p {
  font-size: 0.85rem;
  color: #6b7280;
  margin: 0;
}

/* =============================================
   BUSCADOR
============================================= */
.search-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 1rem;
  padding: 1.1rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  margin-bottom: 1.25rem;
}

.search-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #374151;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.search-row {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.search-input {
  flex: 1;
  border: 1.5px solid #d1d5db;
  border-radius: 0.65rem;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  min-height: 48px;
  min-width: 0;
  color: #111827;
  background: #f9fafb;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
  outline: none;
}

.search-input:focus {
  border-color: #1a56db;
  box-shadow: 0 0 0 0.2rem rgba(26, 86, 219, 0.15);
  background: #fff;
}

.search-input.is-invalid-live {
  border-color: #dc3545;
  box-shadow: 0 0 0 0.18rem rgba(220, 53, 69, 0.15);
}

.btn-buscar {
  background: linear-gradient(135deg, #1a56db, #1e40af);
  color: #fff;
  border: none;
  border-radius: 0.65rem;
  padding: 0.7rem 1.2rem;
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 48px;
  min-width: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  transition:
    opacity 0.15s,
    transform 0.1s,
    box-shadow 0.15s;
  box-shadow: 0 4px 12px rgba(26, 86, 219, 0.3);
  touch-action: manipulation;
  flex-shrink: 0;
}

.btn-buscar:active {
  transform: scale(0.97);
}

.search-hint {
  font-size: 0.75rem;
  color: #9ca3af;
  margin-top: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.field-error-msg {
  font-size: 0.78rem;
  color: #dc3545;
  margin-top: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-weight: 600;
}

/* =============================================
   CARD CLIENTE
============================================= */
.cliente-card {
  background: #fff;
  border: 1.5px solid #1a56db;
  border-radius: 1rem;
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 2px 12px rgba(26, 86, 219, 0.08);
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.cliente-avatar {
  width: 46px;
  height: 46px;
  min-width: 46px;
  background: rgba(26, 86, 219, 0.1);
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1a56db;
  font-size: 1.4rem;
}

.cliente-nombre {
  font-size: 1rem;
  font-weight: 800;
  color: #111827;
  line-height: 1.2;
}

.cliente-meta {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 0.15rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cliente-meta span {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

/* =============================================
   SECCIÓN TÍTULOS
============================================= */
.section-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

.section-icon {
  width: 34px;
  height: 34px;
  border-radius: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.section-title h2 {
  font-size: 1rem;
  font-weight: 800;
  color: #111827;
  margin: 0;
}

.section-title .count-badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 2rem;
}

/* =============================================
   PRÉSTAMO ACTIVO — CARD
============================================= */
.prestamo-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 1rem;
  margin-bottom: 1.1rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.prestamo-card-header {
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.prestamo-nombre {
  font-size: 0.85rem;
  font-weight: 800;
  color: #111827;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.prestamo-fecha {
  font-size: 0.72rem;
  color: #9ca3af;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

/* Tabla de pagos */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 400px;
  overflow-y: auto;
}

.hist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  min-width: 520px;
}

.hist-table thead th {
  background: #f1f5f9;
  padding: 0.6rem 0.75rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #475569;
  text-align: center;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

.hist-table tbody td {
  padding: 0.55rem 0.75rem;
  text-align: center;
  border-bottom: 1px solid #f1f5f9;
  color: #374151;
  vertical-align: middle;
}

.hist-table tbody tr:last-child td {
  border-bottom: none;
}

.hist-table tbody tr:hover td {
  background: #f8fafc;
}

/* Badges estado */
.badge-pagado {
  background: #dcfce7;
  color: #15803d;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 2rem;
  white-space: nowrap;
}

.badge-sinpagar {
  background: #fef9c3;
  color: #854d0e;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 2rem;
  white-space: nowrap;
}

.badge-mora {
  background: #fee2e2;
  color: #991b1b;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 2rem;
  white-space: nowrap;
}

.badge-puntual {
  background: #d1fae5;
  color: #065f46;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 2rem;
  white-space: nowrap;
}

.badge-adelantado {
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 2rem;
  white-space: nowrap;
}

.tipo-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  /* Bordes redondeados */
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  margin-left: 5px;
  line-height: 1.4;
  vertical-align: middle;
  background-color: #4774f158;
  color: #143ae4;
}

/* =============================================
   PRÉSTAMO CANCELADO — COLAPSABLE
============================================= */
.cancelado-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 1rem;
  margin-bottom: 0.85rem;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.cancelado-toggle {
  width: 100%;
  background: #f9fafb;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.cancelado-toggle:hover {
  background: #f1f5f9;
}

.cancelado-toggle.open {
  border-bottom-color: #e5e7eb;
  background: #f1f5f9;
}

.cancelado-info {
  flex: 1;
  min-width: 0;
}

.cancelado-fila1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.cancelado-nombre {
  font-size: 0.82rem;
  font-weight: 800;
  color: #111827;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.cancelado-monto {
  font-size: 0.82rem;
  font-weight: 800;
  color: #374151;
  white-space: nowrap;
}

.cancelado-fila2 {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

@media (max-width: 480px) {
  .cancelado-fila2 {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }
}

.cancelado-fechas {
  font-size: 0.68rem;
  color: #9ca3af;
  margin-top: 0.15rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cancelado-fechas span {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.cancelado-chevron {
  color: #9ca3af;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: transform 0.22s ease;
}

.cancelado-toggle.open .cancelado-chevron {
  transform: rotate(180deg);
}

.cancelado-body {
  display: none;
  padding: 0;
}

.cancelado-body.open {
  display: block;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =============================================
   ESTADO VACÍO
============================================= */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #9ca3af;
}

.empty-state i {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.85rem;
  margin: 0;
  font-weight: 500;
}

/* =============================================
   ALERTAS
============================================= */
.alert {
  border-radius: 0.75rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

/* =============================================
   SAFE AREA
============================================= */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .page-wrapper {
    padding-bottom: calc(4rem + env(safe-area-inset-bottom));
  }
}

.table-wrap,
.seccion-scrollable {
  scrollbar-width: thin;
  /* Scroll más fino en Firefox */
  scrollbar-color: #1a56db #f0f3f8;
}

/* Para Chrome/Safari/Edge */
.table-wrap::-webkit-scrollbar {
  width: 6px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}
