/**
 * 逐光圈 - 全局视觉升级 CSS
 * 包含：呼吸感增强、PC交互感、移动端触控优化、深色模式
 * 对标设计语言：Apple Human Interface + Material Design 3
 * 兼容性：Chrome 90+ / Safari 14+ / Firefox 88+ / Edge 90+
 */

/* ========================================
   1. CSS 变量系统（浅色/深色自动切换）
   ======================================== */
:root {
    /* 品牌色 */
    --brand-primary: #0d6efd;
    --brand-primary-hover: #0b5ed7;
    --brand-secondary: #0dcaf0;
    --brand-accent: #0284c7;
    --brand-accent-hover: #0369a1;

    /* 浅色模式变量 */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f2f5;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: rgba(203, 213, 225, 0.6);
    --glass-bg: rgba(255, 255, 255, 0.92);
    --glass-border: rgba(203, 213, 225, 0.6);

    /* 阴影系统 */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.16);
    --shadow-glow: 0 0 24px rgba(2, 132, 199, 0.12);

    /* 圆角系统 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* 动画时长 */
    --transition-fast: 0.15s;
    --transition-normal: 0.3s;
    --transition-slow: 0.4s;
    --ease-out-expo: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* 布局 */
    --max-content-width: clamp(1200px, 90vw, 1600px);
    --nav-height: 60px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}
/* 新版升级引导弹窗专属样式 */
.upgrade-modal .modal-content {
    border: none;
    border-radius: 20px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    overflow: hidden;
}

.upgrade-modal .upgrade-icon-wrapper {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, #e0f2fe 0%, #dbeafe 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand-primary);
    font-size: 1.75rem;
    animation: pulse-soft 2s infinite ease-in-out;
}

@keyframes pulse-soft {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(13, 110, 253, 0.2); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 12px rgba(13, 110, 253, 0); }
}

.upgrade-modal .btn-upgrade-primary {
    background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%);
    border: none;
    padding: 10px 32px;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
}

.upgrade-modal .btn-upgrade-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.35);
}

.upgrade-modal .form-check-input:checked {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
}

/* 深色模式 - 自动跟随系统 */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border-color: rgba(100, 116, 139, 0.4);
        --glass-bg: rgba(30, 41, 59, 0.92);
        --glass-border: rgba(100, 116, 139, 0.4);
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
        --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.6);
        --brand-accent: #22d3ee;
        --brand-accent-hover: #06b6d4;
    }
}

/* ========================================
   2. 呼吸感增强 - Body 背景光晕
   ======================================== */
body {
    background-color: var(--bg-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* 主光晕 - 跟随鼠标（仅 PC 端） */
@media (min-width: 992px) {
    body::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: radial-gradient(
            600px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
            rgba(2, 132, 199, 0.06),
            transparent 40%
        );
        pointer-events: none;
        z-index: 0;
        transition: opacity var(--transition-slow) var(--ease-out-expo);
    }

    /* 副光晕 - 固定右下角 */
    body::after {
        content: '';
        position: fixed;
        bottom: -200px;
        right: -200px;
        width: 600px;
        height: 600px;
        background: radial-gradient(
            circle,
            rgba(147, 197, 253, 0.08),
            transparent 60%
        );
        pointer-events: none;
        z-index: 0;
    }
}

/* 呼吸动画 - 装饰性光效元素 */
@keyframes breathe {
    0%, 100% { opacity: 0.9; }
    50% { opacity: 1; }
}

.breathe-effect {
    animation: breathe 4s ease-in-out infinite;
}

/* ========================================
   3. 卡片系统 - 呼吸感 + 交互感
   ======================================== */
.card {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--transition-slow) var(--ease-out-expo),
        box-shadow var(--transition-slow) var(--ease-out-expo);
    overflow: hidden;
    background: var(--bg-secondary);
    position: relative;
    z-index: 1;
}

/* PC 端卡片 hover 提升 */
@media (min-width: 992px) {
    .card:hover {
        transform: translateY(-4px);
        box-shadow: var(--shadow-lg);
    }

    /* Vanilla Tilt 效果基础 */
    .tilt-card {
        transform-style: preserve-3d;
        will-change: transform;
    }

    .tilt-card::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.08) 0%,
            transparent 50%
        );
        pointer-events: none;
        opacity: 0;
        transition: opacity var(--transition-normal);
    }

    .tilt-card:hover::after {
        opacity: 1;
    }
}

/* 毛玻璃卡片增强 */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* ========================================
   4. 按钮系统 - 交互反馈
   ======================================== */
.btn {
    transition:
        transform var(--transition-fast) var(--ease-out-expo),
        background-color var(--transition-fast) ease,
        box-shadow var(--transition-fast) ease;
    border-radius: var(--radius-full);
    font-weight: 500;
}

