/* ── 全域 ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --card:      #232636;
  --border:    #2e3145;
  --accent:    #4f8ef7;
  --accent-h:  #6ba3ff;
  --text:      #e2e8f0;
  --muted:     #7c8db0;
  --danger:    #f56565;
  --success:   #48bb78;
  --warn:      #f6ad55;
  --radius:    14px;
  --font:      -apple-system, 'PingFang TC', 'Microsoft JhengHei', sans-serif;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }

body {
  display: flex; flex-direction: column; min-height: 100vh;
  overflow-x: hidden;
}

/* ── 頁首 ────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(10px);
}

.header-inner {
  max-width: 860px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center;
}

.logo { display: flex; align-items: center; gap: 12px; }

.logo-icon { font-size: 28px; }

.logo-text { display: flex; flex-direction: column; }

.brand { font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: 0.3px; }

.sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

.header-badge {
  display: flex; align-items: center; gap: 8px;
  background: rgba(79,142,247,0.12);
  border: 1px solid rgba(79,142,247,0.3);
  border-radius: 20px; padding: 6px 14px;
  font-size: 12px; color: var(--accent);
}

.badge-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ── 主體 ────────────────────────────────────────────────── */
main {
  flex: 1; max-width: 860px; margin: 0 auto;
  width: 100%; padding: 24px 16px 160px;
}

/* ── 建議問題 ────────────────────────────────────────────── */
.suggestions { margin-bottom: 24px; }

.suggest-title {
  font-size: 13px; color: var(--muted);
  margin-bottom: 12px; padding-left: 4px;
}

.suggest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.suggest-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.5;
}

.suggest-btn:hover {
  border-color: var(--accent);
  background: rgba(79,142,247,0.08);
  transform: translateY(-1px);
}

/* ── 對話 ────────────────────────────────────────────────── */
.chat-container { display: flex; flex-direction: column; gap: 20px; }

.messages { display: flex; flex-direction: column; gap: 20px; }

/* 用戶訊息 */
.msg-user {
  display: flex; justify-content: flex-end;
}

.msg-user .bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 18px;
  max-width: 75%;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}

/* AI 訊息 */
.msg-ai {
  display: flex; gap: 12px; align-items: flex-start;
}

.ai-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #4f8ef7, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0; margin-top: 2px;
}

.ai-content { flex: 1; }

.ai-bubble {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px 18px 18px 18px;
  padding: 16px 20px;
  font-size: 15px; line-height: 1.8;
  word-break: break-word;
}

.ai-bubble p { margin-bottom: 10px; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble h1, .ai-bubble h2, .ai-bubble h3 {
  color: var(--accent-h); margin: 12px 0 8px; font-size: 15px;
}
.ai-bubble ul, .ai-bubble ol { padding-left: 20px; margin: 8px 0; }
.ai-bubble li { margin-bottom: 4px; }
.ai-bubble code {
  background: rgba(255,255,255,0.08);
  border-radius: 4px; padding: 2px 6px;
  font-family: 'JetBrains Mono', monospace; font-size: 13px;
}
.ai-bubble pre code { display: block; padding: 12px; }
.ai-bubble strong { color: #fff; }
.ai-bubble table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
.ai-bubble th { background: rgba(255,255,255,0.08); padding: 6px 10px; text-align: left; border: 1px solid var(--border); }
.ai-bubble td { padding: 6px 10px; border: 1px solid var(--border); }

/* 來源文件 */
.sources {
  margin-top: 14px;
  display: flex; flex-wrap: wrap; gap: 8px;
}

.source-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px;
  font-size: 12px; color: var(--muted);
  max-width: 280px; overflow: hidden;
}

.source-chip.masked { border-color: rgba(245,101,101,0.4); }

.chip-score {
  background: rgba(79,142,247,0.2);
  color: var(--accent);
  border-radius: 4px; padding: 1px 5px;
  font-size: 11px; flex-shrink: 0;
}

.chip-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Typing indicator */
.typing { display: flex; gap: 5px; padding: 14px 18px; }
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}

/* 錯誤訊息 */
.error-bubble {
  background: rgba(245,101,101,0.12);
  border: 1px solid rgba(245,101,101,0.3);
  color: var(--danger);
  border-radius: 10px; padding: 12px 16px;
  font-size: 14px;
}

/* ── 輸入區 ────────────────────────────────────────────────── */
.input-area {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, var(--bg) 30%);
  padding: 12px 16px 24px;
  z-index: 100;
}

.input-inner { max-width: 860px; margin: 0 auto; }

.input-box {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 10px 10px 18px;
  transition: border-color 0.2s;
}

.input-box:focus-within { border-color: var(--accent); }

textarea#queryInput {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.6; resize: none;
  max-height: 120px; overflow-y: auto; padding: 0;
}

textarea#queryInput::placeholder { color: var(--muted); }

.send-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.2s; color: #fff;
}

.send-btn:hover { background: var(--accent-h); transform: scale(1.05); }

.send-btn:disabled { background: var(--border); cursor: not-allowed; transform: none; }

.send-btn svg { width: 16px; height: 16px; }

.disclaimer {
  font-size: 11.5px; color: var(--muted);
  text-align: center; margin-top: 8px;
}

/* ── 響應式 ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .suggest-grid { grid-template-columns: 1fr 1fr; }
  .msg-user .bubble, .ai-bubble { font-size: 14px; }
  .header-badge { display: none; }
  .brand { font-size: 16px; }
}
