/* pi hub 网页端样式：暗色为主，移动端 dvh + 安全区。无外部字体/图标资源。 */

/* `hidden` 属性必须赢过 .screen/.field 的 display:flex，否则登录页与主界面会同时渲染。 */
[hidden] { display: none !important; }
:root {
  color-scheme: dark;
  --bg: #0f1115;
  --bg-soft: #151922;
  --bg-raise: #1b2130;
  --line: #262d3b;
  --fg: #e6e9ef;
  --fg-dim: #97a0b3;
  --accent: #5aa9ff;
  --accent-dim: #1d3a5c;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --warn: #fbbf24;
  --radius: 12px;
  /* 桌面折叠态侧栏宽度（图标栏）；必须与 app.js 的 SIDEBAR_RAIL 一致。 */
  --sidebar-rail: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.screen {
  position: fixed;
  inset: 0;
}

/* ---------- 首帧骨架 ---------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2436 0%, var(--bg) 60%);
}

.boot-mark {
  font-size: 40px;
  color: var(--accent);
  opacity: 0.75;
  animation: boot-pulse 1.1s ease-in-out infinite;
}

@keyframes boot-pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.96);
  }
  50% {
    opacity: 0.9;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .boot-mark {
    animation: none;
  }
}

/* ---------- 登录 ---------- */
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  background: radial-gradient(1200px 600px at 50% -10%, #1b2436 0%, var(--bg) 60%);
}

.login-card {
  width: min(420px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.02em;
}

.hint {
  margin: 0;
  color: var(--fg-dim);
  font-size: 13px;
  line-height: 1.5;
}

.hint.small {
  font-size: 12px;
}

/* 登录页里的教程链接：没这行浏览器默认蓝紫在暗底上不可读 */
.hint a {
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-dim);
}

input,
textarea,
select,
button {
  font: inherit;
  color: inherit;
}

input[type="password"],
input[type="search"],
input[type="text"],
input:not([type]),
textarea,
select {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
  width: 100%;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg-raise);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn.primary {
  background: #1d4ed8;
  border-color: #2563eb;
  color: #fff;
}

.btn.danger {
  background: #3a1d1d;
  border-color: #6b2b2b;
  color: #ffd7d7;
}

.btn:disabled {
  opacity: 0.55;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

/* ---------- 主界面 ---------- */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  /*
   * 不要写 `height: 100dvh`：`.screen` 已经是 `position: fixed; inset: 0`，高度由视口定。
   * 显式 dvh 会随移动端地址栏收起/展开变化 ⇒ 首次滚动时整页重排（肉眼就是「闪一下/卡」）。
   */
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--fg-dim);
  font-size: 18px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1;
}

.icon-btn:active {
  background: var(--bg-raise);
}

