/* ============================================================
   MOBILE OPTIMIZATIONS
   Mejoras específicas para móviles (≤768px) y tablets pequeñas.
   Se carga después de los demás CSS para sobrescribir lo necesario.
   ============================================================ */

/* === Reset móvil global === */
@media (max-width: 768px) {
  html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
  body { overflow-x: hidden; }
  * { -webkit-tap-highlight-color: rgba(220, 38, 38, 0.15); }

  /* Container con padding consistente */
  .container,
  .wrap,
  .dash-shell,
  .admin-page {
    padding-left: 16px !important;
    padding-right: 16px !important;
    max-width: 100% !important;
  }

  /* Inputs: tamaño grande para no hacer zoom en iOS */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="password"],
  input[type="date"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px !important;        /* iOS no hace zoom si >=16px */
    min-height: 44px;                  /* Touch target mínimo */
  }

  /* Botones touch-friendly */
  button,
  .btn-primary,
  .btn-outline,
  .flow-submit {
    min-height: 48px;
    font-size: 15px !important;
  }
}

/* === Tablets (≤768px) === */
@media (max-width: 768px) {
  /* Hero / landing */
  .hero {
    padding: 24px 0 32px !important;
  }
  .hero h1 {
    font-size: clamp(28px, 7vw, 36px) !important;
    line-height: 1.15 !important;
  }
  .hero-lead {
    font-size: 15px !important;
  }
  .hero-grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
  .hero-quick-stats {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }
  .hero-quick-divider { display: none !important; }
  .hero-actions {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .hero-actions .btn-primary,
  .hero-actions .btn-outline,
  .hero-actions .btn-link-arrow {
    width: 100% !important;
    justify-content: center !important;
  }
  .hero-visual { display: none !important; }

  /* Stepper del flow */
  .flow-progress {
    gap: 4px !important;
    padding: 12px !important;
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .flow-progress-step {
    min-width: 60px;
    flex: 0 0 auto;
  }
  .flow-progress-label {
    font-size: 10px !important;
    text-align: center;
  }
  .flow-progress-line {
    min-width: 16px;
    flex: 1;
  }
  .flow-progress-dot {
    width: 28px !important;
    height: 28px !important;
    font-size: 12px !important;
  }

  /* Flow grid (formularios) */
  .flow-grid {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }
  .flow-card {
    padding: 24px 20px !important;
  }
  .flow-card-title {
    font-size: 22px !important;
  }
  .flow-card-icon {
    width: 56px !important;
    height: 56px !important;
  }
  .flow-card-icon svg {
    width: 26px !important;
    height: 26px !important;
  }

  /* Sidebar del flow → debajo del card principal */
  .flow-sidebar {
    margin-top: 16px;
  }
  .flow-sidebar-card {
    padding: 18px !important;
  }

  /* Auth row → 1 columna */
  .auth-row {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  /* Bank grid */
  .bank-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .bank-option {
    padding: 12px 8px !important;
  }
  .bank-name {
    font-size: 11px !important;
  }

  /* Footer */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
    text-align: center;
  }
  .footer-brand-block {
    text-align: center;
    align-items: center;
  }
  .footer-bottom {
    flex-direction: column !important;
    gap: 12px !important;
    text-align: center !important;
  }

  /* Tablas → scroll horizontal */
  .table,
  table {
    font-size: 13px !important;
  }
  .table-wrap,
  table {
    overflow-x: auto;
    display: block;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* Banners */
  .flow-banner,
  .banner {
    padding: 12px 14px !important;
    font-size: 13px !important;
  }

  /* WhatsApp float más visible */
  .whatsapp-float {
    bottom: 16px !important;
    right: 16px !important;
    width: 56px !important;
    height: 56px !important;
  }
}

/* === Phones (≤480px) === */
@media (max-width: 480px) {
  .hero h1 {
    font-size: 26px !important;
  }
  .hero-quick-stat {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
  }
  .hero-quick-value {
    font-size: 18px !important;
  }
  .flow-card {
    padding: 20px 16px !important;
  }
  .flow-card-title {
    font-size: 20px !important;
  }
  .flow-card-sub {
    font-size: 14px !important;
  }

  /* Stepper aún más compacto */
  .flow-progress-step {
    min-width: 48px;
  }
  .flow-progress-label {
    font-size: 9px !important;
  }

  /* Bank grid en 2 cols sigue OK, pero más compacto */
  .bank-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  /* Stats / KPIs */
  .dash-stats,
  .perfil-stats {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }
  .dash-stat,
  .perfil-stat {
    padding: 14px 12px !important;
  }
  .dash-stat-value,
  .perfil-stat-value {
    font-size: 22px !important;
  }
}

/* === Admin móvil === */
@media (max-width: 900px) {
  /* Sidebar admin → off-canvas (oculto por defecto) */
  .admin-shell {
    display: block !important;
  }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1000;
    box-shadow: 4px 0 20px rgba(0,0,0,.20);
  }
  body.admin-sidebar-open .sidebar {
    transform: translateX(0);
  }
  body.admin-sidebar-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 999;
  }

  .admin-content {
    width: 100% !important;
    margin-left: 0 !important;
  }

  .admin-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: white;
    border-bottom: 1px solid var(--line);
    padding: 12px 16px !important;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  /* Botón hamburguesa admin (lo creo via JS) */
  .admin-burger {
    display: inline-flex !important;
    width: 40px; height: 40px;
    align-items: center; justify-content: center;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
  }

  .admin-page {
    padding: 16px !important;
  }

  .page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }
  .page-actions {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .page-actions a,
  .page-actions button {
    flex: 1 1 auto;
  }

  /* Stats grid del admin (4 cols → 2) */
  .panel-grid,
  .row-2 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Tablas con muchas columnas */
  .table {
    min-width: 600px;
  }

  /* Filtros */
  .filter-bar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .filter-bar input,
  .filter-bar select {
    width: 100% !important;
  }

  /* Cmd+K en móvil */
  .cmdk-trigger {
    display: none !important;
  }
}

/* === Chat móvil === */
@media (max-width: 768px) {
  .chat-bubble {
    max-width: 88% !important;
    font-size: 14px;
  }
  #chat-messages {
    height: calc(100vh - 220px) !important;
    max-height: 60vh !important;
  }
  /* Admin chat: lista + chat → solo chat al seleccionar */
  body.admin .chat-layout {
    grid-template-columns: 1fr !important;
  }
}

