/* ============ 全球智析 GlobalLens — DeepSeek 风格浅色界面 ============ */
:root {
  --bg: #ffffff;
  --surface: #f7f7f8;
  --surface2: #ececee;
  --border: #e5e5e7;
  --text: #1f1f1f;
  --muted: #8e8e93;
  --accent: #4d6bfe;
  --accent-soft: #eef2ff;
  --danger: #e5484d;
  --radius: 14px;
  --maxw: 660px;
}
html[data-theme="dark"] {
  --bg: #1f1f23;
  --surface: #2a2a30;
  --surface2: #35353c;
  --border: #3c3c44;
  --text: #ececee;
  --muted: #9a9aa3;
  --accent: #6d85ff;
  --accent-soft: #2b2f4a;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  transition: background 0.2s, color 0.2s;
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏（极简，DS 风格） ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px calc(10px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, #4d6bfe, #7c5cfc);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
}
.brand-text h1 { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; white-space: nowrap; }
.brand-text span { display: block; font-size: 11px; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: transparent; border: none;
  color: var(--muted); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: 0.15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 聊天区 ---------- */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* 欢迎页（DS 问候 + 卡片） */
#welcome {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 9vh 0 20px; gap: 8px;
}
#welcomeTitle { font-size: 26px; font-weight: 700; }
#welcomeDesc { color: var(--muted); font-size: 14px; max-width: 440px; margin-bottom: 14px; }
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 520px; }
.chip {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius);
  padding: 13px 14px; font-size: 13.5px; text-align: left;
  cursor: pointer; transition: 0.15s; line-height: 1.5;
}
.chip:active { transform: scale(0.98); border-color: var(--accent); }
.chip small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* 消息：用户左灰气泡，AI 左纯文本（DS 风格） */
#messages { display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; max-width: 100%; }
.msg.user { justify-content: flex-start; }
.msg.assistant { justify-content: flex-start; }
.msg-avatar { display: none; }
.bubble {
  max-width: 88%;
  font-size: 14.5px;
  word-break: break-word; overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 15px;
  border-radius: 18px 18px 18px 4px;
}
.msg.assistant .bubble { padding: 0 2px; color: var(--text); }

/* Markdown */
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 14px 0 6px; line-height: 1.4; }
.bubble h2 { font-size: 17px; font-weight: 700; }
.bubble h3 { font-size: 15.5px; font-weight: 600; }
.bubble p { margin: 6px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble strong { font-weight: 700; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble code {
  background: var(--surface2); border-radius: 5px;
  padding: 1px 6px; font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}
.bubble pre {
  background: #f3f4f6; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; overflow-x: auto;
  margin: 10px 0; color: var(--text);
}
html[data-theme="dark"] .bubble pre { background: #16161a; }
.bubble pre code { background: none; border: none; padding: 0; display: block; white-space: pre; }
.bubble blockquote {
  border-left: 3px solid var(--border); padding-left: 12px;
  color: var(--muted); margin: 8px 0;
}
.bubble table {
  border-collapse: collapse; width: 100%; margin: 10px 0;
  font-size: 13px; display: block; overflow-x: auto;
}
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; white-space: nowrap; }
.bubble th { background: var(--surface); font-weight: 600; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.cursor { display: inline-block; width: 8px; height: 16px; background: var(--accent); margin-left: 2px; vertical-align: -2px; animation: blink 1s step-start infinite; border-radius: 2px; }
@keyframes blink { 50% { opacity: 0; } }

.phase-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 2px 2px 0; }
.spinner {
  width: 13px; height: 13px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

/* ---------- 输入区（DS 圆角框） ---------- */
#composer {
  padding: 6px 16px calc(12px + env(safe-area-inset-bottom));
}
#dataStrip {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
  padding: 0 6px 8px; overflow: hidden; white-space: nowrap;
}
#dataStrip .dot { width: 7px; height: 7px; border-radius: 50%; background: #34c759; flex: none; }
.input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px; padding: 8px 8px 8px 18px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 2px 16px rgba(77, 107, 254, 0.12); }
#input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 15px; line-height: 1.5;
  resize: none; max-height: 120px; padding: 6px 0; font-family: inherit;
}
#input::placeholder { color: var(--muted); }
#sendBtn {
  width: 38px; height: 38px; border-radius: 50%; border: none; flex: none;
  background: var(--text); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: 0.15s;
}
#sendBtn:active { transform: scale(0.92); }
#sendBtn:disabled { opacity: 0.35; cursor: not-allowed; }
#sendBtn svg { width: 17px; height: 17px; fill: currentColor; }
.hint { text-align: center; font-size: 11px; color: var(--muted); padding-top: 8px; }

/* 模型切换（DS 风格分段控件） */
.model-toggle {
  display: inline-flex; background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px;
  margin-bottom: 8px;
}
.model-toggle button {
  border: none; background: transparent; color: var(--muted);
  font-size: 12.5px; padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.model-toggle button.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* ---------- 口令层 ---------- */
#passcodeOverlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
html[data-theme="dark"] #passcodeOverlay { background: rgba(20, 20, 24, 0.92); }
#passcodeOverlay[hidden] { display: none; }
.passcard {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 18px; padding: 26px 22px; width: 100%; max-width: 340px;
  text-align: center; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.08);
}
.pass-logo { font-size: 34px; }
.passcard h3 { font-size: 17px; margin: 8px 0 2px; }
.passcard p { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }
.passcard input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 11px 12px;
  font-size: 15px; outline: none; margin-bottom: 10px;
}
.passcard input:focus { border-color: var(--accent); }
.passcard button {
  width: 100%; padding: 11px; border: none; border-radius: 10px;
  background: var(--text); color: var(--bg);
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.passcard .err { color: var(--danger); font-size: 12.5px; margin-top: 8px; min-height: 16px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px;
  font-size: 13px; z-index: 90;
  max-width: 86vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: toastin 0.2s ease; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
@keyframes toastin { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* ---------- 桌面端 ---------- */
@media (min-width: 768px) {
  body { font-size: 16px; }
  #chat { padding: 16px 24px 20px; }
  .msg.assistant .bubble, .msg.user .bubble { font-size: 15px; }
  #input { font-size: 16px; }
}
