/* 全局样式变量 */
:root { 
    --pm-primary: #0071bc; 
    --pm-secondary: #205493; 
    --pm-accent: #f39c12; 
    --bg-gray: #f1f3f5;
    --text-primary: #2d3748;
    --border-light: #e2e8f0;
    --success: #22c55e;
    /* 期刊信息颜色变量 */
    --cas-1-top-q1: #006400; /* 深绿色 */
    --cas-na: #696969; /* 暗灰色 */
    --jcr-na: #696969; /* 暗灰色 */
    --cas-2-q2: #2FA0ED;    /* 蓝色 */
    --cas-3-q3: #EDB12F;    /* 金黄色 */
    --cas-4-q4: #A79878;    /* 浅棕色 */
    --jif-color: #E737C6;   /* 玫红色 */
    --oa-yes: #483FA2;      /* Open Access Yes 背景色 */
    --articles-year: #2563eb;
}

/* 全局重置 & 基础样式 */
* {
    box-sizing: border-box; /* 统一盒模型，解决布局重叠 */
}

body { 
    font-family: 'Inter', -apple-system, sans-serif; 
    background: var(--bg-gray); 
    margin: 0; 
    display: flex; 
    flex-direction: column; 
    height: 100vh;
    color: var(--text-primary);
    box-sizing: border-box;
}

/* 头部样式 */
.header { 
    background: var(--pm-secondary); 
    color: white; 
    padding: 0.8rem 2rem; 
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 主内容区布局 */
.main-content { 
    display: flex; 
    flex: 1; 
    overflow: hidden; 
    padding: 15px; 
    gap: 15px;
}

/* Sidebar 布局重构 - 核心修改 */
.sidebar { 
    width: 380px; /* 适度加宽，避免内容挤压 */
    background: white; 
    border-radius: 8px; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); 
    padding: 24px; /* 增加内边距 */
    display: flex; 
    flex-direction: column;
    gap: 16px; /* 增加元素间距 */
    overflow-y: auto; /* 内容超出时可滚动 */
}

/* 统一sidebar内的表单组样式 */
.form-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px; /* 标签和输入框间距 */
}

.form-group label {
    margin: 0; /* 重置margin */
}

.operator-buttons {
    display: flex;
    gap: 8px;
    margin: 4px 0; /* 调整按钮组间距 */
}

.operator-buttons .btn {
    flex: 1;
    padding: 8px 0; /* 统一按钮高度 */
}

/* 结果面板 */
.results-panel { 
    flex: 1; 
    background: white; 
    border-radius: 8px; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); 
    display: flex; 
    flex-direction: column;
    overflow: hidden;
}

/* 工具栏：核心修改 - 适配HTML结构（count-info + 分页+导出组合容器） */
.toolbar {
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: nowrap; /* 桌面端强制不换行 */
}

/* 新增：分页+导出的统一容器（适配你的HTML新增的pagination-export-wrapper） */
.pagination-export-wrapper {
    display: flex;
    align-items: center;
    gap: 15px; /* 分页和导出组之间的间距 */
    flex: 1;
    /* 关键修改：justify-content 改为 space-between，实现分页居中、导出靠右 */
    justify-content: space-between;
    /* 新增：给容器设置最小宽度，保证布局稳定 */
    min-width: 300px;
    flex-wrap: nowrap; /* 强制同行 */
}

/* 分页容器：适配你的HTML结构，取消flex:1，改为flex-shrink:0防止挤压 */
.pagination-wrap {
    flex-shrink: 0; /* 禁止分页容器被压缩 */
    min-width: 200px; /* 最小宽度，避免挤压 */
    /* 关键：让分页控件在自身容器内居中 */
    display: flex;
    justify-content: center;
    /* 占满剩余空间，实现整体居中 */
    flex: 1;
}

/* 导出按钮组：优化样式，适配HTML结构 */
.export-group {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap; /* 防止按钮换行 */
    flex-shrink: 0; /* 禁止导出组压缩 */
    /* 固定宽度，保证靠右不偏移 */
    min-width: 180px;
}

/* count-info：防止被压缩 */
#count-info {
    flex-shrink: 0; /* 固定宽度，不被挤压 */
}

.builder-row { margin-bottom: 0; } /* 移除旧的margin，改用gap */
label { 
    display: block; 
    font-size: 11px; 
    font-weight: 700; 
    color: #94a3b8; 
    text-transform: uppercase; 
}

/* 表单控件样式 */
select, input, textarea { 
    width: 100%; 
    padding: 10px; 
    border: 1px solid var(--border-light); 
    border-radius: 4px; 
    font-size: 14px;
}

textarea { 
    height: 120px; /* 适度加高文本框 */
    font-family: monospace; 
    border: 2px solid var(--pm-primary); 
    resize: vertical; /* 允许垂直调整大小 */
}

