/* 来宝创始人驾驶舱 v0.10 —— 呼吸式驾驶舱
   纸张暖白、近黑正文、深墨绿主色；琥珀仅用于需要创始人决定。 */

:root {
  color-scheme: light;
  --paper: #FAF9F7;
  --surface: #FFFFFF;
  --ink: #1A1A18;
  --ink-soft: #6B6A66;
  --brand: #0E4F45;
  --brand-soft: #E7EFEC;
  --decide: #B45309;
  --decide-soft: #F7EBDD;
  --fail: #8F3B36;
  --fail-soft: #F5E7E5;
  --line: #E5E2DC;
  --line-soft: #EFEDE8;
  --radius: 10px;
  --focus: 2px solid #0E4F45;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.65 ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

/* ---------- 布局骨架 ---------- */

.cockpit {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) auto;
}

/* ---------- 左侧导航 ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 26px 20px 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 100vh;
}

.brand {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}

.brand-sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.14em;
  margin-top: 2px;
}

.new-thread {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 18px 0 6px;
  padding: 10px 14px;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.18s var(--ease);
}

.new-thread:hover { background: #0C443C; }
.new-thread:active { transform: scale(0.985); }
.new-thread-mark { font-size: 15px; line-height: 1; }

.side-nav {
  flex: 1;
  overflow-y: auto;
  margin-top: 10px;
  padding-right: 2px;
}

.nav-caption {
  margin: 14px 4px 4px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.nav-block { margin-top: 16px; }

.nav-block h2 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 4px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11px;
  text-align: center;
}

.count-decision { background: var(--decide-soft); color: var(--decide); }

.bucket-list, .thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.bucket-item, .thread-item {
  width: 100%;
  display: block;
  text-align: left;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s var(--ease);
}

.bucket-item:hover, .thread-item:hover { background: var(--line-soft); }
.thread-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.bucket-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--brand);
  vertical-align: 1px;
}

.bucket-item.is-decision .bucket-dot { background: var(--decide); }

.bucket-item .bucket-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bucket-item .bucket-sub {
  display: block;
  font-size: 11.5px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bucket-item.is-decision .bucket-sub { color: var(--decide); }
.bucket-empty { padding: 4px 10px; font-size: 12px; color: var(--ink-soft); }

.thread-item {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-foot {
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
  margin-top: 12px;
}

.privacy-note {
  margin: 0 4px 10px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}

.logout {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  font-family: inherit;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
}

.logout:hover { background: var(--line-soft); color: var(--ink); }

/* ---------- 中间会话区 ---------- */

.conversation {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100vh;
  max-height: 100vh;
}

.conv-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 22px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.eyebrow {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
}

