/* ══ CITALI — AJUSTES SOLO PARA LAS APPS MÓVILES (iOS / Android) ══
   Se inyecta únicamente en mobile/www por scripts/copy-web.sh.
   La app web no carga este archivo. Todo va bajo html.app-movil. */

html.app-movil {
  --tabbar-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* Base del layout móvil (también en celular horizontal, donde el ancho supera
   los 768px de las reglas responsive de styles.css). */
html.app-movil #sidebar,
html.app-movil #sidebar-overlay { display: none !important; }
html.app-movil .mobile-header { display: flex; }
html.app-movil .app-topbar { display: none; }
html.app-movil .main-wrapper { margin-left: 0; }

/* En computadora no existen la barra inferior ni la hoja "Más". */
html:not(.app-movil) .m-tabbar,
html:not(.app-movil) .m-sheet,
html:not(.app-movil) .m-sheet-bg { display: none !important; }

/* clip (no hidden): hidden convierte a body en contenedor de scroll y rompe
   window.scrollTo y el encabezado sticky. */
html.app-movil,
html.app-movil body { overflow-x: clip; }

/* ── Encabezado: respeta la barra de estado / notch ── */
html.app-movil .mobile-header {
  padding-top: calc(var(--safe-top) + 0.6rem);
  padding-bottom: 0.6rem;
}
/* La navegación vive en la barra inferior: no hace falta el menú lateral. */
html.app-movil .mobile-header .hamburger { display: none; }
/* Logo.png es cuadrado con mucho margen transparente: se agranda y se recorta con márgenes negativos. */
html.app-movil .mobile-logo-img { height: 76px; width: auto; margin: -24px -14px -24px -12px; }
html.app-movil .mobile-header .btn-sm { min-height: 34px; }

html.app-movil #trial-banner { padding-top: calc(var(--safe-top) + 0.5rem); }
html.app-movil #trial-banner:not(.hidden) + .mobile-header { padding-top: 0.6rem; }

/* Pantallas sin sesión (login, plan, etc.) */
html.app-movil .page-login { padding-top: calc(var(--safe-top) + 1rem); padding-bottom: calc(var(--safe-bottom) + 1rem); }

/* ── Contenido: deja espacio para la barra inferior ── */
html.app-movil #main-content {
  padding: 1rem 1rem calc(var(--tabbar-h) + var(--safe-bottom) + 5.5rem);
}
html.app-movil .page-header { gap: 0.75rem; flex-wrap: wrap; }
html.app-movil .page-header h1 { font-size: 1.45rem; }
html.app-movil .page-subtitle { font-size: 0.85rem; }
html.app-movil .page-header-actions { flex-wrap: wrap; gap: 0.5rem; width: 100%; }

/* iOS hace zoom al enfocar campos con letra < 16px */
html.app-movil input,
html.app-movil select,
html.app-movil textarea { font-size: 16px !important; }

/* Campos de fecha/hora de iOS tienen ancho propio y se salían del formulario */
html.app-movil input[type="date"],
html.app-movil input[type="time"],
html.app-movil input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  text-align: left;
  min-height: 2.9rem;
}
html.app-movil input::-webkit-date-and-time-value { text-align: left; }
html.app-movil .form-group,
html.app-movil .form-row > * { min-width: 0; }

/* ── Agenda: el buscador ocupa su propia fila ── */
html.app-movil .agenda-toolbar { gap: 0.5rem; }
html.app-movil .agenda-buscar-wrap { flex: 1 1 100%; min-width: 0; }
/* La vista semanal mide ≥560px: debe desplazarse dentro de su recuadro, no estirar la página */
html.app-movil .main-wrapper,
html.app-movil #main-content { min-width: 0; max-width: 100vw; }
html.app-movil .agenda-body-layout { align-items: stretch; }
html.app-movil .agenda-container { width: 100%; max-width: 100%; }
html.app-movil .agenda-weekly { overflow-x: auto; -webkit-overflow-scrolling: touch; }
html.app-movil .search-input { min-width: 0; max-width: 100%; box-sizing: border-box; }

