/* =========================================================================
   Tokens
   ========================================================================= */
:root {
  --source-drawer-width: clamp(360px, 30vw, 520px);
  --chat-column-width: minmax(390px, 1fr);
  --bg:            oklch(99.1% 0.003 78);
  --surface:       oklch(98.6% 0.004 78);
  --surface-2:     oklch(97.1% 0.005 78);
  --text:          oklch(22% 0.01 72);
  --text-2:        oklch(43% 0.011 72);
  --text-3:        oklch(66% 0.009 72);
  --border:        oklch(91.5% 0.006 78);
  --border-strong: oklch(85.5% 0.008 78);

  --pink:          oklch(65% 0.22 10);
  --success:       oklch(56% 0.14 155);
  --warning:       oklch(63% 0.14 65);
  --error:         oklch(56% 0.18 28);

  --font-serif:    'DM Serif Display', Georgia, serif;
  --font-sans:     'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:     'Roboto Mono', ui-monospace, Menlo, monospace;
  --font-display:  'Unbounded', sans-serif;

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-2xl: 24px;
  --r-full: 9999px;
}

/* =========================================================================
   Reset / base
   ========================================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
::selection { background: rgba(255, 40, 103, 0.25); }

html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.625;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.app {
  overflow: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
}

a { color: var(--text); text-decoration: none; }
a:hover { opacity: 0.7; }

button { font: inherit; }
input, textarea { font: inherit; color: inherit; }
button, input, textarea, a { min-width: 0; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid color-mix(in oklch, var(--text), var(--border) 55%);
  outline-offset: 2px;
}
.chat-form textarea:focus-visible {
  outline: none;
}

/* =========================================================================
   Frame layout (records main · chat sidebar)
   ========================================================================= */
.frame {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) var(--chat-column-width);
  height: 100vh;
  min-width: 0;
  overflow: hidden;
}

.mobile-mode { display: none; }

.chat-pane {
  position: relative;
  grid-column: 2;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.content-pane {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

.page {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 64px;
  scroll-behavior: smooth;
}

/* =========================================================================
   Header
   ========================================================================= */
.app-header {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 24px;
  height: 24px;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-size: 0.875rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-name {
  font-weight: 600;
  font-size: 0.875rem;
}

.brand-sub {
  font-size: 0.688rem;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--text-3);
}

.header-meta .sep { color: var(--border-strong); }

.signout {
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  min-height: 36px;
  padding: 5px 10px;
  border-radius: var(--r-md);
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 200ms;
}
.signout:hover { background: var(--surface-2); }

/* =========================================================================
   Nav
   ========================================================================= */
.app-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  background: var(--bg);
}

.nav-link {
  padding: 6px 10px;
  font-size: 0.813rem;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
  transition: background 200ms, color 200ms;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  opacity: 1;
}

.nav-link.active {
  background: var(--text);
  color: var(--bg);
}

/* =========================================================================
   Page elements
   ========================================================================= */
.page-head { margin-bottom: 20px; }

.page-title {
  font-family: var(--font-serif);
  font-size: 1.625rem;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

.page-sub {
  color: var(--text-3);
  font-size: 0.813rem;
}

.section { margin-bottom: 28px; }

.section-title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-title .label {
  font-family: var(--font-sans);
  font-size: 0.688rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 500;
}

/* =========================================================================
   Cards
   ========================================================================= */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  transition: transform 200ms ease;
}

.card.tight { padding: 12px; }

.card-title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  margin-bottom: 4px;
}

.card-sub {
  font-size: 0.75rem;
  color: var(--text-3);
}

/* =========================================================================
   Pills / dots / metrics
   ========================================================================= */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 0.688rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill.success { color: var(--success); border-color: color-mix(in oklch, var(--success), var(--border) 72%); background: color-mix(in oklch, var(--success), var(--bg) 94%); }
.pill.warning { color: var(--warning); border-color: color-mix(in oklch, var(--warning), var(--border) 72%); background: color-mix(in oklch, var(--warning), var(--bg) 94%); }
.pill.planned { color: var(--text-2); border-color: var(--border-strong); background: var(--surface-2); }
.pill.info    { color: var(--text-2); border-color: var(--border); background: transparent; }
.pill.error   { color: var(--error); border-color: color-mix(in oklch, var(--error), var(--border) 72%); background: color-mix(in oklch, var(--error), var(--bg) 95%); }
.pill.outline { background: transparent; }