.title-block {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub {
  font-size: 11px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}

.dot.off {
  background: #4b5563;
}

.dot.busy {
  background: var(--warn);
}

/* 落点由 app.js 的 openMenuAt(anchor) 现算（fixed + 视口 clamp + 越界上翻）：
   以前写死 `absolute; top:48px; right:8px`，菜单挂在折叠态被 hidden 的 #btn-menu 上，
   点图标栏 ⋯ 就跑到窗口右上角（R8-F1）。 */
.menu {
  position: fixed;
  left: 0;
  top: 0;
  /* 必须高于抽屉（z-index:40）与 scrim（35）：rail ⋯ 的菜单要盖在侧栏上；toast(50) 仍在上 */
  z-index: 45;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.menu button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.menu button:hover {
  background: var(--bg-soft);
}

.menu button.danger {
  color: var(--danger);
}

/* ---------- 消息 ---------- */
.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
}

.msg.user {
  align-items: flex-end;
}

.bubble {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: #1c2a44;
  border-color: #263d63;
  max-width: 88%;
}

/* 空正文气泡（只有思考/工具、还没出文字）不画框：否则「思考过程」和工具卡之间
 * 会多出一个空的白板框，看着像空行。 */
.bubble:empty {
  display: none;
}

.meta {
  font-size: 11px;
  color: var(--fg-dim);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 消息操作不再常显：复制/分叉/用量走气泡上的右键 / 长按上下文菜单（见 .ctx-menu）。
 * 以前常显的 `.msg-actions` 行即使 hover 才提亮也永久占一行高度（W1-a/W1-b）。 */

/* 上下文菜单：position:fixed，坐标由 app.js 按指针位置给定并在视口内 clamp。 */
.ctx-menu {
  position: fixed;
  z-index: 70;
  min-width: 132px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.ctx-menu button {
  border: none;
  background: transparent;
  color: var(--fg);
  text-align: left;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.ctx-menu button:hover,
.ctx-menu button:focus-visible {
  background: var(--bg-soft);
}

.empty {
  margin: auto;
  color: var(--fg-dim);
  font-size: 14px;
  text-align: center;
  padding: 24px;
  line-height: 1.7;
}

/* markdown */
.md > *:first-child {
  margin-top: 0;
}

.md > *:last-child {
  margin-bottom: 0;
}

.md p,
.md ul,
.md ol,
.md blockquote,
.md pre,
.md .table-wrap {
  margin: 0 0 8px;
}

/* 表格：md 表格必须画线（此前只有 margin，纯文本一样糊在一起）；
 * 宽表靠 .table-wrap 横向滚动，不撑破气泡。 */
.md .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.md table {
  border-collapse: collapse;
  border-spacing: 0;
  margin: 0;
  width: auto;
  max-width: 100%;
  font-size: 13.5px;
  line-height: 1.5;
}

.md th,
.md td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  vertical-align: top;
  text-align: left;
}

.md thead th {
  background: var(--bg-raise);
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}

.md tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.md .al-c {
  text-align: center;
}

.md .al-r {
  text-align: right;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 12px 0 6px;
  line-height: 1.3;
}

.md h1 {
  font-size: 19px;
}

.md h2 {
  font-size: 17px;
}

.md h3 {
  font-size: 16px;
}

.md code {
  background: #0b0e14;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.md pre {
  background: #0b0e14;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  overflow-x: auto;
}

.md pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.55;
  display: block;
  white-space: pre;
}

.md blockquote {
  border-left: 3px solid var(--line);
  padding-left: 10px;
  color: var(--fg-dim);
}

.md ul,
.md ol {
  padding-left: 20px;
}

.md a {
  color: var(--accent);
}

.md hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

.code-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
  background: #0b0e14;
}

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  background: var(--bg-raise);
  font-size: 11px;
  color: var(--fg-dim);
}

.code-head button {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
}

/* 思考 / 工具 */
.thinking-block {
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #12161f;
  font-size: 13px;
  color: var(--fg-dim);
}

/* 折叠头：一律带 ▸/▾ 指示器（浏览器默认三角被 list-style:none 关掉了，
 * 之前完全没有可点的视觉提示，看不出能展开）。 */
.thinking-block > summary,
.tool-card > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  user-select: none;
}

.thinking-block > summary::before,
.tool-card > summary::before {
  content: "▸";
  flex: none;
  font-size: 10px;
  line-height: 1;
  color: var(--fg-dim);
  transition: transform 0.12s ease;
}

.thinking-block[open] > summary::before,
.tool-card[open] > summary::before {
  transform: rotate(90deg);
}

.thinking-block > summary {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--fg-dim);
}

.thinking-block > summary:hover,
.tool-card > summary:hover {
  color: var(--fg);
}

.thinking-block > summary::-webkit-details-marker,
.tool-card > summary::-webkit-details-marker {
  display: none;
}

.thinking-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-dim);
  opacity: 0.8;
}

.thinking-body {
  padding: 0 10px 8px;
  white-space: pre-wrap;
  line-height: 1.55;
  max-height: 45vh;
  overflow: auto;
}

.tool-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #12161f;
  font-size: 12.5px;
  overflow: hidden;
}

.tool-card > summary {
  padding: 6px 10px;
  cursor: pointer;
}

.tool-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent);
}

.tool-state {
  margin-left: auto;
  color: var(--fg-dim);
  font-size: 11px;
  white-space: nowrap;
}

.tool-state.err {
  color: var(--danger);
}

.tool-body {
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  max-height: 320px;
  overflow: auto;
}

