:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1a2230;
  --ink-soft: #4b5666;
  --ink-faint: #8a96a8;
  --line: #e3e7ee;
  --brand: #1a3a5c;
  --brand-2: #265b8c;
  --accent: #c8a23a;
  --bot-bg: #f0f4fa;
  --user-bg: #1a3a5c;
  --user-ink: #ffffff;
  --shadow: 0 1px 3px rgba(20,28,42,0.06), 0 8px 24px rgba(20,28,42,0.05);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.5;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.app { display: flex; flex-direction: column; height: 100vh; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px;
  background: var(--brand); color: white;
  border-bottom: 3px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--accent); color: var(--brand);
  border-radius: 6px; font-weight: 800; font-size: 22px;
}
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; opacity: 0.78; }
.topbar-link { color: rgba(255,255,255,0.85); text-decoration: none; font-size: 13px; }
.topbar-link:hover { color: white; }

/* Main two-pane layout */
.layout {
  flex: 1; display: grid;
  grid-template-columns: minmax(0,1fr) minmax(380px, 520px);
  gap: 0; overflow: hidden;
}

/* Chat side */
.chat { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-stream {
  flex: 1; overflow-y: auto; padding: 22px 28px 12px;
  scroll-behavior: smooth;
}
.msg { display: flex; margin-bottom: 18px; max-width: 760px; }
.msg-bot { justify-content: flex-start; }
.msg-user { justify-content: flex-end; margin-left: auto; }
.msg-body {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--bot-bg); color: var(--ink);
  box-shadow: var(--shadow);
  max-width: 100%;
}
.msg-user .msg-body { background: var(--user-bg); color: var(--user-ink); }
.msg-body p { margin: 0 0 8px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 6px 0 8px; padding-left: 22px; }
.msg-body li { margin: 3px 0; }
.msg-body strong { color: var(--brand); }
.msg-user .msg-body strong { color: white; }
.msg-body code { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.9em;
  background: rgba(26,58,92,0.08); padding: 1px 5px; border-radius: 3px; }

/* Citation chips inline */
.cite-chip {
  display: inline-flex; align-items: center;
  margin: 0 1px;
  padding: 1px 8px;
  font-size: 12px; font-weight: 600;
  background: var(--brand-2); color: white;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  vertical-align: 1px;
  border: none;
}
.cite-chip:hover { background: var(--accent); color: var(--brand); }
.cite-chip::before { content: "\2197"; margin-right: 3px; font-size: 11px; }

/* Welcome */
.welcome { max-width: 800px; }
.welcome-prompts { color: var(--ink-soft); font-size: 13px; margin-top: 12px !important; }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.suggestion {
  padding: 6px 12px; font-size: 13px;
  background: white; color: var(--brand);
  border: 1px solid var(--line); border-radius: 16px;
  cursor: pointer; transition: all 0.15s;
}
.suggestion:hover { background: var(--brand); color: white; border-color: var(--brand); }

/* Loading dots */
.loading-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.loading-dots span {
  width: 6px; height: 6px; background: var(--ink-faint); border-radius: 50%;
  animation: blink 1.2s infinite ease-in-out both;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* Composer */
.composer {
  display: flex; gap: 10px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
#qbox {
  flex: 1; resize: none; min-height: 44px; max-height: 160px;
  padding: 11px 14px; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  background: white; outline: none;
  transition: border-color 0.15s;
}
#qbox:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(38,91,140,0.12); }
#sendbtn {
  padding: 0 22px; font: inherit; font-weight: 600;
  background: var(--brand); color: white;
  border: 0; border-radius: 8px; cursor: pointer;
  transition: background 0.15s;
}
#sendbtn:hover:not(:disabled) { background: var(--brand-2); }
#sendbtn:disabled { background: var(--ink-faint); cursor: not-allowed; }

/* Preview side */
.preview {
  background: white; border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-width: 0;
}
.preview-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fafbfd 0%, #ffffff 100%);
}
.preview-title { font-weight: 700; color: var(--brand); font-size: 15px; }
.preview-sub { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.preview-body { flex: 1; overflow-y: auto; padding: 16px; }
.preview-empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--ink-faint); text-align: center;
}
.preview-empty p { margin-top: 12px; max-width: 240px; font-size: 13px; }

.preview-card {
  margin-bottom: 14px; background: white;
  border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.preview-card:hover { transform: translateY(-1px); }
.preview-card-label {
  padding: 8px 12px; font-size: 12px; font-weight: 600;
  color: var(--brand); background: #f8fafd;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.preview-card-zoom {
  font-size: 11px; color: var(--ink-faint); cursor: pointer;
  background: none; border: 0; padding: 0;
}
.preview-card-zoom:hover { color: var(--brand-2); }
.preview-card img {
  display: block; width: 100%; height: auto; cursor: zoom-in;
  background: #f4f6f9;
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(15,22,33,0.92);
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 1000; padding: 40px;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 100%; max-height: calc(100vh - 100px);
  background: white; border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.lightbox-caption { color: rgba(255,255,255,0.85); margin-top: 14px; font-size: 13px; }
.lightbox-close {
  position: absolute; top: 16px; right: 22px;
  width: 40px; height: 40px;
  background: rgba(255,255,255,0.1); color: white;
  border: 0; border-radius: 50%;
  font-size: 28px; cursor: pointer;
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }

/* Footer */
.footer {
  padding: 9px 22px; font-size: 11px; color: var(--ink-faint);
  border-top: 1px solid var(--line); background: var(--panel);
  display: flex; justify-content: space-between; gap: 20px;
}
.footer .powered { font-style: italic; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr 280px; }
  .preview { border-left: 0; border-top: 1px solid var(--line); }
  .footer { flex-direction: column; gap: 4px; }
}
