/* ==========================================================================
   三思 · 智能体对话工作室
   设计：浅色纸面 + 靛紫渐变点缀，人设主色用于头像与标签
   无外部字体、无外部脚本，全部样式本地加载
   ========================================================================== */

:root {
  --bg: #f6f5fa;
  --bg-grad: radial-gradient(1200px 600px at 12% -8%, #ece9ff 0%, rgba(236, 233, 255, 0) 60%),
    radial-gradient(900px 500px at 100% 0%, #e6f1ff 0%, rgba(230, 241, 255, 0) 55%);
  --surface: #ffffff;
  --surface-2: #faf9fd;
  --surface-3: #f1eff8;
  --line: #e6e3f0;
  --line-strong: #d5d1e6;
  --text: #1d1b27;
  --text-2: #4f4a68;
  --text-3: #6d6787;
  --brand: #5b4bc4;
  --brand-2: #3056d3;
  --brand-ink: #ffffff;
  --grad: linear-gradient(135deg, #6b5bd6 0%, #3056d3 100%);
  --ok: #1f9d6b;
  --warn: #c77700;
  --err: #cf3f45;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(28, 24, 60, 0.06);
  --shadow: 0 6px 24px -10px rgba(28, 24, 60, 0.22);
  --shadow-lg: 0 24px 60px -24px rgba(28, 24, 60, 0.38);
  --sidebar-w: 272px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
}

[data-theme='dark'] {
  --bg: #0f0e17;
  --bg-grad: radial-gradient(1100px 560px at 10% -10%, #241f45 0%, rgba(36, 31, 69, 0) 60%),
    radial-gradient(900px 520px at 100% 0%, #12253f 0%, rgba(18, 37, 63, 0) 55%);
  --surface: #171623;
  --surface-2: #1c1b2a;
  --surface-3: #232233;
  --line: #2c2a3f;
  --line-strong: #3a3752;
  --text: #eceaf6;
  --text-2: #b3aecb;
  --text-3: #918bab;
  --brand: #8c7bf0;
  --brand-2: #6f9bff;
  --brand-ink: #0f0e17;
  --grad: linear-gradient(135deg, #7d6cf0 0%, #4d84ff 100%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow: 0 8px 28px -12px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 28px 70px -30px rgba(0, 0, 0, 0.85);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.68;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

::selection {
  background: color-mix(in srgb, var(--brand) 26%, transparent);
}

/* ---------------------------------------------------------------- 布局 */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 10px;
  padding: 14px 12px 10px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

/* ---------------------------------------------------------------- 品牌 */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px 8px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--grad);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -1px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}
.brand-text strong {
  font-size: 16px;
  letter-spacing: 0.5px;
}
.brand-text span {
  font-size: 11.5px;
  color: var(--text-3);
}

/* ---------------------------------------------------------------- 按钮 */
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, transform 0.08s, color 0.16s, opacity 0.16s;
  white-space: nowrap;
}
.btn:hover {
  background: var(--surface-3);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  filter: brightness(1.06);
  background: var(--grad);
}
.btn-ghost {
  background: color-mix(in srgb, var(--brand) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--brand) 30%, transparent);
  color: var(--brand);
}
.btn-ghost:hover {
  background: color-mix(in srgb, var(--brand) 15%, var(--surface));
}
.btn-dashed {
  background: transparent;
  border-style: dashed;
  color: var(--text-2);
}
.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn-quiet:hover {
  background: var(--surface-3);
  color: var(--text);
}
.btn-block {
  width: 100%;
  display: block;
}
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 15px;
}
.icon-btn:hover {
  background: var(--surface-3);
}

.side-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ---------------------------------------------------------------- 标签页 */
.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-3);
  border-radius: 11px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 6px 0;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-2);
  cursor: pointer;
}
.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.pane[hidden] {
  display: none;
}
.pane-hint {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-3);
  padding: 0 2px;
}
.pane-search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
}
.pane-search input::placeholder {
  color: var(--text-3);
}

/* ---------------------------------------------------------------- 列表 */
.chat-list,
.persona-list {
  list-style: none;
  margin: 0;
  padding: 0 2px 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  scrollbar-width: thin;
}

