/* ============== 设计系统：简洁高级 ============== */
:root {
    /* 背景层：更纯净 */
    --bg-page: #fafafa;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-hover: #f5f5f5;
    --bg-active: #f0f0f0;
    --bg-subtle: #f8f9fa;

    /* 强调色：更克制的蓝 */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-soft: #dbeafe;
    --primary-subtle: #f0f7ff;

    /* 文字：更好的对比度 */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* 边框：更细腻 */
    --border-soft: #e2e8f0;
    --border-medium: #cbd5e1;
    --border-subtle: #f1f5f9;

    /* 状态 */
    --success: #059669;
    --success-light: #ecfdf5;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #2563eb;
    --info-light: #eff6ff;

    /* 阴影：极轻，更高级 */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 8px 24px rgba(0, 0, 0, 0.06);

    /* 圆角：更现代 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* 间距系统 */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 14px;
    height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
body { min-height: 100vh; }

svg { flex-shrink: 0; vertical-align: middle; }

/* ============== 应用布局 ============== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar：更窄更精致 */
.app-sidebar {
    width: 240px;
    height: 100vh;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.2s ease;
}
@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        left: 0; top: 0;
        z-index: 200;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .app-sidebar.open { transform: translateX(0); }
    .sidebar-backdrop {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.2);
        z-index: 150;
    }
    .sidebar-backdrop.open { display: block; }
    .app-main-subtitle { display: none; }
    .header-user-name { display: none !important; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-actions { margin-top: 8px; }
}

/* Sidebar 折叠(仅桌面端,窄化为纯图标栏) */
@media (min-width: 769px) {
    .app-sidebar { transition: width 0.2s ease, transform 0.2s ease; }
    .app-sidebar.collapsed { width: 64px; }
    .app-sidebar.collapsed .sidebar-brand { justify-content: center; padding: var(--space-lg) 0; }
    .app-sidebar.collapsed .sidebar-brand-text { display: none; }
    .app-sidebar.collapsed .sidebar-group-title { display: none; }
    .app-sidebar.collapsed .sidebar-group { margin-bottom: var(--space-sm); }
    .app-sidebar.collapsed .sidebar-item { justify-content: center; gap: 0; padding: 9px 0; }
    .app-sidebar.collapsed .sidebar-item span:last-child { display: none; }
}

/* 侧边栏底部折叠开关(仅桌面端显示) */
.sidebar-collapse-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    margin: 0 var(--space-sm) var(--space-sm);
    padding: 8px 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    transition: all 0.12s;
    border-top: 1px solid var(--border-subtle);
    padding-top: 12px;
}
.sidebar-collapse-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-collapse-btn svg { width: 16px; height: 16px; }
@media (max-width: 768px) {
    .sidebar-collapse-btn { display: none; }
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm) var(--space-sm) var(--space-md);
}

/* Main */
.app-main {
    flex: 1;
    height: 100vh;
    background: var(--bg-page);
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}
.app-main-header {
    height: 56px;
    flex-shrink: 0;
    background: var(--bg-card);
    color: var(--text-primary);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}
.app-main-header-left { display: flex; align-items: center; gap: var(--space-md); }
.app-main-title { font-size: 15px; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
.app-main-subtitle { font-size: 11px; color: var(--text-muted); letter-spacing: 0.02em; }
.app-main-actions { display: flex; align-items: center; gap: var(--space-xs); }
.app-main-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg) var(--space-xl);
}

.app-header { display: none; }

/* ============== Header 内容 ============== */
.header-hamburger {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.15s;
}
.header-hamburger:hover { background: var(--bg-hover); }
.header-hamburger svg { width: 18px; height: 18px; }
/* 桌面端隐藏汉堡键(侧边栏底部已有收起开关),仅移动端用于打开抽屉 */
@media (min-width: 769px) {
    .header-hamburger { display: none; }
}

.header-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.15s;
}
.header-btn:hover { background: var(--bg-hover); }
.header-btn svg { width: 18px; height: 18px; }

.header-user {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 10px 4px 4px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}
.header-user:hover { background: var(--bg-hover); }
.header-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600;
    overflow: hidden;
}
.header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.header-user-name { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.header-user-caret { font-size: 10px; color: var(--text-muted); }

.header-dropdown {
    position: absolute;
    top: calc(100% + 8px); right: 0;
    min-width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 200;
}
.header-dropdown-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 4px;
}
.header-dropdown-header .email { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.header-dropdown-item {
    padding: 9px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.1s;
    display: flex; align-items: center; gap: 8px;
}
.header-dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.header-dropdown-item.danger { color: var(--danger); }
.header-dropdown-divider { height: 1px; background: var(--border-subtle); margin: 4px 8px; }

/* ============== Sidebar 菜单 ============== */
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: var(--space-lg) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-sm);
}
.sidebar-brand-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: transparent;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.sidebar-brand-text { font-size: 14px; font-weight: 600; color: var(--text-primary); letter-spacing: -0.01em; }

