/* ===== 基础 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #eef1f6;
  --ink: #1a1a2e;
  --muted: #6c757d;
  --primary: #4f6ef7;
  --primary-dark: #3b56d4;
  --accent: #e63946;
  --border: #e2e6ef;
  --card: #ffffff;
}
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(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== 顶栏 ===== */
.topbar {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(90deg, #16213e 0%, #1d2a56 55%, #27346e 100%);
  color: #fff;
  box-shadow: 0 2px 10px rgba(20, 30, 70, .25);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 22px; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: .5px; }
.brand-sub {
  font-size: 11px; color: #9fb0ff;
  border: 1px solid rgba(159, 176, 255, .4);
  padding: 2px 8px; border-radius: 20px;
}
.topbar-actions { display: flex; gap: 8px; }
.btn {
  border: none; cursor: pointer; border-radius: 8px;
  font-size: 13px; padding: 7px 14px;
  transition: all .15s;
}
.btn-ghost {
  background: rgba(255, 255, 255, .12);
  color: #e8ecff;
}
.btn-ghost:hover { background: rgba(255, 255, 255, .24); }

/* ===== 布局 ===== */
.layout {
  flex: 1;
  display: flex;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}
.board-pane {
  flex: 1.5;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-pane {
  flex: 1;
  min-width: 340px;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(30, 40, 80, .06);
}

/* ===== 白板 ===== */
.board-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
}
.tool-btn {
  width: 34px; height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: all .15s;
}
.tool-btn:hover { background: #f0f3fa; }
.tool-btn.active {
  background: #e8edff;
  border-color: #b9c7ff;
}
.tool-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.tool-flex { flex: 1; }
.board-status { font-size: 12px; color: var(--muted); }
.board-status.writing { color: var(--accent); font-weight: 600; }
#penColor {
  width: 30px; height: 30px;
  border: none; background: none;
  cursor: pointer; padding: 0;
}
#penSize {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  background: #fff;
  cursor: pointer;
}

.board-wrap {
  flex: 1;
  position: relative;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  min-height: 0;
  box-shadow: 0 4px 20px rgba(30, 40, 80, .06);
}
#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#board.tool-pen { cursor: crosshair; }
#board.tool-eraser { cursor: cell; }
#board.tool-hand, #board.tool-hand:active { cursor: grab; }
#board.tool-hand.panning { cursor: grabbing; }
.zoom-ctrl {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 6;
}
.zoom-ctrl button {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.92);
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(30,40,80,.10);
  transition: background .15s;
}
.zoom-ctrl button:hover { background: #eef1fb; }

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(2px);
  pointer-events: none;
  z-index: 5;
}
.board-overlay.hidden { display: none; }
.overlay-card {
  text-align: center;
  animation: pulse 1.2s ease-in-out infinite;
}
.overlay-icon { font-size: 42px; }
.overlay-text { margin-top: 8px; font-size: 14px; color: var(--muted); }
@keyframes pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

