/* ================================================================
   HOSPITALITO - MOBILE UI
   UI paralelo para dispositivos móviles (≤768px)
   Mantiene la paleta y estilo de botones del frontend de escritorio.
   Activación: automática por media query, sin cambios de URL.
   ================================================================ */

/* ----------------------------------------------------------------
   1. OVERLAY y DRAWER — Siempre en DOM, visibles solo en móvil
   ---------------------------------------------------------------- */

/* Backdrop semitransparente */
.mob-overlay {
  position: fixed;
  inset: 0;
  z-index: 1050;
  background: rgba(0, 0, 0, 0.52);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.mob-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

/* Drawer lateral */
.mob-drawer {
  position: fixed;
  top: 0;
  left: -300px;
  bottom: 0;
  width: 288px;
  z-index: 1100;
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: 6px 0 32px rgba(0, 0, 0, 0.16);
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  will-change: left;
}

.mob-drawer.open {
  left: 0;
}

/* Header móvil — oculto por defecto */
.mob-header {
  display: none;
}

/* ----------------------------------------------------------------
   3. ACTIVACIÓN EN MÓVIL (≤768px)
   ---------------------------------------------------------------- */
@media (max-width: 768px) {

  /* Ocultar shell de escritorio */
  .app-header { display: none !important; }
  .app-footer { display: none !important; }
  .banner     { display: none !important; }

  /* Mostrar header móvil */
  .mob-header {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 60px;
    z-index: 1000;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
    padding: 0 16px;
    align-items: center;
    gap: 10px;
  }

  /* Empujar el contenido principal bajo el header fijo */
  .app-main {
    padding-top: 60px !important;
  }

  /* Reducir padding de contenedores de módulo */
  .module-container {
    padding: 1rem !important;
  }

  /* ---- Bottom Sheet: modales se transforman en sheets ---- */
  .modal {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .modal-content {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 90dvh !important;
    border-radius: 22px 22px 0 0 !important;
    margin: 0 !important;
    animation: mob-sheet-up 0.32s cubic-bezier(0.4, 0, 0.2, 1) forwards !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Drag handle visual */
  .modal-content::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 14px auto 0;
    flex-shrink: 0;
  }

  /* Modal header sin borde-radius inferior en bottom sheet */
  .modal-content .modal-header {
    border-radius: 0 !important;
  }

  /* Login más cómodo en móvil */
  #auth-section {
    margin: 1rem !important;
    padding: 2rem 1.5rem !important;
    border-radius: var(--radius-lg) !important;
  }

  /* Tables: scroll horizontal suave con indicador */
  .pac-table-wrapper,
  .cit-table-wrapper,
  .med-table-wrapper,
  .usr-table-wrapper,
  .hor-table-wrapper,
  [class*="-table-wrapper"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
  }

  /* Fila sticky de primera columna en tablas */
  .sui-table tbody td:first-child,
  .sui-table thead th:first-child {
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 1;
  }

  /* Tamaño mínimo de fuente en tablas para legibilidad */
  .sui-table {
    font-size: 0.8125rem !important;
  }

  .sui-table thead th,
  .sui-table tbody td {
    padding: 0.75rem 0.625rem !important;
    white-space: nowrap;
  }

  /* Touch targets mínimos */
  .sui-btn,
  .btn,
  button:not(.mob-hamburger):not(.mob-drawer-close):not(.mob-logout-btn) {
    min-height: 44px;
  }
}

@keyframes mob-sheet-up {
  from { transform: translateY(100%); opacity: 0.6; }
  to   { transform: translateY(0);    opacity: 1;   }
}

/* ----------------------------------------------------------------
   4. COMPONENTES DEL HEADER MÓVIL
   ---------------------------------------------------------------- */

/* Botón hamburguesa */
.mob-hamburger {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.mob-hamburger:hover,
.mob-hamburger:focus-visible {
  background: var(--panel-2);
  color: var(--brand);
  outline: none;
}

.mob-hamburger:active {
  transform: scale(0.93);
}

/* Logo + nombre de marca */
.mob-brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
}

.mob-brand-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
}

.mob-brand-name {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Acciones del header (notificaciones) */
.mob-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mob-notif-btn {
  position: relative;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  background: var(--panel-2);
  border-radius: var(--radius-md);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
  -webkit-tap-highlight-color: transparent;
}

.mob-notif-btn:hover,
.mob-notif-btn:focus-visible {
  border-color: var(--brand);
  color: var(--brand);
  background: rgba(37, 99, 235, 0.06);
  outline: none;
}

.mob-notif-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 16px;
  height: 16px;
  background: var(--danger);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--panel);
  pointer-events: none;
}

