/* Overlay base to make the modal visible over any page */
#timeCreditsModal {
  position: fixed !important;
  left: 0; top: 0; right: 0; bottom: 0;
  width: 100vw; height: 100vh;
  display: none; /* toggled to flex by JS */
  align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.45);
  z-index: 10000 !important; /* above badge */
  padding: 12px;
  /* Ajustes para zonas seguras en móviles con notch/barra */
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px) + max(var(--vvb, 0px), 56px));
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
}
/* Badge flotante global (visible en todas las páginas) */
.tc-badge-floating {
  position: fixed !important;
  top: 20px !important;
  right: 80px !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  z-index: 9999 !important;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
  transition: all 0.2s ease;
  pointer-events: auto !important;
}
.tc-badge-floating:hover {
  background: #e2e8f0;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.15);
  transform: translateY(-1px);
}
.tc-badge-floating .tc-mins {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.tc-badge-floating #tcUserShort {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  opacity: 0.8;
}

/* Modal */
#timeCreditsModal .modal-content {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
#timeCreditsModal .tc-card {
  margin-bottom: 20px;
  padding: 16px;
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  border-radius: 12px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(14,165,233,0.3);
}
#timeCreditsModal .tc-card .tc-user-label {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 12px;
}
#timeCreditsModal .tc-card .tc-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
#timeCreditsModal .tc-card .tc-row .tc-balance-title { font-size: 14px; opacity: 0.9; }
#timeCreditsModal .tc-card .tc-row .tc-balance { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; }
#timeCreditsModal .tc-card .tc-row .tc-balance-unit { font-size: 18px; font-weight: 600; }

#timeCreditsModal .tc-info {
  margin-bottom: 20px; 
  padding: 14px; 
  background: #f0f9ff; 
  border-left: 4px solid #0ea5e9; 
  border-radius: 8px; 
  line-height: 1.6; 
  color: #0f172a;
}
#timeCreditsModal .tc-info .tc-info-title {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: #0284c7; font-size: 15px; font-weight: 700;
}
#timeCreditsModal .tc-info .tc-info-text { font-size: 13px; color: #475569; }
#timeCreditsModal .form-row { display: grid; gap: 8px; }
#timeCreditsModal label { font-weight: 600; color: #0f172a; }
#timeCreditsModal input[type="number"] { width: 120px; }
#timeCreditsModal .hint { font-size: 12px; color: #64748b; }
#timeCreditsModal .error { color: #b91c1c; font-size: 13px; display: none; margin-top: 4px; }

/* Asegurar que el cuerpo haga scroll y las acciones se vean */
#timeCreditsModal .modal-body { 
  flex: 1;
  overflow-y: auto; 
  overflow-x: hidden;
  padding: 16px 20px; 
  scroll-behavior: smooth;
}
#timeCreditsModal .modal-actions { 
  display: flex; 
  justify-content: flex-end; 
  gap: 8px; 
  padding: 12px 20px; 
  border-top: 1px solid #e2e8f0; 
  background: #fff;
  flex-shrink: 0;
}
#timeCreditsModal .modal-header { 
  padding: 16px 20px; 
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

/* Asegurar que el modal de créditos quede por encima del botón de ayuda */
#timeCreditsModal { z-index: 10050 !important; }

