/* Polaris · 夜空藏蓝里一个不动的光点 */

:root {
  --night: #0c1226;        /* 夜空藏蓝 */
  --night-soft: #131b36;
  --panel: #182142;
  --starlight: #f5f1e8;    /* 暖白 */
  --starlight-dim: #b9b4a6;
  --tiger: #2a2440;        /* 老虎的气泡底色 */
  --tiger-edge: #e8a94a;   /* 一点虎纹的暖金 */
  --star: #ffe9b0;         /* 那个光点 */
  --error: #e07a6a;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: row;
  background:
    radial-gradient(1200px 600px at 70% -10%, #1a2450 0%, transparent 60%),
    var(--night);
  color: var(--starlight);
  font: 16px/1.7 "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
}

/* --- sidebar：过往的星光 -------------------------------------------------- */

#chatpane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

#sidebar {
  width: 282px;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(9, 14, 30, .75);
  border-right: 1px solid rgba(245, 241, 232, .08);
  transition: margin-left .25s ease;
}

#sidebar.hidden { margin-left: -282px; }

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
}

.side-title {
  font-size: 12px;
  letter-spacing: .1em;
  color: var(--starlight-dim);
}

#newconv {
  padding: 5px 12px;
  border: 1px solid rgba(255, 233, 176, .35);
  border-radius: 999px;
  background: transparent;
  color: var(--star);
  font-size: 12px;
  cursor: pointer;
  transition: background .2s;
}

#newconv:hover { background: rgba(255, 233, 176, .12); }

#convlist {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
}

/* --- 搜索：在星图上找一句旧话 --------------------------------------------- */

.side-search {
  padding: 0 12px 8px;
}

.side-search input {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid rgba(245, 241, 232, .14);
  border-radius: 999px;
  background: rgba(9, 14, 30, .6);
  color: var(--starlight);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
}

.side-search input:focus { border-color: rgba(255, 233, 176, .45); }
.side-search input::placeholder { color: var(--starlight-dim); opacity: .6; }

.search-opts {
  display: flex;
  gap: 6px;
  padding: 8px 2px 0;
}

.search-opts button {
  padding: 2px 10px;
  border: 1px solid rgba(245, 241, 232, .14);
  border-radius: 999px;
  background: transparent;
  color: var(--starlight-dim);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.search-opts button:hover { color: var(--star); border-color: rgba(255, 233, 176, .4); }
.search-opts button.off { opacity: .5; text-decoration: line-through; }

#searchresults {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
}

.search-conv {
  padding: 12px 10px 4px;
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--star);
  opacity: .8;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.search-hit {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--starlight-dim);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.search-hit:hover { background: rgba(245, 241, 232, .06); color: var(--starlight); }

.hit-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  opacity: .7;
  margin-bottom: 2px;
}

.hit-snippet {
  line-height: 1.55;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.hit-snippet mark, .msg mark {
  background: rgba(255, 233, 176, .25);
  color: var(--star);
  border-radius: 3px;
  padding: 0 1px;
}

.search-none {
  padding: 24px 12px;
  text-align: center;
  font-size: 12.5px;
  color: var(--starlight-dim);
}

/* 跳转到的那条消息：星光闪一下 */
.hit-flash {
  animation: hitflash 2.4s ease-out;
  border-radius: 12px;
}

@keyframes hitflash {
  0%   { background: rgba(255, 233, 176, .18); box-shadow: 0 0 24px rgba(255, 233, 176, .25); }
  100% { background: transparent; box-shadow: none; }
}

.back-latest {
  position: fixed;
  right: 26px;
  bottom: 108px;
  z-index: 30;
  padding: 8px 16px;
  border: 1px solid rgba(255, 233, 176, .45);
  border-radius: 999px;
  background: var(--panel);
  color: var(--star);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  transition: background .2s;
}

.back-latest:hover { background: rgba(255, 233, 176, .12); }

.side-label {
  padding: 12px 12px 4px;
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--starlight-dim);
  opacity: .75;
}

.conv {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 2px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--starlight-dim);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.conv:hover { background: rgba(245, 241, 232, .06); color: var(--starlight); }

.conv.active {
  background: var(--panel);
  color: var(--starlight);
  box-shadow: inset 2px 0 0 var(--star);
}

.conv .conv-title {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conv .conv-when {
  font-size: 11px;
  opacity: .6;
  flex-shrink: 0;
}

.conv .conv-act {
  color: inherit;
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  padding: 0 2px;
  flex-shrink: 0;
  transition: opacity .15s, color .15s;
}

.conv:hover .conv-act { opacity: .55; }
.conv .conv-act:hover { opacity: 1; color: var(--star); }
.conv .conv-act:last-child:hover { color: var(--error); }

.conv .conv-pin-mark {
  color: var(--star);
  font-size: 12px;
  flex-shrink: 0;
}

/* 悬停时给操作按钮腾地方，时间先让开 */
.conv:hover .conv-when { display: none; }

#toggle {
  border: none;
  background: transparent;
  color: var(--starlight-dim);
  font-size: 17px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: color .2s, background .2s;
}