/* 按钮通用样式 */
.btn { 
    cursor: pointer; 
    border: none; 
    border-radius: 4px; 
    font-weight: 600; 
    font-size: 13px; 
    transition: 0.2s;
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    gap: 5px;
}
.btn-primary { 
    background: var(--pm-primary); 
    color: white; 
    padding: 12px 20px; /* 加大按钮内边距 */
    width: 100%; /* 搜索按钮全屏宽 */
}
.btn-outline { 
    background: white; 
    border: 1px solid var(--border-light); 
    padding: 6px 12px; 
}
.btn-outline:hover:not(:disabled) { 
    border-color: var(--pm-primary); 
    color: var(--pm-primary); 
}
.btn-success { 
    background: var(--success); 
    color: white; 
    padding: 6px 15px; 
}
.btn-filter { 
    background: #64748b; 
    color: white; 
    padding: 10px 15px; 
    margin-top: 10px; 
    width: 100%; 
}
.btn-filter:hover { 
    background: #475569; 
}

/* 分页样式 */
.pagination { 
    display: flex; 
    align-items: center; 
    gap: 5px; 
    margin: 0;
}
.page-input { 
    width: 45px; 
    text-align: center; 
    padding: 5px; 
    margin: 0 5px; 
}

/* 结果列表 */
#results-list { 
    flex: 1; 
    overflow-y: auto; 
    padding: 15px; 
    background: #f8fafc; 
}

/* 文章卡片 */
.article-card { 
    background: white; 
    border-radius: 8px; 
    padding: 20px; 
    margin-bottom: 12px; 
    border: 1px solid #edf2f7; 
    transition: 0.2s;
}
.article-card:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 4px 12px rgba(0,0,0,0.05); 
}
.article-title { 
    color: var(--pm-primary); 
    font-size: 16px; 
    font-weight: 700; 
    text-decoration: none; 
    display: block; 
    margin-bottom: 8px; 
}
.article-title:hover { 
    text-decoration: underline; 
}

/* 元信息行 */
.meta-line { 
    font-size: 13px; 
    color: #64748b; 
    margin: 5px 0; 
}

/* 通用标签 */
.tag { 
    background: #e2e8f0; 
    padding: 2px 6px; 
    border-radius: 3px; 
    font-weight: 600; 
    color: #475569; 
}

/* 机构信息盒 */
.aff-box { 
    margin-top: 10px; 
    padding: 10px; 
    background: #f1f5f9; 
    border-left: 3px solid var(--pm-primary); 
    font-size: 12px; 
    border-radius: 0 4px 4px 0;
}

/* 期刊信息样式 */
.journal-info-box {
    margin-top: 8px;
    padding: 8px 12px;
    background: #F0F8FF;
    border-left: 3px solid var(--pm-accent);
    font-size: 12px;
    border-radius: 0 4px 4px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.journal-info-item {
    padding: 2px 8px;
    border-radius: 4px;
    color: white;
    font-weight: 600;
}
.journal-info-label {
    margin-right: 4px;
}

/* 期刊信息颜色类 */
.cas-1, .jcr-q1 { background: var(--cas-1-top-q1); } /* 一区仅保留深绿色，移除top-yes */
.cas-1.top-yes, .jcr-q1.top-yes { background: var(--cas-1-top-q1); } /* 一区Top仍用深绿色 */
.cas-2, .jcr-q2 { background: var(--cas-2-q2); } /* 二区基础蓝色 */
.cas-2.top-yes, .jcr-q2.top-yes { background: var(--cas-2-q2); } /* 二区Top强制蓝色（核心修改） */
.cas-3, .jcr-q3 { background: var(--cas-3-q3); }
.cas-4, .jcr-q4 { background: var(--cas-4-q4); }
.cas-na { background: var(--cas-na); }
.jcr-na { background: var(--jcr-na); }
.jif { background: var(--jif-color); }
.oa-yes { background: var(--oa-yes); } /* Open Access Yes 样式 */

/* 加载动画 */
.spinner {
    width: 18px; 
    height: 18px; 
    border: 2px solid #fff;
    border-bottom-color: transparent; 
    border-radius: 50%;
    display: inline-block; 
    animation: rotation 1s linear infinite;
}
@keyframes rotation { 
    0% { transform: rotate(0deg); } 
    100% { transform: rotate(360deg); } 
}

/* 过滤区域 */
.filter-section {
    margin: 8px 0; /* 调整过滤区域间距 */
    padding: 18px; /* 增加内边距 */
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 10px; /* 过滤区域内元素间距 */
}
.filter-row {
    display: flex;
    gap: 12px; /* 加大过滤输入框间距 */
}

.filter-row > div {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-note {
    font-size: 11px; 
    color: #94a3b8; 
    margin: 0; /* 重置margin */
}

/* 期刊数据加载状态提示 */
.journal-load-status {
    font-size: 11px;
    color: #94a3b8;
    margin: 4px 0; /* 调整间距 */
}

/* 过滤状态显示区域 */
.filter-status {
    margin-top: auto; /* 固定在底部 */
    padding-top: 16px; 
    border-top: 1px solid #eee; 
    font-size: 11px; 
    color: #94a3b8; 
    line-height: 1.4;
}

/* 年份标签样式 */
.articles-year {
    background: #2563eb !important; /* 蓝色主色 */
    color: white !important;        /* 文字白色确保可读性 */
    padding: 3px 8px !important;    /* 内边距统一 */
    border-radius: 4px !important;  /* 圆角和其他标签一致 */
    font-size: 12px !important;     /* 新增：和其他标签字体一致 */
}

#status-tag {
    font-size: 12px;
    background: rgba(255,255,255,0.2);
    padding: 4px 20px; /* 左右内边距保证文字和边框有间距 */
    border-radius: 20px;
    width: fit-content; /* 核心：宽度自适应内容 */
    max-width: 300px; /* 限制最大宽度，避免内容过长撑破布局 */
    text-align: center; /* 文字居中 */
    white-space: nowrap; /* 防止文字换行（可选，保持单行） */
    overflow: hidden; /* 超出最大宽度时隐藏 */
    text-overflow: ellipsis; /* 超出最大宽度显示省略号 */
}

#uni-filter {
    font-size: 12px;    /* 输入框正常文字大小 */
}