.dot {
  width: 7px; height: 7px;
  border-radius: var(--r-full);
  display: inline-block;
  background: var(--text-3);
  flex-shrink: 0;
}
.dot.success { background: var(--success); }
.dot.warning { background: var(--warning); }
.dot.error   { background: var(--error); }
.dot.live    { background: var(--success); box-shadow: 0 0 0 0 rgba(5,150,105,0.6); animation: live 2s infinite; }
@keyframes live { 0%{box-shadow:0 0 0 0 rgba(5,150,105,0.45);} 70%{box-shadow:0 0 0 6px rgba(5,150,105,0);} 100%{box-shadow:0 0 0 0 rgba(5,150,105,0);} }

.metric { display: flex; flex-direction: column; gap: 2px; }
.metric-label {
  font-size: 0.688rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.metric-value {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  line-height: 1.1;
}
.metric-value.lg { font-size: 2rem; }
.metric-value.sm { font-size: 1.125rem; }
.metric-foot { font-size: 0.75rem; color: var(--text-2); }
.metric-foot .delta-up   { color: var(--success); }
.metric-foot .delta-down { color: var(--error); }

/* =========================================================================
   Lists
   ========================================================================= */
.list { display: flex; flex-direction: column; gap: 6px; }

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 0.875rem;
  background: var(--bg);
}
.context-row {
  cursor: pointer;
  transition: background 160ms, border-color 160ms;
}
.context-row:hover,
.context-row:focus-visible {
  background: var(--surface);
  border-color: var(--border-strong);
}
.context-row.is-selected {
  border-color: color-mix(in oklch, var(--text), var(--border) 72%);
  background: var(--surface);
}

.list-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.list-item-title {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-meta {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-3);
}

.list-item-aside {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* =========================================================================
   Risk strips
   ========================================================================= */
.risk {
  align-items: flex-start;
  border-color: var(--border);
}
.risk .list-item-title { white-space: normal; }
.risk .list-item-meta {
  white-space: pre-line;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.55;
}
.risk.warning { border-color: color-mix(in oklch, var(--warning), var(--border) 70%); }
.risk.error { border-color: color-mix(in oklch, var(--error), var(--border) 62%); }
.risk.success { border-color: color-mix(in oklch, var(--success), var(--border) 62%); }
.risk.planned, .risk.info { border-color: var(--border); }

/* =========================================================================
   Bars
   ========================================================================= */
.bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: var(--r-full);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--text);
  border-radius: var(--r-full);
}
.bar-fill.success { background: var(--success); }
.bar-fill.warning { background: var(--warning); }
.bar-fill.error   { background: var(--error); }

/* =========================================================================
   Tables
   ========================================================================= */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.813rem;
}
.tbl th, .tbl td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl th {
  font-size: 0.688rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 500;
}
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: none; }

/* =========================================================================
   Grid helpers
   ========================================================================= */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.row    { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack  { display: flex; flex-direction: column; gap: 8px; }
.stack-lg { display: flex; flex-direction: column; gap: 16px; }
.spacer { flex: 1; }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--r-xl);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 200ms;
  text-align: center;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.full { width: 100%; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border-strong); }
.btn.ghost:hover { background: var(--surface-2); opacity: 1; }
.btn.sm { padding: 8px 14px; font-size: 0.813rem; border-radius: var(--r-md); }

/* =========================================================================
   Chat panel
   ========================================================================= */
.chat-header {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  letter-spacing: -0.01em;
}

