/* Tailwind CSS — 本地文件（避免CSP阻止CDN加载） */
@import url('/css/tailwind.min.css');

/* ===== 自定义CSS变量 ===== */
:root {
    --primary-1: #1E40AF;
    --primary-2: #3B82F6;
    --primary-3: #6366F1;
    --bg-dark-1: #0F172A;
    --bg-dark-2: #1E293B;
    --bg-dark-3: #334155;
    --text-light-1: #F1F5F9;
    --text-light-2: #94A3B8;
    --text-light-3: #64748B;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --purple: #8B5CF6;
    --glass-bg: rgba(30, 41, 59, 0.6);
    --glass-border: rgba(148, 163, 184, 0.15);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --sidebar-width: 220px;
    --sidebar-collapsed-width: 56px;
    --topbar-height: 48px;
}

/* ===== 全局样式 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark-1);
    color: var(--text-light-1);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== 毛玻璃效果 ===== */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

.glass-light {
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(148, 163, 184, 0.1);
}

/* ===== 渐变背景 ===== */
.gradient-primary {
    background: linear-gradient(135deg, var(--primary-1), var(--primary-3));
}

.gradient-text {
    background: linear-gradient(135deg, var(--primary-2), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== 粒子动画背景 ===== */
.particles-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    opacity: 0.3;
    animation: float linear infinite;
}

@keyframes float {
    0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
    10% { opacity: 0.3; }
    90% { opacity: 0.3; }
    100% { transform: translateY(-10vh) rotate(720deg); opacity: 0; }
}

/* ===== 输入框样式 ===== */
.input-field {
    width: 100%;
    padding: 12px 16px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-light-1);
    font-size: 14px;
    transition: all 0.3s ease;
    outline: none;
}

.input-field:focus {
    border-color: var(--primary-2);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.input-field::placeholder {
    color: var(--text-light-3);
}

/* ===== 按钮样式 ===== */
.btn-primary {
    width: 100%;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--primary-1), var(--primary-3));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    padding: 8px 16px;
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-light-2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-light-1);
}

/* ===== Tab切换 ===== */
.tab-btn {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    color: var(--text-light-3);
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-btn.active {
    color: var(--primary-2);
    border-bottom-color: var(--primary-2);
}

.tab-btn:hover:not(.active) {
    color: var(--text-light-2);
}

/* ===== 应用卡片 ===== */
.app-card {
    position: relative;
    padding: 24px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.app-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    padding: 1px;
    background: linear-gradient(135deg, var(--card-color, var(--primary-2)), transparent 60%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0.5;
    transition: opacity 0.4s ease;
}

.app-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.app-card:hover::before {
    opacity: 1;
}

.app-card:hover .app-icon {
    transform: scale(1.1);
}

.app-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 16px;
    transition: transform 0.3s ease;
}

/* ===== Toast通知 ===== */
.toast {
    position: fixed;
    top: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 12px;
    color: white;
    font-size: 14px;
    z-index: 9999;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
    max-width: 360px;
}

.toast-success { background: linear-gradient(135deg, #059669, #10B981); }
.toast-error { background: linear-gradient(135deg, #DC2626, #EF4444); }
.toast-warning { background: linear-gradient(135deg, #D97706, #F59E0B); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ===== 加载动画 ===== */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== 页面切换动画 ===== */
.page-enter {
    animation: pageEnter 0.4s ease;
}

@keyframes pageEnter {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== 管理后台表格 ===== */
.admin-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.admin-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--glass-border);
}

.admin-table td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.05);
}

.admin-table tr:hover td {
    background: rgba(148, 163, 184, 0.05);
}

/* ===== 深度融合布局 ===== */

/* 主布局：侧边栏 + 内容区 */
.portal-layout {
    display: flex;
    height: calc(100vh - var(--topbar-height));
    overflow: hidden;
}

/* 侧边栏 — 深度融合版 */
.portal-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-dark-2);
    border-right: 1px solid var(--glass-border);
    padding: 8px 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s ease, min-width 0.25s ease;
    display: flex;
    flex-direction: column;
}

.portal-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    min-width: var(--sidebar-collapsed-width);
}

.portal-sidebar.collapsed .sidebar-label,
.portal-sidebar.collapsed .sidebar-arrow,
.portal-sidebar.collapsed .sidebar-submenu,
.portal-sidebar.collapsed .sidebar-divider,
.portal-sidebar.collapsed .sidebar-title {
    display: none;
}

.portal-sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 12px 0;
}

.portal-sidebar.collapsed .sidebar-icon {
    margin: 0;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
}

.sidebar-item {
    position: relative;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--text-light-3);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: rgba(148, 163, 184, 0.08);
    color: var(--text-light-1);
}

.sidebar-link.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--primary-2);
    border-left-color: var(--primary-2);
    font-weight: 600;
}

/* 菜单组标题 — 有子菜单激活时高亮 */
.sidebar-group-header.group-active {
    color: var(--text-light-1);
    background: rgba(59, 130, 246, 0.06);
}

.sidebar-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.sidebar-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-arrow {
    font-size: 9px;
    transition: transform 0.2s ease;
    color: var(--text-light-3);
}

.sidebar-item.expanded .sidebar-arrow {
    transform: rotate(90deg);
}

/* 子菜单 — 深度融合版：默认展开，更紧凑 */
.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.sidebar-item.expanded .sidebar-submenu {
    max-height: 500px; /* 足够容纳所有子菜单项 */
}

.sidebar-submenu .sidebar-link {
    padding-left: 46px;
    font-size: 12px;
    padding-top: 7px;
    padding-bottom: 7px;
}

.sidebar-divider {
    height: 1px;
    background: var(--glass-border);
    margin: 6px 12px;
}

