:root {
  --brand: #4f6df5;
  --brand-2: #7b8cff;
  --bg: #f2f4fa;
  --panel: #ffffff;
  --text: #232838;
  --muted: #8a93a6;
  --border: #e5e9f3;
  --user-bubble: linear-gradient(135deg, #5472ff, #7d8cff);
  --ai-bubble: #ffffff;
  --danger: #f0616d;
  --radius: 16px;
  --col-w: 880px;
  --shadow-sm: 0 1px 2px rgba(35, 40, 56, .05), 0 4px 14px -8px rgba(35, 40, 56, .10);
  --shadow-md: 0 2px 6px rgba(35, 40, 56, .06), 0 14px 30px -14px rgba(35, 40, 56, .18);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; height: 100vh; overflow: hidden;
}
::selection { background: rgba(79, 109, 245, .16); }

/* 细滚动条 */
.messages::-webkit-scrollbar, .sessions::-webkit-scrollbar,
.thinking .body::-webkit-scrollbar, .tool-card pre::-webkit-scrollbar { width: 8px; height: 8px; }
.messages::-webkit-scrollbar-thumb, .sessions::-webkit-scrollbar-thumb,
.thinking .body::-webkit-scrollbar-thumb, .tool-card pre::-webkit-scrollbar-thumb {
  background: #d3daea; border-radius: 8px;
}
.messages::-webkit-scrollbar-thumb:hover, .sessions::-webkit-scrollbar-thumb:hover { background: #bcc6e0; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 280px; min-width: 280px;
  background: linear-gradient(180deg, #ffffff 0%, #fafbff 100%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px 14px; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 4px; position: relative; }
.sidebar-close, .menu-btn, .sidebar-backdrop { display: none; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 14px; font-size: 22px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px -8px rgba(79, 109, 245, .55);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .01em; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

.new-session {
  border: none; border-radius: 12px; padding: 11px 14px; font-size: 14px; font-weight: 600;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%); color: #fff;
  cursor: pointer; box-shadow: 0 8px 18px -8px rgba(79, 109, 245, .55);
  transition: transform .12s ease, filter .18s ease, box-shadow .18s ease;
}
.new-session:hover { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 12px 22px -8px rgba(79, 109, 245, .6); }
.new-session:active { transform: scale(.98); }

.section-label { font-size: 12px; color: var(--muted); margin: 4px 4px 0; font-weight: 600; letter-spacing: .02em; }

.sessions { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 2px; }
.session-item {
  border: 1px solid transparent; border-radius: 10px; padding: 9px 12px; cursor: pointer;
  font-size: 13px; color: var(--text); line-height: 1.35;
  transition: background .15s ease, border-color .15s ease;
}
.session-item:hover { background: #f3f5fc; }
.session-item.active { background: #eef1ff; border-color: #d3dcff; }
.session-item.active .t { color: var(--brand); font-weight: 600; }
.session-item .t { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.session-item .m { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.sidebar-foot {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 12px;
}
.admin-link-row { width: 100%; }
.admin-link-row a { display: inline-block; font-size: 12px; color: var(--brand); text-decoration: none; }
.admin-link-row a:hover { text-decoration: underline; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #ffb020; display: inline-block; box-shadow: 0 0 0 3px rgba(255, 176, 32, .15); }
.status-dot.online { background: #2fb46b; box-shadow: 0 0 0 3px rgba(47, 180, 107, .14); }

/* ---------- 聊天区 ---------- */
.chat {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background:
    radial-gradient(760px 320px at 88% -8%, rgba(123, 140, 255, .12), transparent 62%),
    radial-gradient(680px 300px at 2% 106%, rgba(79, 109, 245, .09), transparent 58%),
    var(--bg);
}
.chat-header {
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 13px max(22px, calc((100% - var(--col-w)) / 2));
  display: flex; align-items: center; gap: 12px; z-index: 2;
}
.agent-avatar {
  width: 42px; height: 42px; border-radius: 50%; position: relative;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px;
  box-shadow: 0 6px 14px -6px rgba(79, 109, 245, .5);
}
.agent-avatar::after {
  content: ""; position: absolute; right: 0; bottom: 1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #2fb46b; border: 2px solid #fff;
}
.agent-name { font-weight: 700; font-size: 15px; }
.agent-tagline { font-size: 12px; color: var(--muted); margin-top: 2px; }
.model-badge {
  margin-left: auto; font-size: 12px; font-weight: 600; color: var(--brand);
  background: #eef1ff; border: 1px solid #dde4ff;
  padding: 5px 12px; border-radius: 999px; white-space: nowrap;
}


.messages {
  flex: 1; overflow-y: auto;
  padding: 26px max(22px, calc((100% - var(--col-w)) / 2)) 32px;
  display: flex; flex-direction: column; gap: 20px;
}

/* 消息：头像 + 纵向内容列（气泡 / 思考 / 工具卡片依次竖排） */
.msg { display: flex; gap: 11px; max-width: min(82%, 760px); animation: msg-in .22s ease both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; margin-top: 2px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 16px;
  box-shadow: 0 5px 12px -5px rgba(79, 109, 245, .5); user-select: none;
}
.msg.user .avatar {
  background: #fff; color: var(--brand); font-size: 13px; font-weight: 700;
  border: 1px solid #dfe4fb; box-shadow: var(--shadow-sm);
}

.msg-main { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.msg.user .msg-main { align-items: flex-end; }

.bubble {
  width: fit-content; max-width: 100%;
  padding: 11px 15px; border-radius: var(--radius);
  font-size: 14.5px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
}
.msg.assistant .bubble {
  background: var(--ai-bubble); border: 1px solid var(--border); border-top-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}
.msg.user .bubble {
  background: var(--user-bubble); color: #fff; border-top-right-radius: 5px;
  box-shadow: 0 8px 20px -10px rgba(84, 114, 255, .6);
}
.bubble strong { font-weight: 700; }
.msg .time { font-size: 11px; color: var(--muted); padding: 0 6px; margin-top: -2px; user-select: none; }
.err-line { color: var(--danger); }
/* 思考过程 */
.thinking {
  align-self: stretch;
  border: 1px solid #dfe5fb; border-radius: 12px;
  background: linear-gradient(180deg, #f9faff, #f4f7ff);
  font-size: 12.5px; color: #5b6aa8; overflow: hidden; box-shadow: var(--shadow-sm);
}
.thinking summary {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 13px; cursor: pointer; user-select: none;
  font-weight: 600; color: #6577c9; list-style: none;
}
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::after {
  content: "›"; margin-left: auto; color: #9aa7d8; font-size: 14px; line-height: 1;
  transition: transform .18s ease;
}
.thinking details[open] summary::after { transform: rotate(90deg); }
.thinking .body {
  padding: 0 14px 11px 33px; white-space: pre-wrap; line-height: 1.65; color: #4a5480;
  max-height: 260px; overflow-y: auto;
}

/* 工具调用卡片 */
.tool-card {
  align-self: stretch;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  font-size: 13px; overflow: hidden; box-shadow: var(--shadow-sm);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.tool-card:hover { border-color: #d3dbef; }
.tool-card.open { border-color: #c4d0f6; box-shadow: var(--shadow-md); }
.tool-card .head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; cursor: pointer; user-select: none;
}
.tool-card .ico {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, #eef1ff, #f4f6ff); border: 1px solid #e3e9fb;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.tool-card .txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tool-card .lb { font-weight: 600; font-size: 13px; color: var(--text); }
.tool-card .nm {
  font-size: 11px; color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.tool-card .st {
  margin-left: auto; flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
}
.tool-card .st.doing { color: #b96a00; background: #fff3dd; }
.tool-card .st.doing i {
  width: 7px; height: 7px; border-radius: 50%; background: #f5a623;
  animation: st-blink 1s ease-in-out infinite;
}
@keyframes st-blink { 50% { opacity: .25; transform: scale(.8); } }
.tool-card .st.ok { color: #1d9d5b; background: #e5f7ee; }
.tool-card .chev {
  flex-shrink: 0; color: #9aa3b8; font-size: 14px; line-height: 1;
  transition: transform .18s ease;
}
.tool-card.open .chev { transform: rotate(90deg); }
.tool-card .body {
  display: none; border-top: 1px dashed var(--border);
  padding: 11px 12px 12px; background: #fbfcff;
}
.tool-card.open .body { display: block; animation: msg-in .2s ease both; }
.tool-card .sec-label { font-size: 11px; font-weight: 600; color: var(--muted); margin: 8px 0 5px; }
.tool-card .sec-label:first-child { margin-top: 0; }
.tool-card pre {
  margin: 0; padding: 9px 11px;
  background: #f3f5fc; border: 1px solid #e8ecf8; border-radius: 9px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px; line-height: 1.55; color: #4a5268;
  white-space: pre-wrap; word-break: break-word;
  max-height: 220px; overflow: auto;
}

/* 打字光标 */
.cursor { display: inline-block; width: 7px; height: 15px; background: var(--brand); border-radius: 2px; vertical-align: -2px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* 流式状态胶囊 */
.stream-status {
  align-self: center; display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: #6b7590;
  background: rgba(255, 255, 255, .85); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px; box-shadow: var(--shadow-sm);
}
.spinner { width: 12px; height: 12px; border: 2px solid #ccd3e8; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 输入区 ---------- */
.composer-wrap { padding: 12px max(22px, calc((100% - var(--col-w)) / 2)) 14px; }
.composer {
  display: flex; align-items: flex-end; gap: 10px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 18px; padding: 9px 9px 9px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.composer:focus-within { border-color: var(--brand-2); box-shadow: 0 0 0 4px rgba(79, 109, 245, .10), var(--shadow-md); }
#input {
  flex: 1; border: none; outline: none; resize: none; background: transparent;
  font: inherit; font-size: 14px; color: var(--text); max-height: 120px; line-height: 1.55; padding-top: 7px;
}
#input::placeholder { color: #a0a8bb; }
.send-btn {
  width: 40px; height: 40px; border: none; border-radius: 13px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  font-size: 16px; cursor: pointer; flex-shrink: 0;
  box-shadow: 0 6px 14px -6px rgba(79, 109, 245, .55);
  transition: filter .18s ease, transform .12s ease;
}
.send-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.send-btn:active { transform: scale(.93); }
.send-btn:disabled { background: #c3cbe8; box-shadow: none; cursor: not-allowed; transform: none; }
.composer-hint { text-align: center; font-size: 11px; color: var(--muted); margin-top: 9px; }
.composer-hint a { color: var(--brand); text-decoration: none; }
.composer-hint a:hover { text-decoration: underline; }

/* 空状态 + 快捷提问 */
.empty-hint {
  margin: auto; max-width: 560px; text-align: center;
  background: rgba(255, 255, 255, .85); border: 1px solid var(--border);
  border-radius: 22px; padding: 32px 28px 26px;
  color: var(--muted); font-size: 14px; line-height: 1.85;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.empty-hint b { color: var(--brand); font-weight: 600; }
.empty-hint .big { font-size: 40px; margin-bottom: 10px; animation: float 3.2s ease-in-out infinite; }
.empty-hint .empty-desc { margin-bottom: 4px; }
.empty-hint .quick-title {
  margin-top: 18px; margin-bottom: 10px;
  font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em;
}
.empty-hint .quick-prompts {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.empty-hint .chip {
  background: #fff; border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; cursor: pointer; line-height: 1.35;
  color: var(--text); transition: border-color .15s ease, color .15s ease, background .15s ease, box-shadow .15s ease;
}
.empty-hint .chip:hover {
  border-color: var(--brand); color: var(--brand); background: #f5f7ff;
  box-shadow: var(--shadow-sm);
}
@keyframes float { 50% { transform: translateY(-6px); } }

/* ---------- 手机端 ---------- */
@media (max-width: 820px) {
  body {
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(15, 18, 28, .45); backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    width: min(86vw, 300px); min-width: 0;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 8px 0 28px rgba(15, 18, 28, .18);
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-close {
    display: grid; place-items: center; margin-left: auto;
    width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 10px;
    background: #fff; color: var(--muted); font-size: 14px; cursor: pointer;
  }
  .menu-btn {
    display: grid; place-items: center; flex-shrink: 0;
    width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 12px;
    background: #fff; color: var(--text); font-size: 18px; cursor: pointer;
    box-shadow: var(--shadow-sm);
  }

  .chat-header {
    padding: 10px 12px; gap: 10px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .agent-meta { min-width: 0; flex: 1; }
  .agent-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .agent-tagline { display: none; }
  .agent-avatar { width: 36px; height: 36px; font-size: 17px; }
  .model-badge {
    font-size: 10px; padding: 4px 8px; max-width: 38vw;
    overflow: hidden; text-overflow: ellipsis;
  }

  .messages {
    padding: 16px 12px 20px; gap: 14px;
  }
  .msg { max-width: 94%; gap: 8px; }
  .msg .avatar { width: 30px; height: 30px; font-size: 13px; }
  .bubble { font-size: 14px; padding: 10px 12px; }

  .composer-wrap {
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .composer { border-radius: 16px; padding: 8px 8px 8px 12px; gap: 8px; }
  .send-btn { width: 38px; height: 38px; border-radius: 12px; }
  .composer-hint { display: none; }

  .empty-hint {
    max-width: 100%; margin: 8px 0 auto; padding: 22px 16px 18px;
    border-radius: 18px; font-size: 13.5px; line-height: 1.7;
  }
  .empty-hint .big { font-size: 34px; }
  .empty-hint .chip { font-size: 12.5px; padding: 7px 12px; width: 100%; text-align: center; }
  .empty-hint .quick-prompts { flex-direction: column; }
}