/* Research Portal — v1 styling.
   Clinical / professional: blues + whites, clean sans typography. */

:root {
  --brand-blue: #0a5cad;
  --brand-blue-dark: #073e75;
  --brand-blue-light: #e8f1fb;
  --ink: #1b2733;
  --muted: #5b6b7b;
  --line: #d8e1ea;
  --bg: #f4f7fb;
  --agent-bubble: #ffffff;
  --user-bubble: #0a5cad;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(10, 42, 78, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.view { min-height: 100vh; }

/* ---------------- Login ---------------- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--brand-blue) 0%, var(--brand-blue-dark) 100%);
}

.login-card {
  background: #fff;
  padding: 48px 44px;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  text-align: center;
  max-width: 380px;
  width: 90%;
}

.brand { margin-bottom: 8px; }

.brand-name {
  font-weight: 800;
  font-size: 32px;
  letter-spacing: 1px;
  color: var(--brand-blue);
}

.tagline {
  display: block;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 2px;
}

.subtitle {
  color: var(--ink);
  font-weight: 600;
  margin: 18px 0 4px;
}

.synthetic-note {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 24px;
}

/* ---------------- Buttons ---------------- */
.primary-btn {
  background: var(--brand-blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.primary-btn:hover { background: var(--brand-blue-dark); }
.primary-btn:disabled { background: #9db6cf; cursor: not-allowed; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--brand-blue); color: var(--brand-blue); }

.error { color: var(--danger); font-size: 13px; margin-top: 14px; }

/* ---------------- App shell ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 12px 24px;
  box-shadow: var(--shadow);
}

.brand-sm .brand-name { font-size: 22px; }
.brand-sm .tagline {
  display: inline;
  font-size: 11px;
  margin-left: 8px;
}

.user-box { display: flex; align-items: center; gap: 12px; }
.user-email { color: var(--muted); font-size: 14px; }

.role-badge {
  background: var(--brand-blue-light);
  color: var(--brand-blue-dark);
  border: 1px solid #c3dcf5;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.role-banner {
  background: var(--brand-blue-light);
  color: var(--brand-blue-dark);
  font-size: 13px;
  padding: 8px 24px;
  border-bottom: 1px solid #d3e4f7;
}
.role-banner:empty { display: none; }

/* ---------------- Chat ---------------- */
.chat-shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 0;
  height: calc(100vh - 58px);
  display: flex;
  flex-direction: column;
}

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

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.agent { justify-content: flex-start; }

.bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 15px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.agent .bubble {
  background: var(--agent-bubble);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}

.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-right-radius: 4px;
}

/* Structured-data cards rendered from JSON payloads. */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 10px;
  overflow: hidden;
}
.card-header {
  background: var(--brand-blue-light);
  color: var(--brand-blue-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 12px;
}
.card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.card th, .card td {
  text-align: left;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}
.card th { color: var(--muted); font-weight: 600; background: #fafcfe; }
.card tr:last-child td { border-bottom: none; }

/* Rendered markdown inside agent bubbles. Normal whitespace here: line breaks
   come from explicit <br>/block tags, not the source newlines (the bubble's
   pre-wrap would otherwise double them). */
.md { white-space: normal; }
.md ul { margin: 6px 0; padding-left: 20px; }
.md li { margin: 2px 0; }
.md strong { font-weight: 700; }
.md em { font-style: italic; }
.md code {
  background: #eef3f8;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.md pre {
  background: #0f1b29;
  color: #e6edf3;
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.md pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 12.5px;
  white-space: pre;
}

/* Reasoning panel */
.reasoning {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  font-size: 13px;
}
.reasoning > summary {
  cursor: pointer;
  color: var(--brand-blue);
  font-weight: 600;
  list-style: none;
  user-select: none;
}
.reasoning > summary::before { content: "▸ "; }
.reasoning[open] > summary::before { content: "▾ "; }
.reasoning > summary::-webkit-details-marker { display: none; }
.reasoning-body { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.reasoning-row { display: flex; gap: 8px; align-items: baseline; }
.reasoning-key {
  flex: 0 0 64px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.4px;
}
.reasoning-val { color: var(--ink); word-break: break-word; }
.reasoning-val code.sql {
  display: block;
  background: #0f1b29;
  color: #e6edf3;
  border-radius: 6px;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.linklike {
  background: none;
  border: none;
  color: var(--brand-blue);
  cursor: pointer;
  padding: 2px 0 0;
  font-size: 12px;
  text-decoration: underline;
}

/* Thinking indicator */
.thinking .bubble { color: var(--muted); font-style: italic; }
.dots span {
  display: inline-block;
  animation: blink 1.2s infinite both;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* Suggestion chips */
.suggestions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--brand-blue-light);
  border: 1px solid #c3dcf5;
  color: var(--brand-blue-dark);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { background: #d8e9fb; }

/* Composer */
.composer {
  display: flex;
  gap: 10px;
  padding: 14px 0 18px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
#chat-input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: var(--font);
}
#chat-input:focus { outline: none; border-color: var(--brand-blue); }
