/* DocIntel v3 — two-rail information architecture (DESIGN §11).
   Keeps the v2 visual language (fonts, radii, spacing, the gold accent) but in
   LIGHT mode, as requested. Self-contained tokens — does not link main.css. */

:root {
  /* surfaces (light) */
  --bg-primary: #f6f7f9;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eef1f5;
  --bg-elevated: #ffffff;

  --surface-glass: rgba(17, 24, 39, 0.02);
  --surface-glass-hover: rgba(17, 24, 39, 0.045);
  --surface-glass-active: rgba(17, 24, 39, 0.07);

  --border-subtle: rgba(17, 24, 39, 0.06);
  --border-default: rgba(17, 24, 39, 0.11);
  --border-strong: rgba(17, 24, 39, 0.18);

  --text-primary: #1b2330;
  --text-secondary: #45506a;
  --text-tertiary: #6b7689;
  --text-muted: #97a0b0;

  /* gold brand accent, tuned for light backgrounds */
  --accent-primary: #b27a26;
  --accent-primary-hover: #cf9035;
  --accent-primary-glow: rgba(178, 122, 38, 0.16);
  --accent-primary-subtle: rgba(178, 122, 38, 0.10);

  --accent-success: #1f9d6b;  --accent-success-glow: rgba(31, 157, 107, 0.12);
  --accent-warning: #c98a1a;  --accent-warning-glow: rgba(201, 138, 26, 0.12);
  --accent-error:   #d24a4a;  --accent-error-glow:   rgba(210, 74, 74, 0.10);
  --accent-info:    #2f74c9;  --accent-info-glow:    rgba(47, 116, 201, 0.10);

  /* PDF bbox overlay fills — translucent, colored by content type (light). */
  --box-title:     rgba(178, 122, 38, 0.22);
  --box-paragraph: rgba(47, 116, 201, 0.16);
  --box-table:     rgba(31, 157, 107, 0.20);
  --box-list:      rgba(201, 138, 26, 0.20);
  --box-default:   rgba(17, 24, 39, 0.10);

  --font-display: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px; --radius-xl: 20px; --radius-full: 9999px;
  --spacing-xs: 4px; --spacing-sm: 8px; --spacing-md: 16px; --spacing-lg: 24px; --spacing-xl: 32px;
  --shadow-sm: 0 1px 2px rgba(17,24,39,.06), 0 1px 1px rgba(17,24,39,.04);
  --shadow-md: 0 4px 14px rgba(17,24,39,.10);
  --shadow-lg: 0 16px 48px rgba(17,24,39,.16);
  --transition-fast: 120ms ease;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 14px;
}
button { font-family: inherit; cursor: pointer; }

/* ── shell ── */
.v3-app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.v3-topbar {
  height: 48px; flex: 0 0 48px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-default);
  z-index: 30;
}
.v3-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; }
.v3-brand svg { width: 20px; height: 20px; color: var(--accent-primary); }
.v3-topbar-actions { display: flex; gap: 4px; }
.v3-iconbtn {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid transparent; color: var(--text-secondary);
  padding: 6px 10px; border-radius: var(--radius-md); font-size: 13px;
}
.v3-iconbtn:hover { background: var(--surface-glass-hover); color: var(--text-primary); }
.v3-iconbtn.active { background: var(--accent-primary-subtle); color: var(--accent-primary); border-color: var(--border-default); }
.v3-iconbtn svg { width: 16px; height: 16px; }

.v3-body { flex: 1 1 auto; display: flex; min-height: 0; }

