/* 布局与响应式。侧栏、主区、以及各页面自己的结构 */

body { display: flex; min-height: 100vh; }

/* ─────────────────── 侧栏 ─────────────────── */
/*
 * 旧版侧栏里塞了：6 个导航项 + max-height:44vh 的会话列表（每行 5 种元数据）
 * + 底部道法术器统计。180px 宽度装这些必然糊成一团。
 *
 * 现在侧栏**只做导航**：
 *   · 会话列表 → 移到对话页顶部的下拉
 *   · 道法术器数量 → 移到知识梳理页，做成可点击筛选的计数块
 */
.nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: var(--s-5) 0 var(--s-4);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.nav-brand {
  font-size: var(--t-sm);
  font-weight: 500;
  letter-spacing: .2em;
  color: var(--tx-3);
  padding: 0 var(--s-5) var(--s-6);
  text-transform: uppercase;
}
.nav-list { list-style: none; flex: 1; }
.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3) var(--s-5);
  font: inherit;
  font-size: var(--t-base);
  color: var(--tx-2);
  background: none;
  border: none;
  border-left: 2px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: color .12s var(--ease), background .12s var(--ease);
}
.nav-link:hover { color: var(--tx); background: var(--surface-2); }
.nav-link[aria-current="page"] {
  color: var(--tx);
  border-left-color: var(--accent);
  background: var(--surface-2);
  font-weight: 500;
}
.nav-badge {
  font-family: var(--mono);
  font-size: var(--t-xs);
  background: var(--warn);
  color: #1a0d06;
  font-weight: 500;
  padding: 1px var(--s-2);
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}
.nav-foot { padding: var(--s-4) var(--s-5) 0; border-top: 1px solid var(--line); }

.nav-toggle { display: none; }
.scrim { display: none; }

/* ─────────────────── 主区 ─────────────────── */
/* 内边距从 28/34 提到 40/48，并设最大宽度：长文本行宽超过 ~80 字就难读了 */

.main {
  flex: 1;
  min-width: 0;
  padding: var(--s-7) var(--s-7) var(--s-8);
  overflow-x: hidden;
}
.page { max-width: 860px; }
.page-wide { max-width: 1180px; }

.page-head { margin-bottom: var(--s-6); }
.page-head h2 { font-size: var(--t-lg); margin-bottom: var(--s-2); }
.page-head p { font-size: var(--t-base); color: var(--tx-3); line-height: 1.7; }

.toolbar { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; margin-bottom: var(--s-5); }
.toolbar-right { margin-left: auto; display: flex; gap: var(--s-2); align-items: center; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-6); }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; gap: var(--s-5); } }

/* ─────────────────── 统计计数块（知识梳理页顶部）─────────────────── */
/*
 * 旧版把道法术器数量塞在侧栏底部、等宽字体挤成两行，和它真正的语境
 * （知识树）完全割裂，纯装饰。现在做成可点击的筛选入口 —— 数字变成动作。
 */
.counts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s-3);
  margin-bottom: var(--s-6);
}
@media (max-width: 640px) { .counts { grid-template-columns: repeat(2, 1fr); } }

.count {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--s-4);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.count:hover { border-color: var(--line-strong); background: var(--surface-2); }
.count[aria-pressed="true"] { border-color: var(--accent-line); background: var(--accent-dim); }
.count-num {
  font-family: var(--mono);
  font-size: var(--t-xl);
  line-height: 1.1;
  display: block;
  margin-bottom: var(--s-2);
  font-variant-numeric: tabular-nums;
}
.count-label { font-size: var(--t-sm); color: var(--tx-2); display: flex; align-items: center; gap: var(--s-2); }
.count-sub { font-size: var(--t-xs); color: var(--tx-3); margin-top: var(--s-1); }

/* ─────────────────── 知识树 ─────────────────── */

.tree { font-size: var(--t-base); }
.node { border-left: 1px solid var(--line); margin-left: var(--s-2); padding-left: var(--s-4); }
.node-self {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  padding: var(--s-2) 0;
  flex-wrap: wrap;
}
.node-text { color: var(--tx-2); line-height: 1.7; }
.node-self:hover .node-text { color: var(--tx); }
.node-cond { font-size: var(--t-sm); color: var(--tx-3); padding: 0 0 var(--s-2) var(--s-6); line-height: 1.7; }
.node-count { font-family: var(--mono); font-size: var(--t-xs); color: var(--tx-3); }

