/* ==========================================================================
   Enterprise Smart Assistant — 公文档案风格控制台
   纸张 / 油墨 / 宋体 / 印章红。刻意避开「深色终端 + 紫色渐变」的通用 AI 观感，
   因为产品本身就是替员工查阅企业制度公文。
   ========================================================================== */

:root {
  --paper:        #efe9dd;
  --paper-raise:  #f8f4ec;
  --paper-sink:   #e4dccc;
  --ink:          #17150f;
  --ink-2:        #4b453a;
  --ink-3:        #8b8373;
  --rule:         rgba(23, 21, 15, .20);
  --rule-soft:    rgba(23, 21, 15, .09);
  --seal:         #b1362a;
  --seal-deep:    #8c2a20;
  --seal-wash:    rgba(177, 54, 42, .09);
  --jade:         #3d6152;
  --jade-wash:    rgba(61, 97, 82, .10);
  --amber:        #9a7420;
  --amber-wash:   rgba(154, 116, 32, .12);

  --font-display: "Songti SC", "STSong", "SimSun", "Noto Serif SC", "Source Han Serif SC", serif;
  --font-body:    "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  --font-mono:    "Cascadia Mono", "JetBrains Mono", "SFMono-Regular", Consolas, monospace;

  --rail-l: 272px;
  --rail-r: 344px;
  --shadow: 0 1px 0 rgba(23,21,15,.05), 0 12px 28px -22px rgba(23,21,15,.55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  /* flex column instead of `calc(100% - Npx)`: the masthead height depends on
     font metrics, so a hard-coded offset would clip the composer. */
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* 纸张颗粒 — 单层固定纹理，不随滚动移动 */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 9;
  opacity: .5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
}

/* ─────────────────────────── 抬头 ─────────────────────────── */
.masthead {
  position: relative; z-index: 4;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 16px 26px 15px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--paper-raise), rgba(248,244,236,.35));
  animation: drop-in .5s cubic-bezier(.2,.8,.2,1) both;
}
.brand { display: flex; align-items: center; gap: 15px; min-width: 0; }

.seal {
  flex: none; width: 46px; height: 46px; display: grid; place-items: center;
  background: var(--seal); color: #fdf8f2;
  font-family: var(--font-display); font-size: 27px; line-height: 1;
  border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
  transform: rotate(-3deg);
  transition: transform .5s cubic-bezier(.2,.8,.2,1);
}
.seal span { transform: translateY(-1px); }
.masthead:hover .seal { transform: rotate(3deg) scale(1.04); }

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0; font-family: var(--font-display); font-weight: 700;
  font-size: 21px; letter-spacing: .015em; white-space: nowrap;
}
.brand-text p { margin: 1px 0 0; color: var(--ink-3); font-size: 12.5px; letter-spacing: .04em; }

.masthead-right { display: flex; align-items: center; gap: 14px; flex: none; }
.pills { display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 4px; border: 1px solid var(--rule);
  background: var(--paper-raise); border-radius: 999px;
  font-size: 11.5px; font-family: var(--font-mono); color: var(--ink-2);
  white-space: nowrap;
}
.pill b { font-weight: 600; color: var(--ink); }
.pill.ok   { border-color: rgba(61,97,82,.42);  background: var(--jade-wash); }
.pill.warn { border-color: rgba(154,116,32,.45); background: var(--amber-wash); }
.pill.bad  { border-color: rgba(177,54,42,.42);  background: var(--seal-wash); color: var(--seal-deep); }

/* ─────────────────────────── 三栏控制台 ─────────────────────────── */
.console {
  position: relative; z-index: 3;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-l) minmax(0, 1fr) var(--rail-r);
  /* 关键：显式声明行轨道为 minmax(0, 1fr)。
     只写 grid-template-columns 时，隐式行高是 auto —— 行会被内容撑大并溢出
     容器，导致输入框被推到 body 之外（body 又是 overflow:hidden）。 */
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
}

.rail {
  /* min-height:0 → grid/flex item 的默认最小高度是 auto（内容高度），
     不写这一行左/右栏也会被内容撑高而不是自己滚动。 */
  min-height: 0;
  overflow-y: auto; padding: 18px 16px 40px;
  display: flex; flex-direction: column; gap: 16px;
  border-right: 1px solid var(--rule-soft);
  background: linear-gradient(180deg, rgba(228,220,204,.42), rgba(228,220,204,.12));
}
.rail-right { border-right: none; border-left: 1px solid var(--rule-soft); }
.rail-left  { animation: rise .55s .06s cubic-bezier(.2,.8,.2,1) both; }
.rail-right { animation: rise .55s .14s cubic-bezier(.2,.8,.2,1) both; }
.stage      { animation: rise .55s .10s cubic-bezier(.2,.8,.2,1) both; }