/* ── Rail 1: spaces drilldown ── */
.v3-rail1 {
  width: 230px; flex: 0 0 230px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-default);
  display: flex; flex-direction: column; transition: width var(--transition-fast, 120ms ease);
  overflow: hidden;
}
.v3-rail1.collapsed { width: 56px; flex-basis: 56px; }
.v3-rail-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; color: var(--text-tertiary); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.v3-rail1.collapsed .v3-rail-head span, .v3-rail1.collapsed .space-name { display: none; }
.v3-spaces { overflow-y: auto; flex: 1; padding: 4px; }
.space-node { display: flex; align-items: center; gap: 7px; padding: 7px 8px; border-radius: var(--radius-sm); color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.space-node:hover { background: var(--surface-glass-hover); color: var(--text-primary); }
.space-node.active { background: var(--accent-primary-subtle); color: var(--accent-primary); }
.space-node .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .6; flex: 0 0 auto; }
.v3-rail1.collapsed .space-node { justify-content: center; }
.v3-addbtn { margin: 6px; padding: 7px; border: 1px dashed var(--border-strong); background: transparent; color: var(--text-tertiary); border-radius: var(--radius-sm); font-size: 13px; }
.v3-addbtn:hover { color: var(--accent-primary); border-color: var(--accent-primary); }

/* ── Rail 2: space navigator ── */
.v3-rail2 {
  width: 270px; flex: 0 0 270px;
  background: var(--bg-tertiary);
  border-right: 1px solid var(--border-default);
  display: flex; flex-direction: column; overflow: hidden;
}
.v3-rail2-title { padding: 12px 14px 8px; font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.nav-scroll { overflow-y: auto; flex: 1; padding: 0 6px 12px; }
.nav-channel { display: flex; align-items: center; gap: 8px; margin: 4px 6px 10px; padding: 9px 10px; border-radius: var(--radius-md); background: var(--surface-glass); color: var(--text-primary); font-weight: 600; }
.nav-channel:hover { background: var(--surface-glass-hover); }
.nav-channel.active { background: var(--accent-primary-subtle); color: var(--accent-primary); }
.nav-section { margin: 8px 4px; }
.nav-section-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; color: var(--text-tertiary); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; cursor: pointer; user-select: none; }
.nav-section-head:hover { color: var(--text-secondary); }
.nav-section-head .count { background: var(--surface-glass-active); border-radius: var(--radius-full); padding: 1px 7px; font-size: 10px; }
.nav-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-secondary); cursor: pointer; font-size: 13px; }
.nav-item:hover { background: var(--surface-glass-hover); color: var(--text-primary); }
.nav-item.active { background: var(--surface-glass-active); color: var(--text-primary); }
.nav-item .badge { margin-left: auto; font-size: 10px; color: var(--text-muted); }
.nav-item .badge.busy { color: var(--accent-warning); }
.nav-item .badge.parked { color: var(--accent-info); }
.nav-newbtn { width: calc(100% - 12px); margin: 4px 6px; padding: 6px; background: transparent; border: 1px dashed var(--border-strong); color: var(--text-tertiary); border-radius: var(--radius-sm); font-size: 12px; }
.nav-newbtn:hover { color: var(--accent-primary); border-color: var(--accent-primary); }

/* ── Main surface ── */
.v3-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; background: var(--bg-primary); position: relative; }
.surface-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--border-subtle); }
.surface-head h2 { margin: 0; font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.surface-head .sub { color: var(--text-tertiary); font-size: 12px; }
.surface-body { flex: 1; overflow-y: auto; padding: 18px; }
.v3-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); gap: 10px; text-align: center; }

/* ── chat (channel + session share styles) ── */
.chat-wrap { display: flex; flex-direction: column; height: 100%; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 760px; padding: 9px 13px; border-radius: var(--radius-md); line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--accent-primary-subtle); border: 1px solid var(--border-default); }
.msg.them { align-self: flex-start; background: var(--surface-glass); border: 1px solid var(--border-subtle); }
.msg .who { font-size: 11px; color: var(--text-tertiary); margin-bottom: 3px; }
.step { align-self: flex-start; max-width: 820px; font-size: 13px; border-left: 2px solid var(--border-strong); padding: 4px 12px; color: var(--text-secondary); }
.step.thinking { color: var(--text-tertiary); font-style: italic; border-color: var(--text-muted); }
.step.tool_call { border-color: var(--accent-info); }
.step.tool_result { border-color: var(--accent-success); color: var(--text-tertiary); font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap; }
.step.final { align-self: flex-start; max-width: 820px; border-left: none; background: var(--surface-glass); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 10px 14px; color: var(--text-primary); }
.step .label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 2px; }
.consent { align-self: stretch; background: var(--accent-warning-glow); border: 1px solid var(--accent-warning); border-radius: var(--radius-md); padding: 12px 14px; }
.consent .actions { margin-top: 10px; display: flex; gap: 8px; }
.consent button { padding: 6px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-glass); color: var(--text-primary); }
.consent button.approve { background: var(--accent-success-glow); border-color: var(--accent-success); }
.consent button.reject { background: var(--accent-error-glow); border-color: var(--accent-error); }

