<template>
  <a-config-provider :locale="antdLocale">
    <div id="app" :data-route="route.name" :class="{ 'is-admin': isAdminRoute }">
      <!-- 全局科技感背景 -->
      <div class="app-background">
        <div class="bg-gradient"></div>
        <div class="bg-grid"></div>
        <div class="bg-glow bg-glow--1"></div>
        <div class="bg-glow bg-glow--2"></div>
      </div>

      <!-- 主要内容区域 -->
      <main class="app-main">
        <router-view v-slot="{ Component }">
          <transition name="page-fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </main>
    </div>
  </a-config-provider>
</template>

<script setup>
import { computed, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import enUS from 'ant-design-vue/es/locale/en_US'

const route = useRoute()
const { locale } = useI18n()

// 动态计算 Ant Design Vue 的语言配置
const antdLocale = computed(() => {
  return locale.value === 'zh' ? zhCN : enUS
})

// 判断当前是否为后台管理路由
const isAdminRoute = computed(() => !!route.meta?.requiresAdmin)

// 后台管理页面时给 body 加 admin-mode 类，让 Teleport 到 body 的弹窗也能应用暗色主题
watch(isAdminRoute, (isAdmin) => {
  if (isAdmin) {
    document.body.classList.add('admin-mode')
    document.documentElement.classList.add('admin-mode')
  } else {
    document.body.classList.remove('admin-mode')
    document.documentElement.classList.remove('admin-mode')
  }
}, { immediate: true })
</script>

<style>
/* ============================================================
   Global Reset & Base Styles
   Uses UI-UX-Pro-Max Design System Variables
   ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-root);
}

/* Admin 模式下 html 也要暗色 */
html.admin-mode {
  background: #07090F !important;
}

body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-root);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   App Container
   ============================================================ */

#app {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: transparent;
}

/* ============================================================
   Background Layer - 统一科技感背景
   ============================================================ */

.app-background {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-gradient {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(0, 212, 255, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(139, 92, 246, 0.04) 0%, transparent 60%),
    var(--bg-root);
}

.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 70% 50% at 50% 50%, black 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 70% 50% at 50% 50%, black 30%, transparent 80%);
}

.bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  animation: breathe 8s ease-in-out infinite;
}

.bg-glow--1 {
  width: 600px;
  height: 400px;
  top: -10%;
  right: -5%;
  background: rgba(8, 145, 178, 0.06);
}

.bg-glow--2 {
  width: 500px;
  height: 350px;
  bottom: -10%;
  left: -5%;
  background: rgba(139, 92, 246, 0.05);
  animation-delay: -4s;
}

/* 欢迎页和登录页使用自己的背景，隐藏全局背景 */
#app[data-route="Welcome"] .app-background,
#app[data-route="Login"] .app-background {
  display: none;
}

/* ============================================================
   Admin 后台页面 — 隐藏亮色背景层，使用暗色主题
   ============================================================ */
#app.is-admin .app-background {
  display: none !important;
}

#app.is-admin {
  background: #07090F !important;
}

/* ============================================================
   Main Content
   ============================================================ */

.app-main {
  flex: 1;
  position: relative;
  z-index: var(--z-base);
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
}

/* ============================================================
   Page Transition
   ============================================================ */

.page-fade-enter-active,
.page-fade-leave-active {
  transition: opacity 0.2s var(--ease-default);
}

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

/* ============================================================
   Ant Design Vue Overrides - Global Dark Theme
   ============================================================ */

/* Buttons */
.ant-btn {
  font-family: var(--font-sans);
  border-radius: var(--radius-md);
  transition: var(--transition-all);
}

.ant-btn-primary {
  background: var(--primary-500);
  border-color: var(--primary-500);
  box-shadow: none;
}

.ant-btn-primary:hover {
  background: var(--primary-400);
  border-color: var(--primary-400);
  box-shadow: var(--glow-primary);
}

/* Inputs */
.ant-input,
.ant-input-affix-wrapper {
  font-family: var(--font-sans);
  background: var(--bg-surface) !important;
  border: 1px solid var(--border-default) !important;
  border-radius: var(--radius-md) !important;
  color: var(--text-primary) !important;
  transition: var(--transition-all);
}

.ant-input:hover,
.ant-input-affix-wrapper:hover {
  border-color: var(--border-strong) !important;
}

.ant-input:focus,
.ant-input-affix-wrapper-focused {
  border-color: var(--primary-500) !important;
  box-shadow: 0 0 0 2px var(--primary-glow-light) !important;
}

.ant-input::placeholder {
  color: var(--text-tertiary) !important;
}

/* Select */
.ant-select-selector {
  background: var(--bg-surface) !important;
  border-color: var(--border-default) !important;
  color: var(--text-primary) !important;
}

/* Modal */
.ant-modal-content {
  background: var(--bg-overlay) !important;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl) !important;
}

.ant-modal-header {
  background: transparent !important;
  border-bottom: 1px solid var(--border-subtle) !important;
}

.ant-modal-title {
  color: var(--text-primary) !important;
}

.ant-modal-body {
  color: var(--text-primary);
}

.ant-modal-close {
  color: var(--text-secondary) !important;
}

.ant-modal-close:hover {
  color: var(--text-primary) !important;
}

/* Message / Notification */
.ant-message-notice-content {
  background: var(--bg-overlay) !important;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg) !important;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
}

/* Dropdown */
.ant-dropdown-menu {
  background: var(--bg-overlay) !important;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg);
}

.ant-dropdown-menu-item {
  color: var(--text-primary) !important;
}

.ant-dropdown-menu-item:hover {
  background: var(--bg-hover) !important;
}

/* Switch */
.ant-switch {
  background: var(--bg-elevated);
}

.ant-switch-checked {
  background: var(--primary-500) !important;
}

/* Tag */
.ant-tag {
  border-radius: var(--radius-sm);
}

/* ============================================================
   Payment Modal Specific Override
   ============================================================ */

.payment-modal-dialog .ant-modal-content {
  background: var(--bg-base) !important;
  border: 1px solid var(--border-default) !important;
  box-shadow: var(--shadow-xl) !important;
}

.payment-modal-dialog .ant-modal-header {
  background: transparent !important;
  border-bottom: 1px solid var(--border-subtle) !important;
}

.payment-modal-dialog .ant-modal-body {
  background: transparent !important;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
  body {
    font-size: var(--text-sm);
  }
  
  .bg-glow--1,
  .bg-glow--2 {
    display: none; /* 移动端减少特效 */
  }
}
</style>