.panel {
  background: var(--paper-raise);
  border: 1px solid var(--rule-soft);
  border-radius: 4px;
  padding: 13px 14px 15px;
  box-shadow: var(--shadow);
}
.panel-quiet { background: rgba(248,244,236,.55); box-shadow: none; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.panel-head h2 {
  margin: 0; font-family: var(--font-display); font-size: 14.5px; font-weight: 700;
  letter-spacing: .08em; text-transform: none;
}
.panel-head h2::after {
  content: ""; display: block; width: 22px; height: 2px; margin-top: 4px; background: var(--seal); opacity: .8;
}
.hint { margin: 6px 0 0; font-size: 11.5px; line-height: 1.6; color: var(--ink-3); }
.hint code, .footnote code { font-family: var(--font-mono); font-size: 11px; background: var(--paper-sink); padding: 1px 4px; border-radius: 2px; }

/* 规格表 */
.spec { margin: 0; display: grid; grid-template-columns: auto; gap: 5px; }
.spec div { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.spec dt { color: var(--ink-3); }
.spec dd { margin: 0; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink); text-align: right; word-break: break-all; }

/* 按钮 */
.ghost-btn, .mini-btn, .send-btn {
  font-family: var(--font-body); cursor: pointer;
  border-radius: 3px; transition: transform .18s, background .18s, border-color .18s, color .18s;
}
.ghost-btn {
  border: 1px solid var(--rule); background: var(--paper-raise); color: var(--ink-2);
  padding: 6px 12px; font-size: 12.5px;
}
.ghost-btn:hover { border-color: var(--ink); color: var(--ink); }
.mini-btn {
  border: 1px solid var(--rule); background: transparent; color: var(--ink-2);
  padding: 3px 9px; font-size: 11.5px;
}
.mini-btn:hover { background: var(--seal); border-color: var(--seal); color: #fdf8f2; }
.mini-btn.wide { display: block; width: 100%; margin-top: 11px; padding: 6px; }
.mini-btn[disabled], .send-btn[disabled] { opacity: .45; cursor: progress; }
.badge {
  display: inline-block; min-width: 17px; padding: 0 5px;
  background: var(--seal); color: #fdf8f2; border-radius: 9px;
  font-family: var(--font-mono); font-size: 10.5px; text-align: center;
}

/* 会话列表 */
.thread-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.thread-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px;
  border: 1px solid transparent; border-left: 2px solid var(--rule);
  padding: 5px 6px 5px 9px; border-radius: 2px; cursor: pointer;
  transition: background .16s, border-color .16s;
}
.thread-item:hover { background: var(--paper-sink); border-left-color: var(--ink-3); }
.thread-item.active { border-left-color: var(--seal); background: var(--seal-wash); }
.thread-item .tid { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink); }
.thread-item .meta { font-size: 10.5px; color: var(--ink-3); }
.thread-item .drop {
  border: none; background: transparent; color: var(--ink-3); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 2px;
}
.thread-item .drop:hover { color: var(--seal); background: var(--seal-wash); }
.empty-line { font-size: 11.5px; color: var(--ink-3); font-style: italic; }

/* ─────────────────────────── 中栏 ─────────────────────────── */
.stage {
  display: flex; flex-direction: column; min-width: 0;
  /* 聊天面板必须可以收缩到容器高度以内，否则内容决定高度 → 输入框被推走 */
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0) 120px),
    repeating-linear-gradient(180deg, transparent 0 33px, rgba(23,21,15,.035) 33px 34px);
}

