<template>
  <UApp>
    <NuxtRouteAnnouncer />
    <UNotifications />

    <!-- Fondo animado -->
    <AnimatedBackground />

    <!-- Contenido principal -->
    <div class="main-content">
      <UContainer class="py-8">
        <div v-if="isAuthenticated" class="space-y-6">
          <!-- Header principal con info del usuario -->
          <UserHeader />

          <!-- Lista de aplicaciones -->
          <AuthApplicationsList />

          <!-- Acciones rápidas en footer transparente -->
          <div class="quick-actions">
            <AuthSessionStatusButton />
            <AuthProfileButton />
            <AuthLogoutButton />
          </div>
        </div>

        <!-- Mensaje si no está autenticado -->
        <div v-else class="auth-message">
          <UCard class="text-center">
            <div class="py-12">
              <UIcon name="i-heroicons-shield-exclamation" class="w-20 h-20 mx-auto mb-6 text-gray-400" />
              <h2 class="text-3xl font-bold mb-3">No autenticado</h2>
              <p class="text-gray-600 dark:text-gray-400 text-lg">
                Authentik Proxy Outpost debería redirigirte automáticamente.
              </p>
            </div>
          </UCard>
        </div>
      </UContainer>
    </div>
  </UApp>
</template>

<script setup lang="ts">
const { isAuthenticated } = useAuthentik()
const { isNight } = useTheme()

// Configurar meta tags para PWA
useHead({
  link: [
    { rel: 'manifest', href: '/manifest.webmanifest' },
    { rel: 'icon', type: 'image/svg+xml', href: '/icon.svg' },
    { rel: 'apple-touch-icon', href: '/apple-touch-icon.png' }
  ],
  meta: [
    { name: 'theme-color', content: '#00DC82' },
    { name: 'mobile-web-app-capable', content: 'yes' },
    { name: 'apple-mobile-web-app-capable', content: 'yes' },
    { name: 'apple-mobile-web-app-status-bar-style', content: 'default' }
  ]
})
</script>

<style scoped>
.main-content {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding-top: 2rem;
}

.quick-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(20px) saturate(180%);
  border-radius: 1.5rem;
  box-shadow:
    0 8px 32px 0 rgba(31, 38, 135, 0.15),
    inset 0 1px 1px 0 rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

:global(.dark) .quick-actions {
  background: rgba(0, 0, 0, 0.15);
  box-shadow:
    0 8px 32px 0 rgba(0, 0, 0, 0.5),
    inset 0 1px 1px 0 rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.auth-message {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.auth-message :deep(.card) {
  background: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    0 8px 32px 0 rgba(31, 38, 135, 0.15),
    inset 0 1px 1px 0 rgba(255, 255, 255, 0.3);
}

:global(.dark) .auth-message :deep(.card) {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 8px 32px 0 rgba(0, 0, 0, 0.5),
    inset 0 1px 1px 0 rgba(255, 255, 255, 0.05);
}

/* Responsive */
@media (max-width: 768px) {
  .main-content {
    padding-top: 1rem;
  }

  .quick-actions {
    flex-direction: column;
    align-items: stretch;
  }
}
</style>
