:root {
  --bg: #fbfaf7;
  --bg-elev: #f5f3ee;
  --bg-elev-2: #f2efe9;
  --bg-hover: #ebe7df;
  --border: #e8e4dc;
  --text: #1f2330;
  --text-dim: #8a8a85;
  --text-soft: #4a4d54;
  --accent: #3a6890;
  --accent-soft: #dde6ee;
  --user-bubble: #1f3d63;
  --user-bubble-text: #ffffff;
  --assistant-bubble: #ffffff;
  --tool-chip: #f2efe9;
  --tool-chip-ok: #e6f3ec;
  --tool-chip-err: #fce8e6;
  --success: #2e7d56;
  --warning: #a67c1e;
  --danger: #c4413e;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
}
.new-chat {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  margin-bottom: 12px;
  transition: background 0.12s;
}
.new-chat:hover { background: var(--bg-hover); }
.session-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
}
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-soft);
  font-size: 13.5px;
  margin-bottom: 2px;
  transition: background 0.1s;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--accent-soft); color: var(--text); }
.session-item .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.session-item .delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.session-item:hover .delete { opacity: 1; }
.session-item .delete:hover { color: var(--danger); }
.sidebar-footer {
  color: var(--text-dim);
  font-size: 11.5px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ---- Chat column ---- */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.session-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.session-title {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.save-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev);
  color: var(--text-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s, border-color 0.1s;
}
/* The explicit display above overrides the UA [hidden] rule, so a JS `hidden`
   toggle can't hide a .save-btn on its own. Scope the fix to the curator-gated
   Publish button by id; the Save button is meant to stay visible. */
#publish-btn[hidden] {
  display: none;
}
.save-btn:hover:not(:disabled) {
  color: var(--accent);
  background: var(--bg-hover);
  border-color: var(--accent);
}
.save-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.save-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}
.header-controls {
  display: flex;
  align-items: center;
  gap: 18px;
}

/* ---- Messages ---- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
}
.message {
  display: flex;
  flex-direction: column;
  margin: 0 auto 10px;
  max-width: 1180px;
  padding: 0 28px;
}
.message.user {
  align-items: flex-end;
}
.message .bubble {
  border-radius: 12px;
  padding: 10px 14px;
  word-wrap: break-word;
}
.message.user .bubble {
  max-width: 72%;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  white-space: pre-wrap;            /* preserve newlines in user text */
}
.message.assistant .bubble {
  max-width: 100%;                  /* fill the column for tables */
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  color: var(--text);
  overflow-x: auto;                 /* wide tables / code can scroll */
}

/* Markdown rhythm — tighten paragraph + list + heading spacing */
.message.assistant .bubble > *:first-child { margin-top: 0; }
.message.assistant .bubble > *:last-child { margin-bottom: 0; }
.message.assistant .bubble p { margin: 0 0 0.5em; }
.message.assistant .bubble ul,
.message.assistant .bubble ol { margin: 0.35em 0; padding-left: 22px; }
.message.assistant .bubble li { margin: 1px 0; }
.message.assistant .bubble li > p { margin: 0; }
.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3,
.message.assistant .bubble h4 {
  margin: 0.7em 0 0.3em;
  font-weight: 600;
  line-height: 1.25;
}
.message.assistant .bubble h1 { font-size: 1.15em; }
.message.assistant .bubble h2 { font-size: 1.08em; }
.message.assistant .bubble h3 { font-size: 1em; }
.message.assistant .bubble h4 { font-size: 0.95em; color: var(--text-soft); }
.message.assistant .bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}
.message.assistant .bubble blockquote {
  margin: 0.4em 0;
  padding: 2px 12px;
  border-left: 3px solid var(--border);
  color: var(--text-soft);
}

.message.assistant .bubble code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  background: var(--bg-elev-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}
.message.assistant .bubble pre {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
}
.message.assistant .bubble pre code {
  background: transparent;
  padding: 0;
}

