:root {
  --brand: #6a7dff;
  --brand-2: #8aa2ff;
  --success: #2ecc71;
  --warning: #f1c40f;
  --error: #e74c3c;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c0f;
  --surface: #111218;
  --surface-2: #161821;
  --text: #e6e8ef;
  --muted: #9aa3b2;
  --border: #232634;
  --accent: #1e2433;
  --hover: rgba(255,255,255,0.05);
  --primary: #6a7dff;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --text: #0b0c0f;
  --muted: #596273;
  --border: #e5e7ee;
  --accent: #eef1f7;
  --hover: rgba(0,0,0,0.04);
  --primary: #6a7dff;
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; }
}
@media (prefers-color-scheme: light) {
  :root { color-scheme: light; }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  overflow-x: hidden;
}

.app-root {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-auto-rows: minmax(0, 1fr);
  min-height: 100vh;
  overflow-x: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  min-width: 220px;
  max-width: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  transition: transform 220ms ease, box-shadow 220ms ease, width 200ms ease;
}

.sidebar__header {
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand__logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(100% 100% at 50% 0%, var(--brand-2), var(--brand));
  color: #0b0c0f;
  font-weight: 800;
  border-radius: 8px;
}

.brand__name {
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  padding: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
}

.nav-section {
  margin: 12px 0 8px;
}

.nav-section__title {
  padding: 6px 8px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 10px;
  color: var(--text);
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item:hover {
  background: var(--accent);
}

.nav-item.active {
  background: rgba(106, 125, 255, 0.12);
  border-color: rgba(106, 125, 255, 0.28);
}

.nav-item__icon {
  width: 18px;
  text-align: center;
}

.sidebar__footer {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid var(--border);
}

.collapse-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.collapse-btn:hover {
  border-color: rgba(106,125,255,0.38);
}

.collapse-btn:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(106,125,255,0.25);
}

.main {
  display: grid;
  grid-template-rows: 56px 1fr;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 12px;
  min-width: 0;
}

.topbar__title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
}

.topbar__actions {
  flex-shrink: 0;
}

.search {
  width: 220px;
  max-width: 100%;
  padding: 8px 10px;
  color: var(--text);
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.search:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(106,125,255,0.25);
}

.content {
  padding: 18px 20px 36px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.grid {
  display: grid;
  /* 更灵活的栅格：自动填充列并在窄屏时折叠为更少列 */
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.grid > .col-4 { grid-column: span 4; }
.grid > .col-6 { grid-column: span 6; }
.grid > .col-12 { grid-column: span 12; }

/* 表格与工具栏 */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: auto; }

/* 侧边栏打开时的小屏遮罩层 */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 50;
  opacity: 0;
  transition: opacity 180ms ease;
}
.sidebar-backdrop.visible { opacity: 1; }
.table-toolbar { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); justify-content: space-between; align-items: center; }
.input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--accent); color: var(--text); transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease; }
.select {
  /* Make selects/buttons clearly look like dropdowns (not text inputs)
     - add space on the right for an arrow
     - use pointer cursor and disable text selection
     - render a chevron on the right (works for buttons and most selects via background image)
     - keep focus/hover behaviour consistent with other controls */
  position: relative;
  padding: 8px 36px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent) no-repeat right 10px center;
  background-size: 14px;
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
  cursor: pointer;
  user-select: none;
  -webkit-appearance: none;
  appearance: none;
  /* inline SVG chevron (fill/stroke color encoded) */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
}

/* Buttons that use .select should align text to left (they are pseudo-selects) */
button.select { text-align: left; }

/* Ensure keyboard focus is still visible */
.select:focus-visible { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(106,125,255,0.25); outline: none; }

