:root {
  --fx-primary: #131e32;
  --fx-accent: #fcc328;
  --fx-bg: #f3f4f6;
  --fx-text: #0f172a;
  --fx-muted: #64748b;
  --fx-border: #e5e7eb;

  --fx-card: #ffffff;
  --fx-ring: rgba(252, 195, 40, 0.35);
  --fx-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --fx-shadow-hover: 0 12px 32px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Montserrat', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  background: radial-gradient(circle at top left, #f8fafc 0, #eceff4 40%, #dde2ec 100%);
  color: #111827;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ================== Layout ================== */

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 40px 32px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.row-end {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

@media (max-width: 640px) {
  .row-2 { grid-template-columns: 1fr; }
  .row-between, .row-end { flex-direction: column; align-items: stretch; }
}

/* Grid dashboard: 2 columnas en desktop */
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 16px;
  align-items: start;
}
@media (min-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

/* ================== Header ================== */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.site-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

#brandLogo {
  height: 42px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.06));
}

.fx-title {
  margin: 0;
  font-family: 'Anton', system-ui;
  font-size: 1.9rem;
  letter-spacing: 0.03em;
  color: var(--fx-primary);
}

.health-link {
  font-size: 0.9rem;
  text-decoration: none;
  color: #2563eb;
  font-weight: 600;
}
.health-link:hover { text-decoration: underline; }

/* ================== Cards & Headings ================== */

.card {
  position: relative;
  background: var(--fx-card);
  border-radius: 16px;
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--fx-shadow);
  border: 1px solid rgba(148, 163, 184, 0.25);
  transition: box-shadow 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--fx-accent), #ffd864 60%, var(--fx-accent));
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  opacity: 0.85;
}

.card:hover {
  box-shadow: var(--fx-shadow-hover);
  transform: translateY(-1px);
}

.card h2, .card h3 {
  margin-top: 0;
  margin-bottom: 4px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--fx-primary);
}

h2 { font-size: 20px; }
h3 { font-size: 18px; }

.muted { color: var(--fx-muted); font-size: 0.9rem; }
.small { font-size: 0.8rem; }

/* Para que cards en dashboard estiren lindo */
.dashboard-grid > .card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ================== Inputs / Selects ================== */

input, select, button {
  font-family: inherit;
  font-size: 0.95rem;
}

input, select {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  padding: 10px 12px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--fx-accent);
  box-shadow: 0 0 0 4px var(--fx-ring);
}

/* inputs con ícono */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap.has-icon input,
.input-wrap.has-icon select {
  padding-left: 34px;
}

.input-ico {
  position: absolute;
  left: 10px;
  width: 18px;
  height: 18px;
  fill: #9ca3af;
}

/* botón ojo PIN */
.btn-eye {
  position: absolute;
  right: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
}

/* ================== Buttons ================== */

.btn {
  cursor: pointer;
  border-radius: 999px;
  padding: 8px 16px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--fx-primary); color: #f9fafb; }