.notice {
  margin: 14px 22px 0; padding: 11px 14px;
  border: 1px solid var(--amber); border-left-width: 3px;
  background: var(--amber-wash); border-radius: 3px;
  font-size: 12.5px; color: #5c4712;
}
.notice b { font-family: var(--font-mono); }
.notice.severe { border-color: var(--seal); background: var(--seal-wash); color: var(--seal-deep); }
.notice-warn   { border-color: var(--amber); background: var(--amber-wash); color: #5c4712; }
.notice-real   { border-color: var(--jade);  background: var(--jade-wash);  color: #23443a; }
.notice-danger { border-color: var(--seal);  background: var(--seal-wash);  color: var(--seal-deep); font-weight: 500; }
.notice div + div { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--rule); }
.notice code { font-family: var(--font-mono); font-size: 11.5px; background: rgba(255,255,255,.5); padding: 1px 4px; border-radius: 2px; }

/* 消息滚动区：唯一的滚动容器。
   flex:1 + min-height:0 是必须的组合 —— 只写 flex:1 时，flex item 的最小高度
   仍是 auto（内容高度），它会一路把 .stage / .console 撑开。
   不加 scroll-behavior:smooth：流式输出每个 token 都滚一次，动画会拖尾、跳动。 */
.transcript {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 22px 8px;
}

/* 欢迎 / 空状态 */
.cover { max-width: 620px; margin: 6vh auto 0; text-align: left; animation: rise .6s .2s both; }
.cover h3 {
  font-family: var(--font-display); font-size: 30px; line-height: 1.35; margin: 0 0 10px;
  letter-spacing: .01em;
}
.cover h3 em { font-style: normal; color: var(--seal); }
.cover p { color: var(--ink-2); margin: 0 0 18px; max-width: 54ch; }
.cover ol { margin: 0; padding-left: 20px; color: var(--ink-2); font-size: 13px; }
.cover ol li { margin-bottom: 6px; }
.cover .rule { height: 1px; background: var(--rule); margin: 22px 0 16px; }

/* 消息 */
.msg { margin: 0 0 22px; max-width: 78ch; animation: rise .38s cubic-bezier(.2,.8,.2,1) both; }
.msg-user { margin-left: auto; }
.msg-user .bubble {
  background: var(--ink); color: #f7f3ea; border-radius: 3px 3px 3px 12px;
  padding: 9px 14px; font-size: 14px; display: inline-block; max-width: 100%;
  box-shadow: 0 10px 20px -18px rgba(23,21,15,.9);
  overflow-wrap: anywhere; word-break: break-word;
}
.msg-user { display: flex; justify-content: flex-end; }
.msg-label {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .14em;
  color: var(--ink-3); text-transform: uppercase; margin-bottom: 5px;
}
.msg-user .msg-label { text-align: right; }
.msg-assistant .bubble {
  background: var(--paper-raise); border: 1px solid var(--rule-soft);
  border-left: 2px solid var(--seal); padding: 12px 16px; border-radius: 2px;
  box-shadow: var(--shadow);
  /* 长回答不裁剪：允许自然增长，滚动由 .transcript 负责 */
  overflow-wrap: anywhere; word-break: break-word;
}
.msg-assistant .bubble p { margin: 0 0 8px; }
.msg-assistant .bubble p:last-child { margin-bottom: 0; }
.msg-assistant .bubble strong { background: linear-gradient(transparent 62%, rgba(177,54,42,.18) 62%); }
.msg-assistant .bubble code {
  font-family: var(--font-mono); font-size: 12px; background: var(--paper-sink);
  padding: 1px 5px; border-radius: 2px;
}
.msg-assistant .bubble ul { margin: 6px 0 8px; padding-left: 18px; }
.caret {
  display: inline-block; width: 7px; height: 15px; margin-left: 2px;
  background: var(--seal); vertical-align: -2px; animation: blink 1s steps(2) infinite;
}
.msg-error .bubble {
  border-left-color: var(--seal); background: var(--seal-wash);
  color: var(--seal-deep); border-color: rgba(177,54,42,.35);
}
.msg-error .bubble .hintline { display: block; margin-top: 6px; font-size: 12px; color: var(--ink-2); }

/* 工具小票 */
.ticket {
  border: 1px dashed var(--rule); background: rgba(248,244,236,.75);
  border-radius: 3px; padding: 8px 12px; margin: 0 0 12px; max-width: 78ch;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-2);
  animation: slide-in .3s cubic-bezier(.2,.8,.2,1) both;
}
.ticket-head { display: flex; align-items: center; gap: 8px; }
.ticket-head .tname { color: var(--seal-deep); font-weight: 600; }
.ticket .args { color: var(--ink-3); overflow-wrap: anywhere; word-break: break-word; }
/* 不设 max-height / overflow:hidden：工具小票的内容也允许自然增长，
   滚动只发生在 .transcript 一层 */
