/* ══════════════════════════════════════════════════════════════════════════
   mobile.css — Capa responsive opt-in para la plataforma logística
   --------------------------------------------------------------------------
   Reglas scopeadas a @media (max-width: 768px). En desktop NO toca nada.
   Carga después de logistic.css en base.html.

   Patrón:
     · Sidebar lateral → off-canvas (hidden, slide-in via .sb-mobile-open)
     · Bottom-nav fijo aparece (definido en bottom_nav.html como #bn)
     · Topbar genérico se compacta + suma botón hamburguesa
     · Watermark se oculta (no aporta en pantalla pequeña)
     · Contenido principal recibe padding-bottom para no quedar tapado por el bn
     · Tabs/tablas modulares migrarán en sesiones siguientes (cards stackeadas)
   ══════════════════════════════════════════════════════════════════════════ */

/* ─── Variables compartidas entre nav y bottom-nav ─── */
:root {
  --bn-height: 60px;
  --bn-fab-size: 54px;
  --bn-side-margin: 12px;
  --bn-bottom-margin: 14px;
  --bn-radius: 28px;
  --bn-bg: linear-gradient(180deg, rgba(20,28,40,.92) 0%, rgba(13,19,28,.96) 100%);
  --bn-border: rgba(130,150,180,.14);
  --bn-icon: rgba(148,163,184,.60);
  --bn-icon-hover: rgba(255,255,255,.92);
  --bn-accent: #E63946;
  --bn-accent-soft: rgba(230,57,70,.14);
  /* Sombra cálida + halo rojo sutil para el efecto flotante */
  --bn-shadow:
    0 12px 32px rgba(0,0,0,.55),
    0 4px 14px rgba(0,0,0,.35),
    0 0 0 1px rgba(230,57,70,.04),
    inset 0 1px 0 rgba(255,255,255,.03);
}

/* ══════════════════════════════════════════════════════════════════════════
   DESKTOP: bottom-nav, sheet y topbar brand quedan ocultos por defecto
   ══════════════════════════════════════════════════════════════════════════ */
