/* Single Ranking Tables - Frontend Styles */

.single-ranking-table {
  width: 100%;
  position: relative;
  padding: 0 24px 24px;
  box-sizing: border-box;
}

.soso-ranking-title {
  padding: 24px;
  box-sizing: border-box;
}

.soso-ranking-table-notes {
  padding: 0 24px;
  box-sizing: border-box;
  color: #2c3e50;
  line-height: 1.7;
  font-size: 0.8rem !important;
}

.soso-ranking-table-notes.below-table {
  margin: 16px 0 28px;
}

.soso-notes-title {
  font-size: 1rem !important;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex !important;
  align-items: center;
  gap: 8px;
  color: #1a252f;
}

.soso-notes-title .dashicons {
  font-size: 1.2rem;
  width: 1.2rem;
  height: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 767px) {
  .single-ranking-table {
    padding: 0 14px 18px;
  }

  .soso-ranking-title {
    padding: 0 14px;
  }

  .soso-ranking-table-notes {
    padding: 0 14px;
  }
}

/* 筛选栏固定，不随表格滚动 */
.single-rt-controls {
  position: relative;
  z-index: 10;
  background: #fff;
  padding: 20px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 350px) minmax(0, 1fr);
  column-gap: 15px;
  row-gap: 15px;
  align-items: start;
  justify-content: start;
  border: 1px solid #eee;
  border-radius: 8px;
}

.single-rt-search-container {
  display: flex;
  gap: 5px;
  flex: 0 0 auto;
  width: 350px;
  max-width: 350px;
  grid-column: 1;
}

.single-rt-filters {
  display: flex;
  flex: 1 1 auto;
  min-width: 240px;
  width: 100%;
  min-width: 0;
  grid-column: 2;
  justify-content: flex-end;
}

.single-rt-filters form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 15px;
  margin: 0;
  width: 100%;
  justify-content: flex-end;
}

@media (max-width: 900px) {
  .single-rt-controls {
    grid-template-columns: 1fr;
  }

  .single-rt-search-container,
  .single-rt-filters {
    grid-column: 1;
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 767px) {
  .single-rt-filters form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    width: 100%;
  }

  .rt-filter-group {
    width: 100%;
    min-width: 0;
  }

  .rt-filter-group select {
    width: 100%;
    min-width: 0;
  }

  .single-rt-reset-btn {
    width: 100%;
  }
}

/* Font size unification */
.single-rt-controls input,
.single-rt-controls select,
.single-rt-controls button,
.single-rt-controls label,
.single-rt-controls .rt-filter-btn {
  font-size: 0.8rem !important;
}

.single-rt-search-input::placeholder {
  font-size: 0.8rem !important;
  font-weight: 500;
}

.single-rt-search-input {
  padding: 0 10px !important;
  width: 100%;
  height: 38px;
  line-height: 38px;
  border: 1px solid #e0e0e0;
  border-radius: 6px !important;
  box-sizing: border-box;
  color: #333;
  transition: all 0.2s ease;
  background-color: #fff;
}

.single-rt-search-input:focus {
  border-color: steelblue;
  box-shadow: 0 0 0 3px rgba(70, 130, 180, 0.15);
  outline: none;
}

.single-rt-search-input::placeholder {
  color: #aaa;
  opacity: 1;
}

.single-rt-search-btn {
  padding: 0 20px !important;
  height: 38px;
  background: steelblue;
  color: white;
  border: none;
  border-radius: 6px !important;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  line-height: 1;
  font-weight: 500;
  transition: background-color 0.2s ease;
}

.single-rt-search-btn:hover {
  background-color: #36648b;
}

.rt-filter-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  flex: 0 1 auto;
  min-width: 140px;
}

.rt-filter-group label {
  font-size: 0.9rem;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 2px;
  letter-spacing: 0.02em;
}

.rt-filter-group select {
  border-radius: 6px !important;
  border: 1px solid #e0e0e0;
  padding: 0 30px 0 12px;
  height: 38px;
  background-color: #fff;
  min-width: 140px;
  color: #333;
  transition: all 0.2s ease;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8.825L1.175 4 2.238 2.938 6 6.7l3.763-3.763L10.825 4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  font-weight: 500;
}

.rt-filter-group select:focus {
  border-color: steelblue;
  box-shadow: 0 0 0 3px rgba(70, 130, 180, 0.15);
  outline: none;
}

.rt-filter-buttons {
  display: inline-flex;
  gap: 5px;
  flex-wrap: wrap;
}

.rt-filter-btn {
  padding: 4px 12px;
  background: steelblue;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem !important;
  font-weight: 500;
  transition: all 0.2s ease;
}

.rt-filter-btn:hover {
  background: #36648b;
}

.rt-filter-btn.active {
  background: steelblue;
  color: white;
}

