/*
 * Mejoras de UX móvil — añadidas al layout_app.html sobre style.css.
 * Carga DESPUÉS de style.css para sobreescribir donde haga falta.
 *
 * Foco:
 *  1. Tap targets ≥ 44×44 (Apple HIG / WCAG 2.5.5).
 *  2. Tablas con scroll horizontal grácil (data-table-wrap).
 *  3. Inputs con tamaño mínimo táctil + sin zoom-in iOS al focus.
 *  4. Comportamiento smooth/elastic en scroll.
 *  5. Espaciado bottom-nav: que el contenido no quede tapado.
 *  6. Modal y overlay: full-height en móvil (overscroll suave).
 */

/* ─── Reset móvil global ─── */
@media (max-width: 768px) {
  html, body {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    -webkit-overflow-scrolling: touch;
  }

  /* Inputs sin zoom-in iOS: font-size ≥ 16px */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="search"],
  input[type="url"],
  input[type="date"],
  input[type="datetime-local"],
  textarea,
  select {
    font-size: 16px !important;
  }

  /* Tap targets mínimos en botones, enlaces de acción y form controls */
  .btn,
  button:not(.no-mobile-tap),
  .bottom-nav-item,
  .quick-action,
  .icon-btn,
  a.btn,
  input[type="submit"],
  input[type="button"] {
    min-height: 44px;
    min-width: 44px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  /* Espaciado para que el bottom-nav no tape el contenido */
  main,
  .main-content,
  .page-content {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  /* Reducir padding lateral en pantallas pequeñas */
  .container,
  .page-container,
  .card-container {
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* ─── Scroll horizontal para tablas anchas ─── */
.table-wrap,
[data-table-wrap] {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Indicador visual del scroll: gradient en bordes */
  background:
    linear-gradient(90deg, #fff 30%, rgba(255, 255, 255, 0)) left center / 20px 100% no-repeat,
    linear-gradient(-90deg, #fff 30%, rgba(255, 255, 255, 0)) right center / 20px 100% no-repeat,
    linear-gradient(90deg, rgba(0, 0, 0, .12), rgba(255, 255, 255, 0)) left center / 8px 100% no-repeat,
    linear-gradient(-90deg, rgba(0, 0, 0, .12), rgba(255, 255, 255, 0)) right center / 8px 100% no-repeat;
  background-attachment: local, local, scroll, scroll;
  margin-bottom: 16px;
}

@media (prefers-color-scheme: dark) {
  .table-wrap,
  [data-table-wrap] {
    background:
      linear-gradient(90deg, #0f172a 30%, rgba(15, 23, 42, 0)) left center / 20px 100% no-repeat,
      linear-gradient(-90deg, #0f172a 30%, rgba(15, 23, 42, 0)) right center / 20px 100% no-repeat,
      linear-gradient(90deg, rgba(255, 255, 255, .08), rgba(0, 0, 0, 0)) left center / 8px 100% no-repeat,
      linear-gradient(-90deg, rgba(255, 255, 255, .08), rgba(0, 0, 0, 0)) right center / 8px 100% no-repeat;
    background-attachment: local, local, scroll, scroll;
  }
}

.table-wrap table,
[data-table-wrap] table {
  min-width: 100%;
}

/* ─── Modal con scroll suave en móvil ─── */
@media (max-width: 768px) {
  .modal,
  [role="dialog"] {
    -webkit-overflow-scrolling: touch;
  }

  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* ─── Sticky toolbar / footer dentro de main no debe tapar bottom-nav ─── */
@media (max-width: 768px) {
  .sticky-bottom,
  .floating-action {
    bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }
}

/* ─── Ajuste de fuentes en pantallas muy pequeñas ─── */
@media (max-width: 380px) {
  body { font-size: 14px; }
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  .card { padding: 12px !important; }
}

/* ─── Botones primarios full-width en móvil cuando estén en form-actions ─── */
@media (max-width: 768px) {
  .form-actions .btn-primary,
  form .btn-submit,
  form button[type="submit"]:not(.btn-inline) {
    width: 100%;
  }
  .form-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
}

/* ─── Scroll horizontal en pricing cards ─── */
@media (max-width: 720px) {
  .pricing-grid,
  .plans-grid {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
  }
  .pricing-grid > .plan-card,
  .plans-grid > .plan-card {
    scroll-snap-align: center;
    flex-shrink: 0;
  }
}

/* ─── Mejorar contraste y visibilidad de focus en táctil ─── */
@media (max-width: 768px) {
  *:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
  }
}

/* ─── Safe area iOS: que no se corte por el notch ─── */
@supports (padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .bottom-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}