/* For actual <select> elements, hide native caret and keep arrow shown via background-image */
select.select {
  padding-right: 36px;
  background-color: var(--accent);
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.btn { padding: 8px 12px; border: 1px solid var(--border); background: var(--accent); color: var(--text); border-radius: 8px; cursor: pointer; transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease; }
.btn.primary { border-color: rgba(106,125,255,0.28); background: rgba(106,125,255,0.12); }

/* 批量操作按钮样式 */
.btn[data-action="batchDelete"] { border-color: rgba(231, 76, 60, 0.28); background: rgba(231, 76, 60, 0.12); color: var(--error); }
.btn[data-action="batchDelete"]:hover { border-color: rgba(231, 76, 60, 0.38); background: rgba(231, 76, 60, 0.18); }

/* 复选框样式 */
input[type="checkbox"] { 
  width: 16px; 
  height: 16px; 
  border: 1px solid var(--border); 
  border-radius: 3px; 
  background: var(--accent); 
  cursor: pointer; 
  transition: border-color 120ms ease, background 120ms ease;
}

input[type="checkbox"]:checked { 
  background: var(--brand); 
  border-color: var(--brand); 
}

input[type="checkbox"]:indeterminate { 
  background: var(--brand); 
  border-color: var(--brand); 
}

input[type="checkbox"]:hover { 
  border-color: rgba(106,125,255,0.38); 
}

.input:focus-visible, .select:focus-visible { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(106,125,255,0.25); outline: none; }
.btn:hover { border-color: rgba(106,125,255,0.38); }
.btn:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(106,125,255,0.25); }

/* 拖拽上传 */
.dropzone { border: 2px dashed var(--border); background: var(--accent); color: var(--muted); padding: 20px; border-radius: 12px; text-align: center; transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease; }
.dropzone.hover { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(106,125,255,0.25); color: var(--text); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--muted); font-weight: 600; }
.table tbody tr { transition: background 120ms ease; }
.table tbody tr:hover { background: var(--accent); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--accent); color: var(--text); font-size: 12px; }
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; }

/* 中等屏幕优化 (平板横屏) */
@media (max-width: 1200px) and (min-width: 961px) {
  .app-root { grid-template-columns: 240px 1fr; }
  .search { width: 180px; }
}

/* 平板和小屏笔记本 */
@media (max-width: 960px) and (min-width: 769px) {
  .app-root { grid-template-columns: 72px 1fr; }
  .brand__name { display: none; }
  .nav-section__title { display: none; }
  .nav-item { justify-content: center; padding: 10px 8px; }
  .nav-item__icon { margin: 0; }
  .nav-item span:not(.nav-item__icon) { display: none; }
  .search { width: 160px; }
  .sidebar { 
    min-width: 72px; 
    max-width: 72px;
    position: static;
  }
  .sidebar__footer { padding: 8px; }
  .collapse-btn { font-size: 12px; padding: 8px; }
}

/* 临界区域：强制隐藏所有滚动条，防止闪现 */
@media (max-width: 960px) {
  body, html, .app-root {
    overflow-x: hidden !important;
  }
  .sidebar {
    overflow-y: hidden !important;
    overflow-x: hidden !important;
  }
}

/* 769px时预先准备，防止滚动条闪现 */
@media (max-width: 769px) {
  .sidebar {
    overflow: hidden !important;
  }
}

/* 中等手机屏幕 - 768px以下立即切换到移动布局 */
@media (max-width: 768px) {
  .app-root { grid-template-columns: 1fr; }
  .search { width: 140px; }
  .topbar { padding: 10px 12px; }
  .topbar__title { font-size: 13px; }
  .content { padding: 12px 14px 24px; }
  
  /* 侧边栏覆盖层 */
  .sidebar {
    position: fixed !important;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px !important;
    min-width: 280px !important;
    max-width: 280px !important;
    transform: translateX(-100%) !important;
    z-index: 60;
    visibility: visible !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }
  
  /* 防止布局变化时出现水平滚动条 */
  body, html, .app-root {
    overflow-x: hidden !important;
  }

  /* 恢复侧边栏内容在移动端的显示 */
  .sidebar .brand__name { display: block !important; }
  .sidebar .nav-section__title { display: block !important; }
  .sidebar .nav-item { justify-content: flex-start !important; padding: 10px !important; }
  .sidebar .nav-item span:not(.nav-item__icon) { display: inline !important; }
  .sidebar .nav-item__icon { margin: 0 !important; }

  /* 当侧边栏打开时，滑入并显示阴影 */
  .sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 0 12px 40px rgba(2,6,23,0.35);
  }

  /* 当覆盖模式启用，阻止侧边栏占用文档流 */
  .app-root .main { min-height: 100vh; }
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  animation: fadeIn 0.2s ease forwards;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 800px;
  max-height: 80vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95) translateY(10px);
  animation: slideUp 0.2s ease forwards;
}

