/* ==================== 应用骨架与侧边栏 ==================== */

.app-container {
    width: 100%;
    display: flex;
}

/* ==================== SaaS Sidebar (Ant/Semi-inspired) ==================== */
.app-container {
    --sb-accent: var(--color-primary);
    --sb-bg: rgba(255, 255, 255, 0.72);
    --sb-surface: rgba(255, 248, 238, 0.92);
    --sb-text: var(--color-text-secondary);
    --sb-text-strong: var(--color-text-primary);
    --sb-border: rgba(208, 186, 151, 0.48);
    --sb-header-h: 68px;
    --sb-w: 286px;
    --sb-w-collapsed: 76px;
    position: relative;
    isolation: isolate;
}

.app-container.sidebar-collapsed {
    --sb-w: var(--sb-w-collapsed);
}

/* 左侧边栏 */
.sidebar {
    width: var(--sb-w);
    background:
        linear-gradient(180deg, rgba(255, 252, 247, 0.88), rgba(255, 255, 255, 0.78)),
        linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    color: var(--sb-text);
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--sb-header-h));
    position: fixed;
    left: 0;
    top: var(--sb-header-h);
    border-right: 1px solid var(--sb-border);
    box-shadow: 0 24px 60px rgba(32, 24, 14, 0.08);
    z-index: 1000;
    transition: width var(--duration-normal) var(--ease-out),
                background-color var(--duration-normal) var(--ease-out),
                border-color var(--duration-normal) var(--ease-out);
    overflow: hidden;
}

.sidebar::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 180px;
    background:
        radial-gradient(circle at 12% 10%, rgba(255, 194, 102, 0.26), transparent 45%),
        radial-gradient(circle at 88% 0%, rgba(25, 29, 40, 0.08), transparent 40%);
    pointer-events: none;
    opacity: 0.9;
}

[data-theme="dark"] .sidebar {
    background:
        linear-gradient(180deg, rgba(19, 24, 35, 0.92), rgba(15, 23, 36, 0.86)),
        linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0));
    border-right-color: rgba(83, 98, 121, 0.45);
    box-shadow: 0 24px 64px rgba(5, 10, 18, 0.45);
}

[data-theme="dark"] .sidebar::before {
    background:
        radial-gradient(circle at 12% 10%, rgba(255, 158, 44, 0.18), transparent 44%),
        radial-gradient(circle at 88% 0%, rgba(93, 63, 24, 0.18), transparent 40%);
}

.sidebar-header {
    position: relative;
    padding: 12px 14px 10px;
    margin: 8px 10px 6px;
    border: 1px solid rgba(222, 204, 176, 0.52);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 251, 244, 0.9), rgba(255, 248, 240, 0.72));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
    overflow: hidden;
}

.sidebar-header::after {
    content: "";
    position: absolute;
    inset: auto -18px -28px auto;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 170, 59, 0.18), transparent 70%);
    pointer-events: none;
}

[data-theme="dark"] .sidebar-header {
    background: linear-gradient(180deg, rgba(30, 39, 55, 0.86), rgba(17, 24, 39, 0.74));
    border-color: rgba(83, 98, 121, 0.45);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.sidebar-header h2 {
    position: relative;
    z-index: 1;
    font-size: 22px;
    font-weight: 800;
    margin: 0;
    color: #202534;
    letter-spacing: -0.05em;
    font-family: var(--font-display);
}

[data-theme="dark"] .sidebar-header h2 {
    color: #f8fafc;
}

.sidebar-subtitle {
    position: relative;
    z-index: 1;
    margin-top: 4px;
    font-size: 11px;
    color: #7b8798;
    text-transform: uppercase;
    letter-spacing: 0.18em;
}

[data-theme="dark"] .sidebar-subtitle {
    color: #94a3b8;
}

/* 侧边栏导航 */
.sidebar-nav {
    flex: 1;
    padding: 2px 10px 8px;
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.nav-item {
    margin-bottom: 2px;
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--sb-text);
    cursor: pointer;
    transition: background-color 160ms ease, color 160ms ease, transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
    position: relative;
    border-radius: 10px;
    font-weight: 600;
    border: 1px solid transparent;
    background: transparent;
}

.nav-link::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(255, 247, 235, 0.66), rgba(255, 255, 255, 0.22));
    opacity: 0;
    transition: opacity 160ms ease;
    pointer-events: none;
}

/* 悬停效果：微光 + 背景变化 */
.nav-link:hover {
    background: rgba(255, 249, 240, 0.84);
    color: var(--sb-text-strong);
    border-color: rgba(226, 198, 157, 0.52);
    transform: translateX(2px);
    box-shadow: 0 10px 22px rgba(63, 47, 24, 0.06);
}

.nav-link:hover::before {
    opacity: 1;
}

.nav-link:active {
    transform: translateX(0);
}