/* ── Inicio: tarjetas de resumen más compactas ── */
html.app-movil .stats-grid { gap: 0.6rem; }
html.app-movil .stat-card { padding: 0.8rem; gap: 0.6rem; }
html.app-movil .stat-card > :first-child { width: 38px; height: 38px; min-width: 38px; }
html.app-movil .stat-num { font-size: 1.35rem; }
html.app-movil .stats-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }
html.app-movil .dashboard-lists { grid-template-columns: 1fr; gap: 1.25rem; }
html.app-movil .dashboard-col .section-header { flex-wrap: nowrap; }

/* ── Barra de navegación inferior ── */
.m-tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 150;
  display: flex;
  align-items: stretch;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255,255,255,0.96);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.m-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--text-3);
  font: 600 0.68rem/1 var(--f-display);
  position: relative;
}
.m-tab svg { width: 23px; height: 23px; }
.m-tab.active { color: var(--primary); }
.m-tab.active::before {
  content: '';
  position: absolute;
  top: 0; left: 30%; right: 30%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}
.m-tab .m-badge {
  position: absolute;
  top: 7px; left: calc(50% + 6px);
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--rose);
  color: #fff;
  font-size: 0.6rem;
  line-height: 16px;
  text-align: center;
}

/* ── Hoja "Más" ── */
.m-sheet-bg {
  position: fixed; inset: 0;
  z-index: 170;
  background: rgba(20,17,15,0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.m-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 171;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card-bg);
  border-radius: 20px 20px 0 0;
  padding: 0.6rem 1rem calc(var(--safe-bottom) + 1rem);
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--sh-lg);
}
html.m-sheet-open .m-sheet-bg { opacity: 1; pointer-events: auto; }
html.m-sheet-open .m-sheet { transform: translateY(0); }
.m-sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--border-strong); margin: 0 auto 0.9rem; }
.m-sheet-user {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.25rem 0.25rem 1rem;
  border-bottom: 1px solid var(--border-2);
  margin-bottom: 1rem;
}
.m-sheet-user .user-avatar { flex-shrink: 0; }
.m-sheet-user-name { font-weight: 700; font-size: 0.95rem; color: var(--text); }
.m-sheet-user-mail { font-size: 0.8rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.m-sheet-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.45rem;
  min-height: 84px;
  padding: 0.75rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-alt);
  color: var(--text);
  font: 600 0.78rem/1.2 var(--f-display);
  position: relative;
}
.m-sheet-item svg { width: 24px; height: 24px; color: var(--primary); }
.m-sheet-item.active { border-color: var(--primary); background: var(--primary-light); }
.m-sheet-item .m-badge { position: absolute; top: 6px; right: 8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--rose); color: #fff; font-size: 0.65rem; line-height: 18px; }
.m-sheet-list { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.m-sheet-row {
  display: flex; align-items: center; gap: 0.75rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--card-bg);
  color: var(--text);
  font: 600 0.9rem/1.2 var(--f-display);
  text-align: left;
}
.m-sheet-row svg { width: 20px; height: 20px; flex-shrink: 0; }
.m-sheet-row.danger { color: var(--red); }

/* ── Asistente: encima de la barra inferior ── */
html.app-movil .asistente-fab {
  right: 1rem;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 0.9rem);
  width: 52px; height: 52px;
}
html.app-movil .asistente-panel {
  left: 0.5rem; right: 0.5rem;
  width: auto; max-width: none;
  top: calc(var(--safe-top) + 0.5rem);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 0.5rem);
  height: auto; max-height: none;
}

/* ── Notificaciones ── */
html.app-movil .notif-panel {
  position: fixed;
  left: 0.5rem; right: 0.5rem;
  top: calc(var(--safe-top) + 3.6rem);
  width: auto; max-width: none;
  max-height: 70vh;
}

