/**
 * layout.css - Dashboard 布局样式（含完整响应式适配）
 * Mobile-first 设计：默认移动端，@media 逐步增强
 */

/* ============================================
   1. 基础变量 & 通用规则
   ============================================ */

.app-container {
    display: flex;
    height: calc(100vh - 56px);
    position: relative;
}

body {
    overflow: hidden;
}

/* ============================================
   2. 顶部固定导航栏（所有屏幕尺寸可见）
   ============================================ */

.top-nav-fixed {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: linear-gradient(135deg, #141414 0%, #1a1a1a 50%, #111111 100%);
    border-bottom: 1px solid rgba(74, 222, 128, 0.15);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1001;
}

.top-nav-fixed .nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 600;
    font-size: 17px;
    min-width: 0;
}

.top-nav-fixed .brand-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-nav-fixed .nav-links {
    display: flex;
    gap: 4px;
}

.top-nav-fixed .nav-link {
    padding: 8px 14px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
    min-height: 40px;
    display: flex;
    align-items: center;
}

.top-nav-fixed .nav-link:hover {
    background: rgba(74, 222, 128, 0.08);
    color: rgba(74, 222, 128, 0.9);
}

.top-nav-fixed .nav-link.active {
    background: rgba(74, 222, 128, 0.12);
    color: #4ADE80;
}

.top-nav-fixed .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 18px;
    height: 3px;
    background: #4ADE80;
    border-radius: 2px;
}

.top-nav-fixed .nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-nav-fixed .nav-icon-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.top-nav-fixed .nav-icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.top-nav-fixed .user-info {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #fff;
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    min-height: 40px;
}

.top-nav-fixed .user-info:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* 汉堡菜单按钮（移动端显示） */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

.hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.hamburger-btn svg {
    width: 24px;
    height: 24px;
}

/* ============================================
   3. 侧边栏
   ============================================ */

.sidebar {
    width: var(--sidebar-width, 260px);
    height: 100%;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
    flex-shrink: 0;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed, 60px);
}

.sidebar-header {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    position: relative;
}

/* 遮罩层（移动端） */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* 收起状态 */
.sidebar.collapsed .logo-text,
.sidebar.collapsed .tree-label,
.sidebar.collapsed .tree-arrow,
.sidebar.collapsed .user-details {
    display: none;
}

.sidebar.collapsed .tree-item {
    justify-content: center;
    padding: 12px 8px;
}

.sidebar.collapsed .tree-item-header {
    justify-content: center;
}

.sidebar.collapsed .tree-icon {
    display: block !important;
    width: 24px;
    height: 24px;
}

.sidebar.collapsed .tree-children {
    display: none !important;
}

.sidebar.collapsed .tree-item[data-module="settings"]::before {
    content: '⚙️';
    font-size: 20px;
}

.sidebar.collapsed .tree-item[data-module="home"] .tree-icon {
    display: block !important;
}

/* 侧边栏关闭按钮（移动端） */
.sidebar-close-btn {
    display: none;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    min-width: 40px;
    min-height: 40px;
    font-size: 20px;
}

.sidebar-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* 树状导航 */
.tree-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
}

.tree-group {
    margin-bottom: 4px;
}

.tree-item {
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.tree-item:hover {
    background: var(--bg-hover);
}

.tree-item.active {
    background: rgba(74, 222, 128, 0.1);
}

.tree-item.active .tree-label {
    color: var(--accent);
}

.tree-item-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    gap: 10px;
    width: 100%;
}

.tree-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.tree-item.active .tree-icon {
    color: var(--accent);
}

.tree-label {
    font-size: 14px;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-arrow {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.tree-group.expanded .tree-arrow {
    transform: rotate(90deg);
}

.tree-children {
    padding-left: 16px;
    display: none;
}

.tree-group.expanded .tree-children {
    display: block;
}

/* 侧边栏底部 */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #000;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   4. 主内容区
   ============================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.topbar {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    flex-shrink: 0;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-card);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.topbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.topbar-btn svg {
    width: 18px;
    height: 18px;
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    -webkit-overflow-scrolling: touch;
}

/* ============================================
   5. 响应式适配
   ============================================ */

/* --- Mobile (< 768px) --- */
@media (max-width: 767px) {
    /* 顶部导航 */
    .top-nav-fixed {
        height: 48px;
        padding: 0 12px;
    }

    .top-nav-fixed .nav-brand {
        font-size: 15px;
        gap: 6px;
    }

    .top-nav-fixed .nav-links {
        gap: 2px;
    }

    .top-nav-fixed .nav-link {
        padding: 6px 8px;
        font-size: 12px;
        min-height: 36px;
    }

    .top-nav-fixed .nav-icon-btn {
        padding: 6px;
        min-width: 36px;
        min-height: 36px;
        font-size: 16px;
    }

    .top-nav-fixed .user-info {
        font-size: 13px;
        padding: 4px 8px;
        min-height: 36px;
    }

    /* 汉堡菜单 */
    .hamburger-btn {
        display: flex;
    }

    .sidebar-close-btn {
        display: flex;
    }

    /* 侧边栏 → overlay 模式 */
    .app-container {
        height: calc(100vh - 48px);
        margin-top: 48px;
    }

    .sidebar {
        position: fixed;
        top: 48px;
        left: 0;
        bottom: 0;
        z-index: 999;
        transform: translateX(-100%);
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3);
        width: 280px !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        display: none; /* 移动端不需要折叠模式 */
    }

    /* 主内容 */
    .main-content {
        width: 100%;
    }

    .topbar {
        height: 48px;
        padding: 0 16px;
    }

    .page-title {
        font-size: 18px;
    }

    .topbar-btn {
        width: 36px;
        height: 36px;
    }

    .content {
        padding: 16px;
    }

    /* 遮罩层 */
    .sidebar-overlay {
        display: block;
    }

    /* 模块内容适配 */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }

    .module-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .module-header h2 {
        font-size: 20px;
    }
}