.conv-head h1 {
  margin: 3px 0 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.head-status {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.only-you {
  font-size: 11.5px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--surface);
}

/* ---------- 状态点与状态丸：只用五种真实状态 ---------- */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-idle::before { background: #B9B6AF; }
.status-working { color: var(--brand); border-color: #CBDDD7; background: var(--brand-soft); }
.status-working::before { animation: breathe 1.6s ease-in-out infinite; }
.status-decision { color: var(--decide); border-color: #EBD3B8; background: var(--decide-soft); }
.status-action { color: var(--decide); border-color: #EBD3B8; background: var(--decide-soft); }
.status-failed { color: var(--fail); border-color: #E3C6C3; background: var(--fail-soft); }

@keyframes breathe {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* ---------- 消息流 ---------- */

.messages {
  overflow-y: auto;
  padding: 30px 32px 20px;
}

.empty-hint {
  max-width: 520px;
  margin: 60px auto;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 2;
}

.message {
  max-width: 700px;
  margin: 0 0 4px;
  padding: 12px 16px;
  border-radius: 4px 14px 14px 14px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 0.28s var(--ease);
}

.message-user {
  margin-left: auto;
  border-radius: 14px 4px 14px 14px;
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.message-assistant { border-left: 2px solid var(--brand); }

.message time {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-soft);
}

.message-user time { color: rgba(255, 255, 255, 0.65); }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 后台执行卡（锚定在原消息后） ---------- */

.exec-slot { max-width: 700px; margin: 0 0 18px; }

.exec-card {
  margin-top: 8px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  animation: rise 0.28s var(--ease);
}

.exec-card.is-flash { outline: 2px solid var(--brand); outline-offset: 2px; }

.exec-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.exec-action {
  font-size: 13px;
  color: var(--ink);
  font-weight: 550;
}

.exec-summary {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.exec-result {
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  white-space: pre-wrap;
  word-break: break-word;
}

/* 真实进度回执：仅复杂任务、且仅依据后端 coarse_steps */
.stage-track {
  list-style: none;
  display: flex;
  gap: 0;
  margin: 14px 0 4px;
  padding: 0;
}

.stage-track li {
  flex: 1;
  position: relative;
  font-size: 11.5px;
  color: var(--ink-soft);
  text-align: center;
  padding-top: 14px;
}

.stage-track li::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
}

.stage-track li::after {
  content: "";
  position: absolute;
  top: 7.5px;
  left: calc(-50% + 8px);
  right: calc(50% + 8px);
  height: 1.5px;
  background: var(--line);
}

.stage-track li:first-child::after { display: none; }
.stage-track li.done { color: var(--brand); font-weight: 600; }
.stage-track li.done::before { background: var(--brand); }
.stage-track li.done::after { background: var(--brand); }
.stage-track li.current { color: var(--ink); font-weight: 600; }
.stage-track li.current::before { background: var(--brand); animation: breathe 1.6s ease-in-out infinite; }

.exec-failure {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--fail-soft);
  color: var(--fail);
  font-size: 12.5px;
}

.exec-sources, .exec-artifacts { margin-top: 12px; }

.exec-sources h3, .exec-artifacts h3 {
  margin: 0 0 6px;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-weight: 600;
}

.exec-sources ul, .exec-artifacts ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  font-size: 12.5px;
}

.exec-sources a {
  color: var(--brand);
  text-decoration: none;
  border-bottom: 1px solid #C4D8D2;
  word-break: break-all;
}

.exec-sources a:hover { border-bottom-color: var(--brand); }

/* ---------- 工作卡结果 ---------- */

.workcard {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #CBDDD7;
  border-radius: 8px;
  background: #F4F8F6;
}

.workcard-lead {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
}

.workcard-owner {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.workcard-body {
  margin-top: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

.workcard-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ---------- 按钮 ---------- */

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  font-family: inherit;
  padding: 7px 13px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover { background: #0C443C; color: #fff; }

/* ---------- 内联核验面板（900–1439px） ---------- */

.card-verify { display: none; margin-top: 12px; }

.verify-toggle {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  padding: 6px 0;
  cursor: pointer;
}

.verify-toggle:hover { text-decoration: underline; }

.verify-panel {
  margin: 6px 0 0;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

/* ---------- 右侧核验抽屉（≥1440px，宽 376–400px） ---------- */

.verify-drawer {
  display: flex;
  border-left: 1px solid var(--line);
  background: var(--surface);
  width: 52px;
  transition: width 0.25s var(--ease);
  overflow: hidden;
}

.verify-drawer.open { width: 388px; }

.drawer-toggle {
  flex-shrink: 0;
  width: 52px;
  border: 0;
  border-right: 1px solid var(--line-soft);
  background: transparent;
  cursor: pointer;
  writing-mode: vertical-rl;
  letter-spacing: 0.2em;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink-soft);
  padding: 18px 0;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}

.drawer-toggle:hover { color: var(--brand); background: var(--paper); }

.verify-drawer.open .drawer-toggle { color: var(--brand); }

.drawer-panel {
  flex: 1;
  min-width: 0;
  padding: 24px 22px;
  overflow-y: auto;
}

.drawer-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 650;
}

.drawer-content dl, .verify-panel dl { margin: 0; }

.drawer-content dt, .verify-panel dt {
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.drawer-content dt:first-child, .verify-panel dt:first-child { margin-top: 0; }

.drawer-content dd, .verify-panel dd {
  margin: 3px 0 0;
  font-size: 13px;
  word-break: break-word;
}

.drawer-content a { color: var(--brand); text-decoration: none; border-bottom: 1px solid #C4D8D2; }
.drawer-content a:hover { border-bottom-color: var(--brand); }

.drawer-content .drawer-empty { color: var(--ink-soft); font-size: 12.5px; }

.drawer-note {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--ink-soft);
}

/* ---------- 输入区（后台执行期间始终可用） ---------- */

.composer {
  border-top: 1px solid var(--line);
  background: var(--paper);
  padding: 14px 32px 18px;
}

.composer textarea {
  display: block;
  width: 100%;
  resize: vertical;
  min-height: 72px;
  max-height: 220px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  line-height: 1.6;
  transition: border-color 0.15s var(--ease);
}

.composer textarea:focus { outline: none; border-color: var(--brand); }

.composer-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}

.upload-btn {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12.5px;
  padding: 7px 13px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.upload-btn:hover { border-color: var(--brand); color: var(--brand); }
.upload-btn[data-failure="true"] { border-color: var(--fail); color: var(--fail); }

/* 文件输入视觉隐藏但保持键盘可达 */
.upload-btn input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.upload-state { flex: 1; font-size: 12px; color: var(--ink-soft); }

.send-btn {
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 8px 22px;
  cursor: pointer;
  transition: background 0.15s var(--ease);
}

.send-btn:hover { background: #0C443C; }
.send-btn:active { transform: scale(0.98); }

/* ---------- 焦点可见性 ---------- */

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
.upload-btn:focus-within {
  outline: var(--focus);
  outline-offset: 2px;
}

/* ---------- 响应式：宽屏抽屉 / 中屏内联 / 窄侧栏 ---------- */

/* 900–1439px：无右侧抽屉，执行卡内展开核验面板 */
@media (max-width: 1439px) {
  .verify-drawer { display: none; }
  .card-verify { display: block; }
}

/* 1020px 以下：左侧导航收缩为图标轨 */
@media (max-width: 1019px) {
  .cockpit { grid-template-columns: 60px minmax(0, 1fr) auto; }
  .sidebar { padding: 18px 8px 12px; align-items: center; }
  .brand { font-size: 15px; writing-mode: vertical-rl; letter-spacing: 0.3em; }
  .brand-sub { display: none; }
  .sidebar .lbl { display: none; }
  .new-thread { width: 40px; height: 40px; justify-content: center; padding: 0; margin-top: 14px; }
  .nav-block h2 { justify-content: center; margin: 0 0 4px; position: relative; }
  .nav-block h2::before { content: attr(data-short); font-size: 13px; color: var(--ink); }
  .nav-caption { display: none; }
  .bucket-item .bucket-title, .bucket-item .bucket-sub { display: none; }
  .bucket-item { padding: 6px; min-height: 6px; }
  .bucket-item::before {
    content: "";
    display: block;
    width: 8px; height: 8px;
    margin: 2px auto;
    border-radius: 50%;
    background: var(--brand);
  }
  .bucket-item.is-decision::before { background: var(--decide); }
  .thread-item { padding: 6px; font-size: 0; }
  .thread-item::before {
    content: "";
    display: block;
    width: 8px; height: 8px;
    margin: 2px auto;
    border-radius: 50%;
    background: var(--line);
  }
  .thread-item.active::before { background: var(--brand); }
  .count { position: absolute; top: -6px; right: -4px; }
  .side-foot { border-top: 0; }
  .logout { padding: 6px; }
  .logout::after { content: "退"; font-size: 13px; }
  .conv-head, .composer { padding-left: 20px; padding-right: 20px; }
  .messages { padding: 22px 20px 14px; }
}

/* 900px 下限仍可用：状态区允许换行 */
@media (max-width: 960px) {
  .conv-head { flex-wrap: wrap; }
  .conv-head h1 { font-size: 17px; }
}

/* ---------- 克制动效 + 尊重减少动态偏好 ---------- */

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