/* 核心：设置placeholder字体大小（兼容所有主流浏览器） */
#uni-filter::placeholder {
    font-size: 10px;    /* placeholder字体大小（可自定义，比如13px） */
    color: #999;        /* placeholder文字颜色，可选 */
    font-family: Arial, sans-serif; /* 字体，可选 */
}
/* 兼容Firefox旧版本 */
#uni-filter:-moz-placeholder {
    font-size: 10px;
    color: #999;
}
#uni-filter::-moz-placeholder {
    font-size: 10px;
    color: #999;
}
/* 兼容Safari旧版本 */
#uni-filter:-webkit-input-placeholder {
    font-size: 10px;
    color: #999;
}

#school-filter {
    font-size: 12px;    /* 输入框正常文字大小 */
}

/* 核心：设置placeholder字体大小（兼容所有主流浏览器） */
#school-filter::placeholder {
    font-size: 10px;    /* placeholder字体大小（可自定义，比如13px） */
    color: #999;        /* placeholder文字颜色，可选 */
    font-family: Arial, sans-serif; /* 字体，可选 */
}
/* 兼容Firefox旧版本 */
#school-filter:-moz-placeholder {
    font-size: 10px;
    color: #999;
}
#school-filter::-moz-placeholder {
    font-size: 10px;
    color: #999;
}
/* 兼容Safari旧版本 */
#school-filter:-webkit-input-placeholder {
    font-size: 10px;
    color: #999;
}