.chat-item {
  position: relative;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
}
.chat-item:hover {
  background: var(--surface-2);
  border-color: var(--line);
}
.chat-item.is-active {
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--brand) 34%, transparent);
}
.chat-item .ci-body {
  min-width: 0;
}
.chat-item .ci-title {
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.chat-item .ci-sub {
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ci-badge {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex: none;
}
.ci-del {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 6px;
}
.chat-item:hover .ci-del,
.chat-item:focus-within .ci-del {
  opacity: 1;
}
.ci-del:hover {
  color: var(--err);
  background: color-mix(in srgb, var(--err) 12%, transparent);
}
.round-mark {
  background: var(--grad) !important;
}

.empty-inline {
  margin: 6px 4px;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.6;
}
.empty-inline[hidden] {
  display: none;
}

/* 人设卡 */
.persona-card {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 13px;
  padding: 10px;
  display: grid;
  grid-template-columns: 22px 34px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
}
.persona-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.persona-card.is-current {
  border-color: color-mix(in srgb, var(--brand) 45%, transparent);
  background: color-mix(in srgb, var(--brand) 6%, var(--surface));
}
.pc-check {
  width: 17px;
  height: 17px;
  margin-top: 3px;
  accent-color: var(--brand);
  cursor: pointer;
}
.pc-avatar {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex: none;
}
.pc-main {
  min-width: 0;
}
.pc-name {
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.pc-name .tag-sim {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  flex: none;
}
.pc-desc {
  font-size: 11.5px;
  color: var(--text-2);
  line-height: 1.5;
  margin-top: 2px;
}
.pc-theory {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.pc-theory li {
  font-size: 10.5px;
  color: var(--text-2);
  background: var(--surface-3);
  border-radius: 5px;
  padding: 1px 6px;
}
.pc-acts {
  display: flex;
  gap: 4px;
  margin-top: 7px;
  flex-wrap: wrap;
}
.mini-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 550;
  border-radius: 7px;
  padding: 2px 8px;
  cursor: pointer;
}
.mini-btn:hover {
  color: var(--text);
  background: var(--surface-3);
}
.mini-btn.danger:hover {
  color: var(--err);
  border-color: color-mix(in srgb, var(--err) 40%, transparent);
}

/* ---------------------------------------------------------------- 侧栏底部 */
.side-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 2px 4px;
  border-top: 1px solid var(--line);
  flex: none;
}
.foot-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  padding: 5px 7px;
  border-radius: 8px;
  cursor: pointer;
}
.foot-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}
.foot-btn:last-child {
  margin-left: auto;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent);
}
.dot.is-ok {
  background: var(--ok);
}
.dot.is-err {
  background: var(--err);
}
.dot.is-warn {
  background: var(--warn);
}

/* ---------------------------------------------------------------- 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(10px);
}
.top-meta {
  min-width: 0;
  flex: 1;
}
.top-meta h2 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 640;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-meta p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-actions {
  display: flex;
  gap: 2px;
  flex: none;
}

/* ---------------------------------------------------------------- 对话区 */
.thread {
  overflow-y: auto;
  padding: 22px 20px 8px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.thread-inner {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 8px;
}

.msg-user {
  display: flex;
  justify-content: flex-end;
}
.msg-user .bubble {
  max-width: 78%;
  background: color-mix(in srgb, var(--brand) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
  border-radius: 15px 15px 4px 15px;
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}
[data-theme='dark'] .msg-user .bubble {
  background: color-mix(in srgb, var(--brand) 20%, var(--surface));
}

.msg-ai {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.ai-avatar {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex: none;
  box-shadow: var(--shadow-sm);
}
.ai-body {
  min-width: 0;
}
.ai-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  flex-wrap: wrap;
}
.ai-head b {
  font-size: 13px;
  font-weight: 650;
}
.ai-head .sim {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  padding: 1px 4px;
  border-radius: 4px;
}
.ai-head time {
  font-size: 11px;
  color: var(--text-3);
}
.ai-content {
  word-break: break-word;
}
.ai-content > :first-child {
  margin-top: 0;
}
.ai-content > :last-child {
  margin-bottom: 0;
}
.ai-content p {
  margin: 0 0 0.7em;
}
.ai-content h1,
.ai-content h2,
.ai-content h3,
.ai-content h4 {
  margin: 1.1em 0 0.45em;
  line-height: 1.45;
  font-weight: 650;
}
.ai-content h1 {
  font-size: 19px;
}
.ai-content h2 {
  font-size: 17px;
}
.ai-content h3,
.ai-content h4 {
  font-size: 15.5px;
}
.ai-content ul,
.ai-content ol {
  margin: 0 0 0.75em;
  padding-left: 1.35em;
}
.ai-content li {
  margin: 0.2em 0;
}
.ai-content li::marker {
  color: var(--text-3);
}
.ai-content blockquote {
  margin: 0 0 0.75em;
  padding: 2px 0 2px 12px;
  border-left: 3px solid color-mix(in srgb, var(--brand) 40%, transparent);
  color: var(--text-2);
}
.ai-content code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.5px 5px;
}
.ai-content pre {
  margin: 0 0 0.8em;
  padding: 12px 14px;
  background: #14131f;
  color: #eceaf6;
  border-radius: 11px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
}
.ai-content pre code {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.ai-content hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1em 0;
}
.ai-content a {
  color: var(--brand-2);
  text-underline-offset: 2px;
}
.ai-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
  margin-bottom: 0.8em;
}

