/* ============================================================
   星屑手帖 · 研究视图样式（实验台账 + 证据链浏览器）
   ------------------------------------------------------------
   只补充 assets/js/research.js 需要的类；
   通用类（.card .btn .btn-ghost .btn-small .filter-input
   .filter-chip .filter-count .empty-state .prose .tag .toast）一律复用
   style.css，这里不重复定义。
   只用 style.css 里已声明的 CSS 变量，深色模式自动生效。
   ============================================================ */

/* 语义状态色（与主题无关，浅/深色下都够对比） */
:root {
  --lab-ok: #5E7C3C;
  --lab-warn: #B5842A;
  --lab-bad: #C2503C;
}

/* ============================================================
   A. 实验台账
   ============================================================ */

.lab-ledger {
  padding: 18px 20px 20px;
  min-width: 0;
}

.ledger-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 16px;
  min-width: 0;
}
.ledger-controls .filter-input { flex: 1 1 220px; }
.ledger-controls .filter-count { margin-left: auto; }

.ledger-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
/* 脏工作区是独立开关，与状态 chip 之间加一点分隔 */
.ledger-chips [data-ledger-dirty] { border-style: dashed; }
.ledger-chips [data-ledger-dirty].is-active {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: transparent;
}

/* 窄屏唯一允许横向滚动的地方 */
.ledger-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
}

.ledger-table {
  min-width: 520px;
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  line-height: 1.5;
}

/* 表头：小字大写字母间距 */
.ledger-table thead th {
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--card-2);
  border-bottom: 1px solid var(--line-strong);
}
.ledger-table thead th button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.ledger-table thead th button:hover { color: var(--accent-text); }
.ledger-table thead th button[data-dir] { color: var(--accent-text); }
.ledger-table thead th button[data-dir="asc"]::after { content: ' ↑'; }
.ledger-table thead th button[data-dir="desc"]::after { content: ' ↓'; }

.ledger-table td {
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
  min-width: 0;
  /* 长命令 / git 字符串必须能断行 */
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ledger-table tbody tr:first-child td { border-top: 0; }

.ledger-row {
  cursor: pointer;
  transition: background 0.18s;
}
.ledger-row:hover { background: var(--accent-tint); }
.ledger-row.is-open { background: var(--accent-tint); }
.ledger-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* 等宽 + 表格数字 */
.ledger-name code,
.ledger-num,
.ledger-step,
.ledger-detail-grid dd.is-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}
.ledger-name code {
  font-size: 0.86em;
  overflow-wrap: anywhere;
  color: var(--ink-strong);
}
.ledger-num { text-align: right; white-space: nowrap; color: var(--ink); }
.ledger-flag { color: var(--lab-warn); }
.ledger-na { color: var(--ink-3); }
td.ledger-na { text-align: center; padding: 14px 12px; }

/* 进度：细条 + 步数文字 */
.ledger-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.ledger-bar {
  position: relative;
  display: block;
  flex: none;
  width: 52px;
  height: 3px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.ledger-bar-fill {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.ledger-progress.is-done .ledger-bar-fill { background: #5E7C3C; }
.ledger-step {
  font-size: 0.76em;
  color: var(--ink-2);
  white-space: nowrap;
}

/* 迷你折线图 */
.ledger-curve { width: 1%; }
.ledger-spark {
  display: block;
  width: 120px;
  max-width: 100%;
  height: 28px;
  color: var(--accent-deep);
  overflow: visible;
}

/* 展开详情 */
.ledger-detail > td {
  padding: 0 12px 14px;
  background: var(--card-2);
  border-top: 1px dashed var(--line);
}
.ledger-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 6px 18px;
  margin: 12px 0 0;
}
.ledger-detail-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  min-width: 0;
}
.ledger-detail-row dt {
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.ledger-detail-row dd {
  margin: 0;
  min-width: 0;
  font-size: var(--fs-sm);
  color: var(--ink);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ledger-detail-row dd.is-mono { font-size: 0.82em; }

/* ============================================================
   B. 证据链浏览器
   ============================================================ */

.lab-journal { min-width: 0; }

.journal-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.journal-item { min-width: 0; }
.journal-more-item { grid-column: 1 / -1; display: flex; justify-content: center; padding-top: 4px; }
.journal-load-more { width: auto; }

.journal-btn {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  height: 100%;
  padding: 14px 16px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card-2);
  box-shadow: var(--shadow-sm);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s, border-color 0.22s, background 0.22s;
}
.journal-btn:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  background: var(--card);
  box-shadow: var(--shadow);
}
.journal-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.journal-item.is-active .journal-btn {
  border-color: var(--accent);
  background: var(--accent-tint);
  box-shadow: var(--shadow);
}

.journal-title {
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
}
.journal-item.is-active .journal-title { color: var(--accent-text); }

.journal-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  font-size: var(--fs-xs);
  color: var(--ink-3);
  min-width: 0;
}
.journal-file {
  font-family: var(--font-mono);
  font-size: 0.95em;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.journal-dot { opacity: 0.6; }
.journal-date { font-variant-numeric: tabular-nums; }
.journal-kb { font-variant-numeric: tabular-nums; }
.journal-topic { flex: none; }
.journal-na { color: var(--ink-3); padding: 18px 0; }

/* viewer */
.journal-viewer {
  margin-top: 22px;
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  box-shadow: var(--shadow-sm);
  max-height: min(74vh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
  min-width: 0;
}
@media (min-width: 901px) {
  .journal-viewer {
    position: sticky;
    top: calc(var(--hdr-h) + 14px);
  }
}

.journal-viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.journal-viewer-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: 1.45;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
  min-width: 0;
}
.journal-viewer-head .btn { flex: none; }
.journal-viewer .prose { font-size: 1rem; }
.journal-viewer .prose pre,
.journal-viewer .prose code { overflow-wrap: anywhere; }

/* ============================================================
   C. 窄屏（360px 也不许 body 横向溢出）
   ============================================================ */

@media (max-width: 560px) {
  .lab-ledger { padding: 14px 12px 16px; }
  .journal-viewer { padding: 14px 12px 16px; max-height: none; }
  .ledger-table-wrap { border-radius: var(--radius-sm); }
  .ledger-detail-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .ledger-detail-row dt { letter-spacing: 0.04em; }
  .journal-viewer-head { flex-direction: column; align-items: stretch; }
  .journal-viewer-head .btn { align-self: flex-start; }
}

/* ============================================================
   D. 尊重减弱动效
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .ledger-bar-fill,
  .journal-btn,
  .ledger-row {
    transition: none;
  }
  .journal-btn:hover { transform: none; }
}
