/**
 * 移动端布局深度优化 - v6.0 终极全页面适配
 * 1. 解决二级窗口 (Modal) 挤压与溢出
 * 2. 保持 v5.0 的流式布局稳定性
 * 3. 解决按钮组错乱
 */

/* ==================== 1. 全局导航 (可折叠设计) ==================== */
.global-nav-drawer {
    position: fixed; top: 0; left: -280px; width: 260px; height: 100vh;
    background: #fff; z-index: 2000; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 15px rgba(0,0,0,0.05); display: flex; flex-direction: column;
    border-right: 1px solid #edf2f7;
}

/* 激活状态 (展开) */
.global-nav-drawer.active { left: 0 !important; }

/* PC 端布局调整 */
@media screen and (min-width: 769px) {
    /* 默认折叠状态下，页面内容不偏移 */
    body {
        padding-left: 0;
        transition: padding-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background-color: #f7fafc !important;
    }

    /* 当导航栏展开时，内容向右偏移 */
    body.nav-expanded {
        padding-left: 260px !important;
    }

    .container, #app {
        max-width: 1400px !important;
        margin: 0 auto !important;
        padding: 30px !important;
    }

    /* PC 端始终显示切换按钮，用于控制折叠 */
    .mobile-menu-toggle {
        display: flex !important;
        position: fixed !important;
        top: 20px !important;
        left: 20px !important;
        z-index: 2001 !important;
        background: rgba(102, 126, 234, 0.9) !important;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* 展开时按钮随之移动 */
    body.nav-expanded .mobile-menu-toggle {
        left: 280px !important;
    }
    
    /* 展开时隐藏遮罩，PC端不需要遮罩 */
    body.nav-expanded .sidebar-overlay {
        display: none !important;
    }
}

.global-nav-drawer.active { left: 0 !important; }

.nav-drawer-header {
    padding: 20px 15px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff; display: flex; justify-content: space-between; align-items: center;
}

.nav-menu-list { flex: 1; overflow-y: auto; padding: 15px 0; }

.nav-menu-category {
    padding: 15px 20px 8px; font-size: 11px; color: #a0aec0;
    text-transform: uppercase; font-weight: 700; letter-spacing: 1px;
}

.nav-menu-item {
    padding: 12px 20px; display: flex; align-items: center; gap: 12px;
    color: #4a5568; text-decoration: none; font-size: 14px;
    transition: all 0.2s ease;
}

.nav-menu-item:hover {
    background: #f7fafc;
    color: #667eea;
    padding-left: 25px;
}

.nav-menu-item.active {
    background: #ebf4ff;
    color: #667eea;
    font-weight: 600;
    border-left: 4px solid #667eea;
}

