/* =====================================================================
   LecTrace — 深色、极简。所有颜色走 token，浅色主题只需覆盖 :root 变量。
   ===================================================================== */
:root {
  --bg: #0a0a0c;
  --bg-2: #121215;
  --bg-3: #1b1b20;
  --bg-4: #24242b;
  --line: #232329;
  --line-strong: #3a3a44;
  --text: #ededf0;
  --text-2: #a6a6b0;
  --muted: #6c6c78;
  --accent: #f4f4f6;
  --on-accent: #0a0a0c;
  --rec: #ff453a;
  --ok: #34d399;
  --warn: #f5a524;
  --err: #ff6b6b;
  --radius-xl: 28px;
  --radius-lg: 18px;
  --radius: 12px;
  --fade-h: 72px;
  --side-w: 84px;
  --chat-w: 440px;
  --font: "Inter", -apple-system, "Hiragino Sans", "Noto Sans JP", "Segoe UI", system-ui, sans-serif;
}
:root[data-theme="light"] {
  --bg: #fafafa;
  --bg-2: #ffffff;
  --bg-3: #f0f0f2;
  --bg-4: #e6e6ea;
  --line: #e4e4e8;
  --line-strong: #cfcfd6;
  --text: #141418;
  --text-2: #55555f;
  --muted: #8a8a94;
  --accent: #141418;
  --on-accent: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* 细滚动条 */
.transcript, .chat-messages, .sheet-body, .history-list, .menu, .page {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }

.icon { width: 22px; height: 22px; display: block; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }

/* ---------- 通用控件 ---------- */
.btn {
  padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: transparent; color: var(--text);
  font-weight: 500; transition: border-color .15s, background .15s, opacity .15s;
}
.btn:hover { border-color: var(--text-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-primary:hover { opacity: .9; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: transparent; color: var(--text);
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: border-color .15s, background .15s, opacity .15s;
}
.pill:hover:not(:disabled) { border-color: var(--text-2); background: var(--bg-3); }
.pill:disabled { opacity: .4; cursor: not-allowed; }

input[type="text"], textarea, select {
  width: 100%; background: var(--bg-3); border: 1px solid transparent; border-radius: var(--radius);
  padding: 10px 14px; outline: none; transition: border-color .15s, background .15s;
}
input[type="text"]:focus, textarea:focus, select:focus { border-color: var(--line-strong); background: var(--bg-4); }
textarea { resize: none; line-height: 1.5; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 9l6 6 6-6' fill='none' stroke='%238a8a94' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
input[type="range"] { flex: 1; accent-color: var(--text); height: 24px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row b { min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.range-row .unit { color: var(--muted); font-size: 12px; }

/* 弹出菜单 */
.menu-anchor { position: relative; }
.menu {
  position: absolute; z-index: 30; min-width: 240px; max-height: 320px; overflow-y: auto;
  background: var(--bg-3); border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  padding: 6px; box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
}
.menu-anchor .menu { right: 0; top: calc(100% + 8px); }
.menu-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  padding: 9px 12px; border-radius: 10px; border: none; background: transparent; text-align: left;
}
a.menu-item { color: inherit; text-decoration: none; }
.menu-item:hover { background: var(--bg-4); }
.menu-item.active { background: var(--bg-4); }
.menu-item .sub { font-size: 11px; color: var(--muted); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* =====================================================================
   登录
   ===================================================================== */
.login { height: 100%; display: grid; place-items: center; }
.login-card { display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; }
.brand-mark { font-size: 34px; font-weight: 600; letter-spacing: -.02em; }
.login-sub { margin: 0 0 10px; color: var(--text-2); }
.google-btn { min-height: 44px; }
.login-hint { color: var(--muted); font-size: 12px; max-width: 360px; line-height: 1.6; }

/* =====================================================================
   外壳：左侧导航 + 主区
   ===================================================================== */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); height: 100%; }
.side {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 18px 0 16px; border-right: 1px solid var(--line);
}
.side-logo {
  width: 44px; height: 44px; border-radius: 14px; margin-bottom: 14px;
  background: var(--accent); color: var(--on-accent); border: none;
  font-weight: 600; letter-spacing: -.02em; font-size: 15px;
}
.side-item {
  width: 48px; height: 48px; display: grid; place-items: center;
  border: none; background: transparent; border-radius: 14px; color: var(--muted);
  transition: color .15s, background .15s;
}
.side-item:hover { color: var(--text); background: var(--bg-3); }
.side-item.active { color: var(--text); background: var(--bg-3); }
.side-spacer { flex: 1; }

/* 历史抽屉：贴着侧栏展开 */
.drawer {
  position: absolute; top: 0; bottom: 0; left: var(--side-w); width: 340px; z-index: 20;
  background: var(--bg-2); border-right: 1px solid var(--line);
  transform: translateX(calc(-100% - var(--side-w))); opacity: 0; visibility: hidden;
  transition: transform .3s cubic-bezier(.22, .9, .25, 1), opacity .2s, visibility 0s .3s;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; opacity: 1; visibility: visible; transition-delay: 0s; box-shadow: 24px 0 48px rgba(0, 0, 0, .35); }
.drawer-head { padding: 24px 22px 12px; font-size: 13px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.history-list { flex: 1; overflow-y: auto; padding: 0 12px 16px; display: flex; flex-direction: column; gap: 4px; }
.hist-card {
  text-align: left; display: flex; flex-direction: column; gap: 4px; width: 100%;
  padding: 12px 12px; border-radius: 12px; border: none; background: transparent;
  transition: background .15s;
}
.hist-card:hover { background: var(--bg-3); }
.hist-card { position: relative; padding-right: 44px; }
.hist-del {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border-radius: 8px; border: none; background: transparent; color: var(--muted);
  display: grid; place-items: center; opacity: 0; transition: opacity .15s, color .15s, background .15s;
}
.hist-card:hover .hist-del, .hist-del:focus-visible { opacity: 1; }
.hist-del:hover { color: var(--err); background: var(--bg-4); }
.hist-del .icon { width: 17px; height: 17px; }
.hist-card.current { background: var(--bg-3); box-shadow: inset 2px 0 0 var(--text-2); }
.hist-title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-meta { display: flex; gap: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.history-empty { color: var(--muted); padding: 30px 14px; text-align: center; line-height: 1.7; font-size: 13px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: var(--bg-4); color: var(--text-2);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.lg { width: 40px; height: 40px; }
.avatar .icon { width: 18px; height: 18px; }

.main { min-width: 0; min-height: 0; position: relative; }
.view { height: 100%; }

/* 个人资料弹层 */
.profile-menu { left: calc(var(--side-w) + 8px); bottom: 70px; }
.profile-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px 12px; }
.profile-name { font-weight: 500; }
.profile-email { font-size: 12px; color: var(--muted); }

/* =====================================================================
   讲义视图
   ===================================================================== */
.lecture {
  display: grid; grid-template-columns: minmax(0, 1fr) var(--chat-w); gap: 28px;
  padding: 26px 28px 28px;
}
@media (max-width: 1100px) { :root { --chat-w: 380px; } }

/* ---------- 转录舞台 ---------- */
.stage { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.stage-head { display: flex; align-items: center; gap: 22px; height: 64px; flex-shrink: 0; padding-right: 4px; }

.rec {
  width: 58px; height: 58px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  border: 1.5px solid var(--text); background: transparent; color: var(--text);
  position: relative; transition: border-color .2s, color .2s, background .2s, transform .1s;
}
.rec:hover:not(:disabled) { background: var(--bg-3); }
.rec:active:not(:disabled) { transform: scale(.96); }
.rec:disabled { opacity: .35; cursor: not-allowed; }
.rec .rec-icon { width: 26px; height: 26px; }
.rec.live { border-color: var(--rec); color: var(--rec); }
.rec.live::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 1.5px solid var(--rec); opacity: 0; animation: ring 1.8s ease-out infinite;
}
.rec.busy { border-color: var(--line-strong); color: var(--text-2); }
@keyframes ring { 0% { transform: scale(.85); opacity: .7; } 100% { transform: scale(1.25); opacity: 0; } }

.wave-wrap { flex: 1; min-width: 0; position: relative; height: 64px; }
.wave { width: 100%; height: 100%; display: block; }
.live-status {
  position: absolute; left: 2px; bottom: -6px; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums; letter-spacing: .02em; display: flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.live-status.live { color: var(--rec); }
.live-status.live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--rec); animation: blink 1.2s infinite; }
.live-status.err { color: var(--err); }
@keyframes blink { 50% { opacity: .25; } }

.meta-pill { max-width: 260px; }
.meta-pill #metaLabel { overflow: hidden; text-overflow: ellipsis; }
.meta-pill .chev { transition: transform .35s; color: var(--muted); }
.meta-pill.open .chev { transform: rotate(180deg); }
.meta-pill.open { background: var(--bg-3); border-color: var(--text-2); }

.stage-body { position: relative; flex: 1; min-height: 0; margin-top: 10px; }
.transcript {
  position: absolute; inset: 0; overflow-y: auto;
  padding: var(--fade-h) 12px 48px 0;
}
.seg {
  display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 18px;
  padding: 7px 10px 7px 12px; border-radius: 10px; margin: 1px 0;
  font-size: 16px; line-height: 1.75; color: var(--text);
  opacity: 0; animation: fadein .35s ease forwards;
  transition: background .25s, box-shadow .25s;
}
.seg .ts { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; padding-top: 3px; }
.seg.pending { color: var(--text-2); font-style: italic; opacity: 1; animation: none; }
.seg.pending .ts::before { content: "●"; color: var(--ok); font-size: 10px; font-style: normal; }
@keyframes fadein { to { opacity: 1; } }

.transcript-empty {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted);
  text-align: center; line-height: 1.7; padding: 0 40px; pointer-events: none;
}

/* ---------- 渐变分界 + 下拉 meta 面板 ---------- */
.sheet {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0;
  display: flex; flex-direction: column; pointer-events: none;
}
.sheet-inner {
  height: var(--sheet-h, 0px); overflow: hidden; background: var(--bg);
  transition: height .55s cubic-bezier(.22, .9, .25, 1);
  pointer-events: auto;
}
.sheet-body { padding: 8px 14px 20px 12px; overflow-y: auto; max-height: 100%; max-width: 820px; }
.meta-note { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.meta-title, .meta-desc {
  display: block; width: 100%; background: transparent; border: none; border-radius: 0; padding: 6px 0;
  border-bottom: 1px solid transparent;
}
.meta-title { font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.meta-desc { font-size: 14.5px; color: var(--text-2); line-height: 1.6; margin-top: 2px; }
.meta-title:focus, .meta-desc:focus { background: transparent; border-color: var(--line-strong); }
.meta-title::placeholder { color: var(--muted); font-weight: 500; }
.meta-desc::placeholder { color: var(--muted); }
.meta-row { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-top: 18px; }
.mini { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.mini > span { font-size: 11.5px; color: var(--muted); }
.mini select { padding: 7px 32px 7px 12px; font-size: 13px; border-radius: 999px; width: auto; }
.mini .range-row { height: 32px; min-width: 180px; }
.sheet-hint { margin-top: 20px; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.sheet-hint .dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--muted); display: inline-block; }
.sheet-fade {
  height: var(--fade-h); flex-shrink: 0;
  background: linear-gradient(to bottom, var(--bg) 0%, color-mix(in srgb, var(--bg) 78%, transparent) 48%, transparent 100%);
}
.sheet.locked .sheet-body { opacity: .9; }

/* ---------- 对话面板 ---------- */
.chat {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-xl);
  padding: 18px 18px 18px;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 6px 14px; }
.thread-title { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding: 4px 8px; }
.chat-empty { margin: auto; color: var(--muted); text-align: center; line-height: 1.7; padding: 0 20px; }
.msg { font-size: 14.5px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.msg.user {
  align-self: flex-end; max-width: 85%; background: var(--bg-4);
  padding: 10px 15px; border-radius: 18px 18px 6px 18px;
}
.msg.assistant { align-self: stretch; padding: 2px 4px; }
.msg.assistant.err { color: var(--err); }
.msg.catchup {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px 14px 14px;
}
.msg-tag {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 8px;
  font-size: 11.5px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase;
}
/* ---- 回复正文的 markdown 排版 ---- */
.msg-body { white-space: normal; }
.msg-body.loading { color: var(--muted); }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body p { margin: 0 0 10px; }
.msg-body b, .msg-body strong { font-weight: 600; color: var(--text); }
.msg-body em { font-style: italic; color: var(--text-2); }
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 {
  font-weight: 600; line-height: 1.4; margin: 16px 0 6px; color: var(--text);
}
.msg-body h1 { font-size: 16px; }
.msg-body h2 { font-size: 15.5px; }
.msg-body h3, .msg-body h4 { font-size: 14.5px; }
.msg-body ul, .msg-body ol { margin: 4px 0 10px; padding-left: 22px; }
.msg-body li { margin: 3px 0; }
.msg-body li > p { margin: 0; }
.msg-body li::marker { color: var(--muted); }
.msg-body blockquote {
  margin: 6px 0 10px; padding: 2px 0 2px 12px; border-left: 2px solid var(--line-strong);
  color: var(--text-2);
}
.msg-body blockquote p { margin: 0 0 4px; }
.msg-body hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.msg-body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px;
  background: var(--bg-4); padding: 1px 6px; border-radius: 6px;
}
.msg-body pre {
  margin: 6px 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg-4);
  overflow-x: auto; white-space: pre; line-height: 1.55;
}
.msg-body pre code { background: none; padding: 0; font-size: 12.5px; }
.msg-body table { border-collapse: collapse; margin: 6px 0 10px; font-size: 13.5px; max-width: 100%; display: block; overflow-x: auto; }
.msg-body th, .msg-body td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; vertical-align: top; }
.msg-body th { background: var(--bg-3); font-weight: 600; }
.msg-body a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--line-strong); }
.msg-body a:hover { text-decoration-color: var(--text); }
.msg-body img { max-width: 100%; border-radius: 8px; }
/* 流式光标跟在最后一个块的末尾，而不是另起一行 */
.msg.streaming .msg-body > :last-child::after,
.msg.streaming .msg-body:empty::after { content: "▍"; color: var(--muted); animation: blink 1s infinite; }
.msg.streaming .msg-body.loading::after { content: ""; }

.chat-foot { padding-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.quick { display: flex; gap: 10px; }
.quick-btn { flex: 1; justify-content: center; padding: 11px 14px; }
.quick-sub { color: var(--muted); font-weight: 400; font-size: 12px; }
.chat-input { display: flex; align-items: flex-end; gap: 10px; }
.chat-input textarea {
  flex: 1; border-radius: 24px; padding: 13px 18px; max-height: 150px; line-height: 1.5;
  background: var(--bg-3); border: 1px solid transparent;
}
.chat-input textarea:focus { border-color: var(--line-strong); }
.send {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); border: none; transition: opacity .15s, transform .1s;
}
.send:hover:not(:disabled) { opacity: .9; }
.send:active:not(:disabled) { transform: scale(.95); }
.send:disabled { opacity: .35; cursor: not-allowed; }
.send .icon { width: 20px; height: 20px; }

/* =====================================================================
   历史 / 设置 页面
   ===================================================================== */
.page { padding: 34px 48px; overflow-y: auto; }
.page h1 { font-size: 22px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 24px; }

.settings-card { max-width: 460px; display: flex; flex-direction: column; gap: 20px; }
.settings-actions { display: flex; align-items: center; gap: 14px; margin-top: 4px; }

/* =====================================================================
   提示条 / 确认弹窗
   ===================================================================== */
.notice {
  flex-shrink: 0; margin: 14px 12px 0 0;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px 11px 16px; border-radius: 14px;
  background: var(--bg-3); border: 1px solid var(--line-strong); color: var(--text);
  font-size: 13.5px; line-height: 1.5; box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  animation: fadein .25s ease;
}
.notice.warn { border-color: color-mix(in srgb, var(--warn) 55%, var(--line-strong)); }
.notice.warn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex-shrink: 0; }
.notice span { flex: 1; }
.notice-close { border: none; background: transparent; color: var(--muted); width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; }
.notice-close:hover { color: var(--text); background: var(--bg-4); }

.dialog-backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px); animation: fadein .15s ease;
}
.dialog {
  width: min(420px, calc(100vw - 32px)); padding: 24px 24px 20px;
  background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.dialog-title { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.dialog-body { color: var(--text-2); font-size: 14px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.dialog .btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.dialog .btn-danger:hover { opacity: .9; }