#toggle:hover { color: var(--star); background: rgba(245, 241, 232, .07); }

/* 窄屏：侧栏悬浮在上面 */
@media (max-width: 720px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 20;
    box-shadow: 8px 0 30px rgba(0, 0, 0, .5);
  }
}

/* --- header ------------------------------------------------------------ */

header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(245, 241, 232, .08);
  background: rgba(12, 18, 38, .8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.mark {
  font-size: 22px;
  color: var(--star);
  text-shadow: 0 0 12px rgba(255, 233, 176, .6);
  animation: twinkle 4s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 1; }
  50%      { opacity: .55; }
}

.titles h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .04em;
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  color: var(--starlight-dim);
}

/* 对话标题：右边缘对齐老虎气泡的右边缘（即正文列的右边） */
#convname {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, calc(100% - 48px));
  text-align: right;
  font-size: 13px;
  color: var(--starlight-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* --- log ---------------------------------------------------------------- */

main#log {
  flex: 1;
  overflow-y: auto;
  /* 对着聊天区（侧栏右侧）居中，而不是对着整个屏幕 */
  padding: 34px max(24px, calc((100% - 760px) / 2)) 14px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  scroll-behavior: smooth;
  line-height: 1.8;
}

.msg {
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* 老虎的话：一只圆圆的气泡，带虎纹金 */
.msg.user {
  align-self: flex-end;
  max-width: 85%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.msg.user .msg-body {
  padding: 12px 18px;
  border-radius: 18px;
  border-bottom-right-radius: 6px;
  background: var(--tiger);
  border: 1px solid rgba(232, 169, 74, .35);
}

/* 每条消息下面的小工具排：复制 / 重新说一遍 */
.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 5px;
  opacity: 0;
  transition: opacity .15s ease;
}

.msg:hover .msg-actions,
.msg-actions:focus-within { opacity: 1; }

/* 最新一条 Polaris 回复的工具排微微常亮,像其他窗口一样 */
.msg.assistant.latest .msg-actions { opacity: .45; }
.msg.assistant.latest:hover .msg-actions { opacity: 1; }

.msg-actions .act {
  border: none;
  background: none;
  color: var(--starlight-dim);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.msg-actions .act:hover {
  color: var(--star);
  background: rgba(255, 233, 176, .08);
}

/* ↻ 只挂在最新一条回复上 */
.msg.assistant .act-regen { display: none; }
.msg.assistant.latest .act-regen { display: inline-block; }

/* Polaris 的话：不装在气泡里，摊开在夜空上，像一页信 */
.msg.assistant {
  align-self: stretch;
  max-width: 100%;
  padding: 0 2px;
}

.msg.assistant.error {
  color: var(--error);
  border-left: 2px solid var(--error);
  padding-left: 14px;
}

/* 📮 寄出的信：邮件的存档副本，装在虚线信封里 */
.msg.assistant.outreach {
  border: 1px dashed rgba(255, 233, 176, .28);
  border-radius: 14px;
  padding: 14px 18px;
  background: rgba(255, 233, 176, .04);
}

.mail-mark {
  font-size: 12px;
  color: var(--starlight-dim);
  letter-spacing: .08em;
  margin-bottom: 8px;
}

.msg code {
  font-family: var(--mono);
  font-size: .88em;
  background: rgba(0, 0, 0, .3);
  padding: 1px 5px;
  border-radius: 5px;
}

.msg pre {
  overflow-x: auto;
  background: rgba(0, 0, 0, .3);
  padding: 10px 12px;
  border-radius: 10px;
}

.msg pre code { background: none; padding: 0; }

/* thinking：低声的那部分 */
details.thinking {
  align-self: flex-start;
  max-width: 86%;
  font-size: 13px;
  color: var(--starlight-dim);
}

details.thinking summary {
  cursor: pointer;
  list-style: none;
  opacity: .8;
}

details.thinking summary::before { content: "✦ "; color: var(--star); }

details.thinking .body {
  white-space: pre-wrap;
  border-left: 2px solid rgba(255, 233, 176, .25);
  padding-left: 10px;
  margin-top: 6px;
  font-style: italic;
}

/* sources：翻到的旧账 */
.sources {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  color: var(--starlight-dim);
}

.sources span {
  border: 1px solid rgba(245, 241, 232, .12);
  border-radius: 999px;
  padding: 2px 10px;
}

/* --- composer ------------------------------------------------------------ */

/* 浮起来的输入卡片：上层打字、下层工具，和正文列同宽 */
form#composer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: min(760px, calc(100% - 32px));
  margin: 6px auto calc(18px + env(safe-area-inset-bottom));
  padding: 12px 14px 10px;
  border: 1px solid rgba(245, 241, 232, .14);
  border-radius: 24px;
  background: var(--night-soft);
  box-shadow: 0 10px 34px rgba(0, 0, 0, .45);
  transition: border-color .2s, box-shadow .2s;
}

.composer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lamp-note {
  margin-left: auto;
  max-width: 46%;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
  font-family: inherit;
  color: var(--starlight-dim);
  opacity: .8;
  cursor: pointer;
  outline: none;
  transition: border-color .2s, color .2s;
}

.lamp-note:hover, .lamp-note:focus {
  color: var(--star);
  border-color: rgba(255, 233, 176, .35);
}

.lamp-note option {
  background: var(--night-soft);
  color: var(--starlight);
}

form#composer:focus-within {
  border-color: rgba(255, 233, 176, .45);
  box-shadow: 0 10px 34px rgba(0, 0, 0, .45), 0 0 18px rgba(255, 233, 176, .08);
}