/* ====== Responsive (móvil/tablet) ====== */
@media (max-width: 480px) {
  #timeCreditsModal { 
    align-items: flex-start; 
    justify-content: flex-start;
    padding: 8px 0 0 0;
  }
  /* Mostrar SOLO los minutos (números) y permitir que el contenedor crezca para 3 dígitos */
  .tc-badge-floating {
    position: fixed !important; /* mismo contexto que help-button */
    /* El botón de ayuda mantiene top/right:20px por la regla #help-btn.help-button con !important. */
    top: 66px !important;   /* 20(top) + 36(height) + 10px gap => 66 */
    right: 20px !important; /* alinear exactamente con help-button */
    left: auto !important; bottom: auto !important; margin: 0 !important;
    height: 36px; min-width: 36px; border-radius: 18px; padding: 0 8px;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-600));
    color: #fff; border: none;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
    box-sizing: border-box; z-index: 10001; /* igual prioridad visual */
    font-size: 0; /* ocultar nodos de texto como 'min ·' y cualquier otro */
    white-space: nowrap;
  }
  .tc-badge-floating:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(14, 165, 233, 0.5); }
  .tc-badge-floating:active { transform: scale(0.96); }
  .tc-badge-floating::before { content: none; }
  /* Mostrar solo el número de minutos */
  .tc-badge-floating .tc-mins { display: inline; font-size: 16px; font-weight: 700; color: #fff; line-height: 1; }
  .tc-badge-floating #tcUserShort { display: none; }
  #timeCreditsModal .modal-content {
    width: 94vw;
    max-width: 520px;
    /* Alto que ocupa todo el espacio disponible */
    height: calc(var(--vvh, 100dvh) - 16px - env(safe-area-inset-top, 0px));
    max-height: calc(var(--vvh, 100dvh) - 16px - env(safe-area-inset-top, 0px));
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    margin: 8px auto;
  }
  @supports (height: 100svh) {
    #timeCreditsModal .modal-content {
      height: calc(var(--vvh, 100svh) - 16px - env(safe-area-inset-top, 0px));
      max-height: calc(var(--vvh, 100svh) - 16px - env(safe-area-inset-top, 0px));
    }
  }
  #timeCreditsModal .modal-header { flex: 0 0 auto; }
  #timeCreditsModal .modal-actions { flex: 0 0 auto; }
  #timeCreditsModal .modal-body {
    /* Solo el body scrollea dentro del alto máximo */
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    /* Asegurar que el contenido sea visible */
    display: flex;
    flex-direction: column;
  }
  #timeCreditsModal .modal-actions {
    position: sticky; bottom: 0; z-index: 1;
    background: #fff;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding-top: 10px; padding-left: 12px; padding-right: 12px;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
    border-top: 1px solid #e2e8f0;
    backdrop-filter: saturate(120%) blur(4px);
    /* Botones en horizontal en móvil */
    flex-direction: row !important;
    justify-content: space-between;
    gap: 8px;
  }
  #timeCreditsModal .modal-actions button {
    flex: 1 1 48%;
    min-width: 0;
  }
  /* Reducir paddings/márgenes internos para encajar mejor en pantallas pequeñas */
  #timeCreditsModal .modal-header { padding: 10px 12px; }
  #timeCreditsModal .modal-body { padding: 10px 12px; padding-bottom: 6px; }
  #timeCreditsModal .tc-card { margin-bottom: 8px; padding: 10px; }
  #timeCreditsModal .tc-card .tc-user-label { font-size: 18px; margin-bottom: 8px; }
  #timeCreditsModal .tc-card .tc-age-label { font-size: 14px; }
  #timeCreditsModal .tc-card .tc-subtitle { font-size: 11px; }
  #timeCreditsModal .tc-card .tc-row .tc-balance { font-size: 24px; }
  #timeCreditsModal .tc-card .tc-row .tc-balance-title { font-size: 13px; }
  #timeCreditsModal .tc-card .tc-row .tc-balance-unit { font-size: 16px; }
  /* Mensaje informativo destacado en móvil */
  #timeCreditsModal .tc-info { 
    margin-bottom: 10px; 
    padding: 12px 14px;
    min-height: 140px;
    max-height: 180px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Hacer más visible y llamativo */
    background: linear-gradient(135deg, #dbeafe 0%, #e0f2fe 100%);
    border-left: 4px solid #0284c7;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.15);
    flex-shrink: 0;
  }
  #timeCreditsModal .tc-info .tc-info-title { 
    font-size: 14px; 
    margin-bottom: 8px;
    font-weight: 700;
    color: #0284c7;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  #timeCreditsModal .tc-info .tc-info-text { 
    font-size: 12px; 
    line-height: 1.6;
    color: #334155;
  }
  #timeCreditsModal .form-row { gap: 6px; }
  #timeCreditsModal .form-field { margin-bottom: 0; }
  #timeCreditsModal label { font-size: 13px; margin-bottom: 4px; }
  #timeCreditsModal input { padding: 8px 10px; font-size: 16px; }
  #timeCreditsModal .hint { font-size: 10px; margin-top: 2px; }
}

/* Evitar zoom en iOS al enfocar inputs numéricos/clave */
#tcPin, #tcMinutes { font-size: 16px; }
