:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --brand: #2f6bff;
  --brand-soft: #eaf1ff;
  --text: #1f2430;
  --text-2: #5b6472;
  --line: #e7ebf2;
  --user-bubble: #2f6bff;
  --bot-bubble: #ffffff;
  --shadow: 0 6px 24px rgba(31, 36, 48, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------- 顶部栏 ---------- */
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand);
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 14px;
}
.brand-name { font-weight: 700; font-size: 16px; }
.flex-spacer { flex: 1; }
.top-kb {
  border: 1px solid var(--line); background: #fff; color: var(--text-2);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; transition: all .15s;
}
.top-kb:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ---------- 手机标签页（桌面隐藏） ---------- */
#tabs { display: none; }

/* ---------- 双面板区 ---------- */
#panels { flex: 1; display: flex; min-height: 0; }
.panel { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--bg); }
.panel-divider { width: 1px; background: var(--line); flex-shrink: 0; }

/* 面板头 */
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.panel-badge { font-weight: 700; font-size: 13.5px; color: var(--brand); white-space: nowrap; flex-shrink: 0; }
.panel-sub { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-provider { border: 1px solid var(--line); background: #fff; color: var(--text-2); border-radius: 8px; padding: 4px 8px; font-size: 12.5px; cursor: pointer; max-width: 160px; flex-shrink: 0; }.panel-provider:hover { border-color: var(--brand); color: var(--brand); }
.panel-new { border: 1px solid var(--line); background: #fff; color: var(--brand); border-radius: 8px; padding: 5px 10px; font-size: 12.5px; cursor: pointer; transition: all .15s; white-space: nowrap; flex-shrink: 0; }
.panel-new:hover { background: var(--brand-soft); }
.panel-draw { border: 1px solid #ffd7a8; background: #fff8ef; color: #c2680a; border-radius: 8px; padding: 5px 10px; font-size: 12.5px; cursor: pointer; transition: all .15s; white-space: nowrap; flex-shrink: 0; }
.panel-draw:hover { background: #ffeed8; border-color: #ffc078; color: #ad5400; }
.panel-web { border: 1px solid #b9e0c6; background: #f0fbf4; color: #1f7a44; border-radius: 8px; padding: 5px 10px; font-size: 12.5px; cursor: pointer; transition: all .15s; white-space: nowrap; flex-shrink: 0; }
.panel-web:hover { background: #e2f6ea; border-color: #8fd0a9; color: #15663a; }
.panel-web.on { background: #e2f6ea; border-color: #6fc194; color: #15663a; font-weight: 600; }
.panel-conv-toggle { border: 1px solid var(--line); background: #fff; color: var(--text-2); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 14px; flex-shrink: 0; }
.panel-conv-toggle:hover { border-color: var(--brand); color: var(--brand); }
.panel-conv { position: absolute; top: 52px; left: 8px; right: 8px; max-height: 55%; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 20; padding: 6px; }
.conv-item { position: relative; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.conv-label { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 20px; }
.conv-del { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: #c05050; opacity: 0; transition: opacity .15s; cursor: pointer; font-size: 11px; padding: 2px 4px; }
.conv-item:hover .conv-del { opacity: .75; }
.conv-del:hover { opacity: 1; }

/* 聊天区（消息 + 欢迎页叠加） */
.chat-area { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: 22px 0; }
.msg-row { display: flex; padding: 6px 20px; gap: 12px; }
.msg-row.user { flex-direction: row-reverse; }
.avatar { width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; }
.avatar.bot { background: linear-gradient(135deg, #2f6bff, #5b8bff); }
.avatar.user { background: #20a779; }
.bubble { max-width: min(720px, 82%); padding: 12px 15px; border-radius: 14px; line-height: 1.7; font-size: 14.5px; word-wrap: break-word; box-shadow: var(--shadow); }
.msg-row.bot .bubble { background: var(--bot-bubble); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg-row.user .bubble { background: var(--user-bubble); color: #fff; border-top-right-radius: 4px; }
.bubble pre { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 13px; line-height: 1.5; }
.bubble code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.bubble :not(pre) > code { background: var(--brand-soft); color: #1d4ed8; padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.bubble a { color: var(--brand); }
.bubble .md-img { display: block; max-width: 100%; height: auto; margin: 10px 0 4px; border-radius: 10px; border: 1px solid var(--line); background: #f7f9fc; }
.bubble .md-img:only-child { margin-top: 4px; }
.bubble ul, .bubble ol { padding-left: 20px; margin: 6px 0; }
.bubble p { margin: 6px 0; }
.typing span { display: inline-block; width: 6px; height: 6px; margin: 0 1px; border-radius: 50%; background: var(--text-2); animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.2} 40%{opacity:1} }

/* 欢迎页 */
.welcome { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px 20px; overflow: auto; }
.welcome-emoji { font-size: 46px; }
.welcome h1 { font-size: 22px; margin: 12px 0 6px; }
.welcome p { color: var(--text-2); margin: 0 0 22px; }
.suggests { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: min(560px, 92%); }
.suggest { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px; cursor: pointer; font-size: 13.5px; color: var(--text); text-align: left; transition: .15s; }
.suggest:hover { border-color: var(--brand); background: var(--brand-soft); }

/* 输入框 */
.composer { padding: 12px 16px 16px; border-top: 1px solid var(--line); background: #fff; }
.composer-box { display: flex; align-items: flex-end; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 16px; box-shadow: var(--shadow); }
.input { flex: 1; border: none; outline: none; resize: none; font-size: 15px; line-height: 1.6; max-height: 160px; background: transparent; color: var(--text); font-family: inherit; }
.send-btn { border: none; background: var(--brand); color: #fff; font-weight: 600; font-size: 14px; padding: 9px 18px; border-radius: 12px; cursor: pointer; transition: filter .15s; }
.send-btn:hover { filter: brightness(1.05); }
.send-btn:disabled { opacity: .5; cursor: default; }
.tool-btn { border: 1px solid var(--line); background: #fff; color: var(--text-2); border-radius: 8px; padding: 5px 11px; font-size: 13px; cursor: pointer; transition: all .15s; }
.tool-btn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.tool-btn:disabled { opacity: .5; cursor: default; }
.composer-tools { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
#panels .upload-btn { font-size: 15px; padding: 4px 10px; }
.file-chip { font-size: 12px; color: #6b7787; background: #eef2f8; border-radius: 999px; padding: 4px 11px; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; user-select: none; }
.file-chip.attached { background: #e6f0ff; color: var(--brand); border: 1px solid #b9d2ff; }
.file-chip.flash { animation: chipflash .6s; }
@keyframes chipflash { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
.file-chip .detach { color: #b04a4a; text-decoration: none; margin-left: 4px; }
.status-line { font-size: 12px; color: #b26a00; min-height: 16px; margin-top: 4px; }
.composer-tip { text-align: center; font-size: 11.5px; color: #9aa3b2; margin-top: 6px; }
.beian { text-align: center; font-size: 11px; color: #9aa3b2; padding: 3px 0 0; }
.beian a { color: #9aa3b2; text-decoration: none; }

/* 知识库浮层 */
.kb-panel { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; width: min(560px, 92vw); max-height: 52vh; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 34px rgba(20,30,60,.18); z-index: 60; }
.kb-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-weight: 600; border-bottom: 1px solid #eef; }
.kb-close { cursor: pointer; color: #999; padding: 0 4px; }
.kb-list { padding: 6px; }
.kb-item { padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kb-item:hover { background: #eef4ff; }
.kb-item .kb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-item .kb-tag { font-size: 11px; color: var(--brand); white-space: nowrap; }
.kb-foot { padding: 8px 14px; font-size: 11px; color: #999; border-top: 1px solid #eef; }
.kb-loading { padding: 18px; color: #999; text-align: center; }

/* 🎨 绘图面板 */
.img-mask { position: fixed; inset: 0; background: rgba(24,32,50,.42); z-index: 65; }
.img-panel { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(480px, 94vw); max-height: 88vh; overflow: auto; background: #fff; border-radius: 16px; box-shadow: 0 16px 50px rgba(15,23,42,.28); z-index: 70; }
.img-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--line); }
.img-body { padding: 14px 16px 16px; }
.img-prompt { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit; resize: vertical; outline: none; box-sizing: border-box; line-height: 1.6; }
.img-prompt:focus { border-color: var(--brand); }
.img-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.img-sel { flex: 1; min-width: 120px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 9px; padding: 7px 9px; font-size: 12.5px; cursor: pointer; }
.img-sel:hover { border-color: var(--brand); }
.img-ref { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; font-size: 12.5px; outline: none; box-sizing: border-box; }
.img-ref:focus { border-color: var(--brand); }
.img-preview { margin-top: 12px; }
.img-preview .md-img { width: 100%; border-radius: 10px; border: 1px solid var(--line); display: block; }
.img-status { font-size: 12.5px; color: var(--text-2); margin-top: 10px; min-height: 18px; line-height: 1.5; }
.img-actions { display: flex; gap: 10px; margin-top: 12px; }
.img-gen { flex: 1; border: none; background: #ff8a3d; color: #fff; font-weight: 600; font-size: 14px; padding: 10px; border-radius: 10px; cursor: pointer; }
.img-gen:hover { filter: brightness(1.05); }
.img-gen:disabled { opacity: .6; cursor: default; }
.img-foot { font-size: 11.5px; color: #9aa3b2; margin-top: 12px; line-height: 1.6; }

/* 登录浮层 */
.login-mask { position: fixed; inset: 0; background: linear-gradient(135deg,#eef3ff,#f7f9fc); display: flex; align-items: center; justify-content: center; z-index: 100; }.login-card { width: min(340px, 88vw); background: #fff; border-radius: 18px; box-shadow: 0 12px 40px rgba(31,36,48,.12); padding: 34px 26px 28px; text-align: center; }
.login-logo { width: 52px; height: 52px; border-radius: 14px; background: var(--brand); color: #fff; font-weight: 800; font-size: 20px; display: grid; place-items: center; margin: 0 auto 14px; }
.login-title { font-size: 19px; font-weight: 700; }
.login-sub { font-size: 13px; color: #8a94a6; margin: 6px 0 20px; }
.login-input { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; font-size: 16px; outline: none; box-sizing: border-box; }
.login-input:focus { border-color: var(--brand); }
.login-btn { width: 100%; margin-top: 14px; border: none; background: var(--brand); color: #fff; font-size: 15px; font-weight: 600; padding: 12px; border-radius: 11px; cursor: pointer; }
.login-btn:disabled { opacity: .6; }
.login-err { font-size: 12.5px; color: #d64545; margin-top: 10px; min-height: 16px; }

/* ---------- 手机适配 ---------- */
@media (max-width: 768px) {
  * { -webkit-tap-highlight-color: transparent; }
  #app { height: 100dvh; }
  #tabs { display: flex; border-bottom: 1px solid var(--line); background: #fff; }
  .tab { flex: 1; border: none; background: transparent; padding: 12px 8px; font-size: 14px; font-weight: 600; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; }
  .tab.active { color: var(--brand); border-bottom-color: var(--brand); }
  .panel-divider { display: none; }
  .panel { display: none; }
  .panel.active { display: flex; }
  .panel-head { padding: 8px 12px; gap: 6px; flex-wrap: wrap; }
  .panel-sub { display: none; }
  .panel-badge { font-size: 14px; }
  .panel-provider { max-width: 118px; font-size: 12px; padding: 4px 6px; }
  .panel-web, .panel-draw { padding: 7px 9px; font-size: 12.5px; }
  .panel-new { padding: 6px 8px; font-size: 12.5px; }
  .bubble { max-width: 88%; font-size: 15px; }
  .msg-row { padding: 6px 12px; }
  .welcome { padding: 24px 14px; }
  .welcome h1 { font-size: 20px; }
  .suggests { grid-template-columns: 1fr; }
  .composer { padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
  .input { font-size: 16px; }
  .tool-btn { padding: 8px 11px; font-size: 13px; min-height: 38px; touch-action: manipulation; }
  #panels .upload-btn { font-size: 18px; padding: 7px 11px; }
  .file-chip { max-width: 100%; }
  .send-btn { padding: 10px 16px; min-height: 38px; }
  .composer-tip { font-size: 11px; }
  .kb-panel { bottom: calc(12px + env(safe-area-inset-bottom)); width: 94vw; max-height: 55vh; }
  .kb-item { padding: 11px 12px; }
  .messages { overscroll-behavior: contain; }
  .img-panel { left: 0; right: 0; top: auto; bottom: 0; transform: none; width: 100%; max-height: 88vh; border-radius: 16px 16px 0 0; }
  .img-body { padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); }
  .img-sel { min-width: 100%; font-size: 14px; padding: 9px 10px; }
  .img-gen { padding: 12px; font-size: 15px; }
  .panel-draw { padding: 7px 10px; font-size: 13px; }
}