/* Charts / images — never exceed the column; render as a framed card so the
   matplotlib PNGs sit on the cream background cleanly instead of floating. */
.message.assistant .bubble img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(31, 35, 48, 0.06);
}

/* Tables — denser, full-bleed within the bubble, with subtle banding */
.message.assistant .bubble table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 12.5px;
  width: 100%;
}
.message.assistant .bubble th,
.message.assistant .bubble td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
  min-width: 60px;
}
.message.assistant .bubble th {
  background: var(--bg-elev-2);
  font-weight: 600;
  position: sticky;
  top: 0;
}
.message.assistant .bubble tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.025);
}
.message.assistant .bubble tbody tr:hover td {
  background: rgba(58, 104, 144, 0.08);
}

/* Allow the assistant bubble to expand wider than user-text content when a
   wide table is present, by letting the bubble use the full column. */
.message.assistant { width: 100%; }
/* ---- Tool track (live status → collapsed disclosure) ---- */
.tool-track {
  margin-bottom: 4px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.4;
}
.tool-status {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tool-status .spinner {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse 1s ease-in-out infinite;
}
.tool-status strong {
  color: var(--text-soft);
  font-weight: 500;
}
.tool-status .args {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.tool-disclosure {
  display: inline-block;
}
.tool-disclosure summary {
  list-style: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 2px 6px;
  border-radius: 4px;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.1s, background 0.1s;
}
.tool-disclosure summary::-webkit-details-marker { display: none; }
.tool-disclosure summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.12s ease;
  font-size: 10px;
}
.tool-disclosure[open] summary::before {
  transform: rotate(90deg);
}
.tool-disclosure summary:hover {
  color: var(--accent);
  background: var(--bg-hover);
}
.tool-rows {
  margin: 6px 0 0 14px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}
.tool-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-row .icon {
  color: var(--success);
  flex-shrink: 0;
  width: 12px;
}
.tool-row .name {
  color: var(--text-soft);
}
.tool-row .args {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-row .error {
  color: var(--danger);
}
.tool-row.err .icon {
  color: var(--danger);
}

.tool-status .label,
.tool-row .label {
  color: var(--text-soft);
}
.tool-status .tool-name,
.tool-row .tool-name {
  color: var(--text-dim);
  opacity: 0.55;
  font-size: 10.5px;
}
.tool-status .args,
.tool-row .args {
  color: var(--text-dim);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}
.tool-status .ellipsis {
  color: var(--text-dim);
  margin-left: 2px;
}

/* ---- Verification panel ---- */
.verify-track {
  margin-top: 6px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11.5px;
  line-height: 1.4;
}
.verify-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
}
.verify-status.err { color: var(--danger); }
.verify-status .spinner {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.verify-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11.5px;
  cursor: pointer;
  user-select: none;
  transition: color 0.1s, background 0.1s, border-color 0.1s;
}
.verify-btn:hover:not(:disabled) {
  color: var(--accent);
  background: var(--bg-hover);
  border-color: var(--accent);
}
.verify-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.verify-btn .verify-btn-icon {
  font-size: 10px;
}

.verify-disclosure {
  display: block;
}
.verify-disclosure summary {
  list-style: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px 8px;
  border-radius: 6px;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  transition: color 0.1s, background 0.1s;
}
.verify-disclosure summary::-webkit-details-marker { display: none; }
.verify-disclosure summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.12s ease;
  font-size: 10px;
}
.verify-disclosure[open] summary::before {
  transform: rotate(90deg);
}
.verify-disclosure summary:hover {
  color: var(--accent);
  background: var(--bg-hover);
}
.verify-rows {
  margin: 8px 0 0 4px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-family: "Inter", -apple-system, sans-serif;
  font-size: 13px;
}
.verify-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0;
}
.verify-row .head {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.verify-row .icon {
  flex-shrink: 0;
  width: 14px;
  font-weight: 600;
}
.verify-row .claim {
  color: var(--text);
  font-style: italic;
}
.verify-row .note {
  color: var(--text-soft);
  margin-left: 20px;
  font-size: 12.5px;
}
.verify-row .src {
  color: var(--accent);
  margin-left: 20px;
  font-size: 11.5px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  word-break: break-all;
  text-decoration: none;
}
.verify-row .src:hover { text-decoration: underline; }

.verify-row.status-confirmed .icon { color: var(--success); }
.verify-row.status-contradicted .icon { color: var(--danger); }
.verify-row.status-uncertain .icon { color: var(--warning); }

/* ---- Empty state ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 24px 28px;
  color: var(--text-dim);
}
.empty-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 12px;
  padding: 5px 13px 5px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.empty-eyebrow .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(58, 104, 144, 0.18);
}
.empty-state h1 {
  margin: 0 0 7px;
  font-size: 26px;
  letter-spacing: -0.02em;
  color: var(--text);
  font-weight: 700;
}
.empty-state p {
  margin: 0 0 18px;
  max-width: 520px;
  font-size: 13.5px;
  line-height: 1.5;
}

/* Decision starter cards */
.suggestion-groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 960px;
}
.sg-card {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 15px 15px 11px;
  text-align: left;
  box-shadow: 0 1px 2px rgba(31, 35, 48, 0.04);
  transition: box-shadow 0.16s, border-color 0.16s, transform 0.16s;
}
.sg-card:hover {
  border-color: transparent;
  box-shadow: 0 10px 28px rgba(31, 35, 48, 0.10);
  transform: translateY(-2px);
}
.sg-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 2px 11px;
}
.sg-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--sg-tint, var(--accent-soft));
  color: var(--sg-ink, var(--accent));
  flex-shrink: 0;
}
.sg-icon svg { width: 17px; height: 17px; }
.sg-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.sg-q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: transparent;
  color: var(--text-soft);
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 2px;
  text-align: left;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.sg-q:hover { background: var(--sg-tint, var(--accent-soft)); color: var(--text); }