/* --- 极小屏 (< 400px) --- */
@media (max-width: 399px) {
    .top-nav-fixed .nav-link {
        padding: 6px 5px;
        font-size: 11px;
    }

    .top-nav-fixed .nav-link .nav-link-text {
        display: none;
    }

    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    .stat-card {
        padding: 16px;
    }

    .content {
        padding: 12px;
    }

    .topbar-btn {
        width: 32px;
        height: 32px;
    }

    .topbar-btn svg {
        width: 16px;
        height: 16px;
    }
}

/* --- Tablet (768px - 1024px) --- */
@media (min-width: 768px) and (max-width: 1024px) {
    .app-container {
        height: calc(100vh - 56px);
        margin-top: 56px;
    }

    .sidebar {
        width: 220px !important;
    }

    .sidebar.collapsed {
        width: 60px !important;
    }

    .content {
        padding: 20px;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* --- Desktop (> 1024px) --- */
@media (min-width: 1025px) {
    .app-container {
        height: calc(100vh - 56px);
        margin-top: 56px;
    }

    .sidebar {
        width: var(--sidebar-width, 260px);
    }
}
/* 强制桌面端布局 */
@media (min-width: 768px) {
    body {
        min-width: 768px;
    }
    
    .app-container {
        min-width: 768px;
    }
    
    .main-content {
        min-width: 500px;
    }
    
    .sidebar {
        display: flex !important;
        width: 260px !important;
    }
}

/* 内容区域最小宽度 */
.content {
    min-width: 500px;
    padding: 24px;
}

/* 卡片网格 */
.data-cards-row,
.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

/* ============================================
   2026 Polish Layer - 布局质感优化
   ============================================ */
.top-nav-fixed {
    background: rgba(7, 11, 9, 0.78);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border-bottom: 1px solid rgba(74, 222, 128, 0.18);
    box-shadow: 0 10px 34px rgba(0,0,0,0.28);
}

.top-nav-fixed .nav-link,
.top-nav-fixed .nav-icon-btn,
.top-nav-fixed .user-info {
    border: 1px solid transparent;
}

.top-nav-fixed .nav-link:hover,
.top-nav-fixed .nav-icon-btn:hover,
.top-nav-fixed .user-info:hover {
    background: rgba(74, 222, 128, 0.10);
    border-color: rgba(74, 222, 128, 0.16);
}

.sidebar {
    background: rgba(7, 12, 9, 0.78);
    backdrop-filter: blur(20px) saturate(145%);
    -webkit-backdrop-filter: blur(20px) saturate(145%);
    border-right: 1px solid rgba(74, 222, 128, 0.14);
    box-shadow: 16px 0 46px rgba(0,0,0,0.22);
}

.sidebar-header,
.sidebar-footer {
    border-color: rgba(255,255,255,0.07);
}

.tree-nav {
    padding: 12px 10px;
}

.tree-item {
    border-radius: 13px;
    margin: 3px 0;
    border: 1px solid transparent;
}

.tree-item:hover {
    background: rgba(255,255,255,0.045);
    border-color: rgba(255,255,255,0.07);
    transform: translateX(2px);
}

.tree-item.active {
    background: linear-gradient(135deg, rgba(74,222,128,0.18), rgba(74,222,128,0.07));
    border-color: rgba(74,222,128,0.24);
    box-shadow: inset 3px 0 0 rgba(74,222,128,0.9), 0 10px 28px rgba(74,222,128,0.08);
}

.main-content {
    background: transparent;
}

.topbar {
    background: rgba(5, 8, 7, 0.48);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.content {
    padding: 28px;
    scroll-behavior: smooth;
}

.content::-webkit-scrollbar,
.tree-nav::-webkit-scrollbar {
    width: 8px;
}

.content::-webkit-scrollbar-thumb,
.tree-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.14);
    border-radius: 999px;
}

.content::-webkit-scrollbar-thumb:hover,
.tree-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(74,222,128,0.34);
}