.btn-primary:hover { background: #020617; }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-light { background: #e5e7eb; color: #111827; }
.btn-light:hover { background: #d1d5db; }

.btn-accent { background: var(--fx-accent); color: #111827; }
.btn-accent:hover { background: #eab308; }

.btn-link {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: var(--fx-primary);
  font-weight: 600;
  text-decoration: underline;
}
.btn-link:hover { opacity: .85; }

/* ================== Badges ================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #e5e7eb;
  color: #374151;
  font-weight: 600;
  border: 1px solid transparent;
  gap: 6px;
}

.badge-light { background: #f3f4f6; color: #374151; }
.badge-gold { background: #fef3c7; color: #78350f; border-color: #fbbf24; }

/* ================== Login ================== */

.login-card {
  max-width: 520px;
  margin: 40px auto 0;
}

.login-card h2 { font-size: 1.4rem; letter-spacing: 0.01em; }

.login-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.login-switch {
  display: inline-flex;
  background: #e5e7eb;
  border-radius: 999px;
  padding: 3px;
}

.login-switch-btn {
  border: none;
  background: transparent;
  padding: 5px 12px;
  font-size: 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  color: #4b5563;
}

.login-switch-btn.active {
  background: #111827;
  color: #f9fafb;
}

.login-grid { display: grid; gap: 10px; }
.login-grid .btn-primary { width: 100%; justify-content: center; }

/* ================== Session bar ================== */

.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: #0f172a;
  color: #e5e7eb;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.25);
  margin-bottom: 20px;
  border: none;
}

.session-bar .muted { color: #e5e7eb; font-size: 0.85rem; }

#sessionBadge {
  background: #facc15;
  color: #78350f;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.session-bar .btn-light {
  background: #111827;
  color: #f9fafb;
  border-radius: 999px;
  border: 1px solid #1f2937;
}
.session-bar .btn-light:hover { background: #020617; }

/* ================== Summary cliente ================== */

#clientSummary {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f9fafb;
  border: 1px solid rgba(148, 163, 184, 0.45);
}

.summary-main { display: flex; flex-direction: column; gap: 4px; }

.summary-name-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.summary-name, #clientName { font-size: 1rem; font-weight: 700; }

.summary-balance-line { display: flex; gap: 6px; align-items: baseline; }

.summary-label { font-size: 0.85rem; color: #6b7280; }
.summary-balance { font-weight: 600; }

/* Toggle influencer */
.influencer-toggle-wrap {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed rgba(148, 163, 184, 0.6);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #4b5563;
}
.influencer-toggle-wrap input[type='checkbox'] { width: 16px; height: 16px; }

#influencerPill {
  background: #fbbf24;
  color: #78350f;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ================== Toggle pills ================== */

.toggle-group {
  display: inline-flex;
  gap: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  padding: 3px;
}

.toggle-pill { display: inline-flex; align-items: center; gap: 6px; }
.toggle-pill input { display: none; }

.toggle-pill span {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  color: #4b5563;
}

.toggle-pill input:checked + span {
  background: var(--fx-primary);
  color: #f9fafb;
}

/* ================== Tablas (general + historial) ================== */

.table-wrap {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.4);
}

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead { background: #111827; color: #f9fafb; }
th, td { padding: 6px 8px; text-align: left; }
tbody tr:nth-child(even) { background: #f9fafb; }

/* Diferenciar carga vs canje */
.row-carga { border-left: 4px solid #22c55e; }
.row-canje { border-left: 4px solid #f97316; }

/* Card historial/earn altura pareja */
#section-earn.card,
#consulta-ci.card { min-height: 360px; }

#consulta-ci .table-wrap { flex: 1; max-height: none; overflow: visible; }
#consulta-ci th, #consulta-ci td { padding: 6px 10px; }

#consulta-ci h3 {
  font-size: 20px;
  line-height: 1.2;
  margin-top: 0;
  margin-bottom: 4px;
}

/* ================== Notices ================== */

.notice {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  display: inline-block;
}

.notice-success { background: #d1fae5; color: #065f46; border: 1px solid #10b981; }
.notice-error   { background: #fee2e2; color: #991b1b; border: 1px solid #ef4444; }
.notice-warning { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
.notice-info    { background: #dbeafe; color: #1e3a8a; border: 1px solid #3b82f6; }

#earnMsg, #redeemMsg { margin-top: 8px; margin-bottom: 0; }

/* ================== Toasts ================== */

#toastWrap {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 12px 14px;
  border-radius: 14px;
  color: #fff;
  max-width: 360px;
  font-size: 14px;
  box-shadow: 0 10px 24px rgba(2, 8, 23, 0.22);
  transform: translateX(12px);
  opacity: 0;
  background: #111827;
  animation: slideIn 0.18s ease forwards;
}

.toast-info { background: #0ea5e9; }
.toast-success { background: #16a34a; }
.toast-error { background: #ef4444; }
.toast-warning { background: #f97316; }

/* aliases viejos */
.toast.ok { background: #0ea5e9; }
.toast.err { background: #ef4444; }

@keyframes slideIn { to { transform: none; opacity: 1; } }

/* ================== Footer ================== */

footer { margin-top: 10px; color: var(--fx-muted); font-size: 13px; }

/* ================== Utilidades ================== */

.hidden { display: none !important; }

/* ================== Reportes full width ================== */

#reportsSection.reports-fullwidth {
  width: 100%;
  margin-top: 32px;
  background: #ffffff;
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--fx-shadow);
  border: 1px solid rgba(148, 163, 184, 0.25);
  position: relative;
  box-sizing: border-box;
  display: block;
}

#reportsSection.reports-fullwidth::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--fx-accent), #ffd864 60%, var(--fx-accent));
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  opacity: 0.85;
}

#reportsSection.reports-fullwidth h2 {
  margin-top: 0;
  margin-bottom: 4px;
  font-size: 20px;
  font-weight: 700;
  color: var(--fx-primary);
}

#reportsSection.reports-fullwidth p.muted { margin-top: 0; margin-bottom: 16px; }

/* ================== MODALS (BASE ÚNICA, SIN CHOQUES) ================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(19, 30, 50, 0.45);
  backdrop-filter: blur(4px);
  display: none; /* cerrado */
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal.open {
  display: flex; /* abierto */
  animation: modalFadeIn 0.18s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-dialog {
  background: #ffffff;
  width: 95%;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header,
.modal-footer {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-body {
  padding: 12px 20px 18px;
  overflow: auto;
}

.modal-title {
  font-family: 'Anton', sans-serif;
  font-size: 18px;
  letter-spacing: 0.4px;
  margin: 0;
}

.modal-subtitle {
  display: block;
  font-size: 12px;
  font-weight: 400;
  margin-top: 2px;
  color: var(--fx-muted);
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 14px;
  cursor: pointer;
  color: #6b7280;
}
.modal-close:hover { color: #111827; }

body.no-scroll { overflow: hidden; }

/* Tablas dentro de modales (usa tu estilo de table-wrap) */
.modal .table-wrap {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.modal table { width: 100%; border-collapse: collapse; }
.modal th, .modal td { padding: 10px 12px; font-size: 14px; }

/* ========== Modal Detalle por ruta (compacto) ========== */
#modalBalanceRoute .modal-dialog {
  max-width: 620px;
  max-height: 70vh;
}

#modalBalanceRoute thead { background: var(--fx-primary); color: #fff; }

#modalBalanceRoute tbody tr:first-child {
  background: #f8fafc;
  font-weight: 700;
}

/* ========== Modal Historial (grande + sticky thead) ========== */
#modalHistorial .modal-dialog {
  max-width: 1000px;
  max-height: 80vh;
}

/* Sticky header SOLO historial */
#modalHistorial .table-full-history thead tr th {
  position: sticky;
  top: 0;
  background: var(--fx-primary);
  color: #fff;
  z-index: 2;
  box-shadow: 0 2px 3px rgba(0,0,0,0.15);
}

/* Responsive modal */
@media (max-width: 480px) {
  .modal-dialog { width: 100%; border-radius: 0; max-height: 100vh; }
}

/* ===== TITULOS DE MODALES ===== */

/* Historial completo */
#modalHistorial .modal-title,
#modalBalanceRoute .modal-title {
  color: var(--fx-primary);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.2px;
}

/* Subtítulo (casilla / CI) */
#modalHistorial .modal-subtitle,
#modalBalanceRoute .modal-subtitle {
  color: var(--fx-muted);
  font-size: 13px;
}

/* Línea divisoria debajo del header */
#modalHistorial .modal-header,
#modalBalanceRoute .modal-header {
  border-bottom: 1px solid var(--fx-border);
}

/* ===== MINI HISTORIAL (ULTIMOS 5) ===== */

/* contenedor de la tabla */
#consulta-ci .table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

/* tabla no se comprime */
#consulta-ci table {
  min-width: 820px; /* ajusta si agregás más columnas */
  table-layout: auto;
}

/* scrollbar más discreto */
#consulta-ci .table-wrap::-webkit-scrollbar {
  height: 6px;
}

#consulta-ci .table-wrap::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
}

#consulta-ci .table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

/* Título del mini historial */
#consulta-ci h3 {
  color: var(--fx-primary);
  font-weight: 700;
}

/* ================== HISTORIAL (ÚLTIMOS 5) — MINI HISTORIAL LIMPIO ================== */

#consulta-ci.card {
  display: flex;
  flex-direction: column;
  min-height: 460px;   /* ⬅️ antes 420px (más alto, ocupa mejor) */
  gap: 12px;           /* ⬅️ un poco más de aire */
}

/* Header */
#consulta-ci .row-between {
  flex: 0 0 auto;
}

/* Wrapper principal */
#consulta-ci #historial-wrapper {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;           /* ⬅️ separa tabla del footer */
}

/* Contenedor de tabla */
#consulta-ci .table-wrap {
  flex: 1 1 auto;
  overflow: hidden;               /* ❌ sin scroll */
  border-radius: 12px;
  padding-bottom: 12px;           /* ⬅️ aire al final de la tabla */
}

/* Tabla */
#consulta-ci table {
  width: 100%;
  table-layout: fixed;            /* CLAVE: todo entra */
  border-collapse: collapse;
  font-size: 0.84rem;             /* ⬅️ apenas más grande */
}