.chat-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border-subtle); background: var(--bg-secondary); }
.chat-input textarea { flex: 1; resize: none; min-height: 40px; max-height: 160px; background: var(--bg-tertiary); border: 1px solid var(--border-default); border-radius: var(--radius-md); color: var(--text-primary); padding: 10px 12px; font-family: inherit; font-size: 14px; }
.chat-input button { padding: 0 18px; border-radius: var(--radius-md); border: none; background: var(--accent-primary); color: #fff; font-weight: 600; }
.chat-input button:disabled { opacity: .5; cursor: not-allowed; }
.status-pill { font-size: 11px; padding: 2px 9px; border-radius: var(--radius-full); border: 1px solid var(--border-default); color: var(--text-tertiary); }
.status-pill.busy { color: var(--accent-warning); border-color: var(--accent-warning); }
.status-pill.parked { color: var(--accent-info); border-color: var(--accent-info); }
.status-pill.error { color: var(--accent-error); border-color: var(--accent-error); }

/* ── artifact renderer ── */
.renderer-bar { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--border-subtle); flex-wrap: wrap; }
.renderer-pick { padding: 5px 12px; border-radius: var(--radius-full); border: 1px solid var(--border-default); background: var(--surface-glass); color: var(--text-secondary); font-size: 12px; }
.renderer-pick.active { background: var(--accent-primary-subtle); color: var(--accent-primary); border-color: var(--accent-primary); }
.renderer-host { flex: 1; overflow: auto; }
.renderer-host iframe { width: 100%; height: 100%; border: none; background: #fff; }
.renderer-md { padding: 20px 26px; max-width: 1000px; line-height: 1.6; }
.renderer-md pre { background: var(--bg-tertiary); padding: 12px; border-radius: var(--radius-sm); overflow:auto; }
.renderer-md h3 { font-family: var(--font-display); font-size: 14px; margin: 18px 0 8px; color: var(--text-secondary); }
.renderer-md code { font-family: var(--font-mono); font-size: 12px; color: var(--accent-primary); }
.renderer-md ul { padding-left: 18px; }
.v3-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.v3-tbl th { text-align: left; color: var(--text-tertiary); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 10px; border-bottom: 1px solid var(--border-default); }
.v3-tbl td { padding: 6px 10px; border-bottom: 1px solid var(--border-subtle); vertical-align: top; }

/* document dual view: PDF source (reused pdf-viewer-container) ‖ markdown */
.dual .src { padding: 0; }
.dual pdf-viewer-container { display: block; width: 100%; height: 100%; }

/* ── quick-peek slide-over ── */
.v3-peek { position: absolute; top: 0; right: 0; height: 100%; width: 460px; max-width: 92vw; background: var(--bg-secondary); border-left: 1px solid var(--border-strong); box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform 180ms ease; z-index: 40; display: flex; flex-direction: column; }
.v3-peek.open { transform: translateX(0); }
.v3-peek-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border-subtle); }
.v3-peek-body { flex: 1; overflow: auto; }
.v3-peek .close { background: transparent; border: none; color: var(--text-tertiary); font-size: 20px; }

/* ── doc dual view ── */
.dual { display: flex; height: 100%; }
.dual > div { flex: 1; overflow: auto; padding: 16px; }
.dual .src { border-right: 1px solid var(--border-subtle); background: var(--bg-secondary); }
.unparsed-note { margin: 14px; padding: 14px; border: 1px dashed var(--accent-warning); border-radius: var(--radius-md); color: var(--accent-warning); }