/* 激活状态 */
.nav-item.active > .nav-link {
    background: linear-gradient(135deg, rgba(255, 243, 224, 0.98), rgba(255, 248, 239, 0.9));
    color: #e57b00;
    border-color: rgba(238, 190, 119, 0.44);
    box-shadow: 0 14px 30px rgba(221, 139, 17, 0.12);
    font-weight: 700;
}

.nav-item.active > .nav-link::after {
    content: "";
    position: absolute;
    left: -2px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 18px;
    border-radius: 999px;
    background: linear-gradient(180deg, #ffaf47, #ef7b00);
    box-shadow: 0 0 18px rgba(239, 123, 0, 0.25);
}

[data-theme="dark"] .nav-item.active > .nav-link {
    background: linear-gradient(135deg, rgba(78, 54, 24, 0.42), rgba(42, 31, 17, 0.3));
    color: #ffb14a;
    border-color: rgba(138, 100, 51, 0.42);
}

/* 图标样式 */
.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    color: currentColor;
}

.nav-icon svg,
.nav-arrow svg,
.sidebar-collapse-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2px;
}

.nav-text {
    flex: 1;
    font-size: 13px;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.nav-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    transition: transform 160ms ease, color 160ms ease;
    color: #98a2b3;
}

.nav-item.has-children.expanded .nav-arrow {
    transform: rotate(180deg);
    color: var(--sb-text-strong);
}

/* 子菜单 - 动效优化 */
.nav-children {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    margin-top: 2px;
    margin-bottom: 6px;
}

/* 连接线 */
.nav-children::before {
    content: '';
    position: absolute;
    left: 16px;
    top: 2px;
    bottom: 2px;
    width: 2px;
    background: linear-gradient(180deg, rgba(225, 197, 153, 0.08), rgba(225, 197, 153, 0.5), rgba(225, 197, 153, 0.08));
    border-radius: 1px;
}

.nav-item.has-children.expanded .nav-children {
    max-height: 600px; /* 足够大以容纳内容 */
}

.nav-child {
    padding: 6px 14px 6px 28px;
    color: var(--sb-text);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 12px;
    position: relative;
    margin-left: 8px;
    margin-right: 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
}

.nav-child:hover {
    color: var(--sb-text-strong);
    background: rgba(255, 249, 240, 0.78);
}

.nav-child.active {
    color: #e57b00;
    background: rgba(255, 243, 224, 0.9);
    font-weight: 700;
}

.nav-child.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--sb-accent);
    box-shadow: none;
}

/* 侧边栏底部 - 用户卡片 */
.sidebar-footer {
    position: relative;
    padding: 8px 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.72));
    border-top: 1px solid var(--sb-border);
    margin-top: auto;
}

.sidebar-footer::before {
    content: "";
    position: absolute;
    inset: 0 12px auto;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(214, 186, 141, 0.6), transparent);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
    padding: 10px;
    border-radius: 16px;
    transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
    border: 1px solid rgba(226, 198, 157, 0.34);
    background: rgba(255, 250, 242, 0.8);
}

.user-info:hover {
    background: rgba(255, 252, 247, 0.95);
    transform: translateY(-1px);
}

.user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(221, 244, 235, 0.95), rgba(255, 245, 227, 0.92));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: #d27b12;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.user-details {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--sb-text-strong);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.02em;
}

.user-role {
    font-size: 12px;
    color: var(--sb-text);
    margin-top: 2px;
}

.btn-logout {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.68);
    color: var(--sb-text);
    border: 1px solid rgba(208, 186, 151, 0.42);
    border-radius: 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-logout::before {
    content: ''; /* Logout Icon placeholder if needed, using text for now */
}

.btn-logout:hover {
    background: rgba(255, 244, 240, 0.96);
    color: #EF4444;
    border-color: rgba(248, 113, 113, 0.34);
    transform: translateY(-1px);
    box-shadow: 0 12px 22px rgba(127, 29, 29, 0.08);
}

.btn-logout:active {
    background: #FEE2E2;
}

.sidebar-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(214, 186, 141, 0.62), transparent);
    margin: 12px 8px;
}

.sidebar-collapse-btn {
    width: 100%;
    margin-top: 10px;
    padding: 11px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px solid rgba(208, 186, 151, 0.42);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.68);
    color: var(--sb-text);
    cursor: pointer;
    transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.sidebar-collapse-btn:hover {
    background: rgba(255, 249, 240, 0.95);
    color: var(--sb-text-strong);
    transform: translateY(-1px);
}

.sidebar-collapse-btn:active {
    background: #F3F4F6;
}

.app-container.sidebar-collapsed .nav-text,
.app-container.sidebar-collapsed .sidebar-subtitle,
.app-container.sidebar-collapsed .sidebar-header h2,
.app-container.sidebar-collapsed .sidebar-collapse-text,
.app-container.sidebar-collapsed .user-details,
.app-container.sidebar-collapsed .btn-logout {
    display: none;
}

.app-container.sidebar-collapsed .nav-link {
    justify-content: center;
    padding: 8px 10px;
}

.app-container.sidebar-collapsed .nav-arrow {
    display: none;
}