/* === Biometría móvil === */
@media (max-width: 768px) {
  #bio-video-selfie,
  #bio-video-dni-front,
  #bio-video-dni-back {
    max-width: 100% !important;
  }
  .bio-stat {
    font-size: 11px;
    padding: 8px !important;
  }
  .bio-stat-icon {
    font-size: 18px !important;
  }
}

/* === Perfil móvil === */
@media (max-width: 768px) {
  .perfil-hero {
    padding: 20px !important;
  }
  .perfil-hero-grid {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .perfil-avatar-xl {
    width: 72px !important;
    height: 72px !important;
    font-size: 28px !important;
    align-self: center;
  }
  .perfil-hero-name {
    font-size: 22px !important;
    text-align: center;
  }
  .perfil-hero-meta {
    justify-content: center;
    font-size: 12px !important;
  }
  .perfil-hero-completion {
    width: 100% !important;
  }
  .perfil-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 4px !important;
  }
  .perfil-tab {
    flex: 0 0 auto;
    padding: 8px 12px !important;
    font-size: 12px !important;
    white-space: nowrap;
  }
  .perfil-layout {
    grid-template-columns: 1fr !important;
  }
  .perfil-card-body {
    padding: 18px !important;
  }
  .perfil-locked {
    grid-template-columns: 1fr !important;
  }
}

/* === Botones de acción flotantes (mejoras de touch) === */
@media (max-width: 480px) {
  /* CTA fija inferior para flow steps */
  body.flow .flow-submit {
    margin-top: 16px !important;
    padding: 14px 20px !important;
  }
}

/* === Promo banner === */
@media (max-width: 768px) {
  .promo-banner {
    padding: 8px 14px !important;
    font-size: 12px !important;
    text-align: center;
  }
  .promo-banner-text {
    line-height: 1.4;
  }
}

/* === Ajustes finos para iOS Safari === */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 768px) {
    body { min-height: -webkit-fill-available; }
    .nav { position: -webkit-sticky; position: sticky; top: 0; }
    /* Bottom-safe area en iPhones con notch */
    .whatsapp-float {
      bottom: max(16px, env(safe-area-inset-bottom)) !important;
    }
  }
}

/* === Landscape en celular: stepper compacto === */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .hero { padding: 16px 0 !important; }
  .hero h1 { font-size: 24px !important; }
  .flow-progress { padding: 8px !important; }
}
