/* 基础样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f8fafc;
  --text: #111827;
  --muted: #6b7280;
  --card: #ffffff;
  --border: #e5e7eb;
  --primary: #3b82f6;
  --primary-hover: #1d4ed8;
  --row-alt: #fafafa;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --card: #111827;
  --border: #374151;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --row-alt: #0b1220;
}

body {
  padding: 8px;
  min-height: 100vh;
  display: flex;
  /* justify-content: center; */
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
}

/* 夜间模式 */
:root[data-theme="dark"] body {
  background: #0f172a;
  color: #e5e7eb;
}

:root[data-theme="dark"] .selected {
  background-color: #1f2937;
  color: #e5e7eb;
  border-color: #374151;
}
:root[data-theme="dark"] .options {
  background-color: #1f2937;
  color: #e5e7eb;
  border-color: #374151;
  box-shadow: 0 4px 6px rgba(0,0,0,0.4);
}
:root[data-theme="dark"] .option {
  background-color: #1f2937;
  color: #e5e7eb;
}
:root[data-theme="dark"] .option:hover {
  background-color: #374151;
}
:root[data-theme="dark"] .arrow {
  fill: #9ca3af;
}

:root[data-theme="dark"] .table-data {
  background-color: #111827;
}
:root[data-theme="dark"] .table-data thead {
  background-color: #1f2937;
  position: sticky;
  position: -webkit-sticky;
  top: 0;
  z-index: 11;
}
:root[data-theme="dark"] .table-data th {
  color: #e5e7eb;
  border-bottom-color: #374151;
  background-color: #1f2937; /* 深色背景下吸顶背景 */
  box-shadow: 0 2px 0 rgba(255,255,255,0.06);
}
:root[data-theme="dark"] .table-data td {
  color: #d1d5db;
  border-bottom-color: #374151;
}
:root[data-theme="dark"] .table-data tbody tr:hover {
  background-color: #1f2937;
}

:root[data-theme="dark"] .button-primary {
  background-color: #2563eb;
}
:root[data-theme="dark"] .button-primary:hover {
  background-color: #1d4ed8;
}
:root[data-theme="dark"] .button-secondary {
  background-color: #4b5563;
}
:root[data-theme="dark"] .button-tertiary {
  background-color: #374151;
  color: #e5e7eb;
}
:root[data-theme="dark"] .button-tertiary:hover {
  background-color: #4b5563;
}

.select {
  margin: 0 auto;
  width: fit-content;
  cursor: pointer;
  position: relative;
  transition: 300ms;
  color: white;
  overflow: visible; /* 修改为visible，确保下拉选项可以显示 */
  /* font-size: 22px; */
}

.selected {
  background-color: #fff;
  padding: 6px 36px 6px 12px; /* 右侧为箭头预留空间，避免与居中文本重叠 */
  margin-bottom: 0; /* 移除底部边距 */
  border-radius: 5px;
  position: relative;
  z-index: 100000;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 320px;
  height: 50px;
  font-size: 22px;
  color: #111;
  border: 1px solid #e5e7eb;
}

.arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  height: 10px;
  transform: translateY(-50%) rotate(-90deg);
  width: 25px;
  fill: #6b7280;
  z-index: 100000;
  transition: 300ms;
}

.options {
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  padding: 5px;
  background-color: #fff;
  position: absolute; /* 改为绝对定位，覆盖在页面上 */
  top: 100%; /* 定位在selected元素下方 */
  left: 0;
  width: 100%; /* 与selected元素同宽 */
  max-height: 200px; /* 限制最大高度 */
  overflow-y: auto; /* 内容过多时显示滚动条 */
  opacity: 0;
  visibility: hidden; /* 使用visibility替代opacity，实现真正的隐藏 */
  transition: opacity 0.3s, visibility 0.3s; /* 添加visibility过渡 */
  z-index: 99999; /* 确保下拉选项显示在其他内容之上 */
  margin-top: 5px; /* 与selected元素保持一点间距 */
  transform-origin: top center; /* 设置变换原点 */
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
  color: #111;
  border: 1px solid #e5e7eb;
}

/* 仅在 .select.open 时展开 */
/* 移除 hover/focus 自动展开，避免一直保持下拉状态 */

/* 确保下拉选项在点击时也能显示 */
.select.open > .options {
  opacity: 1;
  visibility: visible;
}

.select.open > .selected .arrow {
  transform: translateY(-50%) rotate(0deg);
}

.option {
  border-radius: 5px;
  padding: 5px;
  transition: 300ms;
  background-color: #fff;
  width: 100%;

  font-size: 15px;
  text-align: center;
  color: #111;
}
.option:hover {
  background-color: #f3f4f6;
}

.options input[type="radio"] {
  display: none;
}

.options label {
  display: block;
  width: 100%;
  text-align: center;
  color: #111;
}
.options label::before {
  content: attr(data-txt);
}

