/* ==========================================================================
   FAB Rail — fixed right-middle contact tabs, icon + label on hover
   ========================================================================== */

.fab-rail-stack {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0.65rem;
  width: auto;
  height: 100vh;
  height: 100dvh;
  pointer-events: none;
}

.fab-rail {
  --fab-rail-collapsed: 52px;
  --fab-rail-expanded: 156px;

  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  gap: 0;
  width: var(--fab-rail-collapsed);
  height: 52px;
  padding: 0;
  overflow: hidden;
  border: none;
  border-right: none;
  border-radius: 16px 0 0 16px;
  box-shadow: -4px 4px 24px rgba(0, 0, 0, 0.22);
  color: #fff !important;
  text-decoration: none !important;
  cursor: pointer;
  transition:
    width 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    padding 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    gap 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  animation: fabRailSlideIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.fab-rail--whatsapp {
  --fab-rail-expanded: 158px;
  background: linear-gradient(135deg, #25d366 0%, #1da851 100%);
  animation-delay: 0.15s;
}

.fab-rail--call {
  --fab-rail-expanded: 132px;
  background: linear-gradient(135deg, #0f4c81 0%, #1565c0 100%);
  animation-delay: 0.28s;
}

.fab-rail--whatsapp::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 16px 0 0 16px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  pointer-events: none;
}

.fab-rail--whatsapp::after {
  content: '';
  position: absolute;
  inset: -2px -2px -2px 4px;
  border-radius: 16px 0 0 16px;
  border: 2px solid rgba(37, 211, 102, 0.45);
  animation: fabRailPing 2.2s ease-out infinite;
  pointer-events: none;
}

.fab-rail:hover,
.fab-rail:focus-visible,
.fab-rail:active,
.fab-rail:visited {
  color: #fff !important;
  text-decoration: none !important;
}

.fab-rail--whatsapp:hover,
.fab-rail--whatsapp:focus-visible {
  background: linear-gradient(135deg, #25d366 0%, #1da851 100%);
}

.fab-rail--call:hover,
.fab-rail--call:focus-visible {
  background: linear-gradient(135deg, #0f4c81 0%, #1565c0 100%);
}

@keyframes fabRailPing {
  0% { opacity: 0.7; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(1.08); }
}

@keyframes fabRailSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.fab-rail__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
}

.fab-rail__icon svg {
  width: 24px;
  height: 24px;
  color: #fff;
}

.fab-rail__label {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  max-width: 0;
  opacity: 0;
  pointer-events: none;
  transition:
    max-width 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    opacity 0.35s ease 0.08s;
}

.fab-rail:hover,
.fab-rail:focus-visible {
  width: var(--fab-rail-expanded);
  justify-content: flex-end;
  padding: 0 14px 0 16px;
  gap: 0.625rem;
  outline: none;
}

.fab-rail:hover .fab-rail__label,
.fab-rail:focus-visible .fab-rail__label {
  position: static;
  width: auto;
  height: auto;
  max-width: 100px;
  opacity: 1;
  pointer-events: auto;
}

/* Back-to-top stays bottom-right */
.fab.fab-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99998;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.25s ease;
}

.fab.fab-top.visible {
  opacity: 1;
  visibility: visible;
}

.fab.fab-top:hover {
  transform: scale(1.08);
}

.fab.fab-top svg {
  width: 22px;
  height: 22px;
}

@media (max-width: 768px) {
  .fab-rail-stack {
    display: none !important;
  }

  .fab.fab-top {
    bottom: calc(16px + 4.75rem + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fab-rail,
  .fab-rail__label {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .fab-rail:hover,
  .fab-rail:focus-visible {
    width: var(--fab-rail-expanded);
  }

  .fab-rail:hover .fab-rail__label,
  .fab-rail:focus-visible .fab-rail__label {
    max-width: 100px;
    opacity: 1;
  }
}