.sidebar-title {
    padding: 6px 16px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-light-3);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* 移动端汉堡菜单 */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-2);
    color: white;
    border: none;
    font-size: 20px;
    z-index: 101;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* ===== 内容区 — 深度融合版：全屏无缝 ===== */
.portal-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    position: relative;
    background: var(--bg-dark-1);
}

/* 非iframe内容（欢迎页、设置页等）需要内边距 */
.portal-content > .welcome-section,
.portal-content > .content-welcome,
.portal-content > .settings-form,
.portal-content > .quick-actions,
.portal-content > .dashboard-stats,
.portal-content > .glass,
.portal-content > div:not(.iframe-content-wrapper) {
    padding: 24px 32px;
}

/* iframe全屏无缝嵌入 */
.iframe-content-wrapper {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.content-iframe-seamless {
    width: 100%;
    height: 100%;
    border: none;
    background: #f5f7fa;
}

/* 旧版iframe样式（兼容） */
.content-iframe {
    width: 100%;
    height: calc(100vh - 80px);
    border: none;
    border-radius: 12px;
    background: white;
}

/* Welcome区 */
.welcome-section {
    margin-bottom: 24px;
}

.welcome-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-light-1);
    margin-bottom: 4px;
}

.welcome-subtitle {
    font-size: 13px;
    color: var(--text-light-3);
}

/* 快速入口 */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.quick-action-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    border-radius: 14px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.quick-action-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    border-color: rgba(148, 163, 184, 0.3);
}

.quick-action-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.quick-action-info h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-light-1);
    margin-bottom: 2px;
}

.quick-action-info p {
    font-size: 12px;
    color: var(--text-light-3);
}

/* 内容区 - 仪表盘 */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    padding: 20px;
    border-radius: 14px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-light-3);
}

.stat-card .stat-sub {
    font-size: 11px;
    color: var(--text-light-2);
    margin-top: 4px;
}

/* 内容区 - 默认欢迎 */
.content-welcome {
    text-align: center;
    padding: 60px 20px;
}

.content-welcome h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-light-1);
    margin-bottom: 8px;
}

.content-welcome p {
    font-size: 16px;
    color: var(--text-light-3);
    margin-bottom: 32px;
}

/* 设置页 */
.settings-form {
    max-width: 480px;
}

.settings-form label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-light-2);
    margin-bottom: 6px;
}

.settings-form .form-group {
    margin-bottom: 20px;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .login-layout {
        flex-direction: column !important;
    }
    .login-brand {
        display: none !important;
    }
    .app-grid {
        grid-template-columns: 1fr !important;
    }
    .portal-sidebar {
        transform: translateX(-100%);
        position: fixed !important;
        top: var(--topbar-height);
        left: 0;
        bottom: 0;
        z-index: 100;
        transition: transform 0.3s ease;
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
    }
    .portal-sidebar.open {
        transform: translateX(0);
    }
    .portal-sidebar.collapsed {
        transform: translateX(-100%);
    }
    .sidebar-toggle {
        display: flex;
    }
    .sidebar-overlay.show {
        display: block;
    }
    .quick-actions {
        grid-template-columns: 1fr;
    }
    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    #sidebar-collapse-btn {
        display: none;
    }
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark-1);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-dark-3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-light-3);
}

/* ===== AI对话组件 ===== */
.chat-suggestion-btn {
    padding: 8px 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    color: var(--text-light-2);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.chat-suggestion-btn:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--primary-2);
    color: var(--primary-2);
    transform: translateY(-1px);
}

/* AI对话中的代码块样式 */
.ai-chat-container pre {
    margin: 8px 0;
}

.ai-chat-container code {
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* 对话消息动画 */
@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-chat-container > div > div {
    animation: chatMsgIn 0.3s ease;
}

/* 管理后台弹窗优化 */
.admin-modal-overlay {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 骨架屏loading */
.skeleton {
    background: linear-gradient(90deg, var(--bg-dark-3) 25%, rgba(51, 65, 85, 0.6) 50%, var(--bg-dark-3) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* iframe加载进度条 */
.iframe-loading-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-2), var(--purple));
    border-radius: 2px;
    animation: loadingProgress 2s ease-out forwards;
    z-index: 10;
}

@keyframes loadingProgress {
    0% { width: 0%; }
    30% { width: 60%; }
    60% { width: 80%; }
    100% { width: 100%; opacity: 0; }
}

/* ===== 微信完善信息弹窗 ===== */
.wechat-complete-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.wechat-complete-card {
    width: 100%;
    max-width: 420px;
    padding: 32px;
    border-radius: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

.wechat-complete-card .input-field {
    margin-bottom: 0;
}

/* ===== 注册表单样式 ===== */
#panel-register .input-field {
    margin-bottom: 0;
}

#panel-register .btn-primary {
    margin-top: 8px;
}

/* ===== Landing首页 ===== */
.landing-app-card {
    padding: 32px;
    border-radius: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 20px;
}

.landing-app-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
    border-color: rgba(148, 163, 184, 0.3);
}

.landing-app-icon {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.landing-app-info h3 {
    transition: color 0.3s ease;
}

.landing-app-card:hover .landing-app-info h3 {
    color: var(--primary-2) !important;
}

/* ===== 登录弹窗 ===== */
.login-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.login-modal-card {
    width: 100%;
    max-width: 420px;
    padding: 32px;
    border-radius: 20px;
    background: var(--bg-dark-2);
    border: 1px solid var(--glass-border);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    position: relative;
}

.login-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-light-3);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.login-modal-close:hover {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-light-1);
}

/* ===== select下拉框暗色主题适配 ===== */
select.input-field {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394A3B8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

select.input-field option {
    background: var(--bg-dark-2);
    color: var(--text-light-1);
}
