/* Single Ranking Tables - Frontend Styles */

.single-ranking-table {
  width: 100%;
  position: relative;
}

/* 筛选栏固定，不随表格滚动 */
.single-rt-controls {
  position: relative;
  z-index: 10;
  background: #fff;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 15px;
  justify-content: flex-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;
}

/* 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;
}

.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: 600;
  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;
}

.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: #f0f0f1;
  color: #333;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem !important;
  transition: all 0.2s ease;
}

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

.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-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;
}

.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: none;
}

/* 第一列左侧固定边框 */
.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;
}

/* 第一列右侧固定边框 */
.single-rt-table tbody tr td:nth-child(1)::after {
  content: '';
  position: absolute;
  top: 0;
  right: 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: 60px;
  min-width: 60px;
}

/* 第一列 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: none;
}

/* 第一列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右侧固定边框 */
.single-rt-table thead th:nth-child(1)::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 2px;
  background-color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

/* 第二列（通常是名称列）- Sticky */
.single-rt-table tbody tr td:nth-child(2) {
  position: sticky;
  left: 60px;
  z-index: 20;
  background-color: white;
  border-left: none;
  border-right: 2px solid #dee2e6;
}

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

/* 确保奇数行的 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;
}

/* 响应式调整 - 移动设备 */
@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;
}

/* 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;
}

/* 链接按钮样式 */
.single-rt-link-btn {
  display: inline-block;
  padding: 3px 8px;
  background-color: #0073aa;
  color: white !important;
  text-decoration: none !important;
  border-radius: 3px;
  font-size: 0.8rem !important;
  line-height: 1.2;
  transition: background-color 0.2s ease;
  vertical-align: middle;
}

.single-rt-link-btn:hover {
  background-color: #005a87;
  color: white !important;
  text-decoration: none !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;
}

/* 确保 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: 600;
}

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

/* 大学排名徽标图片优化 */
.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: 6px 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;
  -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;
}

/* 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;
}
