:root {
    /* 亮色 */
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --sidebar-bg: rgba(255, 255, 255, 0.65);
    --sidebar-border: rgba(255, 255, 255, 0.9);
    --hover-bg: rgba(59, 130, 246, 0.08);
    --active-indicator: #3b82f6;
    --toast-bg: rgba(255, 255, 255, 0.85);
    --toast-text: #1e293b;
    --toast-border: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] {
    /* 暗色 */
    --bg-color: #0f172a;
    --text-color: #f1f5f9;
    --sidebar-bg: rgba(30, 41, 59, 0.65);
    --sidebar-border: rgba(255, 255, 255, 0.1);
    --hover-bg: rgba(255, 255, 255, 0.08);
    --active-indicator: #60a5fa;
    --toast-bg: rgba(30, 41, 59, 0.85);
    --toast-text: #f1f5f9;
    --toast-border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    min-height: 100vh;
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
}

.mobile-header {
    display: none;
    width: 100%;
    height: 60px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--sidebar-border);
    align-items: center;
    padding: 0 20px;
    position: fixed;
    top: 0;
    z-index: 90;
}

.mobile-title {
    font-size: 18px;
    font-weight: 600;
    margin-left: 15px;
}

/* 遮罩层 */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    z-index: 95;
    transition: all 0.3s ease;
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
}

.sidebar {
    width: 260px;
    height: 100vh;
    background: var(--sidebar-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    transition: width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), transform 0.4s ease;
    position: sticky;
    top: 0;
    align-self: flex-start;
    z-index: 100;
}

.sidebar.collapsed {
    width: 80px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    height: 80px;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 20px;
    cursor: pointer;
    outline: none;
    transition: color 0.3s;
}

.nav-menu {
    list-style: none;
    margin-top: 10px;
    flex-grow: 1;
    position: relative; 
}

.nav-indicator {
    position: absolute;
    left: 0;
    width: 4px;
    background-color: var(--active-indicator);
    border-radius: 0 4px 4px 0;
    transition: top 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), height 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 2;
    pointer-events: none;
}

.nav-item {
    padding: 0 10px;
    margin-bottom: 5px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 14px 15px;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 12px;
    transition: background-color 0.3s ease, color 0.3s ease;
    position: relative;
    overflow: hidden;
}

.nav-link i {
    font-size: 18px;
    min-width: 35px;
    text-align: center;
}

.nav-text {
    white-space: nowrap;
    opacity: 1;
    font-weight: 500;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.sidebar.collapsed .nav-text {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-10px);
}

.nav-item:hover .nav-link,
.nav-item.active > .nav-link {
    background-color: var(--hover-bg);
}

.nav-item.active > .nav-link {
    color: var(--active-indicator);
}

.sub-arrow {
    margin-left: auto;
    font-size: 12px !important;
    transition: transform 0.3s ease;
}

.has-sub.open .sub-arrow {
    transform: rotate(180deg);
}

.sidebar.collapsed .sub-arrow {
    display: none;
}

.sub-menu {
    list-style: none;
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease, margin 0.3s ease;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 8px;
    margin: 0 10px;
}

[data-theme="dark"] .sub-menu {
    background: rgba(0, 0, 0, 0.2);
}

.has-sub.open .sub-menu {
    max-height: 250px; 
    margin-top: 5px;
    margin-bottom: 5px;
}

.sidebar.collapsed .sub-menu {
    display: none !important; /* 电脑端收起时不显示子菜单 */
}

.sub-link {
    display: block;
    padding: 10px 15px 10px 50px; /* 左边距稍微留空实现层级感 */
    color: var(--text-color);
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.sub-link:hover, .sub-item.active .sub-link {
    background-color: var(--hover-bg);
    color: var(--active-indicator);
}
/* --- 新增：子菜单样式区结束 --- */

.sidebar-footer {
    padding: 20px;
    display: flex;
    justify-content: center;
}

.sidebar.collapsed .sidebar-footer {
    padding: 20px 10px;
}

.sidebar.collapsed #theme-toggle {
    padding-left: 10px;
}

#theme-toggle i {
    transition: transform 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.3s;
}

#theme-toggle.animating i {
    transform: rotate(360deg) scale(0.8);
    opacity: 0.5;
}

.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--toast-bg);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid var(--toast-border);
    padding: 12px 20px;
    border-radius: 12px;
    color: var(--toast-text);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
    animation: toastFadeIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    will-change: transform, opacity;
}

.toast-icon {
    font-size: 16px;
    line-height: 1;
}

.toast.fade-out {
    animation: toastFadeOut 0.3s ease-in forwards;
}

@keyframes toastFadeIn {
    0% { opacity: 0; transform: translateY(-20px) scale(0.9); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastFadeOut {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-20px) scale(0.9); }
}

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px; 
        width: 260px !important;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        transform: translateX(280px); 
    }

    .sidebar-header {
        display: none;
    }
    
    .nav-menu {
        margin-top: 20px;
    }

    .sidebar .nav-text {
        opacity: 1 !important;
        pointer-events: auto !important;
        transform: translateX(0) !important;
    }
}

/* --- 新增：全局加载动画样式 --- */
.global-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9998; /* 层级在toast之下，其他内容之上 */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

[data-theme="dark"] .global-loading-overlay {
    background: rgba(15, 23, 42, 0.5); /* 暗黑模式下的半透明背景 */
}

.global-loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loading-box {
    background: var(--toast-bg);
    border: 1px solid var(--toast-border);
    padding: 24px 32px;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.global-loading-overlay.show .loading-box {
    transform: scale(1);
}

.loading-spinner {
    width: 38px;
    height: 38px;
    border: 3px solid var(--hover-bg);
    border-top: 3px solid var(--active-indicator);
    border-radius: 50%;
    animation: loading-spin 1s linear infinite;
}

.loading-text {
    color: var(--toast-text);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 1px;
}

@keyframes loading-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}