.chat-subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.688rem;
  color: var(--text-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-clear {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-3);
  min-height: 36px;
  padding: 5px 10px;
  border-radius: var(--r-md);
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 200ms, color 200ms;
}
.chat-clear:hover { background: var(--surface-2); color: var(--text); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 clamp(22px, 5vw, 56px);
  gap: 24px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

.chat-empty-eyebrow {
  font-size: 0.688rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 500;
}

.chat-empty-title {
  font-family: var(--font-serif);
  font-size: 2.25rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
}

.chat-empty-title em { font-style: italic; color: var(--text-2); }

.chat-empty-sub {
  color: var(--text-2);
  font-size: 0.938rem;
  max-width: 540px;
  line-height: 1.6;
}

.context-inspector[hidden] { display: none; }
.context-inspector {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: 12px;
  display: grid;
  gap: 8px;
}
.context-inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.context-inspector-head > span {
  color: var(--text-3);
  font-size: 0.688rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.context-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.context-title {
  min-width: 0;
  color: var(--text);
  font-size: 0.938rem;
  line-height: 1.25;
}
.context-inspector p {
  color: var(--text-2);
  font-size: 0.813rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.thread-context {
  flex: 0 0 auto;
  margin: 16px 64px 0;
  max-width: 632px;
  width: calc(100% - 128px);
  align-self: center;
}
.context-clear {
  min-height: 24px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  padding: 2px 7px;
  font-size: 0.688rem;
  line-height: 1.35;
  cursor: pointer;
}
.context-clear:hover { background: var(--surface-2); }

.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.suggestion {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  transition: background 180ms, transform 180ms, border-color 180ms;
  line-height: 1.4;
}
.suggestion:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.suggestion .suggestion-eyebrow {
  display: block;
  font-size: 0.688rem;
  color: var(--text-3);
  margin-bottom: 3px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-messages {
  padding: 22px clamp(18px, 4.5vw, 52px) 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.msg.user { align-self: flex-end; align-items: flex-end; max-width: 85%; }
.msg.assistant { align-self: stretch; }

.msg-role {
  font-size: 0.688rem;
  color: var(--text-3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 500;
}

.msg-bubble {
  font-size: 0.938rem;
  line-height: 1.65;
  color: var(--text);
}

.msg.user .msg-bubble {
  background: var(--surface-2);
  padding: 10px 14px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
}

.msg.assistant .msg-bubble p { margin-bottom: 12px; }
.msg.assistant .msg-bubble p:last-child { margin-bottom: 0; }
.msg.assistant .msg-bubble h3,
.msg.assistant .msg-bubble h4 {
  margin: 18px 0 8px;
  font-family: var(--font-sans);
  font-size: 0.813rem;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}
.msg.assistant .msg-bubble h3:first-child,
.msg.assistant .msg-bubble h4:first-child { margin-top: 0; }
.msg.assistant .msg-bubble strong { color: var(--text); font-weight: 600; }
.msg.assistant .msg-bubble ul {
  list-style: none;
  margin: 8px 0;
  padding: 0;
}
.msg.assistant .msg-bubble li {
  padding: 4px 0 4px 18px;
  position: relative;
  color: var(--text-2);
}
.msg.assistant .msg-bubble li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  width: 6px;
  height: 1px;
  background: var(--text-3);
}
.msg.assistant .msg-bubble code {
  font-family: var(--font-mono);
  font-size: 0.813rem;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: var(--r-sm);
}
.msg.assistant .md-table-wrap {
  overflow-x: auto;
  margin: 12px 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.msg.assistant table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 0.813rem;
  line-height: 1.45;
}
.msg.assistant th,
.msg.assistant td {
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}
.msg.assistant th {
  font-size: 0.688rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
}
.msg.assistant tr:last-child td { border-bottom: 0; }
.msg.assistant td code { white-space: nowrap; }

.source-ref {
  position: relative;
  display: inline;
  vertical-align: baseline;
  appearance: none;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent-ink);
  font: inherit;
  line-height: inherit;
  text-align: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  cursor: pointer;
}
.source-ref:hover { color: var(--text); background: transparent; }
.source-ref:focus-visible { outline: 1px solid var(--border-strong); outline-offset: 2px; border-radius: 2px; }
.source-ref:hover::after,
.source-ref:focus-visible::after {
  content: attr(data-source-full);
  position: absolute;
  left: 0;
  bottom: calc(100% + 7px);
  z-index: 90;
  width: max-content;
  max-width: min(420px, 70vw);
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.source-drawer {
  position: absolute;
  inset: 0;
  z-index: 80;
  width: 100%;
  height: 100%;
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--surface);
}
.source-drawer[hidden] { display: none; }
.source-head {
  min-height: 52px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  padding: 14px 16px 13px;
  border-bottom: 1px solid var(--border);
}
.source-heading {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}
.source-kicker {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.source-title {
  display: block;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-serif);
  font-size: clamp(1.0625rem, 1.4vw, 1.375rem);
  font-weight: 400;
  color: var(--text);
}
.source-meta {
  display: block;
  max-width: 100%;
  margin: 5px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-3);
  font-size: 0.75rem;
}
.source-close {
  min-width: max-content;
  min-height: 36px;
  padding: 5px 10px;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: none;
  color: var(--text-3);
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 200ms, color 200ms;
}
.source-close:hover { background: var(--surface-2); color: var(--text); }
.source-body {
  overflow: auto;
  padding: 16px;
}
.source-artifacts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.source-artifact-tab {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 220px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  padding: 7px 9px;
  cursor: pointer;
}
.source-artifact-tab.active {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
.source-artifact-tab span {
  font-size: 0.75rem;
  font-weight: 600;
}
.source-artifact-tab small {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 0.625rem;
}
.source-notice {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 0.813rem;
}
.source-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 0.813rem;
}
.source-error,
.source-download {
  margin-bottom: 18px;
  color: var(--text-2);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 14px;
  border-radius: var(--r-sm);
}
.source-download-kicker {
  margin: 0 0 6px;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.source-download h3 {
  margin: 0 0 6px;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.938rem;
  font-weight: 600;
}
.source-download p { margin: 0 0 12px; font-size: 0.813rem; }
.source-download-link {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  background: var(--surface);
  font-size: 0.75rem;
}
.source-download-link:hover { opacity: 1; background: var(--bg); }
.source-download-note { display: block; color: var(--text-3); font-size: 0.813rem; }
.source-record-details {
  margin: 18px 0 16px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.source-record-details summary {
  cursor: pointer;
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 600;
}
.source-record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 10px 0 0;
  color: var(--text-3);
  font-size: 0.75rem;
  line-height: 1.5;
}
.source-record-meta span { overflow-wrap: anywhere; }
.source-record-meta strong {
  margin-right: 4px;
  color: var(--text-2);
  font-weight: 600;
}
.source-markdown {
  color: var(--text-2);
  font-size: 0.938rem;
  line-height: 1.62;
}
.source-markdown h3 {
  margin: 0 0 12px;
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 400;
  line-height: 1.12;
}
.source-markdown h4 {
  margin: 22px 0 8px;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.source-markdown p { margin: 0 0 12px; }
.source-markdown ul { margin: 0 0 14px 18px; }
.source-markdown li { margin: 4px 0; }
.source-markdown code {
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82em;
}
.source-code {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-2);
}
.source-image { max-width: 100%; height: auto; display: block; }
.source-pdf { width: 100%; height: calc(100vh - 112px); border: 1px solid var(--border); }

.msg-cite {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.688rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.stream-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--text-3);
  font-size: 0.813rem;
  font-family: var(--font-mono);
}
.stream-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: oklch(45% 0.055 74);
  animation: streamPulse 1.4s ease-in-out infinite;
}
@keyframes streamPulse {
  0%, 100% { opacity: 0.35; transform: scale(0.82); }
  45% { opacity: 0.9; transform: scale(1); }
}

.typing {
  display: inline-flex;
  gap: 5px;
  padding: 6px 0;
  align-items: center;
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
  animation: typing 1.4s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* Chat input */
.chat-input-wrap {
  padding: 12px 64px 20px;
  flex-shrink: 0;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 6px 6px 6px 4px;
  transition: border-color 150ms, background 150ms;
}
.chat-form:focus-within {
  border-color: var(--border-strong);
  background: var(--surface);
}

.chat-textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: var(--font-sans);
  font-size: 0.938rem;
  line-height: 1.55;
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  max-height: 200px;
  min-height: 24px;
}
.chat-textarea::placeholder { color: var(--text-3); }

.chat-send {
  background: var(--text);
  color: var(--bg);
  border: none;
  min-width: 44px;
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity 200ms;
  flex-shrink: 0;
}
.chat-send:hover { opacity: 0.85; }
.chat-send:disabled { opacity: 0.3; cursor: not-allowed; }
.chat-send svg { width: 16px; height: 16px; }

.chat-disclaimer {
  text-align: center;
  font-size: 0.688rem;
  color: var(--text-3);
  margin-top: 8px;
}

/* =========================================================================
   Login + disclaimer (bare pages)
   ========================================================================= */
body.bare {
  background: var(--bg);
  background-image:
    radial-gradient(circle at 15% 10%, rgba(28, 25, 23, 0.025) 0%, transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(28, 25, 23, 0.025) 0%, transparent 40%);
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.gate-inner {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gate-mark-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}
.gate-mark-row .brand-mark { width: 28px; height: 28px; font-size: 1rem; }
.gate-mark-row .gate-mark-text { display: flex; flex-direction: column; line-height: 1.1; }
.gate-mark-row .gate-mark-name { font-weight: 600; font-size: 0.875rem; }
.gate-mark-row .gate-mark-sub  { font-size: 0.688rem; color: var(--text-3); letter-spacing: 0.04em; }

.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 36px 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.gate-eyebrow {
  font-size: 0.688rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  font-weight: 500;
}

.gate-title {
  font-family: var(--font-serif);
  font-size: 1.875rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.gate-sub {
  color: var(--text-2);
  font-size: 0.875rem;
  line-height: 1.55;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 0.688rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 500;
}
.field input {
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  font-size: 0.938rem;
  outline: none;
  transition: border-color 150ms;
}
.field input:focus { border-color: var(--text); }

.gate-foot {
  font-size: 0.75rem;
  color: var(--text-3);
  text-align: center;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 14px;
  line-height: 1.6;
}

.gate-foot strong { color: var(--text-2); font-weight: 500; }

/* Disclaimer-specific */
.disclaimer-card { max-width: 640px; }
.gate-inner.wide { max-width: 640px; }

.disclaimer-body {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 22px 24px;
  max-height: 340px;
  overflow-y: auto;
  font-size: 0.875rem;
  line-height: 1.65;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.disclaimer-body h4 {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 0;
}
.disclaimer-body p { margin: 0; }
.disclaimer-body strong { color: var(--text); font-weight: 600; }

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.875rem;
  color: var(--text-2);
  cursor: pointer;
  line-height: 1.5;
  user-select: none;
}
.checkbox-row input { accent-color: var(--text); margin-top: 4px; flex-shrink: 0; }

/* =========================================================================
   404
   ========================================================================= */
.notfound {
  height: 100vh;
  display: grid;
  place-items: center;
  text-align: center;
}
.notfound h1 { font-size: 4rem; margin-bottom: 8px; }
.notfound p { color: var(--text-2); margin-bottom: 24px; }

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 1100px) {
  .frame { grid-template-columns: minmax(0, 1.3fr) minmax(360px, 1fr); }
  .chat-empty, .chat-messages, .chat-input-wrap { padding-left: 32px; padding-right: 32px; }
  .thread-context { margin-left: 32px; margin-right: 32px; width: calc(100% - 64px); }
}

@media (max-width: 840px) {
  body.app { height: 100%; overflow: hidden; }
  .frame {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100svh;
  }
  .source-drawer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  .mobile-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 8px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .mobile-mode-button {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--text-2);
    font-size: 0.813rem;
    font-weight: 600;
  }
  .mobile-mode-button.active {
    border-color: var(--border-strong);
    background: var(--text);
    color: var(--bg);
  }
  .chat-pane,
  .content-pane {
    grid-row: 2;
    grid-column: 1;
    min-height: 0;
    height: auto;
  }
  body[data-mobile-panel="review"] .chat-pane,
  body[data-mobile-panel="ask"] .content-pane { display: none; }
  .chat-pane { border-left: 0; border-right: none; border-bottom: 0; }
  .content-pane { overflow: hidden; }
  .app-header {
    min-height: 58px;
    height: auto;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
  }
  .brand-text { min-width: 0; }
  .brand-name, .brand-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-meta {
    margin-left: auto;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
  }
  .header-meta .pill { display: none; }
  .signout { min-height: 38px; padding-inline: 10px; }
  .app-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding: 8px;
    scrollbar-width: none;
  }
  .app-nav::-webkit-scrollbar { display: none; }
  .nav-link {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding-inline: 12px;
  }
  .page {
    padding: 18px 16px 40px;
    scroll-behavior: auto;
  }
  .grid-2, .grid-3, .suggestions { grid-template-columns: 1fr; }
  .section { margin-bottom: 22px; }
  .section-title { align-items: flex-start; flex-direction: column; gap: 3px; }
  .list-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
  .list-item-title { white-space: normal; }
  .list-item-aside { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .tbl {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .chat-header { padding-inline: 16px; min-height: 58px; height: auto; }
  .chat-clear { min-height: 44px; }
  .chat-body { min-height: 0; }
  .chat-empty {
    justify-content: flex-start;
    padding: 24px 16px;
    gap: 18px;
  }
  .chat-empty-title { font-size: 1.875rem; }
  .thread-context { margin: 14px 16px 0; width: calc(100% - 32px); }
  .chat-messages { padding: 18px 16px 14px; gap: 16px; }
  .msg.user { max-width: 94%; }
  .chat-input-wrap {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg);
  }
  .chat-textarea { min-height: 44px; font-size: 1rem; }
  .risk { flex-direction: column; gap: 8px; }
  .feedback button { min-height: 44px; padding-inline: 12px; }
  .gate-card { padding: 28px 24px; }
}

/* Unknown Investor Portal additions */
.feedback { display:flex; gap:8px; margin-top:8px; color:var(--text-3); font-size:.75rem; }
.feedback button { background:none; border:1px solid var(--border); color:var(--text-3); padding:5px 10px; border-radius:var(--r-md); cursor:pointer; }
.feedback button:hover { background:var(--surface-2); color:var(--text); }
.form-error { min-height:18px; color:var(--error); font-size:.75rem; }
.page-panel[hidden] { display:none; }
.source-list .list-item-title { white-space:normal; }
.msg.error .msg-bubble { color:var(--error); }
.msg.pending .msg-bubble { color:var(--text-3); }