.tool-body pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11.5px;
  color: var(--fg-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* 工具卡片正文：参数段 + 结果段各自带小标题，空段不画（展开后不再是空白一片） */
.tool-section {
  margin: 0 0 8px;
}

.tool-section:last-child {
  margin-bottom: 0;
}

.tool-section > h4 {
  margin: 0 0 3px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.tool-section > pre.is-error {
  color: var(--danger);
}

.tool-empty {
  font-size: 11.5px;
  color: var(--fg-dim);
  opacity: 0.75;
}

.typing::after {
  content: "▌";
  animation: blink 1s steps(2) infinite;
  color: var(--accent);
}

@keyframes blink {
  0%,
  50% {
    opacity: 1;
  }
  50.01%,
  100% {
    opacity: 0;
  }
}

.jump {
  position: absolute;
  right: 14px;
  bottom: calc(96px + var(--safe-bottom));
  z-index: 20;
  border: 1px solid var(--line);
  background: var(--bg-raise);
  color: var(--fg);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

/* ---------- 输入区 ---------- */
.composer {
  position: relative;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 命令补全浮层：悬在输入区上方（不撑动布局） */
.slash {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(100% - 4px);
  max-height: 40dvh;
  overflow-y: auto;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.slash-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.slash-item.active,
.slash-item:hover {
  background: var(--accent-dim);
}

.slash-name {
  flex: none;
  font-size: 13px;
  font-weight: 600;
}

.slash-src {
  flex: none;
  font-size: 10px;
  color: var(--fg-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 6px;
}

.slash-desc {
  min-width: 0;
  font-size: 11px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer textarea {
  resize: none;
  max-height: 40dvh;
  min-height: 42px;
  line-height: 1.45;
}

.composer-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.select {
  flex: 1;
  min-width: 0;
}

.select select {
  padding: 7px 8px;
  font-size: 12px;
  border-radius: 8px;
  text-overflow: ellipsis;
}

.icon-btn.file {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.send {
  padding: 8px 16px;
  font-size: 14px;
  white-space: nowrap;
}

.usage-bar {
  /* 一行就够：上下文/占用/tok·s/缓存命中/成本合并成一句（W1-b），窄屏再用 CSS 切窄版。 */
  font-size: 11px;
  color: var(--fg-dim);
  padding: 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#usage-narrow {
  display: none;
}

@media (max-width: 419.98px) {
  #usage-full {
    display: none;
  }

  #usage-narrow {
    display: inline;
  }
}

.attachments {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  max-width: 220px;
}

.chip img {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  object-fit: cover;
}

.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip button {
  border: none;
  background: transparent;
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.ui-request {
  border: 1px solid #3b4a63;
  border-radius: 10px;
  padding: 10px;
  background: #16202f;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.ui-request .row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- 抽屉 ---------- */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(86vw, 360px);
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  transform: translateX(0);
}

.drawer[hidden] {
  display: none;
}

/* 折叠态图标栏（只在桌面折叠时显示，见文末 @media (min-width:900px)）。 */
.rail {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  width: 100%;
}

.rail {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  width: 100%;
}

/* 图标栏与顶栏同一套尺寸：36×36、圆角 8px、居中留白 10px（--sidebar-rail 56 - 36 = 20） */
.rail-logo {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--fg);
}

.rail-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-dim);
  font-size: 18px;
  padding: 0;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.rail-btn:hover,
.rail-btn:focus-visible {
  color: var(--fg);
  background: var(--bg-raise);
}

.rail-btn:last-child {
  margin-top: auto;
}

.drawer-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--fg-dim);
  padding: 10px 6px 4px;
}

/* 分组头本体是 button（可折叠，R8-F3）：chevron 旋转 + aria-expanded + 折叠态显示会话数 */
.group-title .group-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 0;
  cursor: pointer;
}

.group-title .group-toggle::before {
  content: "▸";
  display: inline-block;
  flex: none;
  font-size: 9px;
  line-height: 1;
  transition: transform 0.15s ease;
}

.group-title .group-toggle[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

.group-title .group-toggle .cwd {
  flex: 0 1 auto;
  max-width: 60%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
}

/* 组头副行 = `~` 缩写路径（对齐安卓 WorkspaceHeader）；以前这里画的是整条大写绝对路径 */
.group-title .group-toggle .cwd-path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  opacity: 0.75;
}

/* 折叠态才显示「N 个会话」：展开时列表本身就是答案 */
.group-title .group-toggle .count {
  display: none;
  flex: none;
  font-size: 10px;
  opacity: 0.8;
}

.group-title .group-toggle[aria-expanded="false"] .count {
  display: inline;
}

/* 折叠＝整块不占高度（不是 visibility/高度动画），列表无缝缩短 */
.session-group[hidden] {
  display: none;
}

/* 每个仓库分组右侧的 ＋：在当前 cwd 直接开新会话，不用再往下找表单 */
.group-title .group-new {
  flex: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.group-title .group-new:hover,
.group-title .group-more:hover {
  color: var(--fg);
  border-color: var(--line);
  background: var(--bg-raise);
}

/* 组头 ⋮（P1-11）：与 ＋ 同一档视觉，菜单走 openMenuAt(anchor) */
.group-title .group-more {
  flex: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.session-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.session-item.active {
  background: #1c2a44;
}

.session-item:active {
  background: var(--bg-raise);
}

.session-item .name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item .line {
  font-size: 11px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  font-size: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 6px;
  color: var(--fg-dim);
}

.badge.live {
  border-color: #2f6b3f;
  color: var(--ok);
}

.drawer-foot {
  border-top: 1px solid var(--line);
  flex: none;
}

.new-session-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--fg-dim);
  padding: 11px 14px;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.new-session-toggle:hover,
.new-session-toggle[aria-expanded="true"] {
  color: var(--fg);
  background: var(--bg-raise);
}

/* 展开/收起线索（R8-F2）：▸ 收起 ↔ ▾ 展开，与 aria-expanded 一一对应 */
.new-session-toggle .caret {
  display: inline-block;
  flex: none;
  width: 10px;
  font-size: 11px;
  line-height: 1;
}

.new-session-toggle .caret::before {
  content: "▸";
}

.new-session-toggle[aria-expanded="true"] .caret::before {
  content: "▾";
}

.new-session {
  padding: 0 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-session[hidden] {
  display: none;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 35;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #22293a;
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  max-width: 90vw;
}

/* 常驻错误横幅（P1-9）：顶栏下方、不自动消失、可手动关闭；不覆盖输入框 */
.error-banner {
  position: fixed;
  top: calc(56px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(720px, calc(100vw - 24px));
  background: #2a1b1f;
  border: 1px solid var(--danger);
  color: #ffd9d9;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  z-index: 44;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.error-banner[hidden] {
  display: none;
}

.error-banner #error-banner-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.error-banner button {
  flex: none;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.error-banner button:hover {
  background: rgba(255, 255, 255, 0.08);
}

@media (min-width: 760px) {
  .messages {
    padding: 16px max(16px, calc((100% - 900px) / 2));
  }
  .msg.user .bubble {
    max-width: 70%;
  }
}

/* ---------- 桌面（≥900px）：抽屉常驻左侧固定侧栏（可折叠为 56px 图标栏） ---------- */
/*
 * 移动端抽屉是浮层（hidden 控制 + scrim），桌面上改成布局的一部分：
 * - 展开态不受 `hidden` 影响（JS 里 closeDrawer() 仍可调用，窄窗口恢复原语义）
 * - 折叠态（`body.sidebar-collapsed`）把 `--sidebar` 换成 56px 图标栏：logo/＋/搜索/⋯/展开
 *   仍在（对齐 DSH 的 SIDEBAR_COLLAPSED），主区靠 `left: var(--sidebar)` 自动跟着重排（W1-c）
 * - 不画 scrim；开合入口是顶栏 ☰ / 侧栏头部收起按钮 / 图标栏展开按钮
 * - 登录页在前时整块隐藏，避免侧栏压在登录卡上方
 */
@media (min-width: 900px) {
  :root {
    --sidebar: 300px;
  }

  .drawer,
  .drawer[hidden] {
    display: flex !important;
    width: var(--sidebar);
    transform: none;
    padding-top: 0;
    padding-bottom: 0;
  }

  body.sidebar-collapsed {
    --sidebar: var(--sidebar-rail);
  }

  body.sidebar-collapsed .drawer-head,
  body.sidebar-collapsed .session-list,
  body.sidebar-collapsed .drawer-foot {
    display: none;
  }

  body.sidebar-collapsed .rail {
    display: flex;
  }

  #login:not([hidden]) ~ #drawer {
    display: none !important;
  }

  .scrim {
    display: none !important;
  }

  .app {
    left: var(--sidebar);
  }

  .session-item:hover {
    background: var(--bg-raise);
  }

  .topbar {
    padding-top: calc(10px + var(--safe-top));
    padding-left: 16px;
    padding-right: 16px;
  }

  .messages {
    padding: 20px max(20px, calc((100% - 860px) / 2));
  }

  .composer {
    padding-left: max(12px, calc((100% - 860px) / 2));
    padding-right: max(12px, calc((100% - 860px) / 2));
  }

  .toast {
    left: calc(50% + var(--sidebar) / 2);
  }

  .msg.user .bubble {
    max-width: 76%;
  }
}