#bn,
#bn-sheet,
#bn-sheet-backdrop,
.gen-topbar-brand { display: none; }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE: hasta 768px
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ─── Layout principal: una sola columna ─── */
  /* Background defensivo: si por algún motivo el .flex-grow-1
     no cubre todo el viewport en mobile, igual no se ve blanco. */
  html, body {
    overflow-x: hidden;
    background: #0b1118;
  }

  /* En mobile el sidebar desaparece por completo. Toda la navegación
     se hace via bottom-nav + sheet "Más". El sheet replica las secciones
     completas del sidebar para que no se pierda acceso a nada.
     IMPORTANTE: !important porque el <style> inline de sidebar.html vive
     dentro del <body> y carga DESPUÉS de mobile.css (que está en <head>);
     sin !important sus reglas ganan por source order. */
  #sidebar {
    display: none !important;
  }

  /* ─── Main column: ocupa todo, deja espacio para bottom-nav flotante ─── */
  /* home.html hace <div class="d-flex"> con sidebar + flex-grow-1.
     Como #sidebar es display:none en mobile, .flex-grow-1 toma todo. */
  .d-flex > .flex-grow-1 {
    width: 100% !important;
    min-width: 0;
    /* Reserva: alto del nav + margen inferior + safe-area + buffer */
    padding-bottom: calc(
      var(--bn-height) + var(--bn-bottom-margin) +
      env(safe-area-inset-bottom, 0px) + 24px
    );
  }

  /* ─── Topbar mobile: compacto, sin hamburguesa (sidebar removido) ─── */
  .gen-topbar {
    padding: .55rem .85rem;
    gap: .65rem;
    min-height: 52px;
    flex-wrap: nowrap;
  }

  /* ─── Marca Emser arriba a la izquierda — reemplaza al icono
     duplicado que tenía el breadcrumb. Aplica el mismo efecto de glow
     que usa el sidebar (sb-logo) para que se sienta del mismo sistema. */
  .gen-topbar-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    text-decoration: none;
    transition: transform .25s cubic-bezier(.16,1,.3,1);
  }
  .gen-topbar-brand:hover,
  .gen-topbar-brand:active {
    transform: scale(1.08) rotate(-3deg);
  }
  .gen-topbar-brand__logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter:
      drop-shadow(0 2px 10px rgba(230,57,70,.35))
      drop-shadow(0 0 18px rgba(230,57,70,.15));
  }

  /* Breadcrumbs en mobile: SOLO mostramos la página actual (.gen-bc-current).
     Antes se mostraba "Gestión › Pedidos de Cuadrillas" — el padre
     "Gestión" no aporta valor en pantalla chica y el título largo se
     cortaba. Ahora se ve solo el título (con alias si lo definimos). */
  .gen-breadcrumbs {
    font-size: .72rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .gen-breadcrumbs > *:not(.gen-bc-current) {
    display: none;
  }
  /* En mobile el icono dentro del current item se duplica con el icono
     del <h2> del módulo. Lo escondemos — la marca de la izquierda ya
     da el contexto visual. */
  .gen-bc-current > i.fa-solid {
    display: none;
  }
  /* ─── Aliases mobile para títulos largos ─────────────────────────
     Patrón opt-in: el template del módulo agrega
       <span class="gen-bc-current" data-mobile-label="Pedidos">
         <i...></i>
         {% trans "Pedidos de Cuadrillas" %}
       </span>
     y acá nukeamos el texto largo (font-size: 0) y mostramos el alias
     vía ::after. `gap: 0` evita que el flex container deje espacio
     extra antes del ::after (el text node invisible sigue siendo un
     flex item con 0 width, pero el gap lo desplazaba .4rem a la derecha
     y rompía la alineación con módulos sin alias como Inicio).
     Tamaño .72rem para coincidir con el text default heredado de
     .gen-breadcrumbs y que todos los labels se vean uniformes. */
  .gen-bc-current[data-mobile-label] {
    font-size: 0;
    gap: 0;
  }
  .gen-bc-current[data-mobile-label]::after {
    content: attr(data-mobile-label);
    font-size: .72rem;
    font-weight: 600;
    color: rgba(255,255,255,.88);
    letter-spacing: .01em;
  }
  /* Fecha viva se oculta — el dispositivo ya muestra hora en la barra de estado */
  .gen-datetime { display: none; }
  /* Botón notificaciones queda */
  .gen-topbar-btn { width: 36px; height: 36px; font-size: .85rem; }

  /* ─── Watermark fuera ─── */
  .d-flex > .flex-grow-1 > div[style*="emser-icon.png"][style*="opacity"] {
    display: none !important;
  }

  /* ─── Content wrap más compacto ─── */
  .gen-content-wrap {
    padding: .75rem;
  }

  /* ══════════════════════════════════════════════════════════════════
     BOTTOM NAVIGATION — Flotante estilo IG/iOS
     Pill con margen inferior + laterales, sombra cálida y blur potente.
     ══════════════════════════════════════════════════════════════════ */
  #bn {
    display: flex;
    position: fixed;
    left: var(--bn-side-margin);
    right: var(--bn-side-margin);
    bottom: calc(var(--bn-bottom-margin) + env(safe-area-inset-bottom, 0px));
    height: var(--bn-height);
    background: var(--bn-bg);
    backdrop-filter: blur(22px) saturate(160%);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
    border: 1px solid var(--bn-border);
    border-radius: var(--bn-radius);
    box-shadow: var(--bn-shadow);
    z-index: 900;
    align-items: stretch;
    justify-content: space-around;
    font-family: 'Inter', sans-serif;
    /* No hace falta overflow:hidden — el FAB tiene que poder sobresalir */
    overflow: visible;
  }
  /* Glow sutil rojo arriba del nav (tipo halo) */
  #bn::before {
    content: '';
    position: absolute;
    top: -1px; left: 18%; right: 18%; height: 1px;
    background: linear-gradient(90deg, transparent, rgba(230,57,70,.45) 50%, transparent);
    border-radius: 1px;
    pointer-events: none;
  }

  /* ─── Items normales ─── */
  .bn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    text-decoration: none;
    color: var(--bn-icon);
    font-size: .56rem;
    font-weight: 500;
    letter-spacing: .02em;
    transition: color .18s cubic-bezier(.16,1,.3,1);
    border: none;
    background: transparent;
    cursor: pointer;
    position: relative;
    min-width: 0;
    -webkit-tap-highlight-color: transparent;
  }
  .bn-item i {
    font-size: 1.05rem;
    transition: transform .18s, filter .18s;
    z-index: 1;
  }
  .bn-item span {
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    z-index: 1;
  }
  .bn-item:hover { color: var(--bn-icon-hover); }
  .bn-item:active i { transform: scale(.92); }

  /* Active: ícono coloreado + halo radial sutil detrás (no full pill,
     queda más liviano y se integra con la estética flotante) */
  .bn-item.is-active {
    color: #fff;
  }
  .bn-item.is-active i {
    color: var(--bn-accent);
    filter: drop-shadow(0 0 10px rgba(230,57,70,.55));
  }
  .bn-item.is-active::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    width: 38px; height: 38px;
    background: radial-gradient(circle, rgba(230,57,70,.18) 0%, transparent 65%);
    border-radius: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    animation: bnGlow .35s cubic-bezier(.16,1,.3,1);
  }
  @keyframes bnGlow {
    from { opacity: 0; transform: translateX(-50%) scale(.6); }
    to { opacity: 1; transform: translateX(-50%) scale(1); }
  }

  /* ─── FAB central (item destacado) ─── */
  .bn-item--fab {
    flex: 0 0 var(--bn-fab-size);
    position: relative;
    color: #fff !important;
  }
  .bn-item--fab .bn-fab-pill {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    width: var(--bn-fab-size);
    height: var(--bn-fab-size);
    border-radius: 50%;
    background:
      radial-gradient(circle at 30% 25%, rgba(255,255,255,.22) 0%, transparent 55%),
      linear-gradient(135deg, #E63946 0%, #b8232f 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.3rem;
    box-shadow:
      0 10px 28px rgba(230,57,70,.55),
      0 4px 10px rgba(230,57,70,.30),
      0 0 0 4px rgba(13,19,28,.85),  /* anillo de "corte" contra el nav blur */
      inset 0 1px 0 rgba(255,255,255,.22);
    transition: all .25s cubic-bezier(.16,1,.3,1);
  }
  .bn-item--fab:hover .bn-fab-pill,
  .bn-item--fab:active .bn-fab-pill {
    transform: translateX(-50%) translateY(-2px) scale(1.04);
    box-shadow:
      0 14px 32px rgba(230,57,70,.62),
      0 5px 12px rgba(230,57,70,.34),
      0 0 0 4px rgba(13,19,28,.85),
      inset 0 1px 0 rgba(255,255,255,.26);
  }
  /* Active del FAB: tono más oscuro (granate) para que el feedback de
     "estoy en este módulo" se diferencie del rojo accent del estado normal.
     Mantenemos la familia roja (identidad de marca) pero bajamos a un vino
     oscuro que contrasta contra el rojo del nav. */
  .bn-item--fab.is-active .bn-fab-pill {
    background:
      radial-gradient(circle at 30% 25%, rgba(255,255,255,.14) 0%, transparent 55%),
      linear-gradient(135deg, #7a0a18 0%, #4f0510 100%);
    box-shadow:
      0 0 0 4px rgba(13,19,28,.85),
      0 0 0 6px rgba(122,10,24,.45),
      0 14px 32px rgba(122,10,24,.55),
      inset 0 1px 0 rgba(255,255,255,.18);
  }
  /* Hover/active sobre el FAB activo: mantiene el granate, no vuelve al
     rojo brillante (sino el color "salta" al tap). */
  .bn-item--fab.is-active:hover .bn-fab-pill,
  .bn-item--fab.is-active:active .bn-fab-pill {
    background:
      radial-gradient(circle at 30% 25%, rgba(255,255,255,.16) 0%, transparent 55%),
      linear-gradient(135deg, #8a1020 0%, #5a0612 100%);
  }
  /* FAB no usa el halo radial activo: ya tiene su propia jerarquía visual */
  .bn-item--fab.is-active::before { display: none; }
  .bn-item--fab span {
    margin-top: calc(var(--bn-fab-size) - 24px);
    font-weight: 600;
    color: rgba(255,255,255,.88);
  }

  /* ══════════════════════════════════════════════════════════════════
     SHEET ("Más" — bottom sheet con resto de módulos)
     ══════════════════════════════════════════════════════════════════ */
  #bn-sheet-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(5,9,15,.62);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 950;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease-out;
  }
  #bn-sheet {
    display: block;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: linear-gradient(180deg, #131b27 0%, #0e1620 100%);
    border-top: 1px solid rgba(130,150,180,.12);
    border-radius: 18px 18px 0 0;
    padding: 1.1rem 1rem calc(1.1rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -16px 48px rgba(0,0,0,.5);
    transform: translateY(100%);
    transition: transform .28s cubic-bezier(.16,1,.3,1);
    z-index: 951;
    max-height: 78vh;
    overflow-y: auto;
    font-family: 'Inter', sans-serif;
  }
  body.bn-sheet-open #bn-sheet-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  body.bn-sheet-open #bn-sheet { transform: translateY(0); }

  /* Grabber sutil */
  .bn-sheet__grabber {
    width: 36px; height: 4px;
    background: rgba(255,255,255,.18);
    border-radius: 4px;
    margin: 0 auto .85rem;
  }
  .bn-sheet__title {
    font-size: .62rem; font-weight: 700;
    letter-spacing: .14em; text-transform: uppercase;
    color: rgba(148,163,184,.55);
    margin: 0 0 .65rem .25rem;
  }
  .bn-sheet__group {
    display: flex; flex-direction: column; gap: 2px;
    margin-bottom: 1rem;
  }
  .bn-sheet__item {
    display: flex; align-items: center; gap: .8rem;
    padding: .85rem .85rem;
    border-radius: 10px;
    color: rgba(255,255,255,.78);
    text-decoration: none;
    font-size: .82rem;
    font-weight: 500;
    transition: all .18s cubic-bezier(.16,1,.3,1);
    border: 1px solid transparent;
    background: transparent;
    text-align: left;
    width: 100%;
    cursor: pointer;
  }
  .bn-sheet__item:hover,
  .bn-sheet__item:active {
    background: rgba(230,57,70,.06);
    border-color: rgba(230,57,70,.18);
    color: #fff;
  }
  .bn-sheet__item i {
    width: 22px;
    text-align: center;
    color: rgba(148,163,184,.65);
    font-size: .9rem;
  }
  .bn-sheet__item:hover i,
  .bn-sheet__item:active i { color: var(--bn-accent); }
  .bn-sheet__item--danger { color: rgba(255,160,170,.85); }
  .bn-sheet__item--danger i { color: rgba(230,57,70,.7); }

  /* ─── Campaign selector dentro del sheet ─── */
  .bn-sheet__campaign {
    background: linear-gradient(180deg, rgba(230,57,70,.06) 0%, rgba(230,57,70,.02) 100%);
    border: 1px solid rgba(230,57,70,.16);
    border-radius: 12px;
    padding: .7rem .85rem .8rem;
    margin: 0 0 1.1rem;
  }
  .bn-sheet__campaign-label {
    display: flex; align-items: center; gap: .5rem;
    font-size: .58rem; font-weight: 700;
    letter-spacing: .14em; text-transform: uppercase;
    color: rgba(255,255,255,.55);
    margin-bottom: .45rem;
  }
  .bn-sheet__campaign-label i {
    color: var(--bn-accent);
    font-size: .58rem;
    filter: drop-shadow(0 0 4px rgba(230,57,70,.4));
  }
  .bn-sheet__campaign-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 0 2px rgba(52,211,153,.18), 0 0 6px rgba(52,211,153,.5);
    margin-left: auto;
  }
  .bn-sheet__campaign-select {
    width: 100%;
    appearance: none; -webkit-appearance: none;
    background:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23E63946' d='M5 6L0 0h10z'/></svg>") no-repeat right .85rem center,
      rgba(255,255,255,.04);
    background-size: 10px 6px;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 8px;
    padding: .65rem 2.2rem .65rem .8rem;
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: .85rem;
    font-weight: 600;
    letter-spacing: .01em;
    outline: none;
    cursor: pointer;
    transition: border-color .18s, background .18s;
  }
  .bn-sheet__campaign-select:focus {
    border-color: rgba(230,57,70,.45);
    background-color: rgba(255,255,255,.06);
    box-shadow: 0 0 0 3px rgba(230,57,70,.08);
  }
  .bn-sheet__campaign-select option {
    background: #131b27; color: #f0f0f0;
  }

  /* ─── Bloque de usuario en sección "Cuenta" ─── */
  .bn-sheet__user {
    display: flex; align-items: center; gap: .8rem;
    padding: .75rem .85rem;
    background: rgba(255,255,255,.02);
    border: 1px solid rgba(130,150,180,.08);
    border-radius: 10px;
    margin-bottom: .5rem;
  }
  .bn-sheet__avatar {
    width: 38px; height: 38px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #E63946 0%, #b8232f 100%);
    color: #fff;
    font-size: .82rem;
    font-weight: 700;
    letter-spacing: .02em;
    border-radius: 50%;
    box-shadow:
      0 4px 12px rgba(230,57,70,.32),
      inset 0 1px 0 rgba(255,255,255,.18);
  }
  .bn-sheet__user-info { min-width: 0; flex: 1; }
  .bn-sheet__username {
    font-size: .82rem; font-weight: 600;
    color: rgba(255,255,255,.92);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .bn-sheet__version {
    font-size: .58rem;
    color: rgba(148,163,184,.45);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ─── Idioma (form inline) ─── */
  .bn-sheet__lang {
    display: flex; align-items: center; gap: .65rem;
    padding: .75rem .85rem;
    border-radius: 10px;
    background: transparent;
    border: 1px solid transparent;
    margin-bottom: .25rem;
  }
  .bn-sheet__lang label {
    font-size: .82rem;
    color: rgba(255,255,255,.78);
    font-weight: 500;
    flex: 1;
    margin: 0;
  }
  .bn-sheet__lang label::before {
    content: '\f0ac'; /* fa-globe */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-right: .8rem;
    color: rgba(148,163,184,.65);
    font-size: .85rem;
    width: 22px;
    display: inline-block;
    text-align: center;
  }
  .bn-sheet__lang select {
    appearance: none; -webkit-appearance: none;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 6px;
    padding: .35rem .7rem;
    color: rgba(255,255,255,.85);
    font-family: 'Inter', sans-serif;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .04em;
    outline: none;
    cursor: pointer;
  }
  .bn-sheet__lang select option {
    background: #131b27; color: #f0f0f0;
  }

  /* ─── Logout: form sin estilos extra, el button reusa .bn-sheet__item ─── */
  .bn-sheet__logout-form { margin: 0; padding: 0; }
  .bn-sheet__logout-form .bn-sheet__item { margin-top: .25rem; }

  /* NOTA: el override mobile del .notif-panel (bottom-sheet) vive en
     el <style> inline de home.html — mobile.css carga ANTES que ese
     bloque (base.html línea 35 vs 66) y las reglas desktop ganaban por
     source order si las ponía acá. Mantener todas las reglas del panel
     juntas en home.html evita el problema. */

  /* ══════════════════════════════════════════════════════════════════
     Animaciones
     ══════════════════════════════════════════════════════════════════ */
  @keyframes bnFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   Pantallas muy chicas (≤ 380px): ajustes finos
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  :root {
    --bn-height: 60px;
    --bn-fab-size: 52px;
  }
  .bn-item span { font-size: .55rem; }
  .bn-item i { font-size: 1rem; }
  .gen-content-wrap { padding: .6rem; }
}