.ticket .result {
  margin-top: 5px; color: var(--ink-2); white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: break-word;
}
.ticket .status-ok  { color: var(--jade); }
.ticket .status-err { color: var(--seal); }
.ticket .status-wait { color: var(--amber); }

.stamp {
  display: inline-grid; place-items: center; min-width: 34px; height: 20px; padding: 0 6px;
  border: 1.5px solid currentColor; border-radius: 3px; color: var(--jade);
  font-family: var(--font-display); font-size: 11px; letter-spacing: .06em;
  transform: rotate(-4deg); animation: stamp .45s cubic-bezier(.2,1.6,.4,1) both;
}
.stamp.err { color: var(--seal); }
.stamp.wait { color: var(--amber); animation: pulse 1.2s ease-in-out infinite; }

/* 引用 */
.cites { display: grid; gap: 7px; margin-top: 9px; }
.cite {
  border: 1px solid var(--rule-soft); border-top: 2px solid var(--ink-3);
  background: var(--paper); border-radius: 2px; padding: 7px 10px;
  animation: rise .3s both;
}
.cite .cite-head { font-family: var(--font-display); font-size: 12.5px; color: var(--ink); }
.cite .cite-head b { color: var(--seal-deep); }
/* 引用卡片完整显示（不再用 -webkit-line-clamp 裁成两行） */
.cite .cite-body {
  margin-top: 3px; font-size: 11.5px; color: var(--ink-2); line-height: 1.55;
  overflow-wrap: anywhere; word-break: break-word;
}

/* 输入区 */
/* 输入区：flex-shrink:0 —— 消息再多也不能把它挤小或推出视口 */
.composer-wrap {
  flex: 0 0 auto;
  border-top: 1px solid var(--rule);
  background: linear-gradient(180deg, rgba(248,244,236,.6), var(--paper-raise));
  padding: 10px 22px 14px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; }
.chip {
  border: 1px solid var(--rule); background: var(--paper-raise); color: var(--ink-2);
  border-radius: 999px; padding: 3px 11px; font-size: 12px; cursor: pointer;
  transition: all .16s;
}
.chip:hover { border-color: var(--seal); color: var(--seal-deep); background: var(--seal-wash); transform: translateY(-1px); }

.composer { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; font-family: var(--font-body); font-size: 14px; line-height: 1.6;
  color: var(--ink); background: var(--paper-raise);
  border: 1px solid var(--rule); border-radius: 3px; padding: 10px 13px;
  max-height: 168px; outline: none; transition: border-color .18s, box-shadow .18s;
}
.composer textarea:focus { border-color: var(--ink); box-shadow: inset 0 0 0 1px rgba(23,21,15,.08); }
.composer textarea::placeholder { color: var(--ink-3); }

.send-btn {
  flex: none; height: 43px; padding: 0 20px; border: none;
  background: var(--seal); color: #fdf8f2; font-size: 14px; letter-spacing: .1em;
  box-shadow: 0 10px 18px -14px rgba(177,54,42,.9);
}
.send-btn:hover { background: var(--seal-deep); transform: translateY(-1px) rotate(-.6deg); }
.footnote { margin: 8px 0 0; font-size: 11px; color: var(--ink-3); }

/* ─────────────────────────── 决策轨迹 ─────────────────────────── */
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--seal);
  animation: pulse 1.1s ease-in-out infinite;
}
/* 决策轨迹：日志会随轮数无限增长，因此它自己是一个受控滚动区，
   这样「工具直连」面板不会被日志一路推到看不见的地方。 */
