<template>
  <div class="main-layout">
    <!-- Loading Overlay for Initial Load -->
    <Transition name="fade">
      <div v-if="isInitialLoading" class="loading-overlay">
        <div class="loading-content">
          <img src="/favicon.ico" alt="mitlist" class="loading-logo animate-pulse" />
        </div>
      </div>
    </Transition>

    <!-- Responsive Navigation: Sidebar on desktop, Bottom bar on mobile -->
    <nav class="app-nav" :class="{ 'nav-loading': isInitialLoading }">
      <div class="nav-content">
        <!-- Logo for Sidebar view -->
        <div class="nav-header">
          <router-link to="/dashboard" class="nav-logo" @click="preloadDashboard">
            <img src="/favicon.ico" alt="mitlist" class="logo-image" />
            <span class="logo-text">mitlist</span>
          </router-link>
        </div>

        <!-- Navigation Links - Prioritized by usage -->
        <div class="nav-links">
          <router-link to="/dashboard" class="nav-item" active-class="active" @mouseenter="preloadDashboard"
            @focus="preloadDashboard" :title="$t('nav.dashboard', 'Dashboard')">
            <span class="material-icons">dashboard</span>
            <span class="nav-text">{{ $t('nav.dashboard', 'Dashboard') }}</span>
          </router-link>
          <router-link to="/lists" class="nav-item" active-class="active" @mouseenter="preloadLists"
            @focus="preloadLists" :title="$t('nav.lists', 'Lists')">
            <span class="material-icons">list</span>
            <span class="nav-text">{{ $t('nav.lists', 'Lists') }}</span>
          </router-link>
          <router-link to="/expenses" class="nav-item" active-class="active" @mouseenter="preloadExpenses"
            @focus="preloadExpenses" :title="$t('nav.expenses', 'Expenses')">
            <span class="material-icons">payments</span>
            <span class="nav-text">{{ $t('nav.expenses', 'Expenses') }}</span>
          </router-link>
          <router-link to="/chores" class="nav-item" active-class="active" @mouseenter="preloadChores"
            @focus="preloadChores" :title="$t('nav.chores', 'Chores')">
            <span class="material-icons">task_alt</span>
            <span class="nav-text">{{ $t('nav.chores', 'Chores') }}</span>
          </router-link>
          <!-- Groups moved to less prominent position -->
          <router-link to="/groups" class="nav-item nav-item-secondary"
            :class="{ active: $route.path.startsWith('/groups') }" @click.prevent="navigateToGroups"
            @mouseenter="preloadGroups" @focus="preloadGroups" :title="$t('nav.groups', 'Groups')">
            <span class="material-icons">group</span>
            <span class="nav-text">{{ $t('nav.groups', 'Groups') }}</span>
          </router-link>
        </div>

        <!-- User Menu for Sidebar view -->
        <div class="nav-footer">
          <div class="user-control" v-if="authStore.isAuthenticated">
            <button ref="userMenuTrigger" class="user-menu-button" :class="{ 'is-active': userMenuOpen }"
              :aria-expanded="userMenuOpen" aria-controls="user-menu-dropdown" aria-label="User menu"
              @click="toggleUserMenu">
              <img v-if="authStore.user?.avatarUrl" :src="authStore.user.avatarUrl" alt="User Avatar"
                class="user-avatar" />
              <div v-else class="user-avatar-placeholder">
                <span class="material-icons">account_circle</span>
              </div>
              <div class="user-info">
                <strong>{{ authStore.user?.name || authStore.user?.email || 'User' }}</strong>
                <small>{{ currentLanguageCode.toUpperCase() }}</small>
              </div>
              <span class="material-icons user-menu-chevron">
                {{ userMenuOpen ? 'expand_less' : 'expand_more' }}
              </span>
            </button>

            <Transition name="dropdown-slide">
              <div v-if="userMenuOpen" id="user-menu-dropdown" ref="userMenuDropdown" class="dropdown-menu" role="menu">
                <!-- Language Quick Switch -->
                <div class="dropdown-section">
                  <div class="dropdown-header">{{ $t('languageSelector.title', 'Language') }}</div>
                  <div class="language-grid">
                    <button v-for="(name, code) in availableLanguages" :key="code" role="menuitem"
                      class="language-option" :class="{ active: currentLanguageCode === code }"
                      @click.prevent="changeLanguage(code)">
                      {{ code.toUpperCase() }}
                    </button>
                  </div>
                </div>

                <div class="dropdown-divider"></div>

                <!-- Account Actions -->
                <button class="dropdown-item" @click.prevent="navigateToAccount">
                  <span class="material-icons">settings</span>
                  {{ $t('nav.account', 'Account') }}
                </button>

                <button class="dropdown-item dropdown-item-danger" @click.prevent="handleLogout">
                  <span class="material-icons">logout</span>
                  {{ $t('nav.logout', 'Logout') }}
                </button>
              </div>
            </Transition>
          </div>
        </div>
      </div>
    </nav>

    <!-- Main Content Area -->
    <div class="content-wrapper">
      <!-- Mobile Header -->
      <header class="app-header">
        <h1 class="page-title">{{ dynamicPageTitle }}</h1>
        <div class="header-actions">
          <!-- User Menu for Mobile -->
          <div class="mobile-user-menu" v-if="authStore.isAuthenticated">
            <button ref="mobileUserMenuTrigger" class="icon-button" @click="toggleUserMenu">
              <img v-if="authStore.user?.avatarUrl" :src="authStore.user.avatarUrl" alt="User Avatar"
                class="user-avatar" />
              <span v-else class="material-icons">account_circle</span>
            </button>
          </div>
        </div>
      </header>

      <!-- Main Content with Better Loading States -->
      <main class="page-container">
        <Transition name="page-fade" mode="out-in">
          <router-view v-slot="{ Component, route }">
            <Suspense>
              <template #default>
                <keep-alive v-if="route.meta.keepAlive">
                  <component :is="Component" />
                </keep-alive>
                <component v-else :is="Component" :key="route.fullPath" />
              </template>
              <template #fallback>
                <div class="page-loading">
                  <div class="skeleton-page">
                    <div class="skeleton-header"></div>
                    <div class="skeleton-content"></div>
                    <div class="skeleton-content"></div>
                    <div class="skeleton-content short"></div>
                  </div>
                </div>
              </template>
            </Suspense>
          </router-view>
        </Transition>
      </main>

      <!-- Universal FAB - Context Aware -->
      <Transition name="fab-scale">
        <div v-if="showFAB && authStore.isAuthenticated" class="universal-fab">
          <button ref="fabTrigger" class="fab-button" :class="{ 'fab-open': fabMenuOpen }" @click="toggleFABMenu"
            :aria-expanded="fabMenuOpen" aria-label="Quick actions">
            <Transition name="icon-rotate" mode="out-in">
              <span v-if="!fabMenuOpen" class="material-icons" key="add">add</span>
              <span v-else class="material-icons" key="close">close</span>
            </Transition>
          </button>

          <Transition name="fab-menu-scale">
            <div v-if="fabMenuOpen" class="fab-menu">
              <!-- Most common action: Add Expense -->
              <button class="fab-menu-item fab-menu-primary" @click="handleQuickExpense"
                :title="$t('fab.addExpense', 'Add Expense')">
                <span class="material-icons">payments</span>
                <span class="fab-menu-label">{{ $t('fab.expense', 'Expense') }}</span>
              </button>

              <!-- Second most common: Add to List -->
              <button class="fab-menu-item" @click="handleQuickListItem" :title="$t('fab.addToList', 'Add to List')">
                <span class="material-icons">add_shopping_cart</span>
                <span class="fab-menu-label">{{ $t('fab.listItem', 'List Item') }}</span>
              </button>

              <!-- Third: Complete Chore -->
              <button v-if="hasOverdueChores" class="fab-menu-item" @click="handleQuickChore"
                :title="$t('fab.completeChore', 'Complete Chore')">
                <span class="material-icons">task_alt</span>
                <span class="fab-menu-label">{{ $t('fab.chore', 'Chore') }}</span>
              </button>
            </div>
          </Transition>
        </div>
      </Transition>

      <OfflineIndicator />
    </div>

    <!-- Simplified Modals -->
    <CreateListModal v-model="showCreateListModal" @created="handleListCreated" />
    <CreateGroupModal v-model="showCreateGroupModal" @created="handleGroupCreated" />
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted, nextTick, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import OfflineIndicator from '@/components/OfflineIndicator.vue'
import { useNotificationStore } from '@/stores/notifications'
import { useGroupStore } from '@/stores/groupStore'
import { useI18n } from 'vue-i18n'
import CreateListModal from '@/components/CreateListModal.vue'
import CreateGroupModal from '@/components/CreateGroupModal.vue'
import { onClickOutside } from '@vueuse/core'
import { preloadManager } from '@/utils/advancedPerformance'