.sg-arrow {
  flex-shrink: 0;
  display: flex;
  color: var(--sg-ink, var(--accent));
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.12s, transform 0.12s;
}
.sg-arrow svg { width: 15px; height: 15px; display: block; }
.sg-q:hover .sg-arrow {
  opacity: 1;
  transform: translateX(0);
}

/* Post-upload summary card (rendered into the message stream) */
.upload-card {
  width: 100%;
  max-width: 1180px;
  margin: 4px auto 16px;
  padding: 0 28px;                 /* match the message gutter */
  box-sizing: border-box;
}
.uc-box {
  --sg-tint: #e6edf4;             /* blue accent from SG_PALETTE[0] */
  --sg-ink: #3a6890;
  width: min(440px, 100%);
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 15px 15px 11px;
  box-shadow: 0 1px 2px rgba(31, 35, 48, 0.04);
}
.uc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 2px 10px;
}
.uc-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--sg-tint);
  color: var(--sg-ink);
  flex-shrink: 0;
}
.uc-icon svg { width: 17px; height: 17px; }
.uc-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  word-break: break-word;
}
.uc-facts {
  margin: 0 2px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.uc-fact {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.4;
}
.uc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--border);
}
.uc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  color: var(--text-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 10px;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.uc-chip:hover {
  border-color: var(--sg-ink);
  color: var(--text);
  background: var(--sg-tint);
}
.uc-chip-ico { display: inline-flex; color: var(--sg-ink); }
.uc-chip-ico svg { width: 14px; height: 14px; display: block; }
.uc-chip.primary {
  background: var(--sg-ink);
  border-color: var(--sg-ink);
  color: #fff;
}
.uc-chip.primary:hover { background: #2f5677; border-color: #2f5677; }
.uc-chip.primary .uc-chip-ico { color: #fff; }

.bring-data {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 960px;
  margin-top: 12px;
  background: var(--assistant-bubble);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(31, 35, 48, 0.04);
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
}
.bring-data:hover {
  border-color: var(--accent-soft);
  box-shadow: 0 6px 18px rgba(31, 35, 48, 0.08);
  transform: translateY(-1px);
}
.bring-data > svg { width: 18px; height: 18px; color: var(--accent); flex-shrink: 0; }
.bring-data-text { display: flex; flex-direction: column; gap: 3px; }
.bring-data-title { font-weight: 600; font-size: 14px; }
.bring-data-sub { color: var(--text-dim); font-size: 12.5px; line-height: 1.4; }

@media (max-width: 920px) {
  .suggestion-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .suggestion-groups { grid-template-columns: 1fr; }
}

/* ---- Composer ---- */
.composer {
  background: var(--bg);
  padding: 8px 28px 16px;
  max-width: 1180px;              /* keep in sync with .message column width */
  width: 100%;
  margin: 0 auto;
}
.composer-wrap {
  position: relative;
  display: flex;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  background: var(--assistant-bubble);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 52px 14px 16px;     /* right padding makes room for the embedded send button */
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  min-height: 54px;
  max-height: 200px;
  outline: none;
  box-shadow: 0 1px 3px rgba(31, 35, 48, 0.06), 0 4px 16px rgba(31, 35, 48, 0.05);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(58, 104, 144, 0.12), 0 4px 16px rgba(31, 35, 48, 0.05);
}
.composer button {
  position: absolute;
  right: 11px;
  bottom: 11px;                     /* centers the 32px button in the 54px resting input */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, transform 0.08s;
}
.composer button:hover:not(:disabled) {
  background: #2f567a;
}
.composer button:active:not(:disabled) {
  transform: scale(0.94);
}
.composer button:disabled {
  background: var(--bg-hover);
  color: var(--text-dim);
  cursor: not-allowed;
}
.composer button svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* Attach (upload) button — a static ghost button left of the textarea, not the
   accent send circle. Overrides the generic .composer button rule above. */
#composer-attach {
  position: static;
  background: var(--bg-elev);
  color: var(--text-dim);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  margin-right: 8px;
  margin-bottom: 9px;               /* centers the 36px button against the 54px resting input */
}
#composer-attach:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--accent);
  border-color: var(--accent);
}
#composer-attach.has-file {
  color: var(--success);
  border-color: var(--success);
}