.options input[type="radio"]:checked + label {
  display: none;
}

.options input[type="radio"]#all:checked + label {
  display: none;
}

/* 统一选中文本居中显示 */
.selected-text {
  flex: 1 1 auto;
  width: 100%;
  text-align: center;
}

/* 表格容器样式 */
.table-container {
  width: 100%;
  margin: 0 auto;
  margin-top: 2vh;
  overflow-x: auto; /* 水平滚动支持 */
  /* 让页面滚动，而不是容器内部滚动，便于表头相对窗口吸顶 */
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  position: relative; /* 使粘性定位的参考容器明确 */
  background: var(--card);
}

/* 表格基础样式 */
.table-data {
  width: 100%;
  border-collapse: separate; /* 避免部分浏览器下 sticky 失效 */
  border-spacing: 0; /* 还原无间距效果 */
  table-layout: auto; /* 列宽自适应 */
  background-color: var(--card);
}

/* 表头样式 */
.table-data thead {
  background-color: #f3f4f6; /* 浅灰色背景 */
  position: sticky;
  position: -webkit-sticky; /* Safari/iOS */
  top: 0;
  z-index: 11;
}

/* 表头单元格样式 */
.table-data th {
  padding: 12px 15px;
  text-align: center;
  font-weight: 600;
  color: #374151; /* 深灰色文字 */
  border-bottom: 2px solid #e5e7eb; /* 底部分隔线 */
  white-space: nowrap; /* 防止文字换行 */
  position: sticky;
  position: -webkit-sticky; /* Safari/iOS 兼容 */
  top: 0;
  z-index: 10; /* 避免被内容覆盖 */
  background-color: #f3f4f6; /* 与thead背景一致，确保粘滞时遮盖内容 */
  box-shadow: 0 2px 0 rgba(0,0,0,0.03);
}

/* 表格内容样式 */
.table-data td {
  padding: 12px 15px;
  border-bottom: 1px solid #e5e7eb; /* 底部分隔线 */
  max-width: none;
  color: #4b5563; /* 中灰色文字 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* 条纹行与悬停优化 */
.table-data tbody tr:nth-child(even) {
  background: var(--row-alt);
}
:root[data-theme="dark"] .table-data tbody tr:nth-child(even) {
  background: var(--row-alt);
}
.table-data tbody tr:hover {
  background-color: rgba(59, 130, 246, 0.08); /* primary 淡色 */
}
:root[data-theme="dark"] .table-data tbody tr:hover {
  background-color: rgba(37, 99, 235, 0.15);
}

/* 隐藏第1列(ID)和第2列(发送者) */
.table-data th:nth-child(1),
.table-data td:nth-child(1),
.table-data th:nth-child(2),
.table-data td:nth-child(2) {
  display: none;
}

/* 空状态样式 */
.empty-row td {
  padding: 24px 12px;
}
.empty-text {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
/* 确保空状态单元格不被前两列隐藏规则影响 */
.table-data tr.empty-row td { display: table-cell !important; }

/* 响应式表格 - 小屏幕设备 */
@media (max-width: 768px) {
  .table-container {
    border-radius: 0;
    width: 100%;
  }

  .table-data {
    font-size: 14px; /* 减小字体大小 */
  }

  .table-data th,
  .table-data td {
    padding: 10px 12px; /* 减小内边距 */
  }

  .table-data td:nth-child(2) {
    max-width: 80px;
  }

  /* 下拉在手机上占满一行，文本居中，箭头缩小固定右侧 */
  .select {
    width: 100%;
    max-width: 100%;
    position: sticky; /* 置顶 */
    top: 8px;
    z-index: 9000; /* 高于表格等内容 */
  }
  .selected {
    width: 100%;
    height: 44px;
    font-size: 18px;
    padding: 6px 36px 6px 12px; /* 右侧为箭头预留空间 */
    background-color: #fff;
    color: #111;
    border: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-radius: 10px;
  }
  .selected-text {
    width: 100%;
    text-align: center;
  }
  .arrow {
    right: 12px;
    width: 20px;
    height: 10px;
    fill: #6b7280;
  }
  .options {
    width: 100%;
    background-color: #fff;
    color: #111;
    border: 1px solid #e5e7eb;
  }
  .option {
    font-size: 16px;
    padding: 10px;
    background-color: #fff;
    color: #111;
  }
  body {
    padding: 12px;
  }

  /* 主题按钮与下拉不重叠：把按钮下移并调小尺寸 */
  .icon-button {
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    z-index: 10000;
  }

  /* 分页在手机上垂直堆叠并居中 */
  #pagination {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 8px !important;
    width: 100%;
  }
  #pagination .pager-controls,
  #pagination .pager-meta {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  #pagination .pager-jump {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  #pagination .pager-jump input[type="number"] {
    width: 80px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
  }
  #pagination button { min-width: 96px; height: 36px; }
}

