:root {
    /* 
     * 2025 Luminous Linear Design System
     * Concept: Light, Order, Depth
     */

    /* --- Palette: Obsidian (Dark Mode by Default for Premium Feel) --- */
    /* 我们将默认风格偏向深色/高级灰，浅色模式作为“陶瓷白”变体 */
    
    /* Base Colors - Neutral Scale (Zinc/Slate mix) */
    --color-bg-base: #09090b;       /* 最底层的深邃黑 */
    --color-bg-surface: #18181b;    /* 模块背景色 */
    --color-bg-surface-hover: #27272a;
    
    /* Text Colors */
    --color-text-primary: #f4f4f5;  /* 亮白 */
    --color-text-secondary: #a1a1aa;/* 也就是所谓的高级灰 */
    --color-text-tertiary: #52525b; /* 暗灰，用于不重要的信息 */

    /* Brand Colors - Electric Violet (Cyberpunk touch) */
    --color-brand-primary: #6366f1; /* Indigo */
    --color-brand-glow: rgba(99, 102, 241, 0.5);
    
    /* Gradients */
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

    /* Borders & Separators - The Linear Soul */
    /* 核心：极其微弱的边框，主要靠光影 */
    --border-base: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15); /* 用于Hover或顶部高光 */

    /* --- Light Mode Overrides (Ceramic Style) --- */
    --light-bg-base: #fdfdfd;       /* 陶瓷白背景 */
    --light-bg-surface: #ffffff;    /* 纯白卡片 */
    --light-border: #e4e4e7;        /* 极淡的灰线 */
    --light-text-primary: #18181b;
    --light-text-secondary: #71717a;
}

/* 适配亮色模式的变量映射 */
body:not(.night-mode) {
    --bg-app: var(--light-bg-base);
    --bg-card: var(--light-bg-surface);
    --bg-card-hover: #fafafa;
    --text-main: var(--light-text-primary);
    --text-muted: var(--light-text-secondary);
    --border-color: var(--light-border);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.02);
    --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.06);
    --glow-effect: none; /* 浅色模式不强调发光 */

    /* Modal Theme Variables (Mapped) */
    --theme-card-bg: var(--bg-card);
    --theme-border: var(--border-color);
    --theme-text-main: var(--text-main);
    --theme-text-muted: var(--text-muted);
    --theme-primary: var(--color-brand-primary);
    --theme-primary-hover: #4f46e5;
    --theme-bg: var(--bg-app);
    --modal-shadow: var(--shadow-float);
}

/* 暗色模式变量映射 (Premium Default) */
body.night-mode {
    --bg-app: var(--color-bg-base);
    --bg-card: var(--color-bg-surface);
    --bg-card-hover: var(--color-bg-surface-hover);
    --text-main: var(--color-text-primary);
    --text-muted: var(--color-text-secondary);
    --border-color: var(--border-base);
    --shadow-card: 0 0 0 1px rgba(0,0,0,1), 0 4px 12px rgba(0,0,0,0.5); /* 模拟物理厚度 */
    --shadow-float: 0 20px 40px rgba(0,0,0,0.6);
    --glow-effect: 0 0 20px var(--color-brand-glow);

    /* Modal Theme Variables (Mapped) */
    --theme-card-bg: var(--bg-card);
    --theme-border: var(--border-color);
    --theme-text-main: var(--text-main);
    --theme-text-muted: var(--text-muted);
    --theme-primary: var(--color-brand-primary);
    --theme-primary-hover: #818cf8;
    --theme-bg: var(--bg-app);
    --modal-shadow: var(--shadow-float);
}

/* Global Reset */
body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px; /* 更精致的字号 */
    line-height: 1.6;
    letter-spacing: -0.01em; /* 紧凑一点更有现代感 */
    transition: background 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* 
   -----------------------------
   Layout: Floating Bento Dock 
   -----------------------------
*/

/* 侧边栏：现在是一个悬浮的 Dock */
.sidebar {
    position: fixed;
    top: 16px;
    bottom: 16px;
    left: 16px;
    width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px; /* 大圆角 */
    padding: 20px;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: var(--shadow-float);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    overflow: hidden; /* Prevent outer scrolling */
}

/* 主内容区：为悬浮 Dock 让出空间 */
.main-content {
    margin-left: 272px; /* 240 + 16 + 16 */
    margin-top: 16px;
    margin-right: 16px;
    min-height: calc(100vh - 32px);
    border-radius: 20px;
    position: relative;
}

/* 顶部导航：透明化，内容优先 */
.page-header {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0 0 24px 0; /* 减少内边距 */
    margin: 0;
    backdrop-filter: none;
    position: relative; /* 修复下拉菜单被遮挡 */
    z-index: 10;
}