.trace {
  list-style: none; margin: 0; padding: 0 4px 0 2px;
  display: flex; flex-direction: column; gap: 8px;
  max-height: min(44vh, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.trace-item {
  display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: start;
  font-size: 11.5px; animation: slide-in .32s cubic-bezier(.2,.8,.2,1) both;
}
.trace-item .t {
  font-family: var(--font-mono); font-size: 10px; color: var(--ink-3); padding-top: 2px;
}
.trace-item .body { border-left: 2px solid var(--rule); padding-left: 9px; }
.trace-item.kind-tool_call .body   { border-left-color: var(--seal); }
.trace-item.kind-tool_result .body { border-left-color: var(--jade); }
.trace-item.kind-error .body       { border-left-color: var(--seal); color: var(--seal-deep); }
.trace-item .name { font-family: var(--font-mono); color: var(--ink); }
.trace-item .detail { color: var(--ink-3); font-family: var(--font-mono); font-size: 10.5px;
  word-break: break-all; display: block; margin-top: 1px; }
.trace-empty { font-size: 11.5px; color: var(--ink-3); font-style: italic; }

/* 工具直连 */
.tool-deck { display: flex; flex-direction: column; gap: 11px; margin-top: 10px; }
.tool-card { border: 1px solid var(--rule-soft); border-radius: 3px; padding: 9px 10px; background: var(--paper); }
.tool-card h3 { margin: 0 0 3px; font-family: var(--font-mono); font-size: 12px; color: var(--seal-deep); }
.tool-card p { margin: 0 0 7px; font-size: 11px; color: var(--ink-3); line-height: 1.5; }
.tool-card textarea {
  width: 100%; font-family: var(--font-mono); font-size: 11px; line-height: 1.5;
  border: 1px solid var(--rule); border-radius: 2px; background: var(--paper-raise);
  padding: 6px 7px; resize: vertical; min-height: 54px; color: var(--ink); outline: none;
}
.tool-card textarea:focus { border-color: var(--ink); }
.tool-card .row { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 8px; }
.tool-card pre {
  margin: 7px 0 0; max-height: 168px; overflow: auto; font-family: var(--font-mono);
  font-size: 10.5px; line-height: 1.5; background: var(--paper-sink); border-radius: 2px;
  padding: 7px 8px; white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: break-word; color: var(--ink-2);
}

/* ─────────────────────────── 抽屉 ─────────────────────────── */
.drawer-scrim { position: fixed; inset: 0; background: rgba(23,21,15,.34); z-index: 20; animation: fade .2s both; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(460px, 92vw); z-index: 21;
  background: var(--paper-raise); border-left: 1px solid var(--rule);
  padding: 18px 20px 30px; overflow-y: auto;
  animation: slide-left .3s cubic-bezier(.2,.8,.2,1) both;
  box-shadow: -20px 0 40px -30px rgba(23,21,15,.7);
}
/* 人工审批卡片：批准之前操作不会执行 */
.msg.approval .bubble {
  border-left: 3px solid var(--amber);
  background: var(--amber-wash);
  border-color: rgba(154, 116, 32, .45);
}
.approval-action {
  margin: 8px 0; padding: 8px 10px;
  border: 1px dashed var(--rule); border-radius: 3px; background: rgba(255,255,255,.55);
}
.approval-tool {
  font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--amber);
  margin-bottom: 5px;
}
.approval-actions { display: flex; gap: 9px; margin-top: 10px; }
.approval-actions .send-btn { height: 36px; padding: 0 16px; font-size: 13px; }
.approval-actions .ghost-btn { height: 36px; }
.msg.approval button[disabled] { opacity: .45; cursor: default; }
.msg.approval .bubble p { margin: 0 0 6px; }

/* 知识库文档列表 */
.kb-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.kb-item {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 7px;
  border-left: 2px solid var(--rule); padding: 4px 4px 4px 8px; border-radius: 2px;
  transition: background .16s, border-color .16s;
}
.kb-item:hover { background: var(--paper-sink); border-left-color: var(--seal); }
.kb-item .kb-name {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kb-item .kb-size { font-size: 10.5px; color: var(--ink-3); font-family: var(--font-mono); }
.kb-item .drop {
  border: none; background: transparent; color: var(--ink-3); cursor: pointer;
  font-size: 12px; line-height: 1; padding: 2px 4px; border-radius: 2px;
}
.kb-item .drop:hover { color: var(--seal); background: var(--seal-wash); }

.outbox { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }

/* 发件箱抽屉里的邮件模式 / SMTP 检测 */
.mail-status {
  margin-top: 10px; padding: 9px 11px; border-radius: 3px;
  border: 1px solid var(--rule-soft); border-left: 3px solid var(--ink-3);
  background: var(--paper); font-size: 11.5px; line-height: 1.7; color: var(--ink-2);
}
.mail-status[data-state="mock"] { border-left-color: var(--ink-3); }
.mail-status[data-state="real"] { border-left-color: var(--seal); background: var(--seal-wash); }
.mail-status[data-state="ok"]   { border-left-color: var(--jade); background: var(--jade-wash); }
.mail-status[data-state="warn"] { border-left-color: var(--amber); background: var(--amber-wash); }
.mail-status .mono { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); word-break: break-all; }
.mail-status .mail-mode {
  display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 2px;
  background: var(--ink); color: var(--paper-raise);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em;
}
.mail-status button { margin-top: 7px; }
.mail-status code { font-family: var(--font-mono); font-size: 10.5px; background: var(--paper-sink); padding: 1px 4px; border-radius: 2px; }
.envelope {
  border: 1px solid var(--rule-soft); border-left: 2px solid var(--seal);
  background: var(--paper); border-radius: 2px; padding: 9px 11px;
}
.envelope .head { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; }
.envelope .to { font-family: var(--font-mono); color: var(--ink); }
.envelope .when { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); }
.envelope .subject { font-family: var(--font-display); font-size: 13px; margin: 3px 0; }
.envelope .body { font-size: 11.5px; color: var(--ink-2); white-space: pre-wrap; }
.envelope .meta { margin-top: 5px; font-family: var(--font-mono); font-size: 10px; color: var(--ink-3); }

