/* ==========================================================================
   INYMO · Aceros y Techos — barra de navegación inferior (footbar) cristalina.
   Reemplaza al sidebar de 230px. Se carga desde _pwa_head.pug, antes que el
   <style> inline de cada vista, para que las vistas puedan afinar detalles.
   ========================================================================== */

:root {
  --fb-h: 66px;          /* alto de la píldora */
  --fb-gap: 16px;        /* separación con el borde inferior */
  --fb-green: #8cc63f;
  /* Alto total que la barra le roba a la pantalla. Las vistas de alto fijo
     (chats) restan esto en lugar de usar el padding de `body`. */
  --fb-space: calc(var(--fb-h) + var(--fb-gap) * 2);
}

/* El contenido nunca debe quedar debajo de la píldora. `body` (0,0,1) gana
   sobre el `*{padding:0}` del reset inline de cada vista (0,0,0). */
body {
  padding-bottom: calc(var(--fb-space) + env(safe-area-inset-bottom, 0px));
}

/* ═══════════════ Píldora flotante — vidrio cristalino ═══════════════ */
.footbar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--fb-gap) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 220;
  width: min(720px, calc(100% - 24px));
  height: var(--fb-h);
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  /* Vidrio en capas: un degradado diagonal claro arriba-izq a oscuro abajo-der
     da volumen de cristal, sobre el blur del contenido de atrás. */
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.10) 0%, rgba(255, 255, 255, 0.02) 30%, rgba(13, 20, 36, 0.30) 100%),
    rgba(12, 18, 32, 0.55);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.55),
    0 2px 8px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -1px 0 rgba(0, 0, 0, 0.25);
  overflow: hidden;
  isolation: isolate;
}

/* Ola de luz que recorre la barra en reposo (respiración lenta de cristal). */
.footbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(
    100deg,
    transparent 20%,
    rgba(255, 255, 255, 0.06) 40%,
    rgba(140, 198, 63, 0.10) 50%,
    rgba(255, 255, 255, 0.06) 60%,
    transparent 80%
  );
  background-size: 220% 100%;
  animation: fb-ola 7s ease-in-out infinite;
}

@keyframes fb-ola {
  0%   { background-position: 130% 0; }
  100% { background-position: -30% 0; }
}

/* ⚠ [5-ago · C1] LAS COLUMNAS SALEN DEL MARCADO, NO ESTÁN FIJADAS A 5.
   Estaban en `repeat(5, 1fr)`: 4 botones fijos + «Más». Al pedir Ángel seis
   fijos, el séptimo elemento se salía del grid y el botón de «Más» caía a una
   segunda línea — la barra partida que él vio.
   `_footbar.pug` escribe `data-cols` con el número real (fijos + 1). El 5 del
   fallback es lo que había: si alguien pinta la barra sin el atributo, se ve
   exactamente como antes. */
.fb-inner {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--fb-cols, 5), 1fr);
  height: 100%;
  padding: 6px;
  gap: 2px;
}

/* Con 6 o 7 columnas el ancho por botón baja de ~66px a ~49px en un teléfono
   de 390. El icono cabe igual; lo que no cabe es la etiqueta, así que se
   estrecha la letra y se recorta con puntos suspensivos en vez de dejar que
   empuje la columna. Sin esto, una etiqueta larga ensancha su celda y desalinea
   toda la barra. */
.footbar[data-cols="6"] .fb-inner,
.footbar[data-cols="7"] .fb-inner { gap: 1px; padding: 5px; }

.footbar[data-cols="6"] .fb-item,
.footbar[data-cols="7"] .fb-item { font-size: 0.55rem; border-radius: 13px; }

.footbar[data-cols="6"] .fb-item i,
.footbar[data-cols="7"] .fb-item i { font-size: 1.2rem; }

.footbar[data-cols="6"] .fb-item span,
.footbar[data-cols="7"] .fb-item span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Por debajo de 360px ya no hay ancho que repartir entre siete: se queda sólo
   el icono. Es preferible a siete etiquetas ilegibles superpuestas. */
@media (max-width: 359px) {
  .footbar[data-cols="7"] .fb-item span { display: none; }
  .footbar[data-cols="7"] .fb-item i { font-size: 1.3rem; }
}

.fb-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: #9aa8bd;
  font-family: inherit;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  transition: color 0.2s ease, background 0.2s ease, transform 0.2s cubic-bezier(.3, 1.3, .5, 1);
  -webkit-tap-highlight-color: transparent;
}

/* La ola que "pasa por encima" al hacer hover: un barrido de luz diagonal. */
.fb-item::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(
    115deg,
    transparent 30%,
    rgba(255, 255, 255, 0.14) 45%,
    rgba(140, 198, 63, 0.22) 52%,
    rgba(255, 255, 255, 0.14) 59%,
    transparent 74%
  );
  background-size: 250% 100%;
  background-position: 130% 0;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.fb-item:hover::after,
.fb-item:focus-visible::after {
  opacity: 1;
  animation: fb-item-ola 0.7s ease-out;
}

