/**
 * =========================================
 * FAB - Floating Action Button
 * =========================================
 *
 * Mobile-only floating buttons for chat and leaderboard access
 * Hidden on desktop (use sidebars instead)
 *
 * Position: Bottom-right corner (thumb-friendly zone)
 * Size: 56x56px (Material Design standard)
 */

/* ============================================
 * FAB CONTAINER
 * ============================================ */

.fab-container {
  position: fixed;
  bottom: var(--spacing-lg);
  right: var(--spacing-lg);
  z-index: var(--z-fab, 1000);
  display: flex;
  flex-direction: column-reverse; /* Stack from bottom to top */
  gap: var(--spacing-sm);
  pointer-events: none; /* Allow clicks through container */
}

.fab-container > * {
  pointer-events: all; /* But enable clicks on buttons */
}

/* Hide on tablet and above (use sidebars instead) */
/* Exception: Chat FAB stays visible on desktop */
@media (min-width: 768px) {
  .fab-container {
    display: flex !important;
  }

  /* Hide other FABs on desktop (they have sidebars) */
  .fab-container .fab:not(.fab--chat) {
    display: none !important;
  }

  /* Chat FAB stays visible on desktop */
  .fab--chat {
    display: flex !important;
    width: 56px;
    height: 56px;
  }
}

/* Responsive adjustments for narrow screens */
@media (max-width: 360px) {
  .fab-container {
    bottom: var(--spacing-md, 12px);
    right: var(--spacing-md, 12px);
    gap: var(--spacing-xs, 8px);
  }
}

@media (max-width: 280px) {
  .fab-container {
    bottom: var(--spacing-sm, 8px);
    right: var(--spacing-sm, 8px);
    gap: 6px;
  }
}

/* ============================================
 * FAB BUTTON
 * ============================================ */

.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gradient-gold);
  color: var(--color-text-inverse);
  border: none;
  box-shadow: var(--shadow-fab, 0 4px 12px rgba(0, 0, 0, 0.3));
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 24px;
  transition: all var(--transition-button);
  position: relative;
  overflow: visible;
}

.fab::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.fab:hover::before {
  opacity: 1;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.fab:active {
  transform: scale(0.95);
}

/* FAB with icon */
.fab__icon {
  font-size: 24px;
  line-height: 1;
}

/* FAB with badge (notification count) */
.fab--with-badge {
  position: relative;
}

.fab__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #1a1a1a;
  font-size: var(--font-size-xs, 12px);
  font-weight: var(--font-weight-bold, 700);
  min-width: 20px;
  height: 20px;
  border-radius: var(--radius-full, 9999px);
  display: flex;
  z-index: 10;
  overflow: visible;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid var(--color-bg-primary);
  box-shadow: var(--shadow-sm);
  animation: badgePop 0.3s var(--ease-bounce);
}

/* ============================================
 * FAB VARIANTS
 * ============================================ */

/* Chat FAB */
.fab--chat {
  background: linear-gradient(135deg, var(--color-accent-purple), var(--color-accent-purple-dark, #5b48c7));
}

/* Leaderboard FAB */
.fab--leaderboard {
  background: var(--gradient-gold);
}

/* Old Questions FAB */
.fab--old-questions {
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
}

/* Secondary FAB */
.fab--secondary {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border: 2px solid var(--color-border);
}

/* Success FAB */
.fab--success {
  background: linear-gradient(135deg, var(--color-accent-green), var(--color-success-dark, #27ae60));
}

/* ============================================
 * FAB MENU (Expandable)
 * ============================================ */

.fab-menu {
  position: relative;
}

.fab-menu__list {
  position: absolute;
  bottom: 70px; /* Above main FAB */
  right: 0;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all var(--transition-base);
}

.fab-menu.is-open .fab-menu__list {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

.fab-menu__item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  animation: fabSlideIn 0.3s var(--ease-default) both;
}

.fab-menu__item:nth-child(1) { animation-delay: 0.05s; }
.fab-menu__item:nth-child(2) { animation-delay: 0.1s; }
.fab-menu__item:nth-child(3) { animation-delay: 0.15s; }

.fab-menu__label {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-button);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}

.fab-menu.is-open .fab-menu__label {
  opacity: 1;
}

/* Mini FAB (in menu) */
.fab--mini {
  width: 48px;
  height: 48px;
  font-size: 20px;
}

/* Responsive FAB sizes for narrow screens */
@media (max-width: 360px) {
  .fab {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }

  .fab__icon {
    font-size: 20px;
  }

  .fab__badge {
    min-width: 18px;
    height: 18px;
    font-size: 0.65rem;
    padding: 0 4px;
    top: -3px;
    right: -3px;
  }
}

@media (max-width: 280px) {
  .fab {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  .fab__icon {
    font-size: 18px;
  }

  .fab__badge {
    min-width: 16px;
    height: 16px;
    font-size: 0.6rem;
    padding: 0 3px;
    top: -2px;
    right: -2px;
  }
}

/* ============================================
 * FAB STATES
 * ============================================ */

.fab:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.fab.is-active {
  background: var(--color-accent-green);
  box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.2);
}

/* Pulsing animation for attention */
.fab--pulse {
  animation: fabPulse 2s infinite;
}

/* ============================================
 * ANIMATIONS
 * ============================================ */

@keyframes badgePop {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes fabSlideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fabPulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 0 rgba(252, 211, 77, 0.7);
  }
  50% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 10px rgba(252, 211, 77, 0);
  }
}

/* ============================================
 * ACCESSIBILITY
 * ============================================ */

.fab:focus-visible {
  outline: 3px solid var(--color-accent-gold);
  outline-offset: 4px;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .fab,
  .fab-menu__list,
  .fab-menu__item {
    animation: none;
    transition: none;
  }

  .fab:hover {
    transform: none;
  }

  .fab__badge {
    animation: none;
  }
}

/* ============================================
 * TOOLTIP (Optional)
 * ============================================ */

.fab[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 70px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-button);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.fab:hover[data-tooltip]::after {
  opacity: 1;
}

/* Responsive tooltip adjustments */
@media (max-width: 360px) {
  .fab[data-tooltip]::after {
    right: 54px; /* Adjusted for 48px FAB */
    font-size: 0.75rem;
    padding: 4px 8px;
  }
}

@media (max-width: 280px) {
  .fab[data-tooltip]::after {
    right: 50px; /* Adjusted for 44px FAB */
    font-size: 0.7rem;
    padding: 3px 6px;
  }
}