/* selectors modal specifics (used by renderBenchmarkChart) */
.selectors-modal {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  pointer-events: none; /* 允许点击穿透到 overlay 和 content */
}

.selectors-modal .modal-overlay {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  opacity: 1;
  animation: none;
  pointer-events: auto; /* overlay 可点击 */
  z-index: 10000;
}

.selectors-modal .modal-content {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 720px;
  max-width: 92%;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2), 0 0 0 1px rgba(255,255,255,0.05);
  z-index: 10001;
  animation: modalSlideIn 0.3s ease-out;
  pointer-events: auto;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -48%) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* 美化滚动条 */
.selectors-modal .modal-content::-webkit-scrollbar {
  width: 8px;
}

.selectors-modal .modal-content::-webkit-scrollbar-track {
  background: transparent;
}

.selectors-modal .modal-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.selectors-modal .modal-content::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* 选择器菜单美化 */
.select {
  transition: all 0.2s ease;
}

.select:hover:not(:disabled) {
  background: var(--hover);
  border-color: var(--primary);
}

.select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 选择器菜单项hover效果的额外样式 */
#scaffoldSelectorMenu label,
#benchmarkSelectorMenu label,
#modelSelectorMenu label,
#excelSelectorMenu label {
  cursor: pointer;
}

#scaffoldSelectorMenu label input[type="checkbox"],
#benchmarkSelectorMenu label input[type="checkbox"],
#modelSelectorMenu label input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary);
}

#excelSelectorMenu label input[type="radio"] {
  cursor: pointer;
  accent-color: var(--primary);
}

.selectors-placeholder { display: none; }

@keyframes fadeIn {
  to { opacity: 1; }
}

@keyframes slideUp {
  to { 
    transform: scale(1) translateY(0);
  }
}

/* 预览按钮特殊样式 */
.btn[data-action="preview"] {
  border-color: rgba(46, 204, 113, 0.28);
  background: rgba(46, 204, 113, 0.12);
  color: var(--success);
}

.btn[data-action="preview"]:hover {
  border-color: rgba(46, 204, 113, 0.38);
  background: rgba(46, 204, 113, 0.18);
}

/* 小屏手机 */
@media (max-width: 720px) {
  .search { display: none; }
  .topbar__title { font-size: 14px; }
  .sidebar .nav-item { justify-content: flex-start !important; padding: 10px !important; }
  .sidebar .nav-item span:not(.nav-item__icon) { display: inline !important; }
  .sidebar .nav-item__icon { margin: 0 !important; }

  /* 当侧边栏打开时，滑入并显示阴影 */
  .sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 0 12px 40px rgba(2,6,23,0.35);
  }

  /* 当覆盖模式启用，阻止侧边栏占用文档流 */
  .app-root .main { min-height: 100vh; }

  .modal-overlay {
    padding: 10px;
  }

  .modal-content {
    max-height: 90vh;
  }
}

/* 小屏补充：让网格可折叠、图片和 iframe 自适应 */
@media (max-width: 720px) {
  /* 将 grid 从 12 列折叠为单列，便于移动端纵向展示 */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* 将常用的 col-* 在小屏时都占满宽度 */
  .grid > .col-4,
  .grid > .col-6,
  .grid > .col-12 {
    grid-column: span 1 !important;
  }

  /* 图片、视频、iframe 等内嵌内容在容器内自适应 */
  img, video, iframe {
    max-width: 100%;
    height: auto;
    display: block;
  }

  /* 使卡片内容在小屏更易读 */
  .card { padding: 12px; }
}


