/*
 * pwa-standalone.css — Smile Dental Lab
 *
 * Los estilos aplican en DOS situaciones:
 *   A) App instalada en el celular  →  @media (display-mode: standalone)
 *   B) Previsualización en browser  →  html.pwa-sim  (activa con ?pwa=1)
 *
 * ¡NO afecta el sitio normal en el navegador!
 */

/* ─── mixin simulado con selector combinado ──────────────────────────────────
   Usamos :is() para no duplicar reglas.
   Nota: :is(html.pwa-sim) * ≠ html.pwa-sim * en especificidad, pero funciona.
────────────────────────────────────────────────────────────────────────────── */

/* ══ 1. HTML / BODY ══════════════════════════════════════════════════════════ */
@media (display-mode: standalone) { html { background: #0d9488; } }
html.pwa-sim                      { background: #0d9488; }

@media (display-mode: standalone) {
  body {
    background: #f8fafc;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none;
    -webkit-tap-highlight-color: transparent;
  }
}
html.pwa-sim body {
  background: #f8fafc;
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
  -webkit-tap-highlight-color: transparent;
}

/* ══ 2. HEADER COMPLETO STICKY (como unidad, no por partes) ═══════════════════
   El <header> envuelve: topbar + site-header + megamenu.
   Al hacer sticky el <header> completo, todo se mueve junto → sin solapamiento.
══════════════════════════════════════════════════════════════════════════════ */
@media (display-mode: standalone) {
  header {
    position: sticky !important;
    top: 0 !important;
    z-index: 10000 !important;
    /* El fondo teal "rellena" la zona del status bar (safe-area-inset-top) */
    background: #0d9488 !important;
  }
}
html.pwa-sim header {
  position: sticky !important;
  top: 0 !important;
  z-index: 10000 !important;
  background: #0d9488 !important;
}

/* Pseudo-elemento que llena el hueco del status bar en iOS */
@media (display-mode: standalone) {
  header::before {
    content: '';
    display: block;
    width: 100%;
    height: env(safe-area-inset-top, 0px);
    min-height: 0;
    background: #0d9488;
  }
}
html.pwa-sim header::before {
  content: '';
  display: block;
  width: 100%;
  height: 20px; /* altura fija en previsualización desktop */
  background: #0d9488;
}

/* ══ 3. OCULTAR TOPBAR ═══════════════════════════════════════════════════════ */
@media (display-mode: standalone) { .sdl-topbar { display: none !important; } }
html.pwa-sim                      .sdl-topbar { display: none !important; }

/* ══ 4. SITE-HEADER — limpieza visual (ya es sticky como parte del <header>) ══ */
@media (display-mode: standalone) {
  .site-header,
  .container-fluid.bg-white.site-header {
    background: #fff !important;
    box-shadow: 0 2px 16px rgba(15,23,42,.10) !important;
    border-radius: 0 0 16px 16px;
  }
  .site-header-top { padding: 8px 0 !important; }
}
html.pwa-sim .site-header,
html.pwa-sim .container-fluid.bg-white.site-header {
  background: #fff !important;
  box-shadow: 0 2px 16px rgba(15,23,42,.10) !important;
  border-radius: 0 0 16px 16px;
}
html.pwa-sim .site-header-top { padding: 8px 0 !important; }

/* ══ 5. MEGAMÉNÚ — relativo al <header> sticky (no sticky propio) ═════════════ */
@media (display-mode: standalone) {
  .megamenu-bar {
    position: relative !important; /* no sticky individual — ya lo maneja el <header> */
    background: #fff !important;
    border-bottom: 1px solid rgba(15,23,42,.07) !important;
  }
}
html.pwa-sim .megamenu-bar {
  position: relative !important;
  background: #fff !important;
  border-bottom: 1px solid rgba(15,23,42,.07) !important;
}

/* ══ 6. BACK-TO-TOP — no quede bajo la nav inferior ═════════════════════════ */
@media (display-mode: standalone) {
  .back-to-top {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
    right: 16px !important;
  }
}
html.pwa-sim .back-to-top { bottom: 80px !important; right: 16px !important; }

/* ══ 7. DROPDOWNS — no queden tapados ═══════════════════════════════════════ */
@media (display-mode: standalone) {
  .site-header-actions .dropdown-menu {
    max-height: calc(100vh - 140px - env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto !important;
  }
}
html.pwa-sim .site-header-actions .dropdown-menu {
  max-height: calc(100vh - 140px) !important;
  overflow-y: auto !important;
}

/* ══ 8. OCULTAR BANNER DE INSTALACIÓN (ya instalada) ════════════════════════ */
@media (display-mode: standalone) { .sdl-pwa { display: none !important; } }
html.pwa-sim                      .sdl-pwa { display: none !important; }

/* ══════════════════════════════════════════════════════════════════════════════
   9. BARRA DE NAVEGACIÓN INFERIOR
   Oculta en navegador normal. Visible en app instalada o con ?pwa=1
══════════════════════════════════════════════════════════════════════════════ */
.sdl-app-nav { display: none; }

@media (display-mode: standalone) {
  .sdl-app-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 99990;
    background: #fff;
    border-top: 1px solid rgba(15,23,42,.09);
    box-shadow: 0 -2px 20px rgba(15,23,42,.08);
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    align-items: stretch;
    justify-content: space-around;
  }
}
html.pwa-sim .sdl-app-nav {
  display: flex !important;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 99990;
  background: #fff;
  border-top: 1px solid rgba(15,23,42,.09);
  box-shadow: 0 -2px 20px rgba(15,23,42,.08);
  height: 64px;
  align-items: stretch;
  justify-content: space-around;
}

/* Ítems de la nav */
@media (display-mode: standalone), (min-width: 0px) {
  /* Estos estilos aplican siempre que el nav sea visible */
}
.sdl-app-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none !important;
  color: #94a3b8;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  padding: 6px 2px;
  transition: color 0.15s;
  position: relative;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sdl-app-nav__item:hover,
.sdl-app-nav__item--active {
  color: #0d9488 !important;
  text-decoration: none !important;
}
.sdl-app-nav__item--active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 15%; right: 15%;
  height: 3px;
  background: #0d9488;
  border-radius: 0 0 4px 4px;
}
.sdl-app-nav__icon {
  font-size: 1.25rem;
  line-height: 1;
  position: relative;
}
.sdl-app-nav__badge {
  position: absolute;
  top: -5px; right: -9px;
  min-width: 16px; height: 16px;
  background: #dc3545;
  color: #fff;
  border-radius: 999px;
  font-size: 0.58rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid #fff;
}
.sdl-app-nav__badge[data-count="0"],
.sdl-app-nav__badge:empty { display: none; }
.sdl-app-nav__label {
  font-size: 0.6rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ══ 10. iOS notch extra ══════════════════════════════════════════════════════ */
@supports (-webkit-touch-callout: none) {
  @media (display-mode: standalone) {
    header::before { min-height: env(safe-area-inset-top, 44px); }
  }
}

/* ══ 11. BOTÓN FLOTANTE DE PREVISUALIZACIÓN (solo visible con ?pwa=1) ════════ */
.pwa-sim-bar {
  display: none;
}
html.pwa-sim .pwa-sim-bar {
  display: flex;
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 999999;
  background: #0f172a;
  color: #fff;
  writing-mode: vertical-rl;
  font-size: 10px;
  font-weight: 800;
  padding: 10px 6px;
  border-radius: 8px 0 0 8px;
  letter-spacing: 1px;
  cursor: pointer;
  opacity: 0.7;
  gap: 6px;
  align-items: center;
}
html.pwa-sim .pwa-sim-bar:hover { opacity: 1; }