.mob-notif-badge.hidden { display: none; }

/* ----------------------------------------------------------------
   5. DRAWER — Cabecera (usuario)
   ---------------------------------------------------------------- */
.mob-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-light) 100%);
  flex-shrink: 0;
  gap: 12px;
}

.mob-drawer-user {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

/* Avatar con iniciales */
.mob-avatar {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}

.mob-user-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.mob-user-email {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.mob-user-role {
  font-size: 0.6875rem;
  color: rgba(255, 255, 255, 0.78);
  font-weight: 500;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}

/* Botón cerrar drawer */
.mob-drawer-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  transition: background 0.18s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.mob-drawer-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.mob-drawer-close:active {
  transform: scale(0.93);
}

/* ----------------------------------------------------------------
   6. DRAWER — Navegación
   ---------------------------------------------------------------- */
.mob-drawer-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Scrollbar delgado en el nav */
.mob-drawer-nav::-webkit-scrollbar { width: 4px; }
.mob-drawer-nav::-webkit-scrollbar-track { background: transparent; }
.mob-drawer-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.mob-nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 13px;
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  border: 1px solid transparent;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.mob-nav-item svg {
  flex-shrink: 0;
  color: var(--muted);
  transition: color 0.15s;
}

.mob-nav-item span {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mob-nav-item:hover {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--brand);
}

.mob-nav-item:hover svg {
  color: var(--brand);
}

.mob-nav-item:active {
  transform: scale(0.97);
}

/* Estado activo */
.mob-nav-item.active {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.13) 0%, rgba(59, 130, 246, 0.07) 100%);
  border-color: rgba(37, 99, 235, 0.22);
  color: var(--brand);
  font-weight: 600;
}

.mob-nav-item.active svg {
  color: var(--brand);
}

/* Línea indicadora izquierda */
.mob-nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 22%;
  bottom: 22%;
  width: 3px;
  background: var(--brand);
  border-radius: 0 3px 3px 0;
}

/* ----------------------------------------------------------------
   7. DRAWER — Footer (logout)
   ---------------------------------------------------------------- */
.mob-drawer-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

/* Botón cerrar sesión */
.mob-logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
  color: #fff;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  width: 100%;
  text-align: left;
  transition: opacity 0.18s, transform 0.18s;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}

.mob-logout-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.mob-logout-btn:active {
  transform: scale(0.97);
  opacity: 1;
}

.mob-logout-btn svg {
  flex-shrink: 0;
}

/* ----------------------------------------------------------------
   8. AJUSTES ESPECÍFICOS DE MÓDULOS EN MÓVIL
   ---------------------------------------------------------------- */
@media (max-width: 768px) {

  /* Headers de módulo en columna */
  [class$="-header-top"],
  [class*="-header-top"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }

  /* Botón de acción principal en ancho completo */
  [class$="-header-top"] .sui-btn-primary,
  [class*="-header-top"] .sui-btn-primary {
    width: 100%;
    justify-content: center;
  }

  /* Filtros en columna */
  [class$="-filters"],
  [class*="-filters"] {
    flex-direction: column !important;
    gap: 8px !important;
  }

  [class$="-filters"] select,
  [class*="-filters"] select,
  [class$="-filters"] .sui-select,
  [class*="-filters"] .sui-select {
    width: 100% !important;
  }

  /* Stats en grid 2x2 */
  [class$="-stats"],
  [class*="-stats"] {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  /* Formularios en 1 columna */
  [class$="-form-grid"],
  [class*="-form-grid"] {
    grid-template-columns: 1fr !important;
  }

  /* Dashboard: stats 2x2 */
  .dash-stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  /* Dashboard: acciones rápidas 2x2 */
  .dash-actions-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Ocultar columnas no esenciales en tablas */
  .mob-hide {
    display: none !important;
  }
}

/* ----------------------------------------------------------------
   9. ESTADO VACÍO DEL DRAWER (sin sesión)
   ---------------------------------------------------------------- */
.mob-drawer-nav-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.6;
}

/* ----------------------------------------------------------------
   10. SOPORTE SAFE AREA (iPhone X+ / notch)
   ---------------------------------------------------------------- */
@supports (padding-top: env(safe-area-inset-top)) {
  @media (max-width: 768px) {
    .mob-header {
      padding-top: env(safe-area-inset-top);
      height: calc(60px + env(safe-area-inset-top));
    }

    .app-main {
      padding-top: calc(60px + env(safe-area-inset-top)) !important;
    }

    .mob-drawer {
      padding-bottom: env(safe-area-inset-bottom);
    }

    .modal-content {
      padding-bottom: env(safe-area-inset-bottom) !important;
    }
  }
}
