/* 清白AI助手 · 简化版界面（清白AI工坊出品） */
:root {
  --brand1: #06b6d4;
  --brand2: #3b82f6;
  --brand-grad: #2f6df0; /* 纯色，禁止渐变 */
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #1f2937;
  --text2: #6b7280;
  --line: #e5e7eb;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 42, 84, 0.08);
  --sidebar-w: 264px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
textarea, input { font-family: inherit; }

/* ---------- 授权门 ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: #16233b;
  padding: 20px;
}
.gate-card {
  width: 380px; max-width: 100%;
  background: #fff; border-radius: 20px;
  padding: 36px 32px 26px; text-align: center;
  box-shadow: 0 20px 60px rgba(3, 40, 80, 0.35);
  animation: rise 0.35s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.gate-logo { width: 72px; height: 72px; border-radius: 18px; }
.gate-title { font-size: 22px; font-weight: 700; margin-top: 14px; }
.gate-org { color: var(--text2); font-size: 13px; margin-top: 2px; }
.gate-desc { font-size: 14px; color: var(--text2); margin: 16px 0 14px; line-height: 1.6; }
.gate-input {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 16px; text-align: center; letter-spacing: 1px;
  outline: none; transition: border 0.2s;
}
.gate-input:focus { border-color: var(--brand2); }
.gate-btn {
  width: 100%; margin-top: 14px; padding: 12px;
  background: var(--brand-grad); color: #fff;
  border-radius: 12px; font-size: 16px; font-weight: 600;
  transition: opacity 0.2s;
}
.gate-btn:active { opacity: 0.85; }
.gate-btn[disabled] { opacity: 0.6; cursor: default; }
.gate-error { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 10px; }
.gate-foot { color: #9ca3af; font-size: 12px; margin-top: 8px; }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100%; }

/* 侧栏 */
.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 16px 14px 10px; }
.side-logo { width: 38px; height: 38px; border-radius: 10px; }
.side-name { font-weight: 700; font-size: 15px; }
.side-org { font-size: 12px; color: var(--text2); }
.side-close { margin-left: auto; }
.btn-new {
  margin: 6px 14px 10px; padding: 11px;
  background: var(--brand-grad); color: #fff;
  border-radius: 12px; font-size: 14px; font-weight: 600;
}
.side-label { padding: 8px 18px 4px; font-size: 12px; color: var(--text2); }
.session-list { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.session-item {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 8px 9px 10px; border-radius: 10px;
  font-size: 13.5px; color: var(--text);
  cursor: pointer; position: relative;
}
.session-item:hover { background: #f1f5f9; }
.session-item.active { background: #e8f1fe; color: #1d4ed8; font-weight: 600; }
.session-item .s-ico { display: inline-flex; color: #9aa4b2; flex: none; }
.session-item.active .s-ico { color: #1d4ed8; }
.session-item .s-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .s-act {
  display: none; color: #9aa4b2; padding: 3px; border-radius: 6px;
  line-height: 0; flex: none;
}
.session-item:hover .s-act { display: inline-flex; }
.session-item .s-act:hover { color: var(--text); background: #e2e8f0; }
.session-item .s-del:hover { color: var(--danger); background: #fee2e2; }
.session-item.pinned .s-title { font-weight: 600; }
.session-item.pinned .s-pin { color: #f59e0b; display: inline-flex; }
.session-item.pinned .s-pin:hover { background: #fef3c7; color: #d97706; }

/* 回收站 */
.side-tool-btn { position: relative; }
.trash-list { margin: 10px 0 4px; max-height: 46vh; overflow-y: auto; }
.trash-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 8px; border-bottom: 1px solid #f1f5f9;
  font-size: 13.5px;
}
.trash-item .s-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trash-item .t-date { font-size: 11.5px; color: #9ca3af; flex: none; }
.trash-item .s-act { display: inline-flex; color: #9aa4b2; padding: 4px; border-radius: 6px; line-height: 0; }
.trash-item .t-restore:hover { color: #059669; background: #ecfdf5; }
.trash-item .t-purge:hover { color: var(--danger); background: #fee2e2; }
.trash-empty { text-align: center; color: #9ca3af; font-size: 13px; padding: 26px 0; }
.side-foot { padding: 10px 16px 14px; border-top: 1px solid var(--line); }
.foot-status { font-size: 12px; color: #10b981; }
.foot-status.warn { color: var(--danger); }
.foot-source { font-size: 12px; color: var(--text2); margin-top: 2px; }
.foot-source:empty { display: none; }
.foot-credits { font-size: 12px; color: #f59e0b; font-weight: 600; }
.foot-credits:empty { display: none; }
.foot-brand { font-size: 12px; color: #9ca3af; margin-top: 2px; }

/* 积分 */
.credits-row {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 6px 0 8px;
}
#credits-balance { font-size: 22px; font-weight: 700; color: var(--text); }
.credits-rule { font-size: 11.5px; color: #9ca3af; }
.credits-redeem { display: flex; gap: 8px; }
.credits-input {
  flex: 1; padding: 9px 12px; border: 1.5px solid var(--line);
  border-radius: 9px; font-size: 13.5px; outline: none;
  letter-spacing: 0.5px;
}
.credits-input:focus { border-color: var(--brand2); }
.credits-btn {
  padding: 9px 18px; border: none; border-radius: 9px;
  background: var(--brand-grad); color: #fff; font-size: 13.5px; font-weight: 600;
}
.btn-settings {
  margin-top: 8px; padding: 0; width: 100%; text-align: left;
  background: none; border: none; color: #c3cad4;
  font-size: 12px; cursor: pointer;
}
.btn-settings:hover { color: var(--text2); }

/* 侧栏工具行（回收站 / 设置） */
.side-tools {
  display: flex; gap: 6px; padding: 4px 14px 6px;
  border-top: 1px solid var(--line);
}
.side-tool-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 7px 4px; border-radius: 8px;
  font-size: 12px; color: #9aa4b2; background: none;
}
.side-tool-btn:hover { color: var(--text2); background: #f1f5f9; }
.side-tool-btn svg { flex: none; }
.trash-count {
  min-width: 16px; height: 16px; padding: 0 4px;
  background: #ef4444; color: #fff; border-radius: 8px;
  font-size: 10.5px; line-height: 16px; font-weight: 600;
}
.foot-source:empty { display: none; }

/* 设置弹窗 */
.settings-card { text-align: left; max-height: 92vh; overflow-y: auto; }
.settings-section { font-size: 13px; font-weight: 600; color: var(--text); margin: 16px 0 4px; }
.radio-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; padding: 9px 10px; border: 1.5px solid var(--line);
  border-radius: 10px; margin: 8px 0; cursor: pointer;
}
.radio-row:has(input:checked) { border-color: #93c5fd; background: #f0f7ff; }
.own-fields { margin-top: 4px; }
.field { margin: 10px 0; }
.field label { display: block; font-size: 12.5px; color: var(--text2); margin-bottom: 5px; }
.field label .req { color: var(--danger); }
.field input, .field select {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--line);
  border-radius: 10px; font-size: 14px; outline: none; background: #fff;
}
.field input:focus, .field select:focus { border-color: var(--brand2); }
.field-hint { font-size: 12px; color: #9ca3af; margin: 8px 0 2px; line-height: 1.6; }
.settings-close-btn {
  width: 100%; margin-top: 8px; padding: 10px; border-radius: 10px;
  font-size: 14px; color: var(--text2); background: #f3f4f6;
}
.settings-close-btn:hover { background: #e5e7eb; }

/* 主区 */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 54px; flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; min-width: 0; }
.topbar-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-logo { width: 26px; height: 26px; border-radius: 7px; }
.menu-btn { display: inline-flex; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text2); font-size: 15px; cursor: pointer;
}
.icon-btn:hover { background: #f1f5f9; color: var(--text); }
.btn-new-mini {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600;
  color: #1d4ed8; background: #e8f1fe;
}

/* 桌面端侧栏收起 */
@media (min-width: 769px) {
  .sidebar { transition: margin-left 0.25s ease, opacity 0.2s ease; }
  .app.side-hidden .sidebar { margin-left: calc(-1 * var(--sidebar-w)); opacity: 0; }
}

/* 消息区 */
.chat { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.chat-inner, .messages { max-width: 780px; margin: 0 auto; padding: 10px 20px 30px; }

.welcome { text-align: center; padding: 9vh 20px 30px; animation: rise 0.4s ease; }
.welcome-logo { width: 76px; height: 76px; border-radius: 20px; }
.welcome-title { font-size: 24px; font-weight: 700; margin-top: 16px; }
.welcome-sub { color: var(--text2); font-size: 14px; margin-top: 8px; }
.welcome-cards {
  margin: 26px auto 0; display: grid; gap: 10px;
  grid-template-columns: 1fr 1fr; max-width: 640px;
}
.card {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; font-size: 13.5px; color: var(--text); text-align: left;
  box-shadow: var(--shadow); transition: transform 0.15s, border-color 0.15s;
  line-height: 1.5;
}
.card svg { flex: none; }
.card:hover { transform: translateY(-2px); border-color: #bfdbfe; }

/* 消息 */
.msg { margin: 18px 0; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  background: var(--brand-grad); color: #fff;
  padding: 11px 15px; border-radius: 16px 16px 4px 16px;
  max-width: 82%; font-size: 14.5px; line-height: 1.7; white-space: pre-wrap; word-break: break-word;
}
.msg-ai { display: flex; gap: 10px; }
.msg-ai .avatar {
  width: 32px; height: 32px; border-radius: 9px; flex: none; margin-top: 2px;
}
.msg-ai .content { flex: 1; min-width: 0; font-size: 14.5px; line-height: 1.8; }
.md p { margin: 8px 0; }
.md h1, .md h2, .md h3 { margin: 16px 0 8px; line-height: 1.4; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15.5px; }
.md ul, .md ol { margin: 8px 0 8px 22px; }
.md li { margin: 4px 0; }
.md a { color: #2563eb; }
.md code.inline {
  background: #eef2f7; border-radius: 5px; padding: 2px 6px;
  font-size: 13px; font-family: Consolas, Menlo, monospace; color: #c2410c;
}
.md .codeblock {
  background: #0f172a; color: #e2e8f0; border-radius: 12px;
  margin: 10px 0; overflow: hidden;
}
.md .codeblock .cb-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; background: #1e293b; font-size: 12px; color: #94a3b8;
}
.md .codeblock .cb-copy { color: #94a3b8; font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.md .codeblock .cb-copy:hover { color: #fff; background: #334155; }
.md .codeblock pre {
  padding: 12px 14px; overflow-x: auto;
  font-family: Consolas, Menlo, monospace; font-size: 13px; line-height: 1.6;
}
.md table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.md th { background: #f1f5f9; }

/* 工具调用条 */
.tool-strip-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text2);
  background: #f1f5f9; border-radius: 9px;
  padding: 6px 10px; margin: 6px 0;
  cursor: pointer; transition: background 0.15s;
}
.tool-strip-item:hover { background: #e8eef5; }
.tool-strip-item .t-ico { font-size: 13px; display: inline-flex; }
.tool-strip-item .t-name { display: inline-flex; align-items: center; gap: 5px; }
.tool-strip-item.done { color: #059669; background: #ecfdf5; }
.tool-strip-item.error { color: var(--danger); background: #fef2f2; }
.tool-strip-item .t-detail {
  display: none; margin-top: 6px; font-family: Consolas, Menlo, monospace;
  font-size: 12px; color: #64748b; white-space: pre-wrap; word-break: break-all;
  max-height: 200px; overflow-y: auto;
}
.tool-strip-item.open .t-detail { display: block; }

/* 打字动画 */
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #9ca3af; animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* 错误卡 */
.error-card {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  border-radius: 12px; padding: 12px 14px; font-size: 13.5px; line-height: 1.7;
}

/* 输入区 */
.composer { flex: none; padding: 8px 20px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer-row {
  display: flex; align-items: center; gap: 8px;
  max-width: 780px; margin: 0 auto;
  background: var(--panel); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 6px 6px 6px 14px;
  box-shadow: var(--shadow); transition: border 0.2s;
}
.composer-row:focus-within { border-color: #93c5fd; }
.input {
  flex: 1; border: none; outline: none; resize: none;
  font-size: 15px; line-height: 1.5; max-height: 140px;
  padding: 3px 0; background: transparent; color: var(--text);
  min-height: 22px;
}
.btn-send {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--brand-grad); color: #fff; font-size: 13px;
  transition: opacity 0.2s;
}
.btn-send svg { display: block; margin: 0 auto; }
.btn-send[disabled] { opacity: 0.45; cursor: default; }
.btn-send.stop { background: #ef4444; }
.composer-foot {
  max-width: 780px; margin: 6px auto 0;
  display: flex; justify-content: space-between;
  font-size: 11.5px; color: #9ca3af;
}

/* 工具状态条（输入框上方） */
.tool-strip {
  max-width: 780px; margin: 0 auto 6px;
  font-size: 12.5px; color: var(--text2);
  background: #eef6ff; border: 1px solid #dbeafe;
  padding: 7px 12px; border-radius: 10px;
}

/* 遮罩 + toast */
.mask {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: rgba(15, 23, 42, 0.45);
}
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #111827; color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 10px; z-index: 120;
  animation: rise 0.25s ease; max-width: 86vw; text-align: center;
}

/* ---------- 移动端 ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-102%); transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  }
  .sidebar.open { transform: none; }
  .sidebar.open + .mask, .mask.show { display: block; }
  .side-close { display: inline-flex; }
  .menu-btn { display: inline-flex; }
  .btn-new-mini { display: none; }
  .topbar-logo { display: none; }
  .welcome { padding-top: 5vh; }
  .welcome-title { font-size: 20px; }
  .welcome-cards { grid-template-columns: 1fr; }
  .messages, .chat-inner { padding: 8px 14px 20px; }
  .msg-ai .avatar { display: none; }
  .composer { padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); }
  .composer-row { padding: 5px 5px 5px 12px; }
  .btn-send { width: 28px; height: 28px; font-size: 12px; }
  .composer-brand { display: none; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d3dae3; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #b8c2cf; }
