/* === 全局基础 === */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    /* 背景色稍微调亮一点，偏冷色调更护眼 */
    background-color: #f3f4f6; 
    height: 100vh;
    overflow: hidden;
    margin: 0;
}

/* ... 登录页样式保持不变 (或者您想改也可以) ... */
.login-container { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 400px; padding: 2.5rem; border-radius: 12px; background: white; box-shadow: 0 10px 25px rgba(0,0,0,0.08); border-top: 4px solid #0d6efd; }

/* === 主工作台布局 === */
.layout-wrapper { display: flex; width: 100%; height: 100%; }

/* === 1. 新版侧边栏：明亮风格 === */
#sidebar {
    width: 80px; /*稍微宽一点点，呼吸感更强*/
    background: #ffffff; /* 纯白背景 */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
    flex-shrink: 0;
    z-index: 100;
    /* 右侧加一道柔和的分割线，而不是黑乎乎的背景 */
    border-right: 1px solid #e5e7eb;
    box-shadow: 2px 0 10px rgba(0,0,0,0.02);
}

.nav-item {
    width: 56px;
    height: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    
    /* 默认颜色：中性灰 */
    color: #64748b; 
    cursor: pointer;
    margin-bottom: 15px;
    border-radius: 12px; /* 圆角矩形按钮 */
    transition: all 0.2s ease;
}

/* 悬浮和激活状态：变为亮蓝色，背景变浅蓝 */
.nav-item:hover, .nav-item.active {
    color: #0d6efd; /* Bootstrap Primary Blue */
    background-color: #eff6ff; /* 极浅的蓝色背景 */
    transform: translateY(-2px);
}

.nav-icon { font-size: 1.4rem; display: block; margin-bottom: 2px; }
.nav-label { font-size: 0.65rem; font-weight: 500; }

/* === 主体区域 === */
#main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: #f3f4f6; /* 与 Body 背景一致 */
    position: relative;
    overflow: hidden;
}

/* === 2. 新版顶部标签栏：卡片式设计 === */
#tab-bar {
    height: 48px; /* 稍微增高 */
    background: #f3f4f6; /* 背景与网页背景融合，不显突兀 */
    display: flex;
    align-items: flex-end; /* 底部对齐 */
    padding-left: 10px;
    overflow-x: auto;
    flex-shrink: 0;
    /* 去掉底部的分割线，让 Active Tab 与内容区融为一体 */
}

.app-tab {
    padding: 8px 20px;
    margin-right: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    user-select: none;
    transition: all 0.2s;
    
    /* 默认未选中状态：类似文件夹标签 */
    background: #e5e7eb;
    color: #6b7280;
    border-radius: 8px 8px 0 0; /* 上方圆角 */
    border: 1px solid transparent; /* 占位 */
}

.app-tab:hover:not(.active) {
    background: #d1d5db;
    color: #374151;
}

/* 选中状态：纯白，顶部有蓝色高亮条 */
.app-tab.active {
    background: #ffffff;
    color: #0d6efd;
    font-weight: 600;
    /* 顶部高亮条 */
    border-top: 3px solid #0d6efd; 
    /* 只有选中时才有投影，增加立体感 */
    box-shadow: 0 -2px 5px rgba(0,0,0,0.02);
}

.tab-close {
    margin-left: 10px;
    font-size: 0.7rem;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    opacity: 0.6;
}
.tab-close:hover { background: #fee2e2; color: #ef4444; opacity: 1; }

/* === 内容视口 === */
#viewport { 
    flex-grow: 1; 
    position: relative; 
    background: #fff; 
    overflow: hidden; 
    /* 给内容区加一点阴影，强调它是浮在背景上的纸张 */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 10; /* 保证压在 Tab 上方一点点（如果需要做重叠效果） */
}
.app-container { width: 100%; height: 100%; display: none; overflow-y: auto; }
.app-container.active { display: block; animation: fadeIn 0.2s ease-in-out; }