/* 表格容器可滚动 */
.single-ranking-table > table,
.single-ranking-table > .table-wrapper {
  overflow-x: auto;
  display: block;
  max-height: 100vh;
}

.single-ranking .comments-area {
  width: 100%;
  max-width: none;
  margin: 24px 0 32px;
  padding: 24px 20px;
  box-sizing: border-box;
}

.single-rt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem !important;
}

/* 覆盖Elementor字体大小设置 */
.single-rt-table,
.single-rt-table * {
  font-size: 0.8rem !important;
}

.single-rt-table thead {
  background-color: steelblue;
  color: white;
}

.single-rt-table th {
  padding: 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

/* 第二列宽度设置 */
.single-rt-table th:nth-child(2),
.single-rt-table td:nth-child(2) {
  min-width: 150px;
}

/* 手机端第二列宽度 */
@media (max-width: 767px) {
  .single-rt-table th:nth-child(2),
  .single-rt-table td:nth-child(2) {
    min-width: 100px;
  }
}

/* 在桌面端（屏幕宽度大于768px），标题不换行 */
@media (min-width: 768px) {
  .single-rt-table th {
    white-space: nowrap;
  }
}

.single-rt-table td {
  padding: 8px 10px;
  border: 1px solid #dee2e6;
  vertical-align: middle;
  font-weight: 500;
}

.single-rt-table th {
  vertical-align: middle;
  border: 1px solid #dee2e6; /* Ensure header also has consistent borders if needed, though sticky header overrides bottom */
}

.single-rt-table tbody tr:nth-child(odd) td {
  background-color: #f8f9fa;
}

.single-rt-table tbody tr:nth-child(even) td {
  background-color: white;
}

.single-rt-table tbody tr:hover {
  background-color: #eee;
}

.single-rt-error {
  color: #999;
  padding: 10px;
  border: 1px solid #ddd;
  background: #f9f9f9;
  margin: 10px 0;
}

/* ============================================
   Sticky Header 和 Sticky 前两列功能
   ============================================ */

/* Sticky Header - 表头固定在顶部 */
.single-rt-table thead {
  position: sticky;
  top: 0;
  z-index: 30;
  background-color: steelblue;
}

.single-rt-table thead th {
  position: sticky;
  top: 0;
  z-index: 30;
  background-color: steelblue;
  color: white;
  border-bottom: 2px solid #dee2e6;
}

/* 第一列（序号列）- Sticky */
.single-rt-table tbody tr td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 20;
  background-color: white;
  border-left: none;
  border-right: 1px solid #dee2e6;
}

/* 第一列左侧固定边框 */
.single-rt-table tbody tr td:nth-child(1)::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 2px;
  background-color: #dee2e6;
  pointer-events: none;
}

/* 第一列右侧固定边框 */

/* 固定第一列宽度，避免与第二列 sticky offset 不一致产生空隙 */
.single-rt-table thead th:nth-child(1),
.single-rt-table tbody td:nth-child(1) {
  width: 48px;
  min-width: 48px;
  white-space: nowrap;
}

/* 第一列 header - Sticky */
.single-rt-table thead th:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 40;
  background-color: steelblue;
  border-left: none;
  border-right: 1px solid rgba(255, 255, 255, 0.25);
}

/* 第一列header左侧固定边框 */
.single-rt-table thead th:nth-child(1)::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 2px;
  background-color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

/* 第一列header右侧固定边框 */

/* 第二列（通常是名称列）- Sticky */
.single-rt-table tbody tr td:nth-child(2) {
  position: sticky;
  left: 48px;
  z-index: 20;
  background-color: white;
  border-left: none;
  border-right: 1px solid #dee2e6;
  box-shadow: -1px 0 0 #fff, inset 1px 0 0 #dee2e6, inset -2px 0 0 #dee2e6, 2px 0 5px -2px rgba(0, 0, 0, 0.1);
}

/* 第二列 header - Sticky */
.single-rt-table thead th:nth-child(2) {
  position: sticky;
  left: 48px;
  z-index: 40;
  background-color: steelblue;
  border-left: none;
  border-right: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: -1px 0 0 steelblue, inset 1px 0 0 rgba(255, 255, 255, 0.3), inset -2px 0 0 rgba(255, 255, 255, 0.3), 2px 0 5px -2px rgba(0, 0, 0, 0.1);
}

/* 确保奇数行的 sticky 列保持正确的背景色 */
.single-rt-table tbody tr:nth-child(odd) td:nth-child(1),
.single-rt-table tbody tr:nth-child(odd) td:nth-child(2) {
  background-color: #f8f9fa;
}

/* 确保偶数行的 sticky 列保持正确的背景色 */
.single-rt-table tbody tr:nth-child(even) td:nth-child(1),
.single-rt-table tbody tr:nth-child(even) td:nth-child(2) {
  background-color: white;
}