/* 主内容区 */
.main-content {
    margin-left: var(--sb-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.main-content::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 8% 0%, rgba(255, 188, 98, 0.16), transparent 24%),
        radial-gradient(circle at 100% 4%, rgba(20, 25, 35, 0.06), transparent 20%);
    pointer-events: none;
    z-index: 0;
}

[data-theme="dark"] .main-content::before {
    background:
        radial-gradient(circle at 8% 0%, rgba(255, 158, 44, 0.12), transparent 24%),
        radial-gradient(circle at 100% 4%, rgba(86, 58, 24, 0.16), transparent 20%);
}

/* 头部样式 */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--sb-header-h);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.6));
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    padding: 0 24px 0 calc(var(--sb-w) + 26px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sb-border);
    box-shadow: 0 12px 36px rgba(39, 32, 20, 0.05);
    z-index: 1100;
    transition: background-color var(--duration-normal) var(--ease-out),
                border-color var(--duration-normal) var(--ease-out);
}

.header::after {
    content: "";
    position: absolute;
    inset: auto 24px 0 calc(var(--sb-w) + 26px);
    height: 1px;
    background: linear-gradient(90deg, rgba(222, 204, 176, 0), rgba(222, 204, 176, 0.7), rgba(222, 204, 176, 0));
}

[data-theme="dark"] .header {
    background: linear-gradient(180deg, rgba(16, 22, 33, 0.76), rgba(16, 22, 33, 0.62));
    border-bottom-color: rgba(83, 98, 121, 0.45);
}

.header h1 {
    font-size: 17px;
    font-weight: 700;
    color: var(--sb-text-strong);
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    background: #f8f9fa;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s ease;
}

.btn-icon:hover {
    background: var(--sb-surface);
    transform: translateY(-2px);
}

/* 主题切换按钮 */
.btn-theme-toggle {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.72);
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
    border: 1px solid rgba(208, 186, 151, 0.44);
    transition: all var(--duration-normal) var(--ease-out);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.64);
}

.btn-theme-toggle:hover {
    background: rgba(255, 248, 240, 0.96);
    color: var(--color-primary);
    border-color: rgba(239, 123, 0, 0.38);
    transform: translateY(-1px) rotate(12deg);
    box-shadow: 0 12px 24px rgba(56, 40, 18, 0.08);
}

.btn-theme-toggle:active {
    transform: rotate(0deg) scale(0.95);
}

.btn-theme-toggle .theme-icon-light,
.btn-theme-toggle .theme-icon-dark {
    position: absolute;
    transition: all var(--duration-normal) var(--ease-bounce);
}

.btn-theme-toggle .theme-icon-light {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.btn-theme-toggle .theme-icon-dark {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

[data-theme="dark"] .btn-theme-toggle .theme-icon-light {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

[data-theme="dark"] .btn-theme-toggle .theme-icon-dark {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* 页面内容区 */
.page-content {
    flex: 1;
    overflow-y: auto;
    padding: calc(var(--sb-header-h) + 20px) 24px 96px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0)),
        var(--bg-grid),
        linear-gradient(180deg, #f7f2ea 0%, #f2f5f8 100%);
    background-attachment: fixed;
    transition: background-color var(--duration-normal) var(--ease-out);
    position: relative;
    z-index: 1;
}

.page-content::before {
    content: "";
    position: fixed;
    inset: var(--sb-header-h) 0 0 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 18% 0%, rgba(255, 194, 102, 0.1), transparent 18%),
        radial-gradient(circle at 88% 14%, rgba(37, 44, 58, 0.05), transparent 20%);
    z-index: 0;
}

[data-theme="dark"] .page-content {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)),
        var(--bg-grid),
        linear-gradient(180deg, #101827 0%, #0b1220 100%);
}

[data-theme="dark"] .page-content::before {
    background:
        radial-gradient(circle at 18% 0%, rgba(255, 158, 44, 0.08), transparent 18%),
        radial-gradient(circle at 88% 14%, rgba(78, 53, 22, 0.14), transparent 20%);
}

.home-catalog-page {
    padding-bottom: 0;
}

/* ==================== 应用骨架响应式 ==================== */

@media (max-width: 1400px) {
    .sidebar {
        width: 250px;
    }

    .main-content {
        margin-left: 250px;
    }

    .header {
        padding: 20px 30px;
    }

    .page-content {
        padding: 20px 30px;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        min-height: 100vh;
    }

    .sidebar {
        width: 100%;
        position: relative;
        height: auto;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        min-width: 0;
        height: auto;
        min-height: 100vh;
    }

    .header {
        padding: 0 20px;
    }

    .header::after {
        inset: auto 20px 0 20px;
    }

    .header h1 {
        font-size: 18px;
    }

    .page-content {
        padding: calc(var(--sb-header-h) + 15px) 20px 132px;
    }

    .toolbar {
        flex-wrap: wrap;
    }

    .search-box input {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .page-content,
    .home-catalog-page {
        padding-bottom: 132px;
    }
}