/* ---- "Datasets used" chip row (under each assistant answer) ---- */
/* ---- Meta-row under an answer: sources (left) + actions (right) on one line ---- */
.msg-meta {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 8px;
}
.msg-meta .datasets-used {
  flex: 1 1 auto;
  min-width: 0;          /* allow the chip row to wrap instead of pushing actions off */
  margin-top: 0;
}

/* ---- Per-message actions (Export) — always visible, brightening on hover ---- */
.msg-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin-left: auto;     /* pin to the right even when there are no sources */
}
.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.msg-action:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}
.msg-action:disabled { opacity: 0.6; cursor: default; }
.msg-action .ma-icon { font-size: 12px; line-height: 1; }

.datasets-used {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11.5px;
}
.datasets-used .du-label {
  color: var(--text-dim);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 2px;
}
.datasets-used .du-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.datasets-used .du-chip:hover {
  border-color: var(--accent);
  background: #d2dfeb;
}
.datasets-used .du-chip.derived {
  background: #ece5f4;
  color: #7c5fa8;
}
.datasets-used .du-chip.derived:hover {
  border-color: #7c5fa8;
  background: #e2d7f0;
}
.datasets-used .du-chip.derived .du-src {
  background: #7c5fa8;
}
.datasets-used .du-name {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.datasets-used .du-src {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}
/* Footnote number on a chip that an inline [n] citation points at. */
.datasets-used .du-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  margin-right: 2px;
  padding: 0 3px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.datasets-used .du-chip.derived .du-num { background: #7c5fa8; }
.datasets-used .du-chip.cited { border-color: var(--accent); }

/* ---- Inline citations: [n] superscripts grounding figures to their table ---- */
.bubble .cite {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.72em;
  vertical-align: super;
  line-height: 0;
  margin-left: 1px;
  padding: 0 1px;
  border-radius: 3px;
  transition: background 0.12s, color 0.12s;
}
.bubble .cite:hover {
  background: var(--accent-soft);
}
/* Cited a table not loaded this session — shown, but never linked. */
.bubble .cite--unverified {
  cursor: help;
  color: var(--text-dim);
  font-weight: 600;
}
.bubble .cite--unverified:hover { background: transparent; }

/* ---- Ask-user clarifying-question panel ---- */
.ask-panel {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  overflow: hidden;
  max-width: 720px;
}
.ask-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 6px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev-2);
  flex-wrap: wrap;
}
.ask-tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
}
.ask-tab:hover { color: var(--text-soft); }
.ask-tab.active {
  background: var(--bg-elev);
  color: var(--accent);
  border-color: var(--border);
}
.ask-pane { padding: 14px 16px; }
.ask-question {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}
.ask-options { display: flex; flex-direction: column; gap: 8px; }
.ask-option {
  text-align: left;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.1s, background 0.1s;
}
.ask-option:hover:not(:disabled) { border-color: var(--accent); background: var(--bg-hover); }
.ask-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.ask-option:disabled { cursor: default; opacity: 0.85; }
.ask-opt-label { font-size: 13.5px; font-weight: 600; color: var(--text); }
.ask-opt-desc { font-size: 12px; color: var(--text-dim); }
.ask-option.selected .ask-opt-label::after {
  content: " ✓";
  color: var(--accent);
}
.ask-footer {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev-2);
}
.ask-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ask-send:hover:not(:disabled) { background: #2f567a; }
.ask-send:disabled { background: var(--bg-hover); color: var(--text-dim); cursor: not-allowed; }
.ask-panel.answered { opacity: 0.7; }

/* Upload status pill shown above the composer while/after a CSV is attached. */
.upload-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 2px 8px;                /* left-aligned with the input, not the old centered column */
  font-size: 12.5px;
  color: var(--text-soft);
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.upload-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.upload-pill.uploading .dot { animation: pulse 1s ease-in-out infinite; }
.upload-pill.ok .dot { background: var(--success); }
.upload-pill.err { color: var(--danger); }
.upload-pill.err .dot { background: var(--danger); }

/* ---- Partial-response notice (response interrupted, work persisted) ---- */
.partial-note {
  margin-top: 6px;
  padding: 8px 12px;
  border: 1px solid var(--warning);
  border-radius: 8px;
  background: #fbf4e4;
  color: var(--warning);
  font-size: 13px;
  line-height: 1.4;
  max-width: 720px;
}

/* ---- Data panel toggle button (in chat header) ---- */
.data-panel-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px;
  cursor: pointer;
  margin-right: 10px;
  transition: background 0.15s, color 0.15s;
}
.data-panel-toggle:hover { background: var(--bg-hover); color: var(--accent); }
.data-panel-toggle.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---- Data panel (right column) ---- */
.data-panel {
  width: 290px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease, border 0.2s ease;
}
.data-panel.collapsed {
  width: 0;
  border-left: none;
}
.dp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dp-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.dp-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.dp-close:hover { color: var(--text); }
.dp-empty {
  padding: 16px 14px;
  font-size: 12.5px;
  color: var(--text-dim);
  font-style: italic;
}
.dp-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  overflow-y: auto;
  flex: 1;
}
.dp-item {
  display: flex;
  flex-direction: column;
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  gap: 3px;
}
.dp-item:hover { background: var(--bg-hover); }
.dp-item-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dp-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}
.dp-item-meta .du-src {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
}
.dp-item-meta .du-src.derived {
  background: #7c5fa8;
}
.dp-badge {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 10px;
  color: var(--text-soft);
}
.dp-badge.sampled { color: var(--warning); border-color: var(--warning); background: #fbf4e4; }
.dp-badge.derived { color: var(--accent); border-color: var(--accent-soft); }

/* ---- Data viewer modal ---- */
.dv-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dv-overlay.hidden { display: none; }
.dv-modal {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  width: 92vw;
  max-width: 1400px;
  height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dv-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elev);
}
.dv-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.dv-meta {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.dv-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.dv-download {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.dv-download:hover { opacity: 0.85; }
.dv-close-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 3px 8px;
}
.dv-close-btn:hover { color: var(--text); background: var(--bg-hover); }
.dv-table-wrap {
  flex: 1;
  overflow: auto;
}
.dv-table {
  border-collapse: collapse;
  font-size: 12.5px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  width: 100%;
  min-width: max-content;
}
.dv-table th {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 5px 10px;
  font-weight: 600;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}
.dv-table th .col-dtype {
  display: block;
  font-weight: 400;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 1px;
}
.dv-table td {
  border: 1px solid var(--border);
  padding: 4px 10px;
  vertical-align: top;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dv-table tbody tr:nth-child(even) td { background: rgba(0, 0, 0, 0.025); }
.dv-table tbody tr:hover td { background: rgba(58, 104, 144, 0.08); }
.dv-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elev);
}
.dv-prev, .dv-next {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-soft);
  font-size: 13px;
  padding: 4px 12px;
  cursor: pointer;
  transition: background 0.12s;
}
.dv-prev:hover, .dv-next:hover { background: var(--bg-hover); }
.dv-prev:disabled, .dv-next:disabled { opacity: 0.35; cursor: default; }
.dv-page-info { font-size: 12.5px; color: var(--text-dim); min-width: 160px; text-align: center; }