@keyframes fadeIn { from { opacity: 0.95; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* 欢迎页 */
#welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af; /* 浅灰 */
}

/* === 移动端适配 (底部导航) === */
@media (max-width: 768px) {
    .layout-wrapper { flex-direction: column; }
    
    #sidebar {
        width: 100%;
        height: 65px; /* 底部导航稍微高一点 */
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        padding-top: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        border-right: none;
        border-top: 1px solid #e5e7eb; /* 顶部边框 */
        background: rgba(255,255,255,0.95); /* 半透明磨砂感 */
        backdrop-filter: blur(10px);
    }

    .nav-item {
        width: auto; height: auto;
        margin-bottom: 0;
        padding: 8px 15px;
        background-color: transparent !important; /* 移动端不需要背景块，太挤了 */
    }
    
    .nav-item.active {
        color: #0d6efd;
        transform: none; /* 移动端不要位移 */
    }

    #main-content { padding-bottom: 65px; }
    #tab-bar { padding-left: 5px; }
}


/* =========================================
   Step 1 表格响应式优化 (Card View on Mobile)
   ========================================= */

/* 1. 桌面端优化：确保长文本自动换行，不撑破父容器 */
#formula-table-body td {
    white-space: normal !important;  /* 强制允许换行 */
    word-wrap: break-word;           /* 长单词强制断行 */
    word-break: break-word;          /* 防止URL等长字符串撑开 */
    vertical-align: middle;          /* 垂直居中 */
}

/* 2. 移动端优化：表格变卡片 */
@media (max-width: 768px) {
    /* 隐藏表头，卡片模式不需要它 */
    .table-responsive thead {
        display: none;
    }

    /* 将表格行(tr)变成卡片块 */
    .table-responsive tr {
        display: block;
        margin-bottom: 1rem;
        background: #fff;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.02);
        padding: 10px;
    }

    /* 将单元格(td)变成块级元素 */
    .table-responsive td {
        display: flex; /* 使用 Flex 布局方便对齐 */
        justify-content: space-between; /* 左右两端对齐 */
        align-items: center; /* 垂直居中 */
        border: none !important; /* 去掉表格线 */
        padding: 8px 0;
        border-bottom: 1px solid #f3f4f6 !important; /* 改用浅色分割线 */
        text-align: right; /* 内容靠右 */
        font-size: 0.9rem;
    }

    /* 最后一个单元格(操作栏)去掉底边框 */
    .table-responsive td:last-child {
        border-bottom: none !important;
        justify-content: flex-end; /* 按钮靠右 */
        padding-top: 15px;
    }

    /* === 核心魔法：利用 data-label 显示标题 === */
    .table-responsive td::before {
        content: attr(data-label); /* 获取 HTML 里的 data-label 值 */
        font-weight: bold;
        color: #6b7280;
        float: left; /* 靠左显示 */
        text-transform: uppercase;
        font-size: 0.85rem;
        margin-right: 15px;
        text-align: left;
    }

    /* 特殊处理：检索式那一栏 */
    /* 因为检索式很长，在手机上不适合左右排列，改为上下排列 */
    .table-responsive td[data-label="检索式 (Query)"] {
        display: block; /* 变为块级 */
        text-align: left; /* 内容靠左 */
    }
    .table-responsive td[data-label="检索式 (Query)"]::before {
        display: block;
        margin-bottom: 5px; /* 标题和内容分行 */
    }

    /* 操作按钮在手机上稍微大一点，方便点击 */
    .w-100-mobile {
        width: 100%;
        display: flex;
        justify-content: flex-end;
    }
    
    .w-100-mobile .btn {
        flex: 1; /* 按钮均分宽度 */
    }
}


/* =========================================
   文献列表 - 标签系统样式 (Tag System)
   ========================================= */