/* Hover 效果 - 所有列高亮 (包括sticky列) */
.single-rt-table tbody tr:hover td,
.single-rt-table tbody tr:hover td:nth-child(1),
.single-rt-table tbody tr:hover td:nth-child(2) {
  background-color: #eee;
}
/* sticky 第二列右边框视觉固定 */
.single-rt-table tbody tr:nth-child(odd) td:nth-child(2) {
  box-shadow: -1px 0 0 #f8f9fa, inset 1px 0 0 #dee2e6, inset -2px 0 0 #dee2e6, 2px 0 5px -2px rgba(0, 0, 0, 0.1);
}

.single-rt-table tbody tr:nth-child(even) td:nth-child(2) {
  box-shadow: -1px 0 0 #fff, inset 1px 0 0 #dee2e6, inset -2px 0 0 #dee2e6, 2px 0 5px -2px rgba(0, 0, 0, 0.1);
}

.single-rt-table tbody tr:hover td:nth-child(2) {
  box-shadow: -1px 0 0 #eee, inset 1px 0 0 #dee2e6, inset -2px 0 0 #dee2e6, 2px 0 5px -2px rgba(0, 0, 0, 0.1);
}

/* 响应式调整 - 移动设备 */
@media screen and (max-width: 768px) {
  /* 在小屏幕上可以选择禁用第二列 sticky */
  /* 取消注释下面的代码来禁用小屏幕上的第二列 sticky */
  /*
  .single-rt-table tbody tr td:nth-child(2),
  .single-rt-table thead th:nth-child(2) {
    position: static;
    left: auto;
    box-shadow: none;
  }
  */
}

/* 兼容性 - 不支持 position: sticky 的浏览器 */
@supports not (position: sticky) {
  .single-rt-table thead,
  .single-rt-table thead th,
  .single-rt-table tbody tr td:nth-child(1),
  .single-rt-table tbody tr td:nth-child(2) {
    position: relative;
  }
}

/* ============================================
   其他表格特定样式
   ============================================ */

/* 大学排名表格特定样式 */
/* 国家列 - 至少能容纳5个字的国家名称 */
.single-rt-table th[data-column="country"],
.single-rt-table td[data-column="country"] {
  min-width: 120px;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .single-rt-table th[data-column="religion"],
  .single-rt-table td[data-column="religion"] {
    white-space: nowrap;
  }
}

/* QS、USNews全国、USNews全球、THE排名列 - 宽度相同 */
.single-rt-table th[data-column="qs_ranking"],
.single-rt-table td[data-column="qs_ranking"],
.single-rt-table th[data-column="un_ranking"],
.single-rt-table td[data-column="un_ranking"],
.single-rt-table th[data-column="ug_ranking"],
.single-rt-table td[data-column="ug_ranking"],
.single-rt-table th[data-column="times_ranking"],
.single-rt-table td[data-column="times_ranking"] {
  width: 90px;
  min-width: 90px;
}

/* university-ranking-table 数据列居中 */
.single-ranking-table[data-table-key="university-ranking-table"] .single-rt-table th:nth-child(n+3),
.single-ranking-table[data-table-key="university-ranking-table"] .single-rt-table td:nth-child(n+3),
.single-ranking-table[data-table-key="university_placement_ranking"] .single-rt-table th:nth-child(n+3),
.single-ranking-table[data-table-key="university_placement_ranking"] .single-rt-table td:nth-child(n+3) {
  text-align: center !important;
}

/* 链接按钮样式 */
.single-rt-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: none !important;
  border: none !important;
  color: steelblue !important;
  text-decoration: none !important;
  border-radius: 0;
  font-size: 0;
  line-height: 1;
  transition: color 0.2s ease;
  vertical-align: middle;
  white-space: nowrap;
}

.single-rt-link-btn::before {
  content: "\1F517";
  font-size: 16px;
  line-height: 1;
}

.single-rt-link-btn:hover {
  color: #36648b !important;
  text-decoration: none !important;
}

.single-ranking-table .single-rt-controls .rt-filter-btn,
.single-ranking-table .single-rt-controls .single-rt-search-btn {
  background-color: steelblue !important;
  border-color: steelblue !important;
  color: #fff !important;
}

.single-ranking-table .single-rt-controls .rt-filter-btn:hover,
.single-ranking-table .single-rt-controls .single-rt-search-btn:hover {
  background-color: #36648b !important;
  border-color: #36648b !important;
}

/* 表格内链接样式 - 第二列（学校名称列）的链接 */
.single-rt-table td a {
  color: steelblue;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s ease;
}

.single-rt-table td a:hover {
  color: goldenrod;
  text-decoration: underline;
}

.single-rt-table tbody td:nth-child(2),
.single-rt-table tbody td:nth-child(2) a {
  color: steelblue;
  font-weight: 500;
}