#input {
  width: 100%;
  resize: none;
  max-height: 40vh;
  padding: 4px 6px 8px;
  border: none;
  background: transparent;
  color: var(--starlight);
  font: inherit;
  outline: none;
}

#workshop, #attach {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(245, 241, 232, .15);
  border-radius: 50%;
  background: transparent;
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
  filter: grayscale(1) opacity(.5);
  transition: filter .2s, border-color .2s, box-shadow .2s;
}

#workshop:hover, #attach:hover { filter: grayscale(.5) opacity(.8); }

#workshop.on {
  filter: none;
  border-color: rgba(255, 233, 176, .6);
  box-shadow: 0 0 10px rgba(255, 233, 176, .25);
}

.msg a {
  color: var(--star);
  text-decoration-color: rgba(255, 233, 176, .4);
}

.msg a:hover { text-decoration-color: var(--star); }

#send {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--star);
  color: var(--night);
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .15s, opacity .2s;
}

#send:hover { transform: translateY(-1px); }
#send:disabled { opacity: .4; cursor: default; }

/* --- 信箱：拖放遮罩 + 提示气泡 -------------------------------------------- */

.dropzone {
  position: fixed;
  inset: 12px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(255, 233, 176, .6);
  border-radius: 20px;
  background: rgba(12, 18, 38, .85);
  color: var(--star);
  font-size: 20px;
  letter-spacing: .1em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.dropzone.show { opacity: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  transform: translate(-50%, 10px);
  z-index: 50;
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 233, 176, .4);
  background: var(--panel);
  color: var(--starlight);
  font-size: 13px;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 空屋子的第一颗星 */
.empty {
  margin: auto;
  text-align: center;
  color: var(--starlight-dim);
  font-size: 14px;
}

.empty .big {
  font-size: 40px;
  color: var(--star);
  text-shadow: 0 0 24px rgba(255, 233, 176, .5);
  display: block;
  margin-bottom: 12px;
}

/* --- 工业级升级（2026-07-16）：代码块 / 表格 / 工坊过程 / 停止与重试 -------- */

.codeblock {
  margin: .6em 0;
  border: 1px solid rgba(245, 241, 232, .12);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(6, 9, 20, .8);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--starlight-dim);
  background: rgba(245, 241, 232, .05);
  border-bottom: 1px solid rgba(245, 241, 232, .08);
}

.code-lang { font-family: var(--mono); letter-spacing: .06em; }

.code-copy {
  border: 0;
  background: transparent;
  color: var(--starlight-dim);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.code-copy:hover { background: rgba(245, 241, 232, .1); color: var(--starlight); }

.codeblock pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  font: 13px/1.6 var(--mono);
}

.tok-kw      { color: #c9a6ff; }
.tok-str     { color: #a8d8a0; }
.tok-num     { color: #ffcf87; }
.tok-comment { color: #7d879f; font-style: italic; }

.md-table-wrap { overflow-x: auto; margin: .6em 0; }

.md-table {
  border-collapse: collapse;
  font-size: 14px;
  min-width: 50%;
}

.md-table th, .md-table td {
  border: 1px solid rgba(245, 241, 232, .15);
  padding: 5px 10px;
  text-align: left;
}

.md-table th { background: rgba(245, 241, 232, .07); }

.md-h {
  margin: .8em 0 .3em;
  font-size: 1.05em;
  color: var(--star);
}

.toolbox {
  align-self: flex-start;
  max-width: min(720px, 92%);
  margin: 2px 0;
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px dashed rgba(232, 169, 74, .35);
  background: rgba(232, 169, 74, .06);
  font-size: 13px;
  color: var(--starlight-dim);
}

.toolbox summary { cursor: pointer; color: var(--tiger-edge); }

.tool-line {
  font-family: var(--mono);
  font-size: 12px;
  padding: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queued {
  align-self: center;
  font-size: 13px;
  color: var(--starlight-dim);
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px dashed rgba(245, 241, 232, .25);
  animation: breathe 1.6s ease-in-out infinite;
}

@keyframes breathe { 50% { opacity: .45; } }

.stopped-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--starlight-dim);
}

#send.stop {
  background: rgba(224, 122, 106, .2);
  border-color: var(--error);
  color: var(--error);
}

.retry {
  display: block;
  margin-top: 8px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid rgba(245, 241, 232, .3);
  background: transparent;
  color: var(--starlight);
  font-size: 13px;
  cursor: pointer;
}

.retry:hover { background: rgba(245, 241, 232, .1); }