@keyframes fb-item-ola {
  0%   { background-position: 130% 0; }
  100% { background-position: -30% 0; }
}

.fb-item i {
  position: relative;
  z-index: 1;
  font-size: 1.35rem;
  line-height: 1;
  transition: transform 0.2s cubic-bezier(.3, 1.3, .5, 1);
}

.fb-label {
  position: relative;
  z-index: 1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fb-item:hover {
  color: #f1f5f9;
}

.fb-item:hover i {
  transform: translateY(-1px) scale(1.08);
}

.fb-item:active {
  transform: scale(0.94);
}

.fb-item.active {
  color: var(--fb-green);
  /* Blob de vidrio verde bajo el ítem activo. */
  background:
    radial-gradient(120% 90% at 50% 120%, rgba(140, 198, 63, 0.28), transparent 70%),
    rgba(140, 198, 63, 0.10);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* Filo superior iluminado en el ítem activo */
.fb-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  width: 28px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--fb-green), transparent);
  box-shadow: 0 0 12px var(--fb-green), 0 0 4px var(--fb-green);
}

.fb-item:focus-visible {
  outline: 2px solid var(--fb-green);
  outline-offset: -2px;
}

/* Contador rojo (pendientes) */
.fb-badge {
  position: absolute;
  top: 4px;
  right: 50%;
  margin-right: -22px;
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1;
}

/* ═══════════════ Hoja inferior (resto del menú) ═══════════════
   Es HERMANA de .footbar, no hija: en iOS un ancestro con
   backdrop-filter rompe el `position:fixed` de sus descendientes. */
.fb-sheet {
  position: fixed;
  left: 50%;
  bottom: calc(var(--fb-h) + var(--fb-gap) + 10px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(14px);
  z-index: 221;
  width: min(720px, calc(100% - 24px));
  max-height: min(60vh, 520px);
  overflow-y: auto;
  padding: 12px;
  border-radius: 22px;
  border: 1px solid rgba(140, 198, 63, 0.16);
  background: rgba(10, 16, 28, 0.82);
  backdrop-filter: blur(24px) saturate(170%);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.fb-sheet.open {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.fb-sheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 6px;
}

.fb-sheet-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  color: #94a3b8;
  font-size: 0.83rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.18s ease, color 0.18s ease;
}

.fb-sheet-link i {
  font-size: 1.15rem;
  width: 22px;
  text-align: center;
}

.fb-sheet-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #f1f5f9;
}

.fb-sheet-link.active {
  background: rgba(140, 198, 63, 0.1);
  border-color: rgba(140, 198, 63, 0.2);
  color: var(--fb-green);
  font-weight: 700;
}

.fb-sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid rgba(140, 198, 63, 0.12);
}

.fb-user strong {
  display: block;
  color: #f1f5f9;
  font-size: 0.85rem;
}

.fb-user small {
  color: #475569;
  font-size: 0.66rem;
  letter-spacing: 0.4px;
}

.fb-logout {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 9px 14px;
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.06);
  color: #ef4444;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease;
}

.fb-logout:hover {
  background: rgba(239, 68, 68, 0.15);
}

.fb-powered {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 10px;
  opacity: 0.4;
}

.fb-powered span {
  color: #475569;
  font-size: 0.54rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.fb-powered img {
  height: 11px;
}

/* ═══════════════ Velo ═══════════════ */
.fb-scrim {
  position: fixed;
  inset: 0;
  z-index: 219;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
}

.fb-scrim.open {
  opacity: 1;
  visibility: visible;
}

/* El link "Aplicación" no tiene sentido cuando ya corre como PWA instalada. */
html.pwa-standalone .fb-link-app,
body.pwa-standalone .fb-link-app {
  display: none !important;
}

@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui) {
  .fb-link-app { display: none !important; }
}

/* El FAB de leads nuevos vivía a 20px del borde: ahora caería sobre la barra. */
.nav-badge {
  bottom: calc(var(--fb-space) + 12px + env(safe-area-inset-bottom, 0px));
}

/* En pantallas muy angostas las etiquetas estorban más de lo que ayudan. */
@media (max-width: 360px) {
  .fb-label { display: none; }
  .fb-item i { font-size: 1.5rem; }
}

@media print {
  .footbar,
  .fb-sheet,
  .fb-scrim { display: none !important; }
  body { padding-bottom: 0 !important; }
}

@media (prefers-reduced-motion: reduce) {
  .fb-item,
  .fb-sheet,
  .fb-scrim,
  .fb-sheet-link,
  .fb-logout { transition: none; }
  .footbar::before,
  .fb-item::after { animation: none; }
  body { animation: none; }
}

/* ═══════════════ Entrada suave del portal ═══════════════
   Al llegar al portal (tras el login o navegando entre secciones) el contenido
   entra con un fundido en vez de aparecer "a secas". Solo opacidad: un transform
   o filter en `body` rompería el position:fixed de la footbar. */
body {
  animation: portal-entra 0.55s cubic-bezier(.22, .61, .36, 1) both;
}

@keyframes portal-entra {
  from { opacity: 0; }
  to   { opacity: 1; }
}