.board-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #b8c0d0;
  pointer-events: none;
}
.board-placeholder.hidden { display: none; }
.ph-icon { font-size: 52px; filter: grayscale(.3); }
.ph-title { font-size: 17px; font-weight: 600; color: #8d99ae; }
.ph-desc { font-size: 13px; max-width: 380px; text-align: center; line-height: 1.6; }

/* ===== 聊天 ===== */
.chat-header {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.chat-hint { font-size: 11px; font-weight: 400; color: var(--muted); }
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: #d4d9e4; border-radius: 3px; }

.chat-empty {
  margin: auto;
  text-align: center;
  padding: 20px;
}
.ce-icon { font-size: 40px; margin-bottom: 10px; }
.ce-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.ce-desc { font-size: 13px; color: var(--muted); line-height: 1.7; margin-bottom: 16px; }
.ce-samples { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.chip {
  border: 1px solid #ccd5f8;
  background: #f4f6ff;
  color: var(--primary-dark);
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { background: #e8edff; transform: translateY(-1px); }

.msg { display: flex; gap: 8px; max-width: 100%; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  flex: 0 0 30px;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.msg.ai .avatar { background: #e8edff; }
.msg.user .avatar { background: #ffe3d0; }
.bubble-wrap { display: flex; flex-direction: column; gap: 4px; max-width: 86%; }
.msg.user .bubble-wrap { align-items: flex-end; }
.bubble {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}
.msg.ai .bubble {
  background: #f3f5fb;
  border: 1px solid #e6eaf5;
  border-top-left-radius: 4px;
}
.msg.user .bubble {
  background: var(--primary);
  color: #fff;
  border-top-right-radius: 4px;
  white-space: pre-wrap;
}
.bubble p { margin: 0 0 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15px; margin: 8px 0 4px; }
.bubble ul, .bubble ol { margin: 4px 0 6px 20px; }
.bubble code {
  background: #e9edf7;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: "SF Mono", Consolas, monospace;
}
.msg.user .bubble code { background: rgba(255,255,255,.2); }
.bubble pre {
  background: #161a2c;
  color: #dbe2ff;
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 13px;
}
.bubble pre code { background: none; color: inherit; padding: 0; }
.bubble table { border-collapse: collapse; margin: 6px 0; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid #d9deeb; padding: 4px 10px; }
.bubble .katex { font-size: 1.02em; }
.bubble .katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; }

.msg-imgs { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-imgs img {
  width: 120px; height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,.08);
  cursor: pointer;
}

.thinking {
  border: 1px dashed #ccd5f0;
  background: #fafbff;
  border-radius: 10px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
}
.thinking summary {
  cursor: pointer;
  padding: 6px 12px;
  user-select: none;
  list-style: none;
}
.thinking summary::before { content: "💭 "; }
.thinking[open] summary { border-bottom: 1px dashed #dde3f3; }
.thinking-body {
  padding: 8px 12px;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.6;
  white-space: pre-wrap;
}
.thinking.live summary { color: var(--primary); animation: pulse 1.2s infinite; }

.cursor-blink {
  display: inline-block;
  width: 7px; height: 15px;
  background: var(--primary);
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink .9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.error-tip {
  background: #fdecea;
  border: 1px solid #f5c6c0;
  color: #b3261e;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
}
.miss-tip {
  background: #fff8e6;
  border: 1px dashed #e8c96a;
  color: #8a6d1a;
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 12px;
}
.quick-replies {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.qr-chip {
  border: 1px solid #ccd5f8;
  background: #fff;
  color: var(--primary-dark);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}
.qr-chip:hover { background: #e8edff; transform: translateY(-1px); }

/* ===== 输入区 ===== */
.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  background: #fafbfe;
}
.img-tray { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.img-tray:empty { display: none; }
.img-thumb {
  position: relative;
  width: 58px; height: 58px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.img-thumb .rm {
  position: absolute; top: 0; right: 0;
  width: 18px; height: 18px;
  border: none;
  background: rgba(0,0,0,.55);
  color: #fff;
  border-radius: 0 0 0 8px;
  font-size: 11px;
  cursor: pointer;
  line-height: 18px;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.btn-icon {
  flex: 0 0 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: all .15s;
}
.btn-icon:hover { background: #f0f3fa; }
#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 140px;
  outline: none;
  transition: border-color .15s;
}
#input:focus { border-color: #aab8ff; }
.btn-send {
  flex: 0 0 42px;
  height: 38px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-send:hover { background: var(--primary-dark); }
.btn-send:disabled { background: #b9c1e0; cursor: not-allowed; }

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .chat-pane { max-width: none; min-width: 0; flex: 0 0 46vh; }
  .board-pane { flex: 0 0 auto; min-height: 300px; }
}

/* ================= 账号 / 历史 / 弹窗（v2 新增） ================= */
.user-area { display: flex; align-items: center; gap: 8px; }
.user-area .username { font-size: 13px; color: #1d3557; font-weight: 600; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quota-badge { font-size: 12px; color: #2a9d8f; background: #eaf7f4; border-radius: 12px; padding: 3px 10px; white-space: nowrap; }
.quota-badge.guest { color: #7a5a36; background: #faf3ea; }
.admin-link { text-decoration: none; }
.btn-primary { background: #1d3557; color: #fff; border: none; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-size: 13px; }
.btn-primary:hover { background: #274b7a; }

/* 弹窗 */
.modal-mask, .drawer-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 200; display: flex; align-items: center; justify-content: center; }
.drawer-mask { z-index: 190; justify-content: flex-end; }
.modal-card { background: #fff; border-radius: 14px; width: min(380px, 92vw); max-height: 88vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 8px; font-weight: 700; font-size: 16px; color: #16213e; }
.modal-close { border: none; background: none; cursor: pointer; font-size: 15px; color: #8d99ae; padding: 4px 8px; }
.modal-close:hover { color: #e63946; }
.auth-tabs { display: flex; gap: 6px; padding: 0 18px 10px; }
.auth-tab { flex: 1; border: 1px solid #d5dbe7; background: #f8fafc; border-radius: 8px; padding: 7px 0; cursor: pointer; font-size: 13px; color: #5b6b85; }
.auth-tab.active { background: #1d3557; color: #fff; border-color: #1d3557; }
.auth-form { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.auth-form input { border: 1px solid #d5dbe7; border-radius: 8px; padding: 9px 11px; font-size: 13px; outline: none; }
.auth-form input:focus { border-color: #1d3557; }
.captcha-row { display: flex; align-items: center; gap: 8px; }
.captcha-q { font-size: 13px; color: #b08968; background: #faf3ea; border-radius: 8px; padding: 7px 10px; }
.auth-error { background: #fdecea; color: #b3261e; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.auth-tip { font-size: 12px; color: #8d99ae; }

/* 历史抽屉 */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 92vw); background: #fff; z-index: 195; box-shadow: -12px 0 40px rgba(0,0,0,.18); display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; font-weight: 700; color: #16213e; border-bottom: 1px solid #eef1f6; }
.drawer-body { flex: 1; overflow: auto; padding: 10px; }
.history-empty { color: #8d99ae; font-size: 13px; text-align: center; padding: 40px 16px; line-height: 1.7; }
.history-item { display: flex; align-items: center; gap: 8px; border: 1px solid #eef1f6; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.history-item.current { border-color: #2a9d8f; background: #f2fbf9; }
.hi-main { flex: 1; min-width: 0; cursor: pointer; }
.hi-title { font-size: 13.5px; color: #16213e; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hi-time { font-size: 11.5px; color: #8d99ae; margin-top: 3px; }
.hi-actions { display: flex; gap: 4px; }
.hi-btn { border: 1px solid #d5dbe7; background: #fff; border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px; color: #5b6b85; }
.hi-btn.open { background: #1d3557; color: #fff; border-color: #1d3557; }
.hi-btn.del:hover { color: #e63946; border-color: #e63946; }

/* Toast 与额度提示 */
.ab-toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: #16213e; color: #fff; font-size: 13px; border-radius: 10px; padding: 9px 18px; z-index: 300; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.quota-cta { margin: 6px 12px; background: #f2fbf9; border: 1px solid #bfe5dc; color: #1f7a68; border-radius: 10px; padding: 10px 12px; font-size: 13px; display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.privacy-note { font-size: 11.5px; color: #9aa6ba; padding: 6px 2px 0; text-align: right; }
/* 隐藏态优先（弹窗/抽屉） */
.modal-mask.hidden, .drawer-mask.hidden, .drawer.hidden, .auth-error.hidden { display: none !important; }