.msg-tools {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.14s;
}
.msg-ai:hover .msg-tools,
.msg-ai:focus-within .msg-tools,
.msg-user:hover .msg-tools {
  opacity: 1;
}
.msg-user .msg-tools {
  justify-content: flex-end;
}

.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  font-size: 12.5px;
}
.dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
  margin-right: 3px;
  animation: bounce 1.1s infinite ease-in-out;
}
.dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.dots span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes bounce {
  0%,
  70%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  35% {
    transform: translateY(-4px);
    opacity: 1;
  }
}
.caret::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 1.05em;
  background: var(--brand);
  margin-left: 3px;
  vertical-align: -0.16em;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink {
  to {
    visibility: hidden;
  }
}

.sys-peek {
  font-size: 11.5px;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: 9px;
  padding: 6px 9px;
  margin-bottom: 6px;
  white-space: pre-wrap;
  max-height: 120px;
  overflow: auto;
}
.err-bubble {
  color: var(--err);
  background: color-mix(in srgb, var(--err) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13px;
}
.msg-error {
  grid-column: 2;
}

/* 空状态 */
.hero {
  max-width: 800px;
  margin: 26px auto 0;
  padding: 26px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.hero h3 {
  margin: 0 0 6px;
  font-size: 21px;
  letter-spacing: -0.2px;
}
.hero p.lede {
  margin: 0 0 16px;
  color: var(--text-2);
  font-size: 13.5px;
}
.hero-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.hero-card {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 13px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.16s, transform 0.16s, box-shadow 0.16s;
}
.hero-card:hover {
  border-color: color-mix(in srgb, var(--brand) 45%, transparent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.hero-card .hc-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.hero-card .hc-glyph {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex: none;
}
.hero-card strong {
  font-size: 13.5px;
}
.hero-card p {
  margin: 0;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.55;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 16px;
}
.chip {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
}
.chip:hover {
  color: var(--text);
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 7%, var(--surface));
}
.hero-note {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.7;
  border-top: 1px dashed var(--line-strong);
  padding-top: 12px;
}

/* ---------------------------------------------------------------- 输入区 */
.composer-zone {
  padding: 0 20px 12px;
  border-top: 1px solid transparent;
  flex: none;
}
.composer-zone > * {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}
.notice {
  font-size: 12.5px;
  line-height: 1.6;
  border-radius: 11px;
  padding: 9px 12px;
  margin-bottom: 8px;
  border: 1px solid color-mix(in srgb, var(--warn) 34%, transparent);
  background: color-mix(in srgb, var(--warn) 9%, var(--surface));
  color: color-mix(in srgb, var(--warn) 78%, var(--text));
}
.notice[hidden] {
  display: none;
}
.notice b {
  font-weight: 650;
}
.notice .btn {
  margin-left: 8px;
}

.targets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 7px;
}
.target {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-2);
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 2px 9px 2px 3px;
}
.target i {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
}

.composer {
  position: relative;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 8px 8px 6px;
  transition: border-color 0.16s, box-shadow 0.16s;
}
.composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 14%, transparent), var(--shadow);
}
.composer textarea {
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  padding: 6px 8px 2px;
  max-height: 240px;
  min-height: 44px;
  line-height: 1.65;
  font-size: 15px;
  overflow-y: auto;
}
.composer textarea:focus {
  outline: none;
}
.composer textarea::placeholder {
  color: var(--text-3);
}
.composer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}
.kbd-hint {
  font-size: 11px;
  color: var(--text-3);
}
.meter {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.composer-bar .spacer,
.meter {
  margin-left: auto;
}
.composer-bar .btn-primary {
  margin-left: 0;
}
.meter + #btn-stop,
.meter + #btn-send {
  margin-left: 0;
}
.legal {
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--text-2);
  margin: 9px auto 0;
  text-align: center;
}
.legal strong {
  color: var(--warn);
  font-weight: 650;
}