/* 
   -----------------------------
   Components: Linear Cards 
   -----------------------------
*/

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-card);
    transition: all 0.2s ease;
    position: relative;
    overflow: visible !important; /* Fixed dropdown clipping issue */
}

/* 顶部微光高亮 (Top Highlight) - 极具质感的细节 */
.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    opacity: 0.5;
    pointer-events: none;
}

.card:hover {
    border-color: var(--color-brand-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.05); /* 仅在亮色模式明显 */
}

body.night-mode .card:hover {
    box-shadow: 0 0 0 1px var(--color-brand-primary), 0 8px 30px rgba(99, 102, 241, 0.15); /* 暗色模式发光 */
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: 0;
}

/* 
   -----------------------------
   Components: Modern Typography & Badges
   -----------------------------
*/

h1, h2, h3, h4, h5, h6 {
    color: var(--text-main);
    font-weight: 600;
    letter-spacing: -0.02em;
}

.text-main {
    color: var(--text-main) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

/* 胶囊徽章 (Pill Badges) */
.badge {
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 99px; /* 完全圆角 */
    font-size: 11px;
    letter-spacing: 0.02em;
    border: 1px solid transparent; /* 预留边框 */
}

.bg-success-subtle {
    background: rgba(16, 185, 129, 0.1) !important;
    color: #10b981 !important;
    border-color: rgba(16, 185, 129, 0.2) !important;
}

.bg-warning-subtle {
    background: rgba(245, 158, 11, 0.1) !important;
    color: #f59e0b !important;
    border-color: rgba(245, 158, 11, 0.2) !important;
}

/* 
   -----------------------------
   Components: Inputs & Buttons
   -----------------------------
*/

/* Label Styling - Critical Fix for Dark Mode */
.form-label {
    color: var(--text-main);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.form-text {
    color: var(--text-muted) !important;
}

.form-control, .form-select {
    background: var(--bg-card); /* 与卡片同色或稍深 */
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    box-shadow: none;
    transition: all 0.2s;
}

.form-control:focus, .form-select:focus {
    background: var(--bg-card);
    border-color: var(--color-brand-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    color: var(--text-main);
}

/* Placeholder Styling */
.form-control::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.form-control:disabled, .form-control[readonly] {
    background-color: rgba(255, 255, 255, 0.05); /* Slightly transparent background */
    opacity: 1;
    color: var(--text-muted); /* Gray text */
    border-color: var(--border-color); /* Same border color */
}

body.night-mode .form-control:disabled, body.night-mode .form-control[readonly] {
    background-color: rgba(255, 255, 255, 0.05); /* Ensure it's dark in dark mode */
    color: var(--text-muted);
}

.btn {
    border-radius: 10px;
    font-weight: 500;
    font-size: 14px;
    padding: 10px 18px;
    letter-spacing: 0;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--color-brand-primary);
    border: 1px solid transparent;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1), inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn-primary:hover {
    background: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* 
   -----------------------------
   Navigation: Sidebar Styling
   -----------------------------
*/

.sidebar-brand {
    padding: 12px 16px; /* Slightly more padding */
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px; /* Consistent gap */
    color: var(--text-main);
    transition: all 0.3s ease;
}

.sidebar-logo {
    height: 32px; /* Optimal height for sidebar */
    width: auto;
    max-width: 160px; /* Prevent overflow */
    object-fit: contain; /* Maintain aspect ratio */
}

.sidebar-logo-placeholder {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-brand-primary);
    color: white;
    border-radius: 8px;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto; /* Enable vertical scrolling */
    overflow-x: hidden;
    min-height: 0; /* Allow shrinking in flex container */
    scrollbar-width: thin; /* For Firefox */
    scrollbar-color: var(--border-color) transparent;
    flex-wrap: nowrap !important; /* Fix multi-column layout on overflow */
    flex-direction: column !important; /* Ensure vertical layout */
}

/* Custom Scrollbar for Sidebar Menu (WebKit) */
.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.sidebar-menu li {
    margin-bottom: 4px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    color: var(--text-muted);
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s;
    font-weight: 500;
}

.sidebar-menu a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

body:not(.night-mode) .sidebar-menu a:hover {
    background: rgba(0, 0, 0, 0.05);
}

.sidebar-menu a.active {
    background: var(--color-brand-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.sidebar-menu a i {
    width: 20px;
    margin-right: 10px;
    text-align: center;
    font-size: 14px;
}

/* Mobile Adaptation */
@media (max-width: 991px) {
    .sidebar {
        left: -260px; /* Hide off-screen */
        top: 0;
        bottom: 0;
        border-radius: 0;
        border-right: 1px solid var(--border-color);
    }
    
    .sidebar.show {
        transform: translateX(260px);
    }
    
    .main-content {
        margin: 0;
        padding: 16px;
    }
    
    .mobile-overlay.show {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        backdrop-filter: blur(4px);
    }
}

/* Utility: Bento Grid Helpers */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.bento-col-1 { grid-column: span 1; }
.bento-col-2 { grid-column: span 2; }
.bento-col-3 { grid-column: span 3; }
.bento-col-4 { grid-column: span 4; }

@media (max-width: 1200px) {
    .bento-grid { grid-template-columns: repeat(2, 1fr); }
    .bento-col-1, .bento-col-2, .bento-col-3 { grid-column: span 2; }
}

@media (max-width: 768px) {
    .bento-grid { grid-template-columns: 1fr; }
    .bento-col-1, .bento-col-2, .bento-col-3, .bento-col-4 { grid-column: span 1; }
}

/* 
   -----------------------------
   Utilities Override (Ensure Premium Look)
   -----------------------------
*/

/* 强制覆盖 Bootstrap 的 bg-white，确保深色模式下也是深色 */
.bg-white {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

/* 强制覆盖 Bootstrap 的 list-group */
.list-group-item {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

/* 强制覆盖 Bootstrap 的 bg-light (仅在深色模式下) */
body.night-mode .bg-light {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: var(--text-main) !important;
}

/* 强制覆盖 Bootstrap 的 text-dark */
.text-dark {
    color: var(--text-main) !important;
}

/* 强制覆盖 Bootstrap 的 border */
.border, .border-top, .border-bottom, .border-end, .border-start {
    border-color: var(--border-color) !important;
}

/* 表格样式优化 */
.table {
    color: var(--text-main);
    border-color: var(--border-color);
}

.table > :not(caption) > * > * {
    background-color: transparent;
    border-bottom-color: var(--border-color);
    color: var(--text-main);
}

.table-hover > tbody > tr:hover > * {
    background-color: var(--bg-card-hover);
    color: var(--text-main);
}

/* 模态框优化 */
.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-float);
    border-radius: 16px;
}

.modal-header, .modal-footer {
    border-color: var(--border-color);
}

.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%); /* 适配深色模式 */
}

body:not(.night-mode) .btn-close {
    filter: none;
}

/* Custom Colors */
.text-indigo {
    color: #6610f2 !important;
}

.bg-indigo-subtle {
    background-color: rgba(102, 16, 242, 0.1) !important;
    border-color: rgba(102, 16, 242, 0.2) !important;
}

.border-indigo {
    border-color: rgba(102, 16, 242, 0.2) !important;
}

body.night-mode .text-indigo {
    color: #a78bfa !important;
}

/* Dashboard Custom Classes */
.border-theme {
    border: 1px solid var(--border-color) !important;
}

.border-theme-top {
    border-top: 1px solid var(--border-color) !important;
}

.bg-gradient-primary-custom {
    background: linear-gradient(135deg, var(--color-brand-primary), #4f46e5) !important;
}

.stat-card-bg {
    background: var(--bs-tertiary-bg);
    border: 1px solid var(--border-color);
}

/* 
   -----------------------------
   Login Page Styles 
   -----------------------------
*/
.bg-mesh {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(139, 92, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(56, 189, 248, 0.15) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(236, 72, 153, 0.15) 0px, transparent 50%);
    z-index: -2;
}

.bg-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-app);
    opacity: 0.9;
    z-index: -1;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    box-shadow: var(--shadow-float);
    position: relative;
    z-index: 1;
    margin: 0;
    animation: fadeUp 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.login-card img {
    max-height: 48px !important;
    width: auto !important;
    display: inline-block;
}

.brand-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.brand-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 2rem;
}

.custom-input-group .input-group-text {
    background: transparent;
    border: 1px solid var(--border-color);
    border-right: none;
    color: var(--text-muted);
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

.custom-input-group .form-control {
    border-left: none;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    padding-left: 0;
}

.custom-input-group .form-control:focus {
    box-shadow: none;
    border-color: var(--border-color); /* Maintain border color on focus to avoid weirdness with group */
}

.custom-input-group:focus-within .input-group-text,
.custom-input-group:focus-within .form-control {
    border-color: var(--color-brand-primary);
    box-shadow: none;
}

.btn-login {
    background: var(--color-brand-primary);
    color: white;
    padding: 12px;
    font-weight: 600;
    border-radius: 10px;
    border: none;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    transition: all 0.2s;
}

.btn-login:hover {
    background: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

/* Utilities */
.bg-primary-gradient {
    background: var(--primary-gradient) !important;
    color: white;
}

/* Animations */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile adaptation for login */
@media (max-width: 576px) {
    .login-card {
        margin: 1rem;
        width: calc(100% - 2rem);
        padding: 1.5rem;
    }
}
