﻿:root {
  --brand: #7458F0;
  --top-bg: #2A2440;
  --accent: #00D4B8;
  --radius: 16px;
  --muted: #45445C;

  --chat-w: 28%;
  --chat-w-min: 340px;
  --chat-w-max: 480px;
  --top-h: 10vh;
  --top-h-min: 56px;
  --top-h-max: 84px;

  --bg: #F7F8FC;
  --surface: #FFFFFF;
  --ink: #2A2440;
  --ink-soft: #5B5A72;
  --line: #E3E6F2;
  --badge-faq: #1C8A4B;
  --badge-live: #F59E0B;
  --badge-gap: #6B6B7F;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: clamp(var(--top-h-min), var(--top-h), var(--top-h-max));
  background: var(--top-bg);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.topbar-left {
  display: flex;
  align-items: center;
}

.brand {
  font-size: 18px;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  gap: 16px;
  align-items: center;
}

.visitor-chip {
  font-size: 14px;
  padding: 6px 12px;
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  opacity: 0.9;
}

.topbar-link,
.topbar-btn {
  font-size: 13px;
  color: white;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
  text-decoration: none;
  padding: 4px 8px;
}

.topbar-link:hover,
.topbar-btn:hover {
  opacity: 1;
}

.user {
  font-size: 14px;
  opacity: 0.9;
}

body {
  display: grid;
  grid-template-rows: clamp(var(--top-h-min), var(--top-h), var(--top-h-max)) 1fr;
  grid-template-columns: 1fr;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  grid-row: 1;
  grid-column: 1 / -1;
}

main, aside {
  grid-row: 2;
}

body > :not(.topbar) {
  overflow: auto;
}

.chat-pane {
  position: fixed;
  top: clamp(var(--top-h-min), var(--top-h), var(--top-h-max));
  left: 0;
  width: var(--chat-w);
  height: calc(100vh - clamp(var(--top-h-min), var(--top-h), var(--top-h-max)));
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
  z-index: 50;
}

.chat-scroll {
  padding-right: 8px;
}

.pane-handle {
  position: fixed;
  top: clamp(var(--top-h-min), var(--top-h), var(--top-h-max));
  left: calc(var(--chat-w) - 3px);
  width: 6px;
  height: calc(100vh - clamp(var(--top-h-min), var(--top-h), var(--top-h-max)));
  cursor: col-resize;
  background: transparent;
  z-index: 60;
  user-select: none;
}

.pane-handle:hover {
  background: var(--accent);
}

.answer-pane {
  position: fixed;
  top: clamp(var(--top-h-min), var(--top-h), var(--top-h-max));
  left: var(--chat-w);
  right: 0;
  height: calc(100vh - clamp(var(--top-h-min), var(--top-h), var(--top-h-max)));
  background: var(--bg);
  overflow-y: auto;
  padding: 20px;
}

.card-container {
  max-width: 800px;
}

.card-container h2 {
  font-size: 24px;
  margin-top: 0;
  color: var(--ink);
}

.card-container p {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.6;
}

.visual {
  margin: 20px 0;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow-x: auto;
}

.visual svg {
  max-width: 100%;
  height: auto;
}

.visual .mermaid svg {
  /* Wide diagrams (40-entity ER = 15k px natural) keep a readable height and scroll sideways inside pre.mermaid */
  max-width: none !important;
  width: auto;
  height: auto;
  max-height: 70vh;
  min-width: 100%;
}
.visual .mermaid svg[width] {
  width: auto;
  height: 70vh;
  min-width: 0;
}
.visual-hint {
  font-size: 12px;
  color: var(--muted, #6b6b80);
  margin: 4px 0 0;
}

pre.mermaid {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow-x: auto;
}

canvas {
  max-width: 100%;
  height: auto;
}

.facts-banner {
  position: fixed;
  top: clamp(var(--top-h-min), var(--top-h), var(--top-h-max));
  left: 0;
  right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px 20px;
  font-size: 12px;
  color: var(--ink-soft);
  z-index: 99;
  text-align: center;
  line-height: 1.4;
  height: auto;
}

.chat-header {
  padding: 12px 0;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}

.chat-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:focus-visible,
#chat-input:focus-visible,
.send-btn:focus-visible,
.faq-questions button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.tab-btn.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 200px;
}

.bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 90%;
}

.bubble.user {
  background: var(--brand);
  color: white;
  margin-left: auto;
}

.bubble.assistant {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.bubble .view-answer {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
}

.faq-browse {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.faq-category {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.faq-category-title {
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

.faq-questions {
  margin: 8px 0 0 0;
  padding: 0;
  list-style: none;
}

.faq-questions li {
  padding: 6px 0;
  font-size: 13px;
}

.faq-questions button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.chat-input-area {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}

#chat-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: system-ui, sans-serif;
  font-size: 13px;
  resize: none;
  margin-bottom: 8px;
}

.send-btn {
  width: 100%;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.send-btn:hover {
  opacity: 0.9;
}

.busy-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.busy-indicator::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin-top: 0;
  color: var(--ink);
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.badge.faq {
  background: var(--badge-faq);
  color: white;
}

.badge.live {
  background: var(--badge-live);
  color: white;
}

.badge.deeper {
  background: var(--badge-live);
  color: white;
}

.badge.gap {
  background: var(--badge-gap);
  color: white;
}

.tldr {
  font-weight: 600;
  color: var(--ink);
  margin: 12px 0;
}

.card-contents {
  position: sticky;
  top: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  margin-bottom: 20px;
}

.card-contents h3 {
  margin: 0 0 8px 0;
  font-size: 13px;
}

.card-contents ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.card-contents li {
  padding: 4px 0;
}

.card-contents a {
  color: var(--brand);
  text-decoration: none;
  cursor: pointer;
}

.card-contents a:hover {
  text-decoration: underline;
}

.gate-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.gate-modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.gate-modal-content h2 {
  margin-top: 0;
  color: var(--ink);
}

#gateForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#gateForm input,
#gateForm select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: system-ui, sans-serif;
}

.privacy-notice {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 8px 0;
}

.gate-submit {
  padding: 10px 12px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.gate-submit:hover {
  opacity: 0.9;
}

.contents-rail {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  @keyframes spin {
    to { transform: rotate(360deg); }
  }

  .busy-indicator::before {
    animation: none;
    border-top-color: var(--brand);
    border-right-color: var(--brand);
  }

  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1024px) {
  .chat-pane {
    position: fixed;
    width: 100%;
    height: 40vh;
    bottom: 0;
    top: auto;
    left: 0;
    border-right: none;
    border-top: 1px solid var(--line);
    z-index: 45;
  }

  .pane-handle {
    position: fixed;
    left: 0;
    right: 0;
    width: 100%;
    height: 6px;
    top: calc(100vh - 40vh - 3px);
    cursor: row-resize;
  }

  .answer-pane {
    position: fixed;
    top: clamp(var(--top-h-min), var(--top-h), var(--top-h-max));
    left: 0;
    right: 0;
    height: calc(100vh - clamp(var(--top-h-min), var(--top-h), var(--top-h-max)) - 40vh - 6px);
  }

  .facts-banner {
    height: auto;
  }
}
