:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --user-bubble: #2563eb;
  --bot-bubble: #f1f5f9;
  --ok: #16a34a;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.15);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #0f172a, #1e3a8a);
}

/* ---------------- Login gate ---------------- */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.gate-card {
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.gate-card h1 { font-size: 20px; margin: 8px 0 2px; }
.gate-card p { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.lock { font-size: 38px; }
.gate input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  outline: none;
}
.gate input:focus { border-color: var(--brand); }
.gate button {
  margin-top: 12px;
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.gate button:hover { background: var(--brand-dark); }
.gate .err { color: #dc2626; font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------------- App shell ---------------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 820px;
  margin: 0 auto;
  background: #f8fafc;
}
@media (min-width: 860px) {
  .app { height: 100vh; box-shadow: var(--shadow); }
}

header.bar {
  background: var(--bg);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
header.bar .logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--brand);
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px;
}
header.bar .title { line-height: 1.2; }
header.bar .title b { font-size: 15px; }
header.bar .title span { display: block; font-size: 12px; color: #94a3b8; }
header.bar .spacer { flex: 1; }
header.bar button.logout {
  background: transparent;
  border: 1px solid #334155;
  color: #cbd5e1;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

/* ---------------- Chat ---------------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 8px;
  -webkit-overflow-scrolling: touch;
}
.msg { display: flex; margin: 10px 0; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.bot .bubble {
  background: var(--bot-bubble);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.bubble .cat {
  display: inline-block;
  font-size: 11px;
  color: var(--brand-dark);
  background: #dbeafe;
  border-radius: 999px;
  padding: 2px 9px;
  margin-bottom: 8px;
  font-weight: 600;
}
.bubble strong { font-weight: 700; }
.bubble code {
  background: #e2e8f0;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 13px;
}
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble blockquote {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-left: 3px solid #f59e0b;
  background: #fffbeb;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
}

.alts { margin-top: 10px; }
.alts .alt-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chip {
  display: inline-block;
  margin: 4px 6px 0 0;
  padding: 7px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  color: var(--brand-dark);
}
.chip:hover { background: #eff6ff; border-color: var(--brand); }

/* Suggestion chips under the welcome message */
.suggests { margin-top: 4px; }

/* ---------------- Composer ---------------- */
.composer {
  display: flex;
  gap: 8px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
}
.composer input {
  flex: 1;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 16px;
  outline: none;
}
.composer input:focus { border-color: var(--brand); }
.composer button {
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.composer button:hover { background: var(--brand-dark); }
.composer button:disabled { opacity: .5; cursor: default; }

.hidden { display: none !important; }

/* 模式徽章 + AI 打字动画 */
.mode-badge {
  font-size: 12px;
  color: #cbd5e1;
  border: 1px solid #334155;
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}
.typing .bubble { color: var(--muted); }
.dots { display: inline-flex; gap: 3px; margin-right: 6px; vertical-align: middle; }
.dots i {
  width: 6px; height: 6px;
  background: var(--brand);
  border-radius: 50%;
  animation: blink 1.2s infinite;
}
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