const router = useRouter()
const route = useRoute()
const authStore = useAuthStore()
const notificationStore = useNotificationStore()
const groupStore = useGroupStore()
const { t, locale } = useI18n()

// Loading States
const isInitialLoading = ref(true)

// Dynamic page title with context
const dynamicPageTitle = computed(() => {
  const title = String(route.meta.title || 'Dashboard')
  if (route.params.id && route.name === 'GroupDetail') {
    const group = groupStore.groups.find(g => g.id === Number(route.params.id))
    return group?.name || title
  }
  return t(`nav.${title.toLowerCase()}`, title)
})

// FAB State Management
const fabMenuOpen = ref(false)
const fabTrigger = ref<HTMLElement | null>(null)
const showFAB = computed(() => {
  // Show FAB on main pages, hide on auth/settings pages
  return !route.path.startsWith('/auth') && !route.path.startsWith('/settings')
})

const hasOverdueChores = computed(() => {
  // This would check if user has overdue chores
  // For now, return true as placeholder
  return true
})

const toggleFABMenu = () => {
  fabMenuOpen.value = !fabMenuOpen.value
}

// Auto-close FAB on route change
watch(route, () => {
  fabMenuOpen.value = false
})

onClickOutside(fabTrigger, () => {
  fabMenuOpen.value = false
})