/* Header tabla */
#consulta-ci thead th {
  font-size: 0.79rem;             /* ⬅️ apenas más grande */
  letter-spacing: .2px;
  white-space: nowrap;
}

/* Celdas */
#consulta-ci th,
#consulta-ci td {
  padding: 8px 9px;               /* ⬅️ más alto/aire en filas */
  vertical-align: middle;
}

/* ===== Anchos por columna (6 columnas) ===== */
/* Fecha (dd/mm/yy) */
#consulta-ci th:nth-child(1),
#consulta-ci td:nth-child(1) { width: 72px; }

/* Tipo */
#consulta-ci th:nth-child(2),
#consulta-ci td:nth-child(2) { width: 64px; }

/* Monto */
#consulta-ci th:nth-child(3),
#consulta-ci td:nth-child(3) { width: 92px; }

/* Ruta (puede partir en 2 líneas) */
#consulta-ci th:nth-child(4),
#consulta-ci td:nth-child(4) {
  width: 118px;                   /* ⬅️ un pelín más para que no se corte */
  white-space: normal;
  line-height: 1.15;
  word-break: break-word;
}

/* Registrado */
#consulta-ci th:nth-child(5),
#consulta-ci td:nth-child(5) {
  width: 106px;                   /* ⬅️ un pelín más */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Motivo */
#consulta-ci th:nth-child(6),
#consulta-ci td:nth-child(6) {
  width: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Footer (botón abajo) */
#consulta-ci .row-end {
  margin-top: auto;
  padding-top: 6px;               /* ⬅️ separa visualmente del borde */
  justify-content: flex-end;
}

/* Botón Ocultar */
#toggleHistorialBtn.btn-light {
  border-radius: 999px;
  padding: 8px 14px;
}