/* ── overlay panels (Knowledge / Interfaces / Account) ── */
.v3-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; display: none; align-items: flex-start; justify-content: center; padding: 60px 20px; }
.v3-overlay.open { display: flex; }
.v3-overlay-card { width: 720px; max-width: 100%; max-height: 80vh; overflow: auto; background: var(--bg-elevated); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: 20px 24px; }
.v3-overlay-card h2 { margin-top: 0; font-family: var(--font-display); }
.tag-row, .guide-row { display: flex; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border-subtle); align-items: baseline; }
.tag-row .name { font-family: var(--font-mono); color: var(--accent-primary); }
.tag-row .ns { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.tag-row .count { margin-left: auto; color: var(--text-tertiary); }

.muted { color: var(--text-muted); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent-primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── v3 sidebar/page interactions (added) ── */
.space-node { gap: 6px; }
.space-node .space-tag { margin-left: auto; font-size: 9px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); border: 1px solid var(--border-default); border-radius: var(--radius-full); padding: 0 6px; }
.space-node .space-tag.pub { color: var(--accent-info); border-color: var(--accent-info); }
.space-node.drop-into { outline: 2px dashed var(--accent-primary); outline-offset: -2px; background: var(--accent-primary-subtle); }
.v3-rename { font: inherit; width: 100%; border: 1px solid var(--accent-primary); border-radius: var(--radius-sm); padding: 2px 6px; background: var(--bg-secondary); color: var(--text-primary); }

/* context menu + account dropdown */
.v3-ctx, .v3-dropdown { position: fixed; z-index: 80; background: var(--bg-elevated); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 4px; min-width: 180px; }
.v3-ctx-item { display: block; width: 100%; text-align: left; background: transparent; border: none; color: var(--text-primary); padding: 7px 10px; border-radius: var(--radius-sm); font-size: 13px; }
.v3-ctx-item:hover { background: var(--surface-glass-hover); }
.v3-ctx-item.danger { color: var(--accent-error); }
.v3-ctx-sep { height: 1px; background: var(--border-subtle); margin: 4px 2px; }
.v3-dropdown .dd-email { padding: 8px 10px; color: var(--text-tertiary); font-size: 12px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 4px; }

/* navigator collapsible + labels */
.nav-section-head { user-select: none; }
.nav-section-head .chev { display: inline-block; transition: transform var(--transition-fast); margin-right: 4px; font-size: 10px; }
.nav-section-head .chev.open { transform: rotate(90deg); }
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge.parsed { color: var(--accent-success); }
.badge.unparsed { color: var(--text-muted); }

/* file-drop highlight on Rail 2 */
.v3-rail2.file-drop { outline: 2px dashed var(--accent-primary); outline-offset: -4px; background: var(--accent-primary-subtle); }

/* full pages (Knowledge / Interfaces) */
.v3-page { position: absolute; inset: 48px 0 0 0; background: var(--bg-primary); z-index: 25; overflow: auto; display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 28px; border-bottom: 1px solid var(--border-subtle); position: sticky; top: 0; background: var(--bg-primary); }
.page-head h1 { margin: 0; font-family: var(--font-display); font-size: 20px; }
.page-body { padding: 22px 28px; max-width: 1100px; }
.k-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.k-grid h3 { font-family: var(--font-display); font-size: 14px; color: var(--text-secondary); margin: 0 0 8px; }
.k-retrieve input { width: 100%; padding: 9px 12px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-secondary); color: var(--text-primary); font: inherit; }
.k-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.k-tag { font-size: 12px; padding: 3px 10px; border-radius: var(--radius-full); border: 1px solid var(--border-default); background: var(--surface-glass); color: var(--text-secondary); }
.k-tag.active { background: var(--accent-primary-subtle); color: var(--accent-primary); border-color: var(--accent-primary); }
.k-results { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.k-chunk { padding: 10px 12px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: var(--bg-secondary); font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
@media (max-width: 900px) { .k-grid { grid-template-columns: 1fr; } }

/* ── scroll + layout fixes (added) ── */
/* Custom-element surfaces must fill Main and let their inner panes scroll. */
artifact-renderer, ai-session { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.chat-wrap { min-height: 0; }
.renderer-host { min-height: 0; }
.dual { flex: 1 1 auto; min-height: 0; height: auto; }
.surface-body { min-height: 0; }

/* Knowledge: the query window is the main column; tags/guidance to the right. */
.k-grid { grid-template-columns: 1.7fr 1fr; }
.k-retrieve input { font-size: 15px; padding: 12px 14px; }
.k-results { max-height: none; }

/* ── round 2 fixes (added) ── */
/* Knowledge: retrieval is the dominant column, tags/guidance narrower. */
.page-body { max-width: 1400px; }
.k-grid { grid-template-columns: minmax(0, 2.6fr) minmax(240px, 1fr); }
/* back button to the left of the page title */
.page-head { justify-content: flex-start; gap: 12px; }
.page-back { border: 1px solid var(--border-strong); }

/* navigator search */
.nav-search { width: calc(100% - 12px); margin: 0 6px 8px; padding: 7px 10px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-secondary); color: var(--text-primary); font: inherit; font-size: 13px; }

/* rail collapse buttons + collapsed Rail 2 */
.rail-collapse, .rail-expand { background: transparent; border: none; color: var(--text-tertiary); font-size: 14px; padding: 2px 6px; border-radius: var(--radius-sm); }
.rail-collapse:hover, .rail-expand:hover { background: var(--surface-glass-hover); color: var(--text-primary); }
.v3-rail-head { align-items: center; }
.v3-rail1.collapsed .space-tag { display: none; }
.v3-rail2-title { display: flex; align-items: center; justify-content: space-between; }
.rail-expand { display: none; }
.v3-rail2.collapsed { width: 38px; flex-basis: 38px; }
.v3-rail2.collapsed #rail2title, .v3-rail2.collapsed .nav-scroll, .v3-rail2.collapsed .rail-collapse { display: none; }
.v3-rail2.collapsed .v3-rail2-title { justify-content: center; padding: 10px 0; }
.v3-rail2.collapsed .rail-expand { display: block; margin: 8px auto; }

/* session error banner + working indicator */
.session-error { margin: 6px 18px; padding: 8px 12px; border: 1px solid var(--accent-error); background: var(--accent-error-glow); color: var(--accent-error); border-radius: var(--radius-md); font-size: 13px; }
.working { color: var(--text-tertiary); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }

/* ── animations / smoother UX (added) ── */
@keyframes v3pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes v3fade { from { opacity: 0; } to { opacity: 1; } }

/* collapsible nav sections animate via max-height (toggled in place) */
.nav-section-body { overflow: hidden; max-height: 5000px; opacity: 1;
  transition: max-height .22s ease, opacity .16s ease, margin .22s ease; }
.nav-section-body.collapsed { max-height: 0; opacity: 0; margin: 0; }
.nav-section-head .chev { transition: transform .18s ease; }

/* rails resize smoothly */
.v3-rail1, .v3-rail2 { transition: width .2s ease, flex-basis .2s ease; }

/* floating menus + pages animate in */
.v3-ctx, .v3-dropdown { animation: v3pop .12s ease; transform-origin: top; }
.v3-page { animation: v3fade .16s ease; }
.v3-overlay.open { animation: v3fade .14s ease; }
.v3-overlay-card { animation: v3pop .16s ease; }

/* interactive elements ease their hover/active states */
.space-node, .nav-item, .nav-channel, .v3-iconbtn, .renderer-pick, .k-tag,
.v3-ctx-item, .status-pill, .badge { transition: background .14s ease, color .14s ease, border-color .14s ease, transform .12s ease; }
.space-node.drop-into { transition: background .1s ease, outline-color .1s ease; }
.nav-item:active, .space-node:active { transform: translateX(1px); }

/* renderer picker + chat messages fade in */
.msg, .step, .k-chunk { animation: v3fade .18s ease; }