// Simplified User Menu Logic
const userMenuOpen = ref(false)
const userMenuDropdown = ref<HTMLElement | null>(null)
const userMenuTrigger = ref<HTMLElement | null>(null)
const mobileUserMenuTrigger = ref<HTMLElement | null>(null)

const toggleUserMenu = () => {
  userMenuOpen.value = !userMenuOpen.value
}

onClickOutside(
  userMenuDropdown,
  () => {
    userMenuOpen.value = false
  },
  { ignore: [userMenuTrigger, mobileUserMenuTrigger] }
)

// Language Management
const availableLanguages = computed(() => ({
  en: t('languageSelector.languages.en', 'English'),
  de: t('languageSelector.languages.de', 'Deutsch'),
  nl: t('languageSelector.languages.nl', 'Nederlands'),
  fr: t('languageSelector.languages.fr', 'Français'),
  es: t('languageSelector.languages.es', 'Español'),
}))

const currentLanguageCode = computed(() => locale.value)

const changeLanguage = (languageCode: string) => {
  locale.value = languageCode
  localStorage.setItem('language', languageCode)
  userMenuOpen.value = false

  notificationStore.addNotification({
    type: 'success',
    message: t('notifications.languageChanged', 'Language updated'),
    duration: 2000
  })
}

// Modal State
const showCreateListModal = ref(false)
const showCreateGroupModal = ref(false)