/* PC 端按钮 active 态 */
@media (min-width: 992px) {
    .btn:active {
        transform: scale(0.97);
    }

    .btn-primary:hover {
        background-color: var(--brand-primary-hover);
        box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
    }
}

/* 移动端按钮 :active 态 */
@media (max-width: 991px) {
    .btn:active {
        transform: scale(0.97);
        background-color: var(--brand-primary-hover);
    }
}

/* 按钮 shimmer 扫光加载态 */
.btn.loading-shimmer {
    position: relative;
    overflow: hidden;
    pointer-events: none;
}

.btn.loading-shimmer::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    animation: shimmer 2.5s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* ========================================
   5. 进度条 shimmer 扫光
   ======================================== */
.progress-shimmer {
    position: relative;
    overflow: hidden;
}

.progress-shimmer::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: shimmer 2.5s infinite;
}

/* ========================================
   6. 返回按钮统一样式
   ======================================== */
.nav-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    transition:
        color var(--transition-fast) ease,
        transform var(--transition-fast) var(--ease-out-expo),
        background-color var(--transition-fast) ease;
}

.nav-back-btn:hover {
    color: var(--brand-primary);
    background-color: rgba(13, 110, 253, 0.05);
    transform: translateX(-4px);
}

.nav-back-btn:active {
    transform: scale(0.97);
}

/* 移动端返回按钮触控热区 */
@media (max-width: 991px) {
    .nav-back-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 12px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-back-btn::before {
        content: '';
        position: absolute;
        top: -8px;
        left: -8px;
        right: -8px;
        bottom: -8px;
    }
}

/* ========================================
   7. 屏幕适配保障
   ======================================== */
.container,
.container-fluid {
    max-width: var(--max-content-width);
    margin-left: auto;
    margin-right: auto;
}

/* Bento Grid 响应式断点 */
.bento-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .bento-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 992px) {
    .bento-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1400px) {
    .bento-grid { grid-template-columns: repeat(4, 1fr); }
}

/* 字体响应式 */
h1, .h1 { font-size: clamp(2rem, 3vw, 3.5rem); }
h2, .h2 { font-size: clamp(1.5rem, 2.5vw, 2.5rem); }
h3, .h3 { font-size: clamp(1.25rem, 2vw, 2rem); }
p, .body-text { font-size: clamp(0.875rem, 1.2vw, 1rem); }

/* 核心数字大字 */
.stat-number {
    font-size: clamp(2rem, 3vw, 3.5rem);
    font-weight: 800;
    line-height: 1.2;
}

/* ========================================
   8. 移动端触控友好化
   ======================================== */
@media (max-width: 991px) {
    /* 所有可点击元素最小热区 48x48dp */
    a, button, [role="button"], input[type="submit"], input[type="button"] {
        min-width: 48px;
        min-height: 48px;
    }

    /* padding 不足时用透明 border 补齐 */
    .btn-sm, .btn-xs {
        min-width: 48px;
        min-height: 48px;
    }

    /* 移除 hover 依赖，改用 :active / :focus-visible */
    .hover-lift:hover {
        transform: none;
        box-shadow: none;
    }

    .hover-lift:active {
        transform: scale(0.98);
        box-shadow: var(--shadow-md);
    }

    /* 列表项触控优化 */
    .list-group-item {
        padding: 12px 16px;
        min-height: 48px;
        display: flex;
        align-items: center;
    }

    /* 表格行触控优化 */
    table tbody tr {
        min-height: 48px;
    }

    table tbody tr td {
        padding: 12px 8px;
    }
}

/* ========================================
   9. 移动端底部 Tab Bar (MD3 风格)
   ======================================== */
@media (max-width: 991px) {
    .mobile-tab-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(56px + var(--safe-area-bottom));
        padding-bottom: var(--safe-area-bottom);
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: 1050;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
    }

    .mobile-tab-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 8px 12px;
        min-width: 48px;
        min-height: 48px;
        color: var(--text-muted);
        text-decoration: none;
        transition: color var(--transition-fast) ease;
        position: relative;
    }

    .mobile-tab-item.active {
        color: var(--brand-primary);
    }

    .mobile-tab-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 48px;
        height: 3px;
        background: var(--brand-primary);
        border-radius: 0 0 3px 3px;
        animation: tabIndicatorIn 0.3s var(--ease-spring);
    }

    @keyframes tabIndicatorIn {
        from { width: 0; opacity: 0; }
        to { width: 48px; opacity: 1; }
    }

    .mobile-tab-item i {
        font-size: 1.25rem;
        transition: transform var(--transition-fast) var(--ease-spring);
    }

    .mobile-tab-item.active i {
        transform: translateY(-2px) scale(1.1);
    }

    .mobile-tab-label {
        font-size: 0.7rem;
        font-weight: 500;
    }
}