/* ==================== 2. 移动端核心适配 (768px 以下) ==================== */
@media screen and (max-width: 768px) {
    body { margin: 0; padding: 0; background: #f0f2f5; font-size: 13px; min-height: 100vh; }
    .container { width: 100% !important; max-width: 100% !important; padding: 10px !important; margin: 0; }
    .header { padding: 15px !important; margin-bottom: 10px !important; border-radius: 0; }
    .header p { display: none; }

    /* 通用容器间距优化 - 解决“白色空腔”感 */
    .section { padding: 12px !important; margin-bottom: 12px !important; border-radius: 8px !important; }

    /* --- 布局稳定性修复 --- */
    .layout { display: block !important; width: 100% !important; }
    .sidebar, .main-content { width: 100% !important; position: relative !important; display: block !important; height: auto !important; }

    /* 局部账号选择器 - 折叠版 */
    .sidebar { background: #fff !important; border: 1px solid #e2e8f0 !important; border-radius: 8px !important; margin-bottom: 12px !important; }
    .sidebar-header { padding: 12px 15px !important; display: flex !important; justify-content: space-between !important; align-items: center !important; }
    .sidebar-content { display: none; padding: 10px !important; border-top: 1px solid #f0f4f8; }
    .sidebar.expanded .sidebar-content { display: block !important; }

    /* 统计面板 3 列 */
    #stats-panel > div, .stats-panel, .stats-panel-grid {
        display: grid !important; grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important; padding: 0 !important; margin-bottom: 15px !important;
    }
    .stat-item, .stats-card { padding: 10px 5px !important; background: #fff !important; border-radius: 8px !important; }
    .stat-value { font-size: 1.2em !important; font-weight: bold; }
    .stat-label { font-size: 11px !important; color: #718096; }

    /* 主视图 Tabs 修复 */
    .view-tabs { display: flex !important; border-bottom: 2px solid #edf2f7 !important; margin-bottom: 15px !important; overflow-x: auto; }
    .view-tab-btn { flex: 1 !important; padding: 12px 5px !important; border: none !important; background: transparent !important; color: #718096 !important; border-bottom: 2px solid transparent !important; font-size: 14px !important; white-space: nowrap !important; }
    .view-tab-btn.active { color: #667eea !important; border-bottom-color: #667eea !important; font-weight: bold !important; }

    /* --- 3. 二级窗口 (Modal) 深度适配 --- */
    .modal { padding: 0 !important; display: none; align-items: flex-start !important; justify-content: center; }
    .modal-content {
        width: 100% !important; height: 100vh !important; max-height: 100vh !important;
        margin: 0 !important; border-radius: 0 !important; border: none !important;
        display: flex; flex-direction: column; overflow: hidden;
    }
    .modal-header { padding: 15px !important; background: #f8fafc; border-bottom: 1px solid #eee; }
    .modal-body { flex: 1; overflow-y: auto; padding: 15px !important; }
    .modal-footer { padding: 15px !important; background: #f8fafc; border-top: 1px solid #eee; }

    /* 弹窗内元素防溢出 */
    .modal-body * { max-width: 100% !important; word-break: break-all !important; }
    textarea.form-control { width: 100% !important; font-size: 16px !important; }

    /* 核心修复：列表项 (filtered-comment-card) 防挤压逻辑 */
    .filtered-comment-card {
        display: flex !important;
        flex-direction: column !important; /* 强制垂直排列，文字在上按钮在下 */
        padding: 12px 0 !important;
        border-bottom: 1px solid #f0f4f8 !important;
        width: 100% !important;
    }
    
    .filtered-comment-card .comment-author {
        flex: none !important;
        width: 100% !important;
        margin-bottom: 8px !important;
    }
    
    .filtered-comment-card .comment-content {
        width: 100% !important;
        margin: 0 0 12px 0 !important;
        padding-left: 0 !important;
        line-height: 1.6 !important;
        font-size: 14px !important;
    }

    /* 按钮组网格化 (解决截图中的错位与并排挤压问题) */
    .batch-actions, .comment-actions, .modal-body .batch-actions, .filtered-comment-card .comment-actions {
        display: grid !important; grid-template-columns: 1fr 1fr !important;
        gap: 8px !important; width: 100% !important; padding: 10px 0 !important;
    }
    .batch-actions .btn, .comment-actions .btn { width: 100% !important; margin: 0 !important; }

    /* 特殊弹窗内的大按钮 (如拉黑并删除) */
    .btn-primary-danger { grid-column: span 2 !important; }

    /* 编辑器弹窗内部比例 */
    #richTextModal > div > div:nth-child(3) { display: flex !important; flex-direction: column !important; }
    #markdown-input, #html-preview { height: 35vh !important; margin-bottom: 10px; }

    /* --- 4. 其他细节优化 --- */
    .btn, button, .dropdown-toggle { height: 36px !important; padding: 0 10px !important; font-size: 13px !important; }
    
    /* 胶囊标签横排 - 强制不换行并支持平滑滚动 */
    .category-tabs, .hot-period-tabs { 
        display: flex !important; 
        overflow-x: auto !important; 
        overflow-y: hidden !important;
        gap: 8px !important; 
        padding: 5px 5px 12px 5px !important; 
        white-space: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* 隐藏滚动条 */
    }
    .category-tabs::-webkit-scrollbar, .hot-period-tabs::-webkit-scrollbar { display: none; }

    .tab-btn, .period-btn { 
        flex: 0 0 auto !important; 
        height: 34px !important; 
        border-radius: 17px !important; 
        padding: 0 16px !important; 
        margin: 0 !important;
        font-size: 13px !important;
        border: 1px solid #e2e8f0 !important;
    }

    /* 热榜抓取面板重构 */
    .category-hot-panel { 
        flex-direction: column !important; 
        align-items: stretch !important; 
        padding: 12px !important;
        gap: 15px !important;
    }
    .category-hot-panel .panel-left { width: 100% !important; }
    
    .category-hot-panel .panel-left > div:last-child {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 10px !important;
        margin-top: 10px !important;
    }

    /* 输入框样式美化 */
    input[type="number"], input[type="text"], select {
        height: 38px !important;
        border: 1px solid #cbd5e0 !important;
        border-radius: 6px !important;
        padding: 0 10px !important;
        background-color: #f8fafc !important;
        font-size: 14px !important;
    }

    /* 热榜统计面板网格化 */
    .stats-panel-hot {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        width: 100% !important;
        justify-content: stretch !important;
    }
    .stats-panel-hot .stats-card {
        margin: 0 !important;
        background: #f8fafc !important;
        border: 1px solid #edf2f7 !important;
        text-align: center !important;
        padding: 8px !important;
    }
    .stats-panel-hot .stats-card h3 { font-size: 11px !important; margin-bottom: 4px !important; }
    .stats-panel-hot .stats-card p { font-size: 1.4em !important; }

    /* 表格全宽滑动 */
    #questionTableContainer, #trafficTableContainer, #comment-list-container, .comment-table-container { margin: 0 -10px !important; width: calc(100% + 20px) !important; overflow-x: auto !important; background: #fff; }
    table { min-width: 800px !important; }

    /* 账号列表移动端强制单列布局 */
    #accountsList {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* 账号卡片移动端优化 */
    .account-card {
        padding: 15px !important;
    }

    .account-card .account-header {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .account-card .status-badge {
        padding: 4px 10px !important;
        font-size: 0.8em !important;
    }

    /* Cookie状态区域移动端优化 */
    .cookie-status-section {
        padding: 10px !important;
    }

    .cookie-status-badges {
        gap: 6px !important;
    }

    .cookie-badge {
        font-size: 0.75em !important;
        padding: 3px 8px !important;
    }

    .cookie-actions {
        gap: 6px !important;
    }

    .cookie-actions .btn {
        padding: 6px 12px !important;
        font-size: 0.8em !important;
    }

    /* 账号操作按钮移动端优化 */
    .account-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    .account-actions .btn {
        padding: 10px 8px !important;
        font-size: 0.85em !important;
        width: 100% !important;
    }

    /* 隐藏每行显示数量控制（移动端无意义） */
    .layout-control {
        display: none !important;
    }

    /* 全局悬浮按钮 - 左上角固定且最高层级 */
    .mobile-menu-toggle {
        display: flex !important; position: fixed !important; top: 15px !important; left: 15px !important;
        width: 44px !important; height: 44px !important; z-index: 99999 !important;
        background: rgba(102, 126, 234, 0.9) !important; color: #fff !important;
        border-radius: 8px !important; box-shadow: 0 4px 15px rgba(0,0,0,0.2) !important;
    }
    .header h1 { padding-left: 50px !important; }
}

/* 白色空腔补丁 */
#view-questions, #commentTableContainer, #articleTableContainer { height: auto !important; min-height: 0 !important; }