/* ---------------------------------------------------------------- 弹窗 */
.modal {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(880px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  overflow: visible;
  color: var(--text);
}
.modal::backdrop {
  background: rgba(16, 14, 32, 0.46);
  backdrop-filter: blur(3px);
}
.modal-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 20px 22px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-head h3 {
  margin: 0;
  font-size: 18px;
}
.modal-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.65;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.field > label {
  font-size: 12.5px;
  font-weight: 620;
  color: var(--text-2);
}
.field input[type='text'],
.field input[type='password'],
.field input[type='search'],
.field select,
.field textarea {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 14px;
  width: 100%;
}
.field textarea {
  resize: vertical;
  line-height: 1.6;
  font-family: var(--sans);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}
.field code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-3);
  padding: 0.5px 4px;
  border-radius: 4px;
}
.tip {
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.6;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.key-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.key-row input {
  flex: 1;
  min-width: 0;
}
input[type='range'] {
  width: 100%;
  accent-color: var(--brand);
}
.check {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  line-height: 1.55;
}
.check input {
  margin-top: 3px;
  accent-color: var(--brand);
  flex: none;
}
.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.spacer {
  flex: 1;
}
.test-out {
  margin: 0;
  font-size: 12.5px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 190px;
  overflow: auto;
}
.test-out[hidden] {
  display: none;
}
.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

/* 通用确认框 */
#dlg-ask {
  width: min(470px, calc(100vw - 32px));
}
#ask-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14.5px;
}
#ask-input:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}
#ask-input[hidden] {
  display: none;
}
.export-card {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 14px 12px;
  font-size: 13.5px;
  font-weight: 560;
  cursor: pointer;
  text-align: left;
}
.export-card:hover {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 7%, var(--surface));
}

/* ---------------------------------------------------------------- 提示条 */
.toast-wrap {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 60;
  pointer-events: none;
  width: min(560px, calc(100vw - 24px));
}
.toast {
  background: #1d1b27;
  color: #fff;
  border-radius: 11px;
  padding: 9px 14px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: pop 0.2s ease-out;
  max-width: 100%;
  word-break: break-word;
}
[data-theme='dark'] .toast {
  background: #2e2b42;
  border: 1px solid var(--line-strong);
}
.toast.is-err {
  background: var(--err);
}
.toast.is-ok {
  background: #16754f;
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(16, 14, 32, 0.4);
  z-index: 40;
}
.scrim[hidden] {
  display: none;
}
.only-mobile {
  display: none;
}

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 960px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    z-index: 50;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    transform: translateX(-102%);
    transition: transform 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
  }
  .app.drawer-open .sidebar {
    transform: none;
  }
  .only-mobile {
    display: grid;
  }
  #btn-close-drawer.only-mobile {
    margin-left: auto;
  }
  .topbar {
    padding: 10px 12px;
  }
  .top-actions .btn-quiet {
    display: none;
  }
  #btn-settings-top {
    display: inline-block;
  }
  .thread {
    padding: 16px 12px 6px;
  }
  .composer-zone {
    padding: 0 12px 10px;
  }
  .msg-user .bubble {
    max-width: 88%;
  }
  .hero {
    padding: 20px 16px;
  }
  .hero-grid {
    grid-template-columns: 1fr;
  }
  .grid-2,
  .grid-3,
  .export-grid {
    grid-template-columns: 1fr;
  }
  .modal-form {
    padding: 16px;
  }
  .legal {
    text-align: left;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 14.5px;
  }
  .kbd-hint {
    display: none;
  }
  .meta-host {
    display: none;
  }
  .side-actions {
    gap: 6px;
  }
  .side-actions .btn {
    padding: 7px 8px;
    font-size: 13px;
  }
  .ai-avatar {
    width: 29px;
    height: 29px;
    font-size: 13px;
    border-radius: 9px;
  }
  .msg-ai {
    grid-template-columns: 29px minmax(0, 1fr);
    gap: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .sidebar,
  .composer-zone,
  .topbar,
  .msg-tools {
    display: none !important;
  }
  .app {
    display: block;
    height: auto;
    overflow: visible;
  }
  .thread {
    overflow: visible;
  }
}