/* 1. 基础颜色定义 */
.tag-extensive { background-color: #ffc107 !important; } /* 黄色 - 泛读 */
.tag-intensive { background-color: #dc3545 !important; } /* 红色 - 精读 */
.tag-core { background-color: #198754 !important; }      /* 绿色 - 核心模仿 */

/* 2. 圆形色点 (用于表格行内显示) */
.tag-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
    /* 强制显示，防止被隐藏 */
    content: " "; 
}

/* 3. 移动端卡片右上角：竖条色块 (无文字，省空间) */
.tag-bar-vertical {
    display: inline-block;
    width: 6px;
    height: 18px;
    border-radius: 2px;
    margin-left: 4px;
    vertical-align: middle;
}

/* 4. 移动端标签胶囊 (带文字版本，备用) */
.mobile-tag-pill {
    font-size: 0.7rem;
    padding: 2px 6px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    color: #6c757d;
    white-space: nowrap;
    margin-right: 4px;
}

/* 5. 选择区域：矩形色块图例 (用于 Checkbox 文字前) */
.tag-rect-legend {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: middle;
    position: relative;
    top: -1px;
    /* 确保背景色能显示 */
    border: 1px solid rgba(0,0,0,0.1); 
}

/* 表格选中背景微调 */
.table-success.bg-opacity-10 {
    background-color: rgba(25, 135, 84, 0.08) !important;
}


/* =========================================
   筛选按钮交互样式 (Filter Buttons)
   ========================================= */

/* 1. 基础按钮样式 (未选中状态) */
.btn-filter-base {
    background-color: #fff;
    border: 1px solid #e9ecef;
    color: #6c757d;
    transition: all 0.2s;
}
.btn-filter-base:hover {
    background-color: #f8f9fa;
}

/* 2. 选中状态 - 全部 (灰色系) */
.btn-check:checked + .btn-filter-all {
    background-color: #6c757d;
    color: #fff;
    border-color: #6c757d;
}

/* 3. 选中状态 - 泛读 (黄色系) */
.btn-check:checked + .btn-filter-ext {
    background-color: rgba(255, 193, 7, 0.2); /* 浅黄背景 */
    color: #000;
    border-color: #ffc107;
    font-weight: 600;
}

/* 4. 选中状态 - 精读 (红色系) */
.btn-check:checked + .btn-filter-int {
    background-color: rgba(220, 53, 69, 0.15); /* 浅红背景 */
    color: #000;
    border-color: #dc3545;
    font-weight: 600;
}

/* 5. 选中状态 - 模仿 (绿色系) */
.btn-check:checked + .btn-filter-core {
    background-color: rgba(25, 135, 84, 0.15); /* 浅绿背景 */
    color: #000;
    border-color: #198754;
    font-weight: 600;
}

/* 6. 选中状态 - 未分类 (深灰轮廓) */
.btn-check:checked + .btn-filter-none {
    background-color: #e9ecef;
    color: #495057;
    border-color: #adb5bd;
    font-weight: 600;
}

/* =========================================
   移动端底部防遮挡修复 (Mobile Safe Area)
   ========================================= */

@media (max-width: 768px) {
    /* 1. 针对主滚动容器增加底部内边距 */
    /* 假设您的主内容区在 #viewport 或 body 中，或者直接加在 .container-fluid 上 */
    #viewport, .container-fluid, body {
        /* 增加 100px 的底部留白，确保内容能滚到导航栏上方 */
        padding-bottom: 100px !important; 
        
        /* 适配 iPhone X 等全面屏底部的黑条 */
        padding-bottom: calc(100px + env(safe-area-inset-bottom)) !important;
    }

    /* 2. 修复全屏高度计算 */
    /* 如果您之前的布局用了 height: 100vh，改为 100dvh (Dynamic Viewport Height) */
    /* 100dvh 会自动减去浏览器地址栏的高度 */
    html, body, #viewport {
        min-height: 100dvh;
    }
}

/* 7. 选中状态 - 未入库 (优化版：蓝灰色背景 + 白色图标修复) */
.btn-check:checked + .btn-filter-unsaved {
    background-color: #495057; /* 稍微浅一点的深灰色 */
    color: #fff;
    border-color: #495057;
    font-weight: 600;
}

