/* ---------- baseline ---------- */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17222e;
  --muted: #5d6b7a;
  --border: #e2e6ec;
  --accent: #1e5aa8;
  --accent-soft: #eaf1fb;
  --user-bubble: #1e5aa8;
  --user-bubble-text: #ffffff;
  --assistant-bubble: #ffffff;
  --source-bg: #f9fafc;
  --source-border: #dfe4eb;
  --not-found-bg: #f4f2ec;
  --not-found-border: #d9d3c1;
  --footer-fg: #5d6b7a;
  --shadow: 0 1px 2px rgba(23, 34, 46, 0.04),
            0 8px 24px rgba(23, 34, 46, 0.05);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
               "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent); color: white;
  display: grid; place-items: center; font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-name { font-weight: 600; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.corpus-pill {
  color: var(--muted); font-size: 12px;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel);
}
.corpus-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #2ea86a;
}

/* ---------- chat ---------- */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 12px;
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 8px 0 20px;
  overflow-y: auto;
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
}
.empty-title { color: var(--text); font-weight: 600; margin-bottom: 6px; }
.empty-hint { font-size: 13px; line-height: 1.55; }

/* ---------- messages ---------- */
.msg { display: flex; flex-direction: column; gap: 8px; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }
.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 720px;
  box-shadow: var(--shadow);
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: var(--assistant-bubble); color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.assistant.not-found .bubble {
  background: var(--not-found-bg);
  border-color: var(--not-found-border);
  color: #4a412a;
  font-style: italic;
}

/* ---------- source cards ---------- */
.sources { display: grid; grid-template-columns: 1fr; gap: 8px; max-width: 720px; }
.source-card {
  background: var(--source-bg);
  border: 1px solid var(--source-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.source-head {
  display: flex; align-items: center; gap: 10px;
  color: var(--accent); font-weight: 600; margin-bottom: 6px;
}
.source-head .cite { }
.source-head .sim {
  margin-left: auto; font-weight: 500; color: var(--muted); font-size: 12px;
  background: white; border: 1px solid var(--border); padding: 1px 8px;
  border-radius: 999px;
}
.source-snippet {
  color: var(--muted); line-height: 1.5;
  white-space: pre-wrap;
}

/* ---------- meta / status ---------- */
.meta-row {
  display: flex; gap: 12px; flex-wrap: wrap;
  color: var(--muted); font-size: 12px; margin-top: 2px;
}
.meta-row .tag {
  background: var(--accent-soft); color: var(--accent);
  padding: 1px 8px; border-radius: 999px; font-weight: 500;
}

/* ---------- context bar ---------- */
.context-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--accent-soft);
  border: 1px solid #c9dcf4;
  color: #12406f;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 13.5px;
}
.context-bar.hidden { display: none; }
.context-filename { font-weight: 600; }
.context-note { color: #4a6a91; }
.context-remove {
  margin-left: auto;
  background: transparent; border: 1px solid #b7cdea;
  color: #12406f;
  padding: 2px 10px; border-radius: 999px; cursor: pointer;
  font-size: 12px;
}
.context-remove:hover { background: white; }

/* ---------- composer ---------- */
.composer {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 10px;
  box-shadow: var(--shadow);
}
.upload-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border);
  display: grid; place-items: center; cursor: pointer;
  font-size: 18px; line-height: 1; color: var(--muted);
  transition: background 0.12s;
}
.upload-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: #c9dcf4; }
.question-input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 15px; padding: 8px 4px; color: var(--text);
}
.send-btn {
  background: var(--accent); color: white;
  border: 0; border-radius: 999px;
  padding: 8px 18px; font-weight: 600; cursor: pointer;
  transition: background 0.12s;
}
.send-btn:hover { background: #17497e; }
.send-btn:disabled { background: #7fa3ce; cursor: default; }

/* ---------- footer ---------- */
.app-footer {
  text-align: center; color: var(--footer-fg);
  font-size: 12px; padding: 14px; border-top: 1px solid var(--border);
  background: var(--panel);
}

/* ---------- typing dots ---------- */
.typing { display: inline-flex; gap: 4px; padding: 6px 4px; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); opacity: 0.5;
  animation: blink 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}