/* ---- Early-access lead capture (vertical front doors) ---- */
.access-cta { margin: 2px 0 0; font-size: 13.5px; color: var(--text-dim); }
.access-cta-btn {
  border: none; background: none; padding: 0;
  color: var(--accent); font: inherit; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}
.access-cta a { color: var(--accent); }

.ra-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1100;
  display: flex; align-items: center; justify-content: center;
}
.ra-overlay.hidden { display: none; }
.ra-modal {
  position: relative;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  width: min(92vw, 460px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px 26px 22px;
}
.ra-modal h2 { margin: 0 0 6px; font-size: 19px; color: var(--text); }
.ra-sub { margin: 0 0 16px; font-size: 13.5px; line-height: 1.5; color: var(--text-dim); }
.ra-close {
  position: absolute; top: 10px; right: 12px;
  border: none; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--text-dim);
}
.ra-close:hover { color: var(--text); }
/* Honeypot: visually gone but present for bots that fill every field. */
.ra-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.ra-label { display: block; margin: 0 0 12px; font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.ra-label input, .ra-label textarea {
  display: block; width: 100%; margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 13.5px;
  box-sizing: border-box;
  resize: vertical;
}
.ra-label input:focus, .ra-label textarea:focus { outline: none; border-color: var(--accent); }
.ra-row { display: flex; gap: 12px; }
.ra-row .ra-label { flex: 1; min-width: 0; }
.ra-error { margin: 0 0 10px; font-size: 13px; color: var(--danger); }
.ra-submit {
  width: 100%;
  padding: 10px 14px;
  border: none; border-radius: 8px;
  background: var(--accent); color: #fff;
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.ra-submit:hover { filter: brightness(1.06); }
.ra-submit:disabled { opacity: 0.6; cursor: default; }
.ra-book { margin: 8px 0 0; font-size: 13.5px; color: var(--text-dim); }
.ra-book a { color: var(--accent); }