// Quick Actions
const handleQuickExpense = () => {
  fabMenuOpen.value = false
  router.push('/expenses?action=create')
}

const handleQuickListItem = () => {
  fabMenuOpen.value = false
  router.push('/lists?action=add')
}

const handleQuickChore = () => {
  fabMenuOpen.value = false
  router.push('/chores?action=complete')
}

const handleListCreated = (newList: any) => {
  notificationStore.addNotification({
    message: t('notifications.listCreated', `List '${newList.name}' created`),
    type: 'success',
  })
  showCreateListModal.value = false
}

const handleGroupCreated = (newGroup: any) => {
  notificationStore.addNotification({
    message: t('notifications.groupCreated', `Group '${newGroup.name}' created`),
    type: 'success',
  })
  showCreateGroupModal.value = false
  groupStore.fetchGroups()
}

const handleLogout = async () => {
  try {
    userMenuOpen.value = false
    authStore.logout()
    notificationStore.addNotification({
      type: 'success',
      message: t('notifications.loggedOut', 'Logged out successfully')
    })
    await router.push('/auth/login')
  } catch (error: unknown) {
    notificationStore.addNotification({
      type: 'error',
      message: error instanceof Error ? error.message : t('notifications.logoutFailed', 'Logout failed'),
    })
  }
}

const navigateToAccount = () => {
  userMenuOpen.value = false
  router.push('/account')
}

const navigateToGroups = () => {
  preloadGroups()
  if (groupStore.isLoading) return

  if (groupStore.groupCount === 1 && groupStore.firstGroupId) {
    router.push(`/groups/${groupStore.firstGroupId}`)
  } else {
    router.push('/groups')
  }
}

// Preload helpers
const preloadDashboard = () => preloadManager.preloadRoute('dashboard')
const preloadLists = () => preloadManager.preloadRoute('lists')
const preloadGroups = () => preloadManager.preloadRoute('groups')
const preloadChores = () => preloadManager.preloadRoute('chores')
const preloadExpenses = () => preloadManager.preloadRoute('expenses')

// Initialization
onMounted(async () => {
  try {
    if (authStore.isAuthenticated) {
      // Parallel loading for better UX
      const promises = []

      if (!authStore.user) {
        promises.push(authStore.fetchCurrentUser())
      }

      promises.push(groupStore.fetchGroups())

      await Promise.allSettled(promises)
    }

    // Set language from storage
    const savedLanguage = localStorage.getItem('language')
    if (savedLanguage && Object.keys(availableLanguages.value).includes(savedLanguage)) {
      locale.value = savedLanguage
    }
  } catch (error) {
    console.error('Failed to initialize app data:', error)
  } finally {
    // Delay to ensure smooth loading experience
    await nextTick()
    setTimeout(() => {
      isInitialLoading.value = false
    }, 300)
  }
})
</script>

<style lang="scss" scoped>
@import url('https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Outlined');

:root {
  --sidebar-width: 240px;
  --header-height-mobile: 60px;
  --nav-height-mobile: 64px;
  --fab-size: 56px;
  --fab-menu-item-size: 48px;
}

.main-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--background-color, #f8f9fa);
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.loading-logo {
  width: 48px;
  height: 48px;
}

.loading-dots {
  display: flex;
  gap: 0.5rem;

  span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary, #3B82F6);
    animation: loading-bounce 1.4s ease-in-out infinite both;

    &:nth-child(1) {
      animation-delay: -0.32s;
    }

    &:nth-child(2) {
      animation-delay: -0.16s;
    }

    &:nth-child(3) {
      animation-delay: 0s;
    }
  }
}

@keyframes loading-bounce {

  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1);
  }
}

.content-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease;
}

/* --- App Navigation --- */
.app-nav {
  background-color: #ffffff;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  transition: opacity 0.3s ease;

  &.nav-loading {
    opacity: 0.7;
  }
}