.sidebar-group { margin-bottom: var(--space-lg); }
.sidebar-group-title {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 var(--space-md);
    margin-bottom: var(--space-xs);
    font-weight: 500;
}
.sidebar-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all 0.12s;
    text-decoration: none;
}
.sidebar-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.sidebar-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}
.sidebar-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.app-layout svg { width: 24px; height: 24px; }
.header-btn svg { width: 18px; height: 18px; }
.sidebar-item svg { width: 16px; height: 16px; }

/* ============== 知识库分类/标签徽章 ============== */
.kb-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.6;
    margin-right: 4px;
    vertical-align: middle;
}
.kb-badge-cat {
    background: var(--primary-light);
    color: var(--primary);
}
.kb-badge-tag {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

/* ============== 卡片 ============== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-xs);
    transition: box-shadow 0.15s;
}
.card:hover { box-shadow: var(--shadow-sm); }
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); letter-spacing: -0.01em; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============== 统计卡片 ============== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}
@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    display: flex; align-items: center; gap: var(--space-md);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-xs);
    transition: all 0.15s;
}
.stat-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    color: var(--primary);
    background: var(--primary-light);
    flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1.1; letter-spacing: -0.02em; }
.stat-foot { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ============== 欢迎条 ============== */
.welcome-banner {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: var(--space-xl) var(--space-xl);
    margin-bottom: var(--space-lg);
    display: flex; align-items: center; justify-content: space-between;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-xs);
}
.welcome-banner h2 { font-size: 18px; font-weight: 600; margin: 0 0 4px 0; letter-spacing: -0.01em; }
.welcome-banner p { font-size: 13px; color: var(--text-muted); margin: 0; }
.welcome-banner .btn-banner {
    background: var(--primary);
    color: var(--text-inverse);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.15s;
}
.welcome-banner .btn-banner:hover { background: var(--primary-dark); transform: translateY(-1px); }

/* ============== 页面标题 ============== */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: var(--space-lg);
}
.page-title { font-size: 20px; font-weight: 600; color: var(--text-primary); letter-spacing: -0.01em; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.page-actions { display: flex; gap: var(--space-sm); }

/* ============== 按钮 ============== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    text-decoration: none;
    font-weight: 500;
}
.btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-medium);
}
.btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: var(--text-inverse);
}
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-light); border-color: #fecaca; }
.btn svg { width: 14px; height: 14px; }

/* ============== 表格 ============== */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border-subtle); }
.tbl th { color: var(--text-muted); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--bg-subtle); }

/* ============== 标签 ============== */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}
.tag-success { background: var(--success-light); color: var(--success); }
.tag-warning { background: var(--warning-light); color: var(--warning); }
.tag-info { background: var(--info-light); color: var(--info); }
.tag-error { background: var(--danger-light); color: var(--danger); }
.tag-muted { background: var(--bg-hover); color: var(--text-secondary); }
.tag-processing { background: var(--info-light); color: var(--info); }
.tag-ready { background: var(--success-light); color: var(--success); }
.tag-failed { background: var(--danger-light); color: var(--danger); }

/* ============== 提示 ============== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: var(--space-md);
    display: none;
    border: 1px solid transparent;
}
.alert.show { display: block; }
.alert-error { background: var(--danger-light); border-color: #fecaca; color: var(--danger); }
.alert-success { background: var(--success-light); border-color: #bbf7d0; color: var(--success); }
.alert-info { background: var(--info-light); border-color: var(--primary-soft); color: var(--info); }

/* ============== Empty ============== */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--bg-hover);
    color: var(--primary);
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: 12px;
}
.empty-icon svg { width: 32px; height: 32px; }
.empty-title { font-size: 15px; color: var(--text-primary); margin-bottom: 4px; font-weight: 500; }
.empty-desc { font-size: 12.5px; max-width: 360px; margin: 0 auto; }

/* ============== Loading ============== */
.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid var(--border-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============== 骨架屏 ============== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-subtle) 50%, var(--bg-hover) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-sm);
}
@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============== 工具类 ============== */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-lg { font-size: 16px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

/* ============== 丝滑动效(全局微交互) ============== */

/* 滚动行为与滚动条 */
html { scroll-behavior: smooth; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* 页面内容淡入(每次切换页面时柔和入场) */
.app-main-body > * {
    animation: page-fade-in 0.22s ease-out;
}
@keyframes page-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 按钮按压反馈 */
.btn { transition: all 0.15s ease; }
.btn:active { transform: scale(0.96); }

/* 输入控件聚焦过渡 */
input, textarea, select {
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    outline: none;
}

/* 侧边栏菜单项:活跃指示 + 过渡 */
.sidebar-item {
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.sidebar-item:hover { transform: translateX(2px); }
.sidebar-item.active {
    box-shadow: inset 3px 0 0 var(--primary);
}

/* 卡片悬浮(统一浮起手感) */
.card { transition: box-shadow 0.2s ease, transform 0.2s ease; }

/* 表格行过渡 */
.tbl tbody tr { transition: background 0.12s ease; }

/* 弹层淡入(SweetAlert 适配) */
.swal2-popup { animation: modal-pop 0.18s ease-out !important; }
@keyframes modal-pop {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* 链接/可点元素的统一过渡 */
a, .kb-item, .session-item, .upload-item, .kb-cat-row, .kb-tag {
    transition: all 0.15s ease;
}

/* 尊重减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