/* 移动端响应式适配 - 核心修改 */
@media (max-width: 768px) {
  /* 全局滚动核心：移除所有固定高度和溢出隐藏 */
  body {
    height: auto !important;
    overflow-y: auto !important;
    flex-direction: column;
  }

  /* 主内容区：改为垂直排列，移除溢出隐藏 */
  .main-content {
    flex-direction: column;
    padding: 0;
    gap: 12px;
    overflow: visible !important;
    height: auto !important;
  }

  /* Sidebar：全屏宽，移除固定高度和滚动 */
  .sidebar {
    width: 100%;
    max-height: none !important;
    padding: 16px;
    gap: 12px;
    overflow: visible !important;
    height: auto !important;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  }

  /* 结果面板：全屏宽，移除固定高度和滚动 */
  .results-panel {
    flex: none;
    width: 100%;
    min-height: auto !important;
    overflow: visible !important;
    height: auto !important;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  }

  /* 工具栏：垂直排列，适配移动端 */
  .toolbar {
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-start;
    gap: 10px;
    padding: 16px;
    flex-direction: column;
  }

  /* count-info：占满一行，居中显示 */
  #count-info {
    width: 100%;
    text-align: left;
    font-size: 14px;
  }

  /* 分页+导出容器：重置布局 */
  .pagination-export-wrapper {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 10px;
    padding: 0;
    position: static !important;
  }

  /* 移除占位元素 */
  .pagination-export-wrapper > div:first-child {
    display: none;
  }

  /* 分页组：取消绝对定位，正常流排列 */
  .pagination-group {
    position: static !important;
    transform: none !important;
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
  }

  /* 分页容器：适配移动端 */
  .pagination-wrap {
    flex: none;
    width: auto;
    justify-content: flex-start;
    min-width: auto;
  }

  /* 导出按钮组：占满一行，调整样式 */
  .export-group {
    flex: none;
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
    min-width: auto;
  }

  /* 过滤行：垂直排列 */
  .filter-row {
    flex-direction: column;
    gap: 10px;
  }

  /* 分页控件：适配移动端尺寸 */
  .pagination {
    justify-content: flex-start;
    width: auto;
  }

  /* 期刊信息盒：适配移动端 */
  .journal-info-box {
    padding: 8px;
    font-size: 11px;
    border-left: none;
    background: transparent;
  }

  /* 元信息行：优化换行 */
  .meta-line {
    font-size: 13px;
    word-break: break-all;
  }

  /* 按钮样式：适配移动端 */
  .btn {
    font-size: 14px;
    padding: 12px;
    border-radius: 8px;
  }

  /* 输入框：适配移动端 */
  input, select, textarea {
    font-size: 15px;
    padding: 12px;
    border-radius: 8px;
  }

  /* 过滤状态：调整间距 */
  .filter-status {
    margin-top: 16px;
    padding-top: 12px;
    font-size: 12px;
  }

  /* 头部：适配移动端 */
  .header {
    padding: 14px 20px;
    font-size: 16px;
  }

  /* 状态标签：缩小 */
  #status-tag {
    font-size: 12px;
    padding: 4px 12px;
  }

  /* 结果列表：移除滚动，适配全局滚动 */
  #results-list {
    padding: 16px;
    background: transparent;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  /* 结果列表默认提示：适配移动端 */
  #results-list > div {
    padding: 5px 10px !important;
    color: #aaa !important;
  }

  /* 操作按钮组：适配移动端 */
  .operator-buttons {
    gap: 8px;
    margin-bottom: 14px;
  }

  /* 过滤按钮：适配移动端 */
  .btn-filter {
    padding: 14px;
    font-size: 15px;
  }
}

/* 小屏手机额外适配（480px以下） */
@media (max-width: 480px) {
  .operator-buttons {
    flex-direction: column; /* 逻辑运算符按钮垂直排列 */
  }

  .journal-info-item {
    padding: 3px 6px;
    font-size: 11px;
  }

  /* 导出组：小屏允许按钮换行 */
  .export-group {
    flex-wrap: wrap;
    gap: 8px;
  }

  .export-group .btn {
    flex: 1;
    min-width: 120px;
  }

  /* 分页按钮：更小尺寸 */
  .pagination button {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .page-input {
    width: 40px;
    height: 28px;
  }
}

/* ============================================== */
/* 桌面端：左右面板独立滚动 —— 鼠标在哪滚哪，互不干扰 */
/* ============================================== */
@media (min-width: 769px) {
  /* 1. 布局核心：确保高度受限，才能触发溢出滚动 */
  .main-content {
    height: calc(100vh - 110px) !important;
    overflow: hidden !important;
    display: flex !important;
  }

  /* 2. 左侧和右侧列表：必须有独立高度和 overflow */
  .sidebar, #results-list {
    height: 100% !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    
    /* 兼容 Firefox 的滚动条隐藏/显示 */
    scrollbar-color: transparent transparent;
    transition: scrollbar-color 0.3s ease;
  }

  /* 3. Chrome/Edge/Safari 滚动条基础设置 */
  .sidebar::-webkit-scrollbar, 
  #results-list::-webkit-scrollbar {
    width: 6px; /* 滚动条宽度 */
    background-color: transparent; /* 轨道背景设为透明 */
  }

  /* 4. 关键：默认状态下，滑块设为完全透明 (视觉上完全隐藏) */
  .sidebar::-webkit-scrollbar-thumb, 
  #results-list::-webkit-scrollbar-thumb {
    background-color: transparent; 
    border-radius: 10px;
    /* 注意：webkit 伪元素不支持 transition 动画，颜色切换会比较直接 */
  }

  /* 5. 关键：当鼠标悬停在容器上时，给滑块上色 */
  .sidebar:hover::-webkit-scrollbar-thumb, 
  #results-list:hover::-webkit-scrollbar-thumb {
    background-color: #cbd5e1; /* 鼠标放回来后的滚动条颜色 */
  }

  /* 6. 针对 Firefox 的悬停处理 */
  .sidebar:hover, #results-list:hover {
    scrollbar-color: #cbd5e1 transparent;
  }

  /* 7. 右侧面板结构修正：确保 results-list 能正确滚动 */
  .results-panel {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    flex: 1;
  }

  #results-list {
    flex: 1 !important;
    min-height: 0; /* 必须加这一行，否则 flex 容器内的滚动会失效 */
  }
}