/* Research Document Workspace — app shell. Palette unchanged from Day 3 (green on soft grey). */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #dce4df;
  --border-strong: #aebeb6;
  --text: #19332e;
  --muted: #64756f;
  --accent: #196647;
  --accent-hover: #14523a;
  --accent-soft: #e1f2e8;
  --danger: #a43c2c;
  --danger-soft: #ffebe6;
  --focus: #68a68e;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-lg: 22px;
  --shadow: 0 1px 2px rgba(25, 51, 46, .04), 0 4px 16px rgba(25, 51, 46, .05);
  --shadow-lift: 0 10px 30px rgba(25, 51, 46, .12);
  --sidebar-w: 264px;
  --sources-w: 360px;
  --inspector-w: 320px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: clamp(24px, 3vw, 32px); letter-spacing: -.025em; overflow-wrap: anywhere; }
h2 { font-size: 16px; letter-spacing: -.01em; }
p { margin: 0 0 10px; }
small { display: block; color: var(--muted); font-size: 12px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small-text { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; vertical-align: -3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.shell.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.shell.sidebar-collapsed .sidebar { visibility: hidden; border-right: 0; }
.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.body { flex: 1; display: flex; min-height: 0; }
.canvas { flex: 1; min-width: 0; overflow: auto; padding: 32px clamp(20px, 4vw, 48px) 56px; }
.canvas > * { max-width: 1040px; margin-left: auto; margin-right: auto; }

/* ---------- standalone login page (no sidebar shell) ---------- */
/* ---------- account pages (login, sign-up, password): illustration left, form right ---------- */
.auth-body { min-height: 100vh; margin: 0; background: #eaf5f0; overflow-x: hidden; }
.auth-page { position: relative; min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(380px, 520px); align-items: center; gap: clamp(24px, 4vw, 64px); max-width: 1440px; margin: 0 auto; padding: clamp(24px, 4vw, 56px); isolation: isolate; }
/* soft decorative circles, like the illustration's own */
.auth-page::before, .auth-page::after { content: ""; position: absolute; z-index: -1; border-radius: 50%; }
.auth-page::before { width: 520px; height: 520px; top: -180px; right: -140px; background: #f1f9f5; }
.auth-page::after { width: 380px; height: 380px; bottom: -190px; right: -120px; background: #dfefe7; }
.auth-art { min-width: 0; }
.auth-art img { display: block; width: 100%; height: auto; max-height: 82vh; object-fit: contain; }  /* transparent areas pre-filled with the page colour: no visible edges */
.auth-card { width: 100%; padding: clamp(28px, 3.4vw, 44px); background: var(--surface); border: 1px solid #e3eee8; border-radius: 24px; box-shadow: 0 1px 2px rgba(25, 51, 46, .04), 0 18px 48px rgba(25, 81, 58, .08); }
.auth-brand { display: inline-flex; align-items: center; gap: 12px; color: #17402f; text-decoration: none; font-size: 17px; letter-spacing: -.01em; }
.auth-brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(25, 102, 71, .25); }
.auth-card h1 { margin: 28px 0 22px; font-size: clamp(28px, 3vw, 36px); line-height: 1.15; letter-spacing: -.02em; color: #17402f; }
.auth-card .notice { margin: 0 0 18px; }
.auth-lead { margin: -8px 0 18px; color: var(--muted); }
.auth-card .small-text { margin: 14px 0 0; line-height: 1.5; }
.auth-form { display: grid; gap: 20px; }
.auth-field { display: grid; gap: 8px; }
.auth-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 14.5px; font-weight: 500; color: var(--text); }
.auth-link { font-size: 14px; font-weight: 500; color: var(--accent); text-decoration: none; }
.auth-input { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; border: 1px solid #dbe7e1; border-radius: 14px; background: #f5f9f7; color: #6f817a; transition: border-color .15s, box-shadow .15s, background .15s; }
.auth-input:focus-within { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 4px var(--accent-soft); color: var(--accent); }
.auth-input input, .auth-input input:focus { flex: 1; min-width: 0; width: auto; height: 100%; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; outline: 0; font-size: 15px; color: var(--text); }
.auth-input input::placeholder { color: #93a39c; }
.auth-reveal { display: none; place-items: center; width: 36px; height: 36px; margin-right: -8px; padding: 0; border: 0; border-radius: 10px; background: none; color: #6f817a; cursor: pointer; }
.js .auth-reveal { display: grid; }
.auth-reveal:hover { background: var(--accent-soft); color: var(--accent); }
.auth-reveal .when-shown, .auth-reveal.on .when-hidden { display: none; }
.auth-reveal.on .when-shown { display: contents; }
.auth-submit { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 56px; margin-top: 6px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; font: inherit; font-size: 16px; font-weight: 600; text-decoration: none; cursor: pointer; box-shadow: 0 8px 20px rgba(25, 102, 71, .22); transition: background .15s, transform .1s, box-shadow .15s; }
.auth-submit:hover { background: var(--accent-hover); box-shadow: 0 10px 24px rgba(25, 102, 71, .28); }
.auth-submit:active { transform: scale(.99); }
.auth-submit .icon { transition: transform .15s; }
.auth-submit:hover .icon { transform: translateX(3px); }
.notice.success { background: var(--accent-soft); color: var(--accent-hover); }
.notice.pending { background: #fff4d6; color: #7a5a00; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; }
.field-hint { display: block; margin-top: 4px; font-size: 12px; font-weight: 400; color: var(--muted); }
.auth-link:hover, .auth-switch a:hover { text-decoration: underline; }
.auth-switch { margin: 22px 0 0; text-align: center; font-size: 14px; color: var(--muted); }
.auth-switch a { color: var(--accent); font-weight: 600; text-decoration: none; }
@media (max-width: 960px) {
  .auth-page { grid-template-columns: 1fr; justify-items: center; align-content: center; }
  .auth-art { width: min(440px, 80%); order: -1; }
  .auth-page::before { display: none; }  /* would show behind the stacked illustration's edges */
  .auth-art img { max-height: 28vh; }
  .auth-card { max-width: 520px; }
}
@media (max-width: 560px) {
  .auth-page { padding: 16px; }
  .auth-art { display: none; }
  .auth-card { padding: 24px 20px; border-radius: 20px; }
}

/* ---------- sidebar ---------- */
.sidebar { display: flex; flex-direction: column; min-height: 0; overflow: hidden; background: var(--surface); border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px; text-decoration: none; color: var(--text); }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff; }
.brand-text strong { display: block; font-size: 15px; letter-spacing: .06em; line-height: 1.2; }
.brand-text small { line-height: 1.2; }
.side-section { padding: 10px 12px; border-top: 1px solid var(--border); }
.side-section.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-head { display: flex; align-items: center; justify-content: space-between; }
.side-title { margin: 0 4px 6px; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.side-head .side-title { margin-bottom: 0; }
summary.side-head { list-style: none; cursor: pointer; }
summary.side-head::-webkit-details-marker { display: none; }
summary.side-head .side-title::before { content: '▸'; display: inline-block; margin-right: 5px; font-size: 9px; transition: transform .15s; }
details[open] > summary.side-head .side-title::before { transform: rotate(90deg); }
.stores { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.stores li { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; font-size: 13px; color: var(--text); }
.stores li .icon { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex: none; }
.stores li[data-state="up"] .dot { background: #2e9d63; box-shadow: 0 0 0 3px #e1f2e8; }
.stores li[data-state="down"] .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.search { position: relative; display: block; margin: 8px 0 4px; }
.search .icon { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.search input { width: 100%; padding: 6px 10px 6px 30px; border: 1px solid var(--border); border-radius: 7px; font: inherit; font-size: 13px; background: var(--surface-2); color: var(--text); }
.project-search { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.project-search .search { margin: 0; width: min(320px, 100%); }
.tree { display: grid; gap: 1px; margin-top: 6px; overflow: auto; align-content: start; min-height: 0; }
.tree-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 13.5px; }
.tree-item .icon { color: var(--muted); }
.tree-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item:hover { background: var(--surface-2); }
.tree-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-item.active .icon { color: var(--accent); }
.side-empty { margin: 6px 8px; font-size: 13px; color: var(--muted); }
.side-link { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 13px; }
.side-link:hover { background: var(--surface-2); color: var(--text); }
button.side-link { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; }
.side-link.see-all { margin-top: 6px; padding-top: 10px; border-top: 1px dashed var(--border); font-weight: 600; }
.side-link.see-all .icon { color: var(--muted); }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex: none; }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; font-size: 13.5px; overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--muted); text-decoration: none; }

/* ---------- user menu (topbar) ---------- */
.user-menu { position: relative; margin-left: 4px; }
.user-menu-btn { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px 0 6px; border: 0; border-radius: 20px; background: transparent; color: var(--text); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.user-menu-btn:hover { background: var(--bg); }
.user-menu-btn .icon { color: var(--muted); transform: rotate(90deg); }
.user-menu-btn[aria-expanded="true"] .icon { transform: rotate(-90deg); }
.user-avatar { display: grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; }
.user-menu-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-panel { display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 220px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(25, 51, 46, .12); }
.user-menu:focus-within .user-menu-panel, .user-menu.open .user-menu-panel { display: block; }
.user-menu-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.crumbs a:hover { color: var(--text); text-decoration: underline; }
.crumbs .icon { color: var(--border-strong); }
.crumb-current { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; }
.page-actions { display: contents; }
/* While a document is loading into the main panel (app.js openInMain). */
.canvas { transition: opacity .15s; }
.canvas.loading { opacity: .55; pointer-events: none; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ---------- page pieces ---------- */
.page-head { margin-bottom: 24px; }
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head-row .actions { flex: none; }
.eyebrow { margin-bottom: 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.lead { margin: 8px 0 0; font-size: 15.5px; overflow-wrap: anywhere; }
.card { margin-bottom: 20px; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.split { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.split.even { grid-template-columns: 1fr 1fr; }
.split > .card { margin-bottom: 0; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { display: flex; align-items: center; gap: 12px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card > div { min-width: 0; flex: 1; }
.stat-card strong { display: block; overflow-wrap: anywhere; line-height: 1.3; }
.stat-icon { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.narrow { max-width: 560px !important; }
.center-card { text-align: center; margin-top: 8vh; }
.center-card h1 { margin-bottom: 14px; }
.center-card .actions { justify-content: center; margin-top: 18px; }
.warn-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; margin-bottom: 12px; border-radius: 50%; background: var(--danger-soft); color: var(--danger); }
.file-pill { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 6px 12px; border-radius: 8px; background: var(--bg); overflow-wrap: anywhere; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--danger-soft); color: #7b2c20; font-size: 14px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13.5px; }
.pager-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; width: 32px; height: 32px; padding: 0; border-radius: 999px; background: var(--surface-2); color: var(--text); text-decoration: none; font-weight: 600; }
.pager-btn:hover { background: var(--accent-soft); color: var(--accent); }
.pager-btn.disabled { color: var(--muted); opacity: .4; pointer-events: none; }
.pager-info { color: var(--muted); }
.pager.numbered { justify-content: center; gap: 6px; }
.pager-pages { display: inline-flex; align-items: center; gap: 4px; }
.pager-num { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; padding: 0 6px; border-radius: 999px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 13.5px; }
.pager-num:hover { background: var(--surface-2); }
.pager-num.current { background: var(--accent); color: #fff; }
.pager-ellipsis { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; color: var(--muted); }

/* ---------- NotebookLM-style Q&A chat panel ---------- */
.chat-thread { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.chat-bubble { display: flex; gap: 10px; align-items: flex-start; }
.chat-bubble.chat-user { flex-direction: row-reverse; }
.chat-avatar { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); color: var(--muted); }
.chat-avatar.ai { background: var(--accent-soft); color: var(--accent); }
.chat-bubble-body { max-width: 80%; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); overflow-wrap: anywhere; }
.chat-user .chat-bubble-body { background: var(--accent-soft); border-top-right-radius: 4px; }
.chat-ai .chat-bubble-body { border: 1px solid var(--border); border-top-left-radius: 4px; }
.chat-bubble-body p { margin: 0 0 8px; }
.chat-bubble-body p:last-child { margin-bottom: 0; }
.chat-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chat-model { display: flex; align-items: center; gap: 4px; margin-top: 8px !important; }

/* rendered markdown inside an AI answer bubble */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h3, .md h4, .md h5, .md h6 { margin: 12px 0 6px; font-weight: 700; color: var(--text); line-height: 1.3; }
.md h3 { font-size: 15px; }
.md h4 { font-size: 14px; }
.md h5, .md h6 { font-size: 13px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md li { margin-bottom: 3px; }
.md li:last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.md code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: var(--mono); }
.md strong { font-weight: 700; }
.md-table-wrap { overflow-x: auto; margin: 0 0 8px; }
.md-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.md-table th { background: var(--surface-2); font-weight: 700; }
.chat-empty { padding: 28px 16px; }
.chat-form { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 16px; }
.chat-form-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.model-select { width: auto; min-width: 220px; margin-top: 0; flex: 1; }
.empty { display: grid; justify-items: center; padding: 28px 12px; text-align: center; }
.empty p { margin: 2px 0; }
.empty-icon { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 10px; border-radius: 14px; background: var(--bg); color: var(--muted); }

/* ---------- badges & chips ---------- */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 20px; background: #edf0ee; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.up, .ready { background: var(--accent-soft); color: #175b37; }
.badge.pending { background: #fff4d6; color: #7a5a00; }
.chat-unread { margin: 8px 0 0; padding: 6px 10px; border-radius: 8px; background: #fff7e0; color: #6b5310; }
.signup-setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.signup-setting h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; font-size: 15px; }
.signup-setting p { margin: 0; }
.inline-form { display: inline; margin: 0; }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.down, .failed, .deleting { background: var(--danger-soft); color: #903d2d; }
.pending { background: #fff4d6; color: #7a5a00; }
.chip { display: inline-block; margin: 0 6px 6px 0; padding: 2px 10px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 500; }
.badge.sm { padding: 1px 8px; font-size: 10.5px; }

/* ---------- admin: one card holding every nav row (section tabs, and on the
   stats page the range tabs right below) — without it each row was its own
   fit-content pill floating in whitespace, disconnected from the page. ---------- */
.admin-toolbar { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin: 18px 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.admin-tabs { display: flex; gap: 4px; padding: 4px; border-radius: var(--radius-sm); background: var(--surface-2); width: fit-content; max-width: 100%; flex-wrap: wrap; }
.admin-tabs a { display: flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.admin-tabs a:hover { color: var(--text); }
.admin-tabs a.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.key-edit-form { display: inline-flex; gap: 6px; align-items: center; }
.key-edit-form input { width: 160px; }
.settings-notice { padding: 12px 16px; }
.settings-notice p { margin: 0; display: flex; align-items: center; gap: 6px; }
.field-row { gap: 8px; }
.field-row input { flex: 1; min-width: 0; }

/* ---------- admin: AI usage chart (plain CSS bars, no JS/chart library needed) ---------- */
.usage-chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding: 8px 4px 0; overflow-x: auto; }
.usage-bar-col { display: flex; flex-direction: column; align-items: center; flex: 1 0 18px; min-width: 18px; height: 100%; }
.usage-bar-track { position: relative; width: 100%; max-width: 28px; height: 100%; display: flex; flex-direction: column-reverse; align-items: stretch; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.usage-bar { width: 100%; background: var(--accent); min-height: 0; }
.usage-bar-fail { background: var(--danger); }
.usage-bar-label { margin-top: 6px; font-size: 10px; color: var(--muted); white-space: nowrap; transform: rotate(-40deg); transform-origin: top center; }
.usage-legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 3px; }
.usage-legend-dot.fail { background: var(--danger); margin-left: 10px; }

/* ---------- forms & buttons ---------- */
.stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: block; font-size: 13.5px; font-weight: 600; }
input, textarea, select { display: block; width: 100%; margin-top: 6px; padding: 10px 13px; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 400; transition: background .15s, box-shadow .15s; }
textarea { resize: vertical; }
.role-select { width: auto; margin-top: 0; padding: 5px 8px; font-size: 13px; }
input:focus, textarea:focus, select:focus { outline: none; background: #fff; box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--focus) inset; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border: 1px solid transparent; border-radius: 999px; font: inherit; font-weight: 600; font-size: 14px; line-height: 1.3; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, box-shadow .15s, transform .1s; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 2px 10px rgba(25, 102, 71, .25); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:active { transform: scale(.98); }
.btn.secondary { background: #e6ece8; color: var(--text); }
.btn.secondary:hover { background: #d9e2dc; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #8a3123; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { padding: 6px 12px; font-size: 13px; gap: 6px; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger) !important; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- documents ---------- */
.table-wrap { overflow-x: auto; }
.doc-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
.doc-table th { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.doc-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.doc-table tbody tr:last-child td { border-bottom: 0; }
.doc-table tbody tr:hover { background: var(--surface-2); }
.file-cell { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.file-cell > div { min-width: 0; }
.file-icon { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 8px; background: var(--bg); color: var(--muted); }
.file-icon.lg { width: 52px; height: 52px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.file-name { display: block; overflow-wrap: anywhere; font-weight: 600; color: var(--text); text-decoration: none; }
a.file-name:hover { color: var(--accent); text-decoration: underline; }
.row-actions { display: inline-flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- projects ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.project-card { display: block; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text); text-decoration: none; overflow-wrap: anywhere; transition: border-color .15s, box-shadow .15s, transform .15s; }
.project-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.project-card strong { display: block; margin: 10px 0 2px; }
.project-card p { margin: 0 0 8px; color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-card small { display: flex; align-items: center; gap: 5px; }
.project-icon { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }

/* ---------- document detail ---------- */
.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.doc-title { display: flex; gap: 16px; min-width: 0; }
.doc-title p { margin: 4px 0 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tabs button { display: inline-flex; align-items: center; gap: 8px; margin-bottom: -1px; padding: 9px 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.props { margin: 0; display: grid; gap: 14px; }
.props > div { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 12px; align-items: start; }
.props dt { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; padding-top: 1px; }
.props dd { margin: 0; overflow-wrap: anywhere; }
.hash { line-height: 1.7; }
pre { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--bg); font: 12.5px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
pre.json { background: #14231f; color: #d7ece1; padding: 18px 20px; font-size: 13px; overflow: auto; max-height: 60vh; }

/* ---------- inspector ---------- */
.inspector { flex: none; width: var(--inspector-w); padding: 22px 18px; overflow: auto; background: var(--surface); border-left: 1px solid var(--border); }
.inspector .side-title { margin-left: 0; }
.store-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 18px; }
.store-list li { display: flex; gap: 12px; }
.store-list li > div { min-width: 0; flex: 1; }
.store-list small { margin-bottom: 6px; }
.mini { margin: 0; display: grid; gap: 4px; font-size: 12.5px; }
.mini dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.mini dd { margin: 0; overflow-wrap: anywhere; }
.shell.inspector-hidden .inspector { display: none; }

/* ---------- sources panel (NotebookLM-style left rail for a project's documents) ---------- */
.sources-panel { flex: none; width: var(--sources-w); display: flex; flex-direction: column; min-height: 0; padding: 18px 14px; overflow: auto; background: var(--surface); border-right: 1px solid var(--border); transition: background .15s, box-shadow .15s; }
.sources-panel.drag { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.sources-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; padding: 0 2px; }
.sources-head .side-title { margin: 0; }

/* Three labelled, equal-height controls: pick (soft), upload (primary), options (outline). */
.upload-row { display: flex; align-items: center; gap: 6px; }
.upload-btn, .upload-go, .upload-more summary { display: flex; align-items: center; justify-content: center; gap: 5px; height: 32px; padding: 0 11px; border: 1px solid transparent; border-radius: 999px; font: inherit; font-size: 12.5px; font-weight: 600; white-space: nowrap; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.upload-btn { flex: 1 1 auto; background: var(--accent-soft); color: var(--accent); }
.upload-btn:hover { background: #cfe9da; }
.upload-go { flex: 1 1 auto; background: var(--accent); color: #fff; }
.upload-go:hover { background: var(--accent-hover); }
/* Disabled only by app.js until a file is picked; without JS it stays usable. */
.upload-go:disabled { background: var(--surface-2); color: var(--muted); border-color: var(--border); cursor: not-allowed; }
.upload-more { flex: none; position: relative; }
.upload-more summary { list-style: none; background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.upload-more summary::-webkit-details-marker { display: none; }
.upload-more summary:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }
.upload-more[open] summary { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* The picked file, shown before upload: readable name, size, and a way to unpick it. */
.upload-file { display: flex; align-items: flex-start; gap: 10px; margin-top: 10px; padding: 10px 6px 10px 12px; background: var(--accent-soft); border: 1px solid #b9dcc8; border-radius: var(--radius-sm); }
.upload-file[hidden] { display: none; }
.upload-file-icon { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--surface); color: var(--accent); }
.upload-file-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.upload-file-name { font-size: 13px; font-weight: 600; line-height: 1.4; color: var(--text); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.upload-file-meta { font-size: 12px; color: var(--muted); }
.upload-file.too-big { background: var(--danger-soft); border-color: #efc2b8; }
.upload-file.too-big .upload-file-icon, .upload-file.too-big .upload-file-meta { color: var(--danger); }
.upload-file-clear { flex: none; width: 28px; height: 28px; }
.upload-progress { display: block; height: 6px; margin-top: 4px; border-radius: 999px; background: var(--surface); overflow: hidden; }
.upload-progress > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .2s; }
/* Autosaved draft of a form (app.js setupDraft). */
.draft-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px 8px 12px; border-radius: 10px; background: #fff7e0; border: 1px solid #f0dca0; color: #6b5310; font-size: 12.5px; line-height: 1.4; }
.draft-discard { flex: none; padding: 3px 10px; border: 1px solid #e2c877; border-radius: 999px; background: var(--surface); color: #6b5310; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.draft-discard:hover { background: #fff0c2; }
.upload-row.has-draft .upload-more summary { position: relative; }
.upload-row.has-draft .upload-more summary::after { content: ""; position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%; background: #d49a00; border: 2px solid var(--surface); }
.upload-hint { margin: 8px 2px 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border); font-size: 12px; line-height: 1.5; color: var(--muted); }
.upload-hint summary { cursor: pointer; }
.upload-hint summary:hover { color: var(--text); }
.upload-types { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.upload-types li { display: flex; flex-wrap: wrap; gap: 0 6px; }
.upload-types strong { color: var(--text); font-weight: 600; }
.upload-types em { margin-left: auto; font-style: normal; }

/* File-kind icon in the source list, tinted per kind. */
.source-kind { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--surface-2); color: var(--muted); }
.source-kind.kind-document { color: #3a6ea5; background: #e8f0f9; }
.source-kind.kind-presentation { color: #b35a1f; background: #fcefe4; }
.source-kind.kind-data { color: #2f7d5b; background: #e3f3ea; }
.source-kind.kind-image { color: #8a4bb0; background: #f3eafa; }
.source-kind.kind-audio { color: #a23e6f; background: #fbe9f2; }
.source-kind.kind-video { color: #b23b3b; background: #fbe8e8; }
.source-kind.kind-archive { color: #6b6250; background: #f1eee7; }

/* Image / audio / video preview on the document page. */
.media-preview { display: grid; gap: 8px; margin-bottom: 16px; }
.media-preview img, .media-preview video { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; border-radius: var(--radius-sm); background: #0f1a17; }
.media-preview.preview-image img { background: var(--surface-2); object-fit: contain; }
.media-preview audio { width: 100%; }
.media-preview p { margin: 0; text-align: center; }
.upload-more .stack.tight { position: absolute; top: 38px; right: 0; z-index: 5; width: 240px; gap: 10px; padding: 14px; background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow-lift); }
.upload-more .field { font-size: 12px; }

/* Search + kind filter above the list. */
/* Both controls: same 34px box, same border, no global input/select margins
   (the global `input, select` rule adds margin-top and padding). */
.source-filter { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.source-search, .source-kind-filter { height: 34px; border: 1px solid var(--border-strong); border-radius: 999px; background-color: var(--surface); }
.source-search { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 0 12px; color: var(--muted); }
.source-search:focus-within, .source-kind-filter:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.source-search:focus-within { color: var(--accent); }
.source-search input, .source-search input:focus { flex: 1; min-width: 0; width: auto; height: 100%; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; font-size: 13px; line-height: 1; appearance: none; -webkit-appearance: none; }
.source-kind-filter { flex: none; width: auto; max-width: 44%; margin: 0; padding: 0 30px 0 12px; font-size: 13px; line-height: 32px; cursor: pointer; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364756f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
.source-kind-filter:focus { background-color: var(--surface); }
.source-results { display: flex; flex-direction: column; flex: 1; min-height: 0; transition: opacity .15s; }
.source-results.loading { opacity: .5; }
.source-results-head { display: flex; justify-content: space-between; align-items: baseline; margin: 2px 2px 8px; font-size: 12px; color: var(--muted); }
.source-clear { color: var(--accent); font-weight: 600; text-decoration: none; }
.source-clear:hover { text-decoration: underline; }

/* Items: outlined at rest, green fill on hover or when shown in the main panel. */
.source-list { display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 0; }
.source-item { position: relative; display: flex; align-items: center; gap: 6px; padding: 0 4px 0 8px; border: 1px solid #c6e3d2; border-radius: var(--radius-sm); background: var(--surface); transition: background .12s, border-color .12s; }
.source-item:hover { background: var(--accent-soft); border-color: var(--accent); }
.source-item.active { background: var(--accent-soft); border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.source-item.active .source-name { color: var(--accent-hover); }
.source-item.failed, .source-item.deleting { border-color: #efc2b8; }
.source-item.pending { border-style: dashed; }
.source-check, .source-check-spacer { flex: none; width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.source-main { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 8px 2px; color: var(--text); text-decoration: none; overflow: hidden; }
a.source-main { cursor: pointer; }
.source-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 700; color: var(--text); }
.source-meta { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.status-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }
.status-dot.ready { background: #2e9d63; }
.status-dot.failed, .status-dot.deleting { background: var(--danger); }
.status-dot.pending { background: #d9a300; }
.source-action { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 7px; color: var(--muted); text-decoration: none; }
.source-action:hover { background: var(--danger-soft); color: var(--danger); }
.source-view:hover { background: var(--surface); color: var(--accent); }
/* Row actions stay out of the way until the row is hovered, focused or open;
   touch screens (no hover) always show them. */
@media (hover: hover) {
  .source-item .source-action { opacity: 0; transition: opacity .12s; }
  .source-item:hover .source-action, .source-item:focus-within .source-action, .source-item.active .source-action { opacity: 1; }
}
.source-list .side-empty { text-align: center; padding: 24px 8px; line-height: 1.6; }

.kind-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.kind-card { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; transition: background .12s, border-color .12s; }
.kind-card:hover, .kind-card.selected { background: var(--accent-soft); border-color: var(--accent); }
.kind-card .source-kind { width: 34px; height: 34px; border-radius: 9px; }
.kind-card strong { display: block; font-size: 13.5px; }
.kind-card small { color: var(--muted); font-size: 12px; }
.research-hint { display: grid; justify-items: center; text-align: center; gap: 4px; padding: 56px 24px; background: var(--surface-2); border: 0; }
.research-hint .empty-icon { margin-bottom: 6px; }

/* ---------- floating AI chat (FAB + slide-over) ---------- */
.ai-panel { grid-column: 1 / -1; }
.ai-fab { position: fixed; right: 24px; bottom: 24px; z-index: 40; display: grid; place-items: center; width: 56px; height: 56px; border: 0; border-radius: 50%; background: var(--accent); color: #fff; box-shadow: var(--shadow-lift); cursor: pointer; transition: transform .18s ease, background .15s, box-shadow .18s ease; }
.ai-fab:hover { background: var(--accent-hover); transform: translateY(-3px) scale(1.04); box-shadow: 0 14px 34px rgba(25, 51, 46, .22); }
.ai-fab:active { transform: translateY(0) scale(.96); }
.ai-fab[aria-expanded="true"] { background: var(--accent-hover); }
.ai-scrim { position: fixed; z-index: 39; inset: 0; background: rgba(17, 30, 26, .38); backdrop-filter: blur(1px); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.ai-panel-head { display: none; }
.ai-thread { padding: 18px; }
.ai-panel .chat-form { padding: 14px 16px; }

/* JS-enhanced state: chat becomes a floating action button + slide-over panel */
.shell.ai-enhanced .ai-panel {
  position: fixed; z-index: 40; top: 0; right: 0; bottom: 0; width: clamp(360px, 30vw, 440px);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); box-shadow: var(--shadow-lift); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.32, .72, 0, 1); overflow: hidden;
}
.shell.ai-enhanced .ai-panel-head { display: flex; align-items: center; justify-content: space-between; flex: none; height: 58px; padding: 0 10px 0 20px; border-bottom: 1px solid var(--border); }
.shell.ai-enhanced .ai-panel-head h2 { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.shell.ai-enhanced .ai-panel-head h2 .icon { color: var(--accent); }
.shell.ai-enhanced .ai-thread { flex: 1; min-height: 0; overflow-y: auto; background: var(--bg); }
.shell.ai-enhanced .ai-panel .chat-form { flex: none; background: var(--surface); border-top: 1px solid var(--border); }
.ai-panel-actions { display: flex; align-items: center; gap: 2px; }
.ai-panel-actions form { margin: 0; }

/* chat switcher: a <details> popover listing past threads, newest first */
.ai-chat-switcher { position: relative; }
.ai-chat-switcher summary { list-style: none; cursor: pointer; }
.ai-chat-switcher summary::-webkit-details-marker { display: none; }
.ai-chat-switcher[open] summary { background: var(--accent-soft); color: var(--accent); }
.ai-chat-dropdown { position: absolute; top: calc(100% + 6px); right: 0; z-index: 10; width: 280px; max-height: 360px; overflow-y: auto; padding: 6px; background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow-lift); }
.ai-chat-list { display: grid; gap: 1px; }
.ai-chat-item { display: flex; align-items: center; gap: 2px; border-radius: 8px; }
.ai-chat-item:hover, .ai-chat-item.active { background: var(--surface-2); }
.ai-chat-item.active { background: var(--accent-soft); }
.ai-chat-item-link { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; padding: 8px 8px; color: var(--text); text-decoration: none; }
.ai-chat-item-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 600; }
.ai-chat-item-time { font-size: 10.5px; }
.ai-chat-item-delete { flex: none; display: grid; place-items: center; width: 24px; height: 24px; margin-right: 4px; border-radius: 7px; color: var(--muted); opacity: 0; text-decoration: none; }
.ai-chat-item:hover .ai-chat-item-delete, .ai-chat-item-delete:focus-visible { opacity: 1; }
.ai-chat-item-delete:hover { background: var(--danger-soft); color: var(--danger); }

/* a source chip pulled in via the entity graph instead of a direct keyword match */
.chip.graph-linked { background: transparent; border: 1px dashed var(--accent); }

/* document's entity/relation graph: connector rows instead of flat chips, so
   the *link* between two entities actually reads as a graph edge */
.graph-section { margin-top: 16px; }
.graph-section:first-of-type { margin-top: 0; }
.graph-section .side-title { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; }
.graph-entities-chips { display: flex; flex-wrap: wrap; gap: 2px; }
.graph-relations { display: grid; gap: 8px; }
.graph-relation { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.graph-node { padding: 4px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.graph-edge { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 60px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.graph-edge::before, .graph-edge::after { content: ''; flex: 1; min-width: 12px; height: 1px; background: var(--border-strong); }

/* JS enhancement: draggable 2D node-link network drawn above the row list
   (app.js, enhanceEntityGraphs) — the list itself stays in the DOM as the
   no-JS fallback and is only hidden once the SVG actually renders. */
.graph-relations.graph-enhanced > .graph-relation { display: none; }
.graph-svg { display: block; width: 100%; height: 380px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); touch-action: none; }
.graph-link { stroke: var(--border-strong); stroke-width: 1.5; }
.graph-link-label { fill: var(--muted); font-size: 10.5px; paint-order: stroke; stroke: var(--surface-2); stroke-width: 3px; }
.graph-node-g { cursor: grab; }
.graph-node-g.dragging { cursor: grabbing; }
.graph-node-circle { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; transition: fill .15s; }
.graph-node-g:hover .graph-node-circle, .graph-node-g:focus-visible .graph-node-circle { fill: var(--accent); }
.graph-node-g:hover .graph-node-label, .graph-node-g:focus-visible .graph-node-label { fill: #fff; }
.graph-node-label { fill: var(--accent); font-size: 11px; font-weight: 700; pointer-events: none; }
.shell.ai-open .ai-panel { transform: none; }
.shell.ai-open .ai-scrim { opacity: 1; pointer-events: auto; }
.shell.ai-open .ai-fab { transform: scale(.4); opacity: 0; pointer-events: none; }

/* compact composer: rounded pill input + collapsed model picker */
.chat-options { margin-bottom: 8px; font-size: 12px; }
.chat-options summary { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; list-style: none; font-weight: 600; }
.chat-options summary::-webkit-details-marker { display: none; }
.chat-options .model-select { margin-top: 6px; }
.chat-input-row { display: flex; align-items: flex-end; gap: 6px; padding: 6px 6px 6px 16px; background: var(--surface-2); border-radius: 22px; }
.chat-input-row textarea { flex: 1; margin: 0; padding: 6px 0; border-radius: 0; background: transparent; resize: none; max-height: 120px; }
.chat-input-row textarea:focus { box-shadow: none; }
.chat-send { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--accent); color: #fff; cursor: pointer; transition: background .15s, transform .1s; }
.chat-send:hover { background: var(--accent-hover); }
.chat-send:active { transform: scale(.92); }
.chat-send:disabled { opacity: .5; cursor: default; }

/* thinking indicator */
.chat-thinking .chat-bubble-body { display: flex; align-items: center; gap: 4px; padding: 14px 16px; }
.thinking-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: thinking-bounce 1.1s infinite ease-in-out; }
.thinking-dot:nth-child(2) { animation-delay: .15s; }
.thinking-dot:nth-child(3) { animation-delay: .3s; }
@keyframes thinking-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
.chat-bubble.chat-error .chat-bubble-body { background: var(--danger-soft); color: #7b2c20; border: 0; }

/* ---------- document quick-look modal ---------- */
dialog.doc-modal { padding: 0; border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lift); width: min(520px, 92vw); max-height: min(640px, 84vh); background: var(--surface); }
dialog.doc-modal::backdrop { background: rgba(17, 30, 26, .45); backdrop-filter: blur(1px); }
dialog.doc-modal[open] { animation: doc-modal-in .18s ease; }
@keyframes doc-modal-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.doc-modal-inner { position: relative; display: flex; flex-direction: column; max-height: min(640px, 84vh); }
.doc-modal-close { position: absolute; top: 10px; right: 10px; z-index: 1; }
.doc-modal-body { padding: 24px 22px 18px; overflow-y: auto; min-height: 120px; }
.doc-modal-loading { display: flex; align-items: center; gap: 6px; padding: 40px 0; justify-content: center; color: var(--muted); }
.doc-modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: none; padding: 12px 18px; border-top: 1px solid var(--border); }
.doc-modal-body .doc-head { padding: 0; margin: 0 0 16px; border: 0; }
.doc-modal-body .doc-title { gap: 12px; }
.doc-modal-body .file-icon.lg { width: 40px; height: 40px; border-radius: 10px; }
.doc-modal-body h1 { font-size: 18px; }
.doc-modal-body .doc-title p { margin-top: 3px; }
.doc-modal-body .actions { margin-top: 10px; }
.doc-modal-body .actions .btn { padding: 6px 12px; font-size: 12.5px; }
.doc-modal-body .split.even { display: grid; grid-template-columns: 1fr; gap: 14px; }
.doc-modal-body .card { margin: 0; padding: 16px; box-shadow: none; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.doc-modal-body .props { gap: 10px; }
.doc-modal-body .props > div { grid-template-columns: 108px minmax(0, 1fr); }

/* ---------- delete confirmation modal (reuses .doc-modal chrome) ---------- */
dialog.confirm-modal { width: min(420px, 90vw); }
#confirm-modal-body .card { border: 0; box-shadow: none; padding: 0; }
#confirm-modal-body .center-card { margin-top: 0; text-align: center; }

/* ---------- entity graph modal (document or whole-project view, zoomed in) ---------- */
dialog.graph-modal { width: min(960px, 95vw); max-height: min(820px, 92vh); }
#graph-modal-body { padding: 20px; min-height: 320px; }
#graph-modal-body .graph-svg { height: min(640px, 72vh); }
#graph-modal-body .graph-relations > .graph-relation { display: none; } /* the list is redundant once the SVG fills the modal */

/* ---------- upload options modal (tags / authors / metadata) ---------- */
dialog.upload-modal { width: min(480px, 92vw); max-height: min(600px, 84vh); }
.upload-modal-head { display: flex; align-items: center; justify-content: space-between; flex: none; padding: 18px 20px 0; }
.upload-modal-head h2 { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.upload-modal .doc-modal-body { padding: 14px 20px 18px; }

/* a field's label + (i) guidance button, kept outside the kv-editor's wrap so
   it stays visible in both raw-JSON and visual (key/value) mode */
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.field-label-text { font-size: 13.5px; font-weight: 600; }
.kv-info { position: relative; }
.kv-info summary { list-style: none; cursor: pointer; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.kv-info summary::-webkit-details-marker { display: none; }
.kv-info[open] summary { background: var(--accent-soft); color: var(--accent); }
.kv-info-popover { position: absolute; top: calc(100% + 6px); right: 0; z-index: 10; width: 220px; padding: 12px 14px; background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow-lift); }
.kv-info-popover p { margin: 0 0 6px; font-size: 12.5px; line-height: 1.5; }
.kv-info-popover p:last-child { margin-bottom: 0; }

/* key/value metadata editor */
.kv-wrap { margin-top: 4px; }
.kv-group { display: grid; gap: 8px; }
.kv-row { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; background: var(--surface-2); }
.kv-row-main { display: flex; align-items: flex-start; gap: 8px; }
.kv-fields { flex: 1; min-width: 0; display: grid; gap: 6px; }
.kv-key, .kv-value { margin-top: 0; padding: 7px 10px; font-size: 13px; background: var(--surface); }
.kv-key { font-weight: 600; }
.kv-hint { margin: -2px 0 0; font-size: 11px; line-height: 1.4; }
.kv-row-actions { flex: none; display: flex; gap: 2px; padding-top: 1px; }
.kv-icon-btn { display: inline-flex; align-items: center; justify-content: center; height: 26px; padding: 0 8px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.kv-icon-btn:hover { background: var(--bg); color: var(--text); }
.kv-icon-btn.danger { width: 26px; padding: 0; font-size: 13px; }
.kv-icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.kv-row .kv-group { margin-top: 8px; padding-left: 12px; border-left: 2px solid var(--border); }
.kv-add-row-btn { justify-self: start; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; border: 1px dashed var(--border-strong); cursor: pointer; }
.kv-add-row-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.kv-error { font-size: 12px; color: var(--danger); margin: 8px 0 0; }
.kv-raw-toggle { display: block; margin-top: 10px; padding: 0; border: 0; background: none; color: var(--muted); font-size: 11.5px; text-decoration: underline; cursor: pointer; }
.kv-raw-toggle:hover { color: var(--accent); }

/* ---------- user management ---------- */
.search.inline { margin: 0; width: 220px; flex: none; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-avatar-sm { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--bg); color: var(--muted); font-size: 12.5px; font-weight: 700; }
.user-avatar-sm.admin { background: var(--accent); color: #fff; }
.role-badge.admin { background: var(--accent); color: #fff; }
.toggle-switch { position: relative; flex: none; display: inline-block; width: 38px; height: 21px; padding: 0; border: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background .15s; }
.toggle-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(25, 51, 46, .3); transition: transform .15s; }
.toggle-switch.on { background: var(--accent); }
.toggle-switch.on::after { transform: translateX(17px); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .body { flex-direction: column; overflow: auto; }
  .canvas { overflow: visible; flex: none; }
  .inspector { width: auto; border-left: 0; border-top: 1px solid var(--border); overflow: visible; }
  .sources-panel { width: auto; max-height: 46vh; border-right: 0; border-bottom: 1px solid var(--border); }
}
@media (max-width: 900px) {
  .shell, .shell.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-100%); transition: transform .2s ease; visibility: visible !important; border-right: 1px solid var(--border) !important; box-shadow: 0 0 40px rgba(25, 51, 46, .2); }
  .shell.sidebar-open .sidebar { transform: none; }
  .scrim { position: fixed; z-index: 20; inset: 0; background: rgba(25, 51, 46, .4); }
  .split, .split.even { grid-template-columns: 1fr; }
  .split > .card { margin-bottom: 0; }
}
@media (max-width: 640px) {
  .canvas { padding: 22px 16px 40px; }
  .card { padding: 18px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .props > div { grid-template-columns: 1fr; gap: 2px; }
  .actions .btn { flex: 1; }
  .doc-title { flex-direction: column; gap: 10px; }
  .ai-fab { right: 16px; bottom: 16px; }
  .shell.ai-enhanced .ai-panel { width: 100vw; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