/* 响应式表格 - 更小屏幕设备 */
@media (max-width: 480px) {
  .table-container {
    border: none;
  }

  .table-data th,
  .table-data td {
    padding: 8px 10px; /* 进一步减小内边距 */
    font-size: 13px;
  }

  /* 表头单元格在小屏幕上可能需要换行 */
  .table-data th {
    white-space: normal;
    font-weight: 700;
  }

  .selected {
    height: 42px;
    font-size: 16px;
    padding: 6px 34px 6px 10px;
    background-color: #fff;
    color: #111;
    border: 1px solid #e5e7eb;
  }
  .arrow {
    right: 10px;
    width: 18px;
    fill: #6b7280;
  }
  .option {
    font-size: 15px;
    padding: 9px;
    background-color: #fff;
    color: #111;
  }
  .button-primary,
  .button-secondary,
  .button-tertiary {
    padding: 4px 8px;
    font-size: 13px;
  }

  /* 主题按钮进一步微调位置以免遮挡 */
  .icon-button {
    top: 6px;
    right: 6px;
    width: 34px;
    height: 34px;
  }
}

/* 按钮美化 */
.button-primary,
.button-secondary,
.button-tertiary {
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.05s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.button-primary:active,
.button-secondary:active,
.button-tertiary:active {
  transform: translateY(1px);
}
.button-primary {
  background-color: var(--primary);
  color: white;
}
.button-primary:hover { background-color: var(--primary-hover); }

.button-secondary {
  background-color: #6b7280;
  color: white;
}
.button-secondary:hover { background-color: #4b5563; }

.button-tertiary {
  background-color: #e5e7eb;
  color: #374151;
}
.button-tertiary:hover { background-color: #d1d5db; }
:root[data-theme="dark"] .button-tertiary { background-color: #374151; color: #e5e7eb; }
:root[data-theme="dark"] .button-tertiary:hover { background-color: #4b5563; }

/* 分页样式（通用） */
#pagination {
  color: #374151;
}
#pagination span {
  color: inherit;
}
#pagination select {
  background-color: #fff;
  color: #111827;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px 8px;
}

/* 夜间模式下分页颜色覆盖 */
:root[data-theme="dark"] #pagination,
:root[data-theme="dark"] #pagination span {
  color: #e5e7eb !important;
}
:root[data-theme="dark"] #pagination select {
  background-color: #111827;
  color: #e5e7eb;
  border-color: #374151;
}

/* 顶部主题按钮增强 */
.icon-button {
  position: fixed;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  z-index: 10000;
}
.icon-button:hover { filter: brightness(0.97); }
.icon-button svg { fill: currentColor; }
:root[data-theme="dark"] .icon-button { color: #f9fafb; }

/* 内容点击弹窗 */
.content-popover {
  position: absolute;
  max-width: min(80vw, 600px);
  background: #ffffff;
  color: #111827;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 1000000;
  word-break: break-word;
  white-space: normal;
}
.content-popover .actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
.content-popover .content-text {
  max-height: 50vh;
  overflow: auto;
  line-height: 1.5;
}
.content-popover .icon-only {
  background: transparent;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #4b5563;
}
.content-popover .icon-only:hover {
  background: #f3f4f6;
}
:root[data-theme="dark"] .content-popover .icon-only {
  background: #2d3748; /* 更亮一些以与弹窗背景区分 */
  border-color: #9ca3af; /* 边框对比更强 */
  color: #f9fafb; /* 图标更亮 */
  box-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
:root[data-theme="dark"] .content-popover .icon-only:hover {
  background: #4b5563;
}
.content-popover .icon-only svg { fill: currentColor; width: 16px; height: 16px; }
:root[data-theme="dark"] .content-popover {
  background: #1f2937;
  color: #e5e7eb;
  border-color: #374151;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}

/* 下拉选优化：过渡更顺滑 */
.options {
  transition: opacity 0.25s ease, visibility 0.25s ease;
  border: 1px solid var(--border);
}
.selected { border: 1px solid var(--border); border-radius: 10px; }
.option { border-radius: 8px; }

/* 分页区域微调 */
#pagination { gap: 8px; }
#pagination select {
  background-color: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
}
:root[data-theme="dark"] #pagination select {
  background-color: #111827;
}

/* 选择框尺寸与可见性优化 */
.row-select,
#selectAllCurrentPage {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}
:root[data-theme="dark"] .row-select,
:root[data-theme="dark"] #selectAllCurrentPage {
  accent-color: var(--primary);
}

/* Desktop pagination layout */
@media (min-width: 769px) {
  #pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px !important;
    gap: 16px;
  }
  #pagination > div:first-child {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  #pagination > div:last-child {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  #pagination button {
    min-width: 94px;
    height: 34px;
  }
  #pagination #pageInfo {
    margin: 0 8px;
    color: var(--muted) !important;
    font-size: 14px;
  }
}