/* ========================================
   10. 移动端卡片全屏通栏
   ======================================== */
@media (max-width: 991px) {
    .mobile-card-full {
        margin-left: -12px;
        margin-right: -12px;
        border-radius: 0;
    }

    .mobile-card-spaced {
        margin: 12px;
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-md);
        /* 内阴影模拟玻璃质感 */
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.1),
            var(--shadow-md);
    }
}

/* ========================================
   11. 页面转场动画
   ======================================== */
@supports (animation-timeline: view()) {
    .page-transition-enter {
        animation: slideIn 0.3s var(--ease-out-expo);
    }

    @keyframes slideIn {
        from {
            opacity: 0;
            transform: translateX(20px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }
}

/* 降级方案：CSS slide-in */
.page-slide-in {
    animation: slideInFallback 0.3s var(--ease-out-expo);
}

@keyframes slideInFallback {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   12. 横屏检测与适配
   ======================================== */
@media (orientation: landscape) and (max-height: 500px) {
    /* 隐藏非必要装饰 */
    .decorative-element,
    .hero-image,
    .gallery-overlay {
        display: none !important;
    }

    /* 保证内容可读 */
    body {
        padding-top: 40px !important;
    }

    .navbar-custom {
        height: 40px !important;
    }
}

/* ========================================
   13. 安全区适配
   ======================================== */
.fixed-bottom,
.mobile-tab-bar {
    padding-bottom: var(--safe-area-bottom);
}

/* ========================================
   14. 图片/图表容器防护
   ======================================== */
.image-container,
.chart-container {
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
}

.image-container img,
.chart-container canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ========================================
   15. 状态高亮动画（任务四恢复用）
   ======================================== */
@keyframes highlightPulse {
    0% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(13, 110, 253, 0); }
    100% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0); }
}

.state-highlight {
    animation: highlightPulse 2s ease-in-out;
    border-radius: var(--radius-md);
}

/* ========================================
   16. 下拉刷新指示器（移动端）
   ======================================== */
@media (max-width: 991px) {
    .pull-refresh-indicator {
        position: absolute;
        top: -50px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        transition: opacity 0.2s ease;
    }

    .pull-refresh-indicator.visible {
        opacity: 1;
    }

    .pull-refresh-indicator .spinner {
        width: 24px;
        height: 24px;
        border: 2px solid var(--border-color);
        border-top-color: var(--brand-primary);
        border-radius: 50%;
        animation: spin 0.6s linear infinite;
    }

    @keyframes spin {
        to { transform: rotate(360deg); }
    }
}

/* ========================================
   17. 长按上下文菜单（移动端 BottomSheet）
   ======================================== */
@media (max-width: 991px) {
    .context-menu-trigger {
        -webkit-touch-callout: default;
        -webkit-user-select: none;
        user-select: none;
    }

    .bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        box-shadow: var(--shadow-xl);
        transform: translateY(100%);
        transition: transform 0.3s var(--ease-out-expo);
        z-index: 1060;
        max-height: 80vh;
        overflow-y: auto;
        padding-bottom: var(--safe-area-bottom);
    }

    .bottom-sheet.open {
        transform: translateY(0);
    }

    .bottom-sheet-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: 1059;
    }

    .bottom-sheet-backdrop.visible {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ========================================
   18. 深色模式强调色切换
   ======================================== */
@media (prefers-color-scheme: dark) {
    .btn-primary {
        --bs-btn-bg: #0284c7;
        --bs-btn-border-color: #0284c7;
        --bs-btn-hover-bg: #0369a1;
        --bs-btn-hover-border-color: #0369a1;
    }

    .text-accent {
        color: #22d3ee !important;
    }

    .bg-accent {
        background-color: #22d3ee !important;
    }
}

/* ========================================
   19. 浮动操作按钮 (FAB) 增强
   ======================================== */
.fab {
    position: fixed;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition-normal) var(--ease-spring);
    z-index: 1040;
}

.fab:hover {
    transform: scale(1.1) rotate(10deg);
}

.fab:active {
    transform: scale(0.95);
}

@media (max-width: 991px) {
    .fab {
        bottom: calc(24px + var(--safe-area-bottom));
    }
}

/* ========================================
   20. 表单输入框增强
   ======================================== */
.form-control,
.form-select {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition:
        border-color var(--transition-fast) ease,
        box-shadow var(--transition-fast) ease;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

@media (prefers-color-scheme: dark) {
    .form-control,
    .form-select {
        background-color: var(--bg-tertiary);
        border-color: var(--border-color);
        color: var(--text-primary);
    }

    .form-control:focus,
    .form-select:focus {
        background-color: var(--bg-secondary);
    }
}