/* 确保 sticky 第二列的链接在不同背景色下都清晰可见 */
.single-rt-table tbody tr:nth-child(odd) td:nth-child(2) a,
.single-rt-table tbody tr:nth-child(even) td:nth-child(2) a {
  color: steelblue;
  font-weight: 500;
}

.single-rt-table tbody tr:hover td:nth-child(2) a {
  color: goldenrod;
}

.rt-school-short-name {
  font-size: 0.7rem;
  color: #999;
  font-weight: 400;
  margin-top: 2px;
  line-height: 1.2;
}

/* 大学排名徽标图片优化 */
.single-rt-table .university-badges-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.single-rt-table .university-badge-img {
  width: auto;
  height: 24px;
  object-fit: contain;
}

/* 重置按钮样式（提高优先级，避免被 Elementor 全局 button 样式覆盖） */
.single-rt-reset-btn,
.single-ranking-table .single-rt-reset-btn,
.single-ranking-table button.single-rt-reset-btn {
  padding: 0 12px;
  border: 1px solid #999 !important;
  border-radius: 4px;
  background: #999 !important;
  color: #fff !important;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.3s ease;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-appearance: none;
  appearance: none;
}

.single-rt-reset-btn:hover,
.single-ranking-table .single-rt-reset-btn:hover,
.single-ranking-table button.single-rt-reset-btn:hover {
  background: #777 !important;
  border-color: #777 !important;
  color: #fff !important;
}

.rt-delta-up {
  color: #2e7d32;
  font-weight: 600;
}

.rt-delta-down {
  color: #c62828;
  font-weight: 600;
}

/* Loading 动画 */
.single-rt-loading {
  position: fixed; /* 改为 fixed 确保在长表格滚动时始终在屏幕中央可见 */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  z-index: 99999; /* 极高层级，确保在所有元素之上 */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 180px;
}

.single-rt-loading:before {
  content: "";
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid steelblue;
  border-radius: 50%;
  animation: rt-spin 1s linear infinite;
  margin-bottom: 10px;
}

.single-rt-loading:after {
  content: "正在加载数据...";
  color: steelblue;
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
  width: auto;
  height: auto;
  border: none;
  animation: none;
}

/* 初始加载时的 Loading 遮罩 */
.single-rt-initial-loading {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 60px 20px;
  background: #f9f9f9;
  border: 1px solid #eee;
  border-radius: 8px;
  margin: 10px 0;
  color: steelblue;
  font-weight: 600;
  min-height: 200px;
}

.single-rt-initial-loading:before {
  content: "";
  display: block;
  width: 48px;
  height: 48px;
  border: 4px solid #e0e0e0;
  border-top: 4px solid steelblue;
  border-radius: 50%;
  animation: rt-spin 1s linear infinite;
  margin-bottom: 15px;
}

.single-rt-initial-loading:after {
  content: "正在准备数据，请稍候...";
  font-size: 1rem;
  animation: none;
  margin: 0;
  border: none;
  width: auto;
  height: auto;
}

/* 初始隐藏表格内容，等待JS渐进式渲染 */
.single-rt-table.rt-init-hidden tbody {
  display: none;
}

@keyframes rt-spin {
  to { transform: rotate(360deg); }
}

/* AJAX刷新时的半透明效果 */
.single-ranking-table.rt-loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

/* AI / 报告入口按钮（学校名称下方） */
.rt-ai-actions {
  margin-top: 6px;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}

.rt-ai-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  appearance: none;
  border: 1px solid #d0d7de;
  background: #fff;
  color: #111827;
  font-size: 12px;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}

@media (max-width: 420px) {
  .rt-ai-actions {
    flex-wrap: wrap;
    white-space: normal;
  }
}

.rt-ai-actions button:hover {
  background: #f6f8fa;
}

.rt-ai-actions .soso-sp-report-btn {
  border-color: steelblue;
  color: steelblue;
}

.rt-ai-actions .soso-sp-report-btn:hover {
  background: rgba(70, 130, 180, 0.08);
}

/* AI Summary Modal */
#soso-ai-summary-modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 99999;
  background: rgba(0, 0, 0, 0.55);
}

#soso-ai-summary-modal.active {
  display: block;
}

#soso-ai-summary-modal .soso-ai-summary-modal__dialog {
  background: #fff;
  width: min(880px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  margin: 14px auto;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

#soso-ai-summary-modal .soso-ai-summary-modal__header {
  position: sticky;
  top: 0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #eee;
}

#soso-ai-summary-modal .soso-ai-summary-modal__title {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
}

#soso-ai-summary-modal .soso-ai-summary-modal__close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}

#soso-ai-summary-modal .soso-ai-summary-modal__body {
  padding: 0;
}