/* ─────────────────────────── 动画 ─────────────────────────── */
@keyframes rise      { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes drop-in   { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes slide-in  { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }
@keyframes slide-left{ from { opacity: 0; transform: translateX(26px); } to { opacity: 1; transform: none; } }
@keyframes fade      { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink     { 0%,49% { opacity: 1; } 50%,100% { opacity: 0; } }
@keyframes pulse     { 0%,100% { opacity: 1; } 50% { opacity: .28; } }
@keyframes stamp     { 0% { opacity: 0; transform: rotate(-16deg) scale(1.9); }
                       60% { opacity: 1; transform: rotate(-2deg) scale(.94); }
                       100% { opacity: 1; transform: rotate(-4deg) scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .transcript { scroll-behavior: auto; }
}

/* ─────────────────────────── 响应式 ───────────────────────────
   断点策略：三栏 → 窄三栏 → 「左栏 + (对话 / 决策轨迹 上下叠放)」→ 单栏堆叠。
   关键点：任何宽度下「决策轨迹 / 工具直连 / 发件箱」都必须可用，
   绝不能用 display:none 把功能面板藏掉。*/

@media (max-width: 1320px) {
  :root { --rail-l: 240px; --rail-r: 304px; }
}

@media (max-width: 1080px) {
  body { height: auto; min-height: 100vh; overflow-y: auto; }
  .console {
    grid-template-columns: 226px minmax(0, 1fr);
    /* 第二行 auto 放右栏；第一行给聊天面板一个**确定高度**，
       这样 .transcript 才会内部滚动而不是把页面撑长。 */
    grid-template-rows: 68vh auto;
  }
  /* 窄屏下页面可以整体滚动，但聊天面板必须是确定高度的，
     否则消息区又会退化成「内容多高就多高」。 */
  .stage { height: 68vh; min-height: 420px; }
  .rail-right {
    grid-area: 2 / 2 / 3 / 3;
    flex-direction: row; flex-wrap: wrap; align-content: flex-start;
    border-left: none; border-top: 1px solid var(--rule-soft);
  }
  .rail-right .panel { flex: 1 1 300px; }
  .trace { max-height: min(38vh, 320px); }
}

@media (max-width: 760px) {
  .masthead { flex-wrap: wrap; gap: 12px; padding: 14px 18px; }
  .brand-text h1 { font-size: 18px; }
  .brand-text p { font-size: 11.5px; }
  .pills { justify-content: flex-start; }
  /* 单栏时把对话区放到最前面：手机/窄窗口打开就能看到输入框，
     档案、索引、决策轨迹依次排在下面。 */
  .console { display: flex; flex-direction: column; grid-template-columns: none; grid-template-rows: none; }
  /* 单栏时聊天面板同样要有确定高度：74vh 的滚动对话区 + 常驻输入框 */
  .stage { order: 1; height: 74vh; min-height: 420px; border-bottom: 1px solid var(--rule-soft); }
  .rail-left { order: 2; }
  .rail-right { order: 3; flex-direction: column; }
  .rail { border: none; border-bottom: 1px solid var(--rule-soft); }
  .transcript, .composer-wrap { padding-left: 15px; padding-right: 15px; }
  .notice { margin-left: 15px; margin-right: 15px; }
}
@media (max-width:760px) { .masthead-right { flex-wrap:wrap; min-width:0; max-width:100%; } .pills { flex-wrap:wrap; min-width:0; } }