.nav-content {
  display: flex;
  height: 100%;
}

.nav-header {
  padding: 1rem 1.5rem;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary, #3B82F6);
  text-decoration: none;
  transition: transform 0.2s ease;

  &:hover {
    transform: scale(1.02);
  }
}

.logo-image {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.logo-text {
  font-weight: 700;
}

.nav-links {
  display: flex;
  align-items: center;
  flex-grow: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #6c757d;
  transition: all 0.2s ease;
  position: relative;

  &.active {
    color: var(--primary, #3B82F6);
    background-color: rgba(59, 130, 246, 0.05);
  }

  &.nav-item-secondary {
    opacity: 0.8;
  }

  .material-icons {
    font-size: 24px;
  }
}

.nav-text {
  font-weight: 500;
  font-size: 0.9rem;
}

/* --- Mobile styles (Bottom Bar) --- */
@media (max-width: 767px) {
  .app-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height-mobile);
    z-index: 1000;
    border-top: 1px solid #e9ecef;
  }

  .nav-header,
  .nav-footer {
    display: none;
  }

  .nav-links {
    justify-content: space-around;
    padding: 0;
  }

  .nav-item {
    flex-direction: column;
    flex-grow: 1;
    padding: 0.5rem 0;
    gap: 4px;
    border-radius: 0;

    &:hover {
      background-color: #f1f3f5;
    }
  }

  .nav-text {
    font-size: 0.7rem;
  }

  .page-container {
    padding-bottom: calc(var(--nav-height-mobile) + 1rem);
  }

  .app-header {
    display: flex;
  }

  .content-wrapper {
    padding-top: var(--header-height-mobile);
  }
}

/* --- Tablet/Desktop styles (Sidebar) --- */
@media (min-width: 768px) {
  .main-layout {
    flex-direction: row;
  }

  .app-nav {
    width: var(--sidebar-width);
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    flex-direction: column;
    border-right: 1px solid #e9ecef;
    box-shadow: none;
  }

  .nav-content {
    flex-direction: column;
    padding: 1rem 0;
  }

  .nav-links {
    flex-direction: column;
    align-items: stretch;
    padding: 0 1rem;
    gap: 0.5rem;
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;

    &:hover {
      background-color: #f1f3f5;
    }
  }

  .app-header {
    display: none;
  }
}

/* --- Header --- */
.app-header {
  height: var(--header-height-mobile);
  background-color: #ffffff;
  border-bottom: 1px solid #e9ecef;
  padding: 0 1rem;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900;
}

.page-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: #212529;
  margin: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-button {
  background: none;
  border: none;
  color: #495057;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  display: flex;
  transition: all 0.2s ease;

  &:hover {
    background-color: #f1f3f5;
    transform: scale(1.05);
  }

  .material-icons {
    font-size: 24px;
  }
}

.mobile-user-menu .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

/* --- User Menu --- */
.user-control {
  position: relative;
}