/* 🔥 关键修复：选中时，强制把里面的图标变成白色 (覆盖 text-muted) */
.btn-check:checked + .btn-filter-unsaved i {
    color: #fff !important;
}

/* === 8. 强制重构：已读状态开关 (纯 CSS 绘制版) === */
/* 抛弃 SVG 图片，直接用 CSS 画圆，100% 可见 */

.form-check-input.switch-is-read {
    /* 1. 清除 Bootstrap 默认的背景图 (那个 SVG) */
    background-image: none !important;
    appearance: none !important;
    
    /* 2. 定义轨道 (容器) 样式 */
    position: relative;
    width: 2.8em !important;   /* 稍微宽一点，手感更好 */
    height: 1.5em !important;  /* 高度 */
    border-radius: 1.5em !important;
    border: 1px solid rgba(255, 255, 255, 0.4) !important; /* 边框 */
    background-color: rgba(255, 255, 255, 0.2) !important; /* 未选中：半透明底 */
    cursor: pointer;
    transition: all 0.3s ease;
}

/* 3. 定义圆点 (使用 ::after 伪元素手画一个圆) */
.form-check-input.switch-is-read::after {
    content: '';
    position: absolute;
    top: 0.15em;   /* 居中定位 */
    left: 0.15em;
    width: 1.1em;  /* 圆点大小 */
    height: 1.1em;
    border-radius: 50%;
    background-color: #ffffff; /* 未选中：白球 */
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1); /* 丝滑移动动画 */
    box-shadow: 0 1px 3px rgba(0,0,0,0.2); /* 加一点阴影更有质感 */
}

/* 4. 选中状态 (Checked) */
.form-check-input.switch-is-read:checked {
    background-color: #ffffff !important; /* 轨道变纯白 */
    border-color: #ffffff !important;
}

/* 5. 选中后的圆点变化 */
.form-check-input.switch-is-read:checked::after {
    background-color: #198754 !important; /* 球变绿色 (#198754) */
    transform: translateX(1.3em); /* 向右移动 */
}

/* 6. 去除聚焦时的蓝色光晕 */
.form-check-input.switch-is-read:focus {
    box-shadow: none !important;
    outline: none !important;
}


/* Step 4 精读模块样式 */

/* PC 端 Split Layout */
@media (min-width: 768px) {
    #s4-view-pdf { width: 70%; height: 100%; display: flex !important; }
    #s4-view-notes { flex: 1; height: 100%; display: flex !important; }
}

/* 手机端 Stack Layout */
@media (max-width: 767px) {
    .transition-view {
        width: 100% !important; 
        height: 100%; 
        position: absolute; 
        top: 0; 
        left: 0;
        background: #fff;
        transition: transform 0.3s ease-in-out;
    }
    
    /* 状态切换 */
    .mobile-mode-pdf #s4-view-pdf { transform: translateX(0); z-index: 10; }
    .mobile-mode-pdf #s4-view-notes { transform: translateX(100%); z-index: 5; }
    
    .mobile-mode-notes #s4-view-pdf { transform: translateX(-100%); z-index: 5; }
    .mobile-mode-notes #s4-view-notes { transform: translateX(0); z-index: 10; }
}

/* 辅助样式 */
.writing-card { border-left: 3px solid #0d6efd; background: #f8f9fa; margin-bottom: 8px; padding: 8px; }
.vocab-card { border-left: 3px solid #ffc107; background: #fff; margin-bottom: 8px; padding: 0; }


/* Resizer 样式 */
#s4-resizer:hover {
    background-color: #e9ecef !important; /* 悬停变色 */
    width: 10px !important; /* 稍微变宽 */
}
#s4-resizer:active {
    background-color: #0d6efd !important; /* 拖动时变蓝 */
    cursor: col-resize;
}

/* 覆盖层级修正 */
/* 强制工作台层级极高，覆盖任何侧边栏 */
#intensive-workspace {
    z-index: 99999 !important;
}

/* 鼠标悬停变成主题色 */
.hover-primary:hover {
    color: #0d6efd !important;
    text-decoration: underline !important;
}