/* ─────────────────── 递归矩阵 ─────────────────── */
/* 行=领域，列=法。空格 = 向下演绎机会 */

.matrix-wrap { overflow-x: auto; margin: var(--s-4) 0; }
.matrix { border-collapse: separate; border-spacing: 0; font-size: var(--t-sm); min-width: 100%; }
.matrix th, .matrix td {
  padding: var(--s-3);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
.matrix thead th {
  font-weight: 500;
  color: var(--tx-2);
  font-size: var(--t-xs);
  line-height: 1.5;
  max-width: 150px;
  border-bottom-color: var(--line-strong);
}
.matrix tbody th { font-weight: 400; color: var(--tx-2); white-space: nowrap; }
.matrix-cell { font-family: var(--mono); text-align: center; color: var(--tx); }
.matrix-cell-0 { color: var(--tx-3); }
/* 演绎机会：这个领域参与了这条道，但这一路没试过 */
.matrix-gap {
  background: rgba(240, 136, 90, .1);
  color: var(--warn);
  cursor: pointer;
  border-radius: var(--r-sm);
  font-family: var(--mono);
  text-align: center;
}
.matrix-gap:hover { background: rgba(240, 136, 90, .2); }
.matrix-gap-strong { background: rgba(240, 136, 90, .18); font-weight: 600; }

.legend { display: flex; gap: var(--s-4); flex-wrap: wrap; font-size: var(--t-xs); color: var(--tx-3); margin-top: var(--s-3); }
.legend span { display: inline-flex; align-items: center; gap: var(--s-2); }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ─────────────────── 对话 ─────────────────── */

.chat { display: flex; flex-direction: column; height: calc(100vh - var(--s-7) * 2 - var(--s-8) + var(--s-7)); max-width: 820px; }
.chat-head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap; }

/* 会话切换下拉：从侧栏搬到这里。每行只留标题 + 相对时间 */
.conv-picker { position: relative; }
.conv-btn {
  display: flex; align-items: center; gap: var(--s-2);
  max-width: 320px;
  font-size: var(--t-md);
  font-weight: 500;
  color: var(--tx);
  background: none; border: none; cursor: pointer;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  font-family: inherit;
}
.conv-btn:hover { background: var(--surface-2); }
.conv-btn-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-btn-caret { color: var(--tx-3); font-size: 10px; flex: 0 0 auto; }

.conv-menu {
  position: absolute;
  top: calc(100% + var(--s-2));
  left: 0;
  z-index: 40;
  width: 340px;
  max-width: calc(100vw - var(--s-6));
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: var(--s-2);
}
.conv-menu-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-2) var(--s-3);
  font-size: var(--t-xs); color: var(--tx-3);
}
.conv-item {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.conv-item:hover, .conv-item.is-active { background: var(--surface-3); }
.conv-item-main { flex: 1; min-width: 0; }
.conv-item-title {
  font-size: var(--t-sm); color: var(--tx);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-item-time { font-family: var(--mono); font-size: var(--t-xs); color: var(--tx-3); }
/* 旧版这块按钮（.cvops）在 CSS 里写了 3 条规则，但 loadConvs() 从未渲染过它 ——
   于是「悬停出现重命名/删除」在界面上根本不存在。这里补活。 */
.conv-item-ops { display: flex; gap: var(--s-1); opacity: 0; transition: opacity .12s var(--ease); }
.conv-item:hover .conv-item-ops, .conv-item:focus-within .conv-item-ops { opacity: 1; }

.msgs { flex: 1; overflow-y: auto; padding-right: var(--s-2); }
.msg { margin-bottom: var(--s-6); }
.msg-who {
  font-size: var(--t-xs);
  color: var(--tx-3);
  margin-bottom: var(--s-2);
  display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap;
}
.msg-body { white-space: pre-wrap; line-height: 1.85; }
.msg-user .msg-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--s-4);
}
.msg details { margin-top: var(--s-3); }
.msg summary { cursor: pointer; font-size: var(--t-xs); color: var(--tx-3); }
.msg summary:hover { color: var(--tx-2); }
.msg pre {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: var(--t-xs);
  color: var(--tx-2);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: var(--s-4);
  border-radius: var(--r-sm);
  margin-top: var(--s-2);
  overflow-x: auto;
  line-height: 1.7;
}