.user-menu-button {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem;
  border-radius: 0.5rem;
  background-color: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;

  &:hover,
  &.is-active {
    background-color: #f1f3f5;
  }
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #e9ecef;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;

  .material-icons {
    color: #6c757d;
    font-size: 24px;
  }
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-grow: 1;

  strong {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  small {
    font-size: 0.8rem;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.user-menu-chevron {
  color: #6c757d;
  font-size: 20px;
  transition: transform 0.2s ease;
}

/* Dropdown */
.dropdown-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background-color: white;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1010;
  overflow: hidden;
}

.dropdown-section {
  padding: 0.5rem 0;
}

.dropdown-header {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  color: #212529;
  text-decoration: none;
  font-size: 0.9rem;
  background: none;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s ease;
  text-align: left;

  &:hover {
    background-color: #f8f9fa;
  }

  &.dropdown-item-danger {
    color: #dc3545;

    &:hover {
      background-color: rgba(220, 53, 69, 0.1);
    }
  }

  .material-icons {
    font-size: 20px;
  }
}

.dropdown-divider {
  height: 1px;
  background-color: #e9ecef;
  margin: 0.5rem 0;
}

.language-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
  gap: 0.25rem;
  padding: 0 1rem;
}

.language-option {
  padding: 0.5rem;
  text-align: center;
  border: 1px solid #e9ecef;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.2s ease;

  &:hover {
    background-color: #f8f9fa;
    border-color: #dee2e6;
  }

  &.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary, #3B82F6);
    border-color: var(--primary, #3B82F6);
    font-weight: 600;
  }
}

/* --- FAB (Floating Action Button) --- */
.universal-fab {
  position: fixed;
  bottom: calc(var(--nav-height-mobile) + 1rem);
  right: 1rem;
  z-index: 1000;
}

@media (min-width: 768px) {
  .universal-fab {
    bottom: 1.5rem;
    right: 1.5rem;
  }
}

.fab-button {
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: var(--primary, #3B82F6);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  &:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.5);
  }

  &.fab-open {
    background: #6c757d;
    transform: rotate(45deg);
  }

  .material-icons {
    font-size: 24px;
  }
}

.fab-menu {
  position: absolute;
  bottom: 3rem;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-end;
}

.fab-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: white;
  border: none;
  border-radius: 28px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  &.fab-menu-primary {
    background: var(--primary, #3B82F6);
    color: white;

    &:hover {
      background: #2563eb;
    }
  }

  .material-icons {
    font-size: 20px;
  }
}

.fab-menu-label {
  font-size: 0.9rem;
  font-weight: 500;
}

/* --- Page Loading States --- */
.page-loading {
  padding: 1.5rem;
}

.skeleton-page {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.skeleton-header,
.skeleton-content {
  height: 1.5rem;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;

  &.short {
    width: 60%;
  }
}

.skeleton-header {
  height: 2rem;
  width: 40%;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* --- Page Container --- */
.page-container {
  flex-grow: 1;
  padding: 1.5rem;
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 767px) {
  .page-container {
    padding: 1rem;
  }
}

/* --- Transitions --- */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.dropdown-slide-enter-active,
.dropdown-slide-leave-active {
  transition: all 0.2s ease;
  transform-origin: top;
}

.dropdown-slide-enter-from,
.dropdown-slide-leave-to {
  opacity: 0;
  transform: scaleY(0.8) translateY(-10px);
}

.fab-scale-enter-active,
.fab-scale-leave-active {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fab-scale-enter-from,
.fab-scale-leave-to {
  opacity: 0;
  transform: scale(0.8);
}

.fab-menu-scale-enter-active,
.fab-menu-scale-leave-active {
  transition: all 0.2s ease;
}

.fab-menu-scale-enter-from,
.fab-menu-scale-leave-to {
  opacity: 0;
  transform: translateY(10px);
}

.icon-rotate-enter-active,
.icon-rotate-leave-active {
  transition: all 0.2s ease;
}

.icon-rotate-enter-from,
.icon-rotate-leave-to {
  opacity: 0;
  transform: rotate(90deg);
}

.page-fade-enter-active,
.page-fade-leave-active {
  transition: all 0.3s ease;
}

.page-fade-enter-from,
.page-fade-leave-to {
  opacity: 0;
  transform: translateY(10px);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .main-layout {
    background-color: #1a1a1a;
  }

  .app-nav,
  .app-header,
  .dropdown-menu {
    background-color: #2d2d2d;
    border-color: #404040;
  }

  .nav-item,
  .dropdown-item,
  .user-menu-button {
    color: #e0e0e0;

    &:hover {
      background-color: #404040;
    }
  }

  .skeleton-header,
  .skeleton-content {
    background: linear-gradient(90deg, #2d2d2d 25%, #404040 50%, #2d2d2d 75%);
    background-size: 200% 100%;
  }
}
</style>