/* ── Ventanas (modales) como hojas inferiores ── */
html.app-movil .modal { align-items: flex-end; padding: 0; }
html.app-movil .modal-box {
  max-width: none;
  width: 100%;
  max-height: calc(100vh - var(--safe-top) - 1rem);
  border-radius: 20px 20px 0 0;
  padding-bottom: var(--safe-bottom);
  animation: mSheetIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
html.app-movil .modal-header { position: sticky; top: 0; z-index: 2; background: var(--card-bg); padding: 1rem 1.1rem; }
html.app-movil .modal-body { padding: 1rem 1.1rem 0; }
html.app-movil .modal-body-scroll { max-height: none; }
@keyframes mSheetIn {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* Cuando hay una hoja abierta, la barra inferior no estorba */
html.m-modal-open .m-tabbar,
html.m-modal-open .asistente-fab { display: none; }

/* ── Arranque en las apps nativas: sin video, el isotipo continúa el splash nativo.
   (En el navegador del celular el video se muestra igual que en computadora.) ── */
html.app-nativa #intro-video,
html.app-nativa #intro-spinner { display: none !important; }
html.app-nativa #video-intro {
  background: #fff url('../assets/isotipo.png') center / auto 144px no-repeat;
}

/* ══ TABLETS (iPad, tablets Android) ══
   Misma navegación de app, pero aprovechando el ancho: más columnas, ventanas
   centradas y paneles flotantes en lugar de hojas a pantalla completa. */
@media (min-width: 700px) {
  html.app-movil #main-content { padding: 1.5rem 2rem calc(var(--tabbar-h) + var(--safe-bottom) + 6rem); }
  html.app-movil .page-header h1 { font-size: 1.75rem; }
  html.app-movil .page-header-actions { width: auto; }
  html.app-movil .mobile-header { padding-left: 1.5rem; padding-right: 1.5rem; }

  /* Inicio */
  html.app-movil .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.9rem; }
  html.app-movil .stats-grid > :last-child:nth-child(odd) { grid-column: auto; }
  html.app-movil .stat-card { padding: 1rem; }
  html.app-movil .dashboard-lists { grid-template-columns: 1fr 1fr; gap: 1.5rem; }

  /* Listas en cuadrícula: las mismas columnas automáticas que en computadora */
  html.app-movil .contactos-grid,
  html.app-movil .equipo-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  html.app-movil .notas-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  html.app-movil .form-row { grid-template-columns: 1fr 1fr; }

  /* Agenda: el buscador vuelve a compartir fila */
  html.app-movil .agenda-buscar-wrap { flex: 1 1 240px; }

  /* Barra inferior: íconos con etiqueta al lado, centrados */
  html.app-movil .m-tabbar { justify-content: center; }
  html.app-movil .m-tab { flex: 0 1 150px; flex-direction: row; gap: 8px; font-size: 0.8rem; }
  html.app-movil .m-tab.active::before { left: 20%; right: 20%; }
  html.app-movil .m-tab .m-badge { top: 10px; left: auto; right: 18px; }

  /* Hoja "Más": tarjeta centrada abajo */
  html.app-movil .m-sheet {
    left: 50%; right: auto;
    width: min(560px, calc(100vw - 2rem));
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 0.75rem);
    border-radius: 20px;
    padding-bottom: 1rem;
    transform: translate(-50%, calc(100% + var(--tabbar-h) + 2rem));
  }
  html.m-sheet-open .m-sheet { transform: translate(-50%, 0); }
  html.app-movil .m-sheet-grip { display: none; }

  /* Ventanas: centradas, como en computadora */
  html.app-movil .modal { align-items: center; padding: calc(var(--safe-top) + 1.5rem) 1.5rem calc(var(--safe-bottom) + 1.5rem); }
  html.app-movil .modal-box {
    width: 100%;
    max-width: 560px;
    max-height: 100%;
    border-radius: var(--r-lg);
    padding-bottom: 0;
    animation: modalIn 0.2s ease;
  }
  html.app-movil .modal-box-lg { max-width: 680px; }

  /* Asistente y notificaciones: paneles flotantes a la derecha */
  html.app-movil .asistente-panel {
    left: auto; right: 1.5rem;
    width: 400px;
    top: auto;
    height: min(620px, calc(100vh - var(--safe-top) - var(--tabbar-h) - var(--safe-bottom) - 6.5rem));
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 5.5rem);
  }
  html.app-movil .asistente-fab { right: 1.5rem; }
  html.app-movil .notif-panel { left: auto; right: 1.5rem; width: 380px; }
}