.composer {
  display: flex; gap: var(--s-3); align-items: flex-end;
  padding-top: var(--s-4);
  border-top: 1px solid var(--line);
}
.composer textarea { flex: 1; }
.composer-btns { display: flex; gap: var(--s-2); align-items: center; }
.btn-icon.is-recording {
  background: rgba(240, 136, 90, .18);
  border-color: var(--warn);
  color: var(--warn);
}
.attachments { display: flex; flex-wrap: wrap; gap: var(--s-2); padding-bottom: var(--s-3); }
.attachment {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--t-xs);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--s-1) var(--s-3);
  color: var(--tx-2);
}

/* ─────────────────── 投喂 ─────────────────── */

.tabs { display: flex; gap: var(--s-1); margin-bottom: var(--s-5); border-bottom: 1px solid var(--line); }
.tab {
  font: inherit; font-size: var(--t-base);
  background: none; border: none;
  border-bottom: 2px solid transparent;
  padding: var(--s-3) var(--s-4);
  color: var(--tx-3);
  cursor: pointer;
  margin-bottom: -1px;
}
.tab:hover { color: var(--tx-2); }
.tab[aria-selected="true"] { color: var(--tx); border-bottom-color: var(--accent); }

.drop {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r);
  padding: var(--s-8) var(--s-5);
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.drop:hover, .drop.is-over { border-color: var(--accent-line); background: var(--surface-2); }
.drop-title { font-size: var(--t-md); margin-bottom: var(--s-2); }
.drop-hint { font-size: var(--t-sm); color: var(--tx-3); line-height: 1.8; }

.recorder {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--s-6);
  text-align: center;
}
.recorder-time { font-family: var(--mono); font-size: var(--t-lg); color: var(--tx-2); margin: var(--s-4) 0 0; }

/* ─────────────────── 移动端 ─────────────────── */

@media (max-width: 860px) {
  .nav-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: var(--s-3); left: var(--s-3); z-index: 70;
    width: 40px; height: 40px;
    font-size: 17px; line-height: 1;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm);
    color: var(--tx);
    cursor: pointer;
  }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 65; }
  .scrim[hidden] { display: none; }

  .nav {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 68;
    width: 264px; flex-basis: 264px; height: 100vh;
    transform: translateX(-100%);
    transition: transform .2s var(--ease);
    box-shadow: 2px 0 24px rgba(0,0,0,.5);
  }
  body.nav-open .nav { transform: none; }

  .main { padding: var(--s-8) var(--s-4) var(--s-8); }
  .chat { height: calc(100vh - 140px); }
  .composer { flex-wrap: wrap; }
  .composer textarea { flex: 1 1 100%; }
  .composer-btns { width: 100%; justify-content: flex-end; }

  /* 触控目标放大 */
  .btn { padding: var(--s-3) var(--s-4); font-size: var(--t-base); }
  .btn-sm { padding: var(--s-2) var(--s-3); font-size: var(--t-sm); }
  .nav-link { padding: var(--s-4) var(--s-5); }
  /* iOS 上 <16px 的输入框会让整页缩放 */
  input, textarea, select { font-size: 16px; }
  /* 手机没有 hover，会话操作按钮常驻 */
  .conv-item-ops { opacity: 1; }
  .card { padding: var(--s-4); }
  .node { padding-left: var(--s-3); margin-left: var(--s-1); }
  .tabs { overflow-x: auto; }
  .kbd-hint { display: none; }
}

@media (max-width: 480px) {
  .nav { width: 86vw; flex-basis: 86vw; }
  .conv-btn { max-width: 180px; }
}

/* 登录门 */
.gate {
  position: fixed; inset: 0; z-index: 110;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: var(--s-4);
}
.gate[hidden] { display: none; }
.gate-box { width: 100%; max-width: 360px; }
.gate-box h1 { font-size: var(--t-lg); margin-bottom: var(--s-3); }
.gate-box p { font-size: var(--t-sm); color: var(--tx-3); margin-bottom: var(--s-5); line-height: 1.7; }
.gate-box input { margin-bottom: var(--s-4); }
.gate-err { color: var(--warn); font-size: var(--t-sm); margin-top: var(--s-3); min-height: 1.5em; }
