/* ==========================================================================
   new.css — Research Station redesigned layout
   Clean rebuild: no hacks, CSS Grid + Flexbox where appropriate.
   ========================================================================== */

/* ==========================================================================
   Reset
   ========================================================================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ==========================================================================
   Design Tokens
   ========================================================================== */
:root {
  /* Colour palette — same family as existing app */
  --bg:             #f6f3ee;
  --surface:        #fffdf9;
  --surface-muted:  #f3efe7;
  --border:         #e5ded2;
  --text:           #262626;
  --muted:          #706b63;

  /* Accent — toned down from the original vivid #4f46e5 */
  --accent:               #6366f1;
  --accent-hover:         #4f46e5;
  --accent-subtle-bg:     #eef2ff;
  --accent-subtle-border: #c7d2fe;

  --danger: #b42318;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(31, 29, 24, 0.06);
  --shadow-sm: 0 1px 4px rgba(31, 29, 24, 0.08);

  /* Layout dimensions */
  --sidebar-width:          220px;
  --sidebar-collapsed-width: 2.5rem;
  --chat-width:             22%;
  --header-height:          3.25rem;
  --footer-height:          4.25rem;
}

/* ==========================================================================
   Base
   ========================================================================== */
html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

/* ==========================================================================
   App Shell
   Three rows: header | body | footer
   Body fills the remaining viewport height.
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-rows: var(--header-height) 1fr var(--footer-height);
  height: 100vh;
  overflow: hidden;
  background: var(--surface);
}

/* ==========================================================================
   Header
   ========================================================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  background: rgba(255, 253, 249, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

.app-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.user-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-name {
  font-size: 0.875rem;
  color: var(--muted);
}

/* ==========================================================================
   Shared button styles
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}

/* Subtle/ghost — used for Logout */
.btn-ghost {
  padding: 0.3rem 0.85rem;
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.btn-ghost:hover {
  background: #ebe4d8;
  border-color: #ccc;
}

/* Send button */
.btn-send {
  padding: 0.45rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  font-size: 0.875rem;
  border-radius: 10px;
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--accent-hover);
}

/* ==========================================================================
   App Body
   Three columns: sidebar | workspace | chat
   Each column is independently scrollable.
   ========================================================================== */
.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--chat-width);
  min-height: 0; /* required: let grid rows shrink below content height */
  overflow: hidden;
}

/*
  Sidebar collapse — driven by the #sidebar-toggle checkbox inside .sidebar.
  :has() on the parent lets us react to the child's checked state without JS.
*/
.app-body:has(#sidebar-toggle:checked) {
  grid-template-columns: var(--sidebar-collapsed-width) 1fr var(--chat-width);
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

/* The toggle checkbox is hidden; its labels are the interactive controls */
.sidebar-toggle-input {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--surface-muted);
  border-right: 1px solid var(--border);
}

/* ---
   Sidebar content area — hidden when sidebar is collapsed
   --- */
.sidebar-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 0.625rem 0.625rem 1rem;
  gap: 0.375rem;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.app-body:has(#sidebar-toggle:checked) .sidebar-body {
  display: none;
}

/* ---
   Collapse / expand toggle buttons
   These are <label> elements targeting #sidebar-toggle
   --- */
.sidebar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.12s ease, background 0.12s ease;
  user-select: none;
}

.sidebar-btn:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
}

/* Collapse button (‹) — inside sidebar-body, right-aligned */
.sidebar-btn--collapse {
  align-self: flex-end;
  padding: 0.2rem 0.3rem;
  margin-bottom: 0.125rem;
}

/* Expand button (›) — outside sidebar-body, centred in the narrow strip */
.sidebar-btn--expand {
  display: none; /* hidden when sidebar is expanded */
  padding: 0.75rem 0;
  width: 100%;
}

.app-body:has(#sidebar-toggle:checked) .sidebar-btn--expand {
  display: flex;
}

/* ---
   New Workspace button
   --- */
.new-workspace-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  text-align: left;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.new-workspace-btn:hover {
  background: var(--accent-subtle-bg);
  border-color: var(--accent-subtle-border);
  color: var(--accent);
}

.new-workspace-icon {
  font-size: 0.95rem;
  line-height: 1;
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.125rem 0;
}

/* ---
   Workspace list
   --- */
.workspace-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  min-height: 0;
}

/* Row is the positioning context for the overlaid pencil */
.workspace-row {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 6px;
}

.workspace-item {
  flex: 1;
  min-width: 0; /* allow text-overflow to work inside flex */
  padding: 0.4rem 0.5rem;
  background: none;
  border: none;
  border-radius: 6px;
  text-align: left;
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s ease;
}

.workspace-row:hover .workspace-item,
.workspace-item.active {
  background: rgba(0, 0, 0, 0.04);
}

.workspace-item.active {
  background: var(--accent-subtle-bg);
  color: var(--accent);
  font-weight: 500;
}

/* Pencil rename button — overlaid on the right of the active workspace item */
.workspace-rename-btn {
  position: absolute;
  right: 0.15rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  background: linear-gradient(to right, transparent, var(--surface-muted) 35%);
  border: none;
  border-radius: 0 6px 6px 0;
  color: var(--muted);
  font-size: 0.7rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, color 0.12s ease;
}

/* Only reveal the pencil when hovering the active workspace's row */
.workspace-row:has(.workspace-item.active):hover .workspace-rename-btn {
  opacity: 1;
  pointer-events: auto;
}

.workspace-rename-btn:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.07);
}

/* Inline rename input — replaces the name button during editing */
.workspace-rename-input {
  flex: 1;
  min-width: 0;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

/* Lifecycle UI container — separate row below workspace title, right-aligned.
   Hidden by default and only shown while editing the active workspace. */
.workspace-lifecycle-ui {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 0.2rem 0.1rem 0.15rem 0.1rem;
}

.workspace-list-item.editing .workspace-lifecycle-ui {
  display: flex;
}

.workspace-list-item .workspace-lifecycle-ui[hidden] {
  display: none;
}

.workspace-archive-btn {
  border: none;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.3rem 0.6rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

.workspace-archive-btn:hover {
  background: var(--accent-hover);
}

.workspace-archive-btn.confirming {
  background: var(--danger);
  color: #fff;
}

.workspace-archive-btn.confirming:hover {
  background: var(--danger);
  opacity: 0.9;
}

.workspace-lifecycle-error {
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 500;
}

/* Home view — "No workspace selected" state */
.home-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  flex: 1;
  background: var(--surface);
  color: var(--muted);
  font-size: 1rem;
  text-align: center;
  grid-column: 2; /* Centre column of the app-body grid */
}

.home-view p {
  margin: 0;
  padding: 2rem;
}

/* Hide workspace content when home view is visible */
.app-body:has(.home-view) .workspace-main,
.app-body:has(.home-view) .chat-pane {
  display: none;
}

.app-shell:has(.home-view) .message-footer {
  display: none;
}

/* ==========================================================================
   Not Found View — 404 error page
   ========================================================================== */
.not-found-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  flex: 1;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  grid-column: 2; /* Centre column of the app-body grid */
  padding: 2rem;
}

.not-found-content {
  max-width: 600px;
}

.not-found-content h2 {
  margin-bottom: 1rem;
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 600;
}

.not-found-content p {
  margin: 0 0 1.5rem 0;
  line-height: 1.6;
}

.not-found-suggestion {
  margin-top: 2rem;
}

.not-found-suggestion a {
  text-decoration: none;
}

/* Hide workspace content when not-found view is visible */
.app-body:has(.not-found-view) .workspace-main,
.app-body:has(.not-found-view) .chat-pane {
  display: none;
}

.app-shell:has(.not-found-view) .message-footer {
  display: none;
}

/* ==========================================================================
   Workspace Main — centre column
   Tab bar at top, scrollable content panel below
   ========================================================================== */

/* Radio inputs that drive CSS-only tab switching */
.tab-input {
  display: none;
}

.workspace-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

/* ---
   Tab bar
   --- */
.tab-bar {
  display: flex;
  flex-shrink: 0;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tab-label {
  padding: 0.55rem 0.875rem;
  font-size: 0.775rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--muted);
  cursor: pointer;
  /* The border-bottom creates the active underline; margin overlaps the bar border */
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s ease, border-color 0.12s ease;
  user-select: none;
}

.tab-label:hover {
  color: var(--text);
}

/*
  Active tab — CSS :has() lets us style labels based on their radio's checked state.
  The radio inputs and labels all live inside .workspace-main so the selector works.
*/
.workspace-main:has(#tab-overview:checked)  label[for="tab-overview"],
.workspace-main:has(#tab-sources:checked)   label[for="tab-sources"],
.workspace-main:has(#tab-synthesis:checked) label[for="tab-synthesis"],
.workspace-main:has(#tab-products:checked)  label[for="tab-products"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---
   Tab panels
   Only the active panel is shown; all others are display:none.
   --- */
.tab-panels {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  position: relative;
}

.tab-panel {
  display: none;
  padding: 1.5rem;
}

.workspace-main:has(#tab-overview:checked)  #panel-overview,
.workspace-main:has(#tab-sources:checked)   #panel-sources,
.workspace-main:has(#tab-synthesis:checked) #panel-synthesis,
.workspace-main:has(#tab-products:checked)  #panel-products {
  display: block;
}

.placeholder-text {
  color: var(--muted);
  font-size: 0.875rem;
}

/* ==========================================================================
   Chat Pane — right column
   Seamless with the workspace (same background, no border).
   Independently scrollable — does not move with the workspace.
   ========================================================================== */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--surface); /* deliberately same as workspace-main */
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  min-height: 0;
  border-left: 1px solid var(--border);
}

/* ==========================================================================
   Message bubbles
   ========================================================================== */
.message {
  padding: 0.65rem 0.875rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-xs);
}

/* User messages: soft accent tint rather than full solid colour */
.message.user {
  align-self: flex-end;
  max-width: 90%;
  background: var(--accent-subtle-bg);
  color: var(--text);
  border: 1px solid var(--accent-subtle-border);
}

/* Assistant messages: muted surface */
.message.assistant {
  align-self: flex-start;
  max-width: 100%;
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
}

.message.error {
  align-self: center;
  background: #fff0f0;
  color: var(--danger);
  border: 1px solid #fcc;
}

/* Markdown elements inside messages */
.message p            { margin: 0.4em 0; }
.message p:first-child { margin-top: 0; }
.message p:last-child  { margin-bottom: 0; }
.message ul,
.message ol            { padding-left: 1.4em; margin: 0.4em 0; }
.message li            { margin: 0.2em 0; }
.message strong        { font-weight: 600; }
.message em            { font-style: italic; }
.message h1, .message h2, .message h3, .message h4 {
  margin: 0.6em 0 0.35em;
  font-weight: 600;
  line-height: 1.25;
}
.message h1 { font-size: 1.1em; }
.message h2 { font-size: 1.05em; }
.message h3 { font-size: 1em; }
.message code {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 3px;
  padding: 0.1em 0.3em;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 0.87em;
}
.message pre {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 6px;
  padding: 0.6em 0.75em;
  overflow-x: auto;
  margin: 0.5em 0;
}
.message pre code { background: none; padding: 0; }
.message blockquote {
  border-left: 3px solid var(--border);
  padding-left: 0.85em;
  margin: 0.5em 0;
  color: var(--muted);
}

/* Action / flow-update notifications */
.flow-update {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.775rem;
  color: var(--muted);
  font-style: italic;
}

.flow-update-open {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-style: normal;
  text-decoration: underline;
  cursor: pointer;
}

/* ==========================================================================
   Message Footer — pinned, centred input bar
   ========================================================================== */
.message-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1rem;
  background: rgba(255, 253, 249, 0.97);
  border-top: 1px solid var(--border);
}

.message-form {
  width: 70%;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

#message-input {
  flex: 1;
  padding: 0.6rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.45;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
  box-shadow: var(--shadow-xs);
}

#message-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#message-input::placeholder {
  color: #b0a89e;
}

/* ==========================================================================
   Problem Statement Card
   ========================================================================== */

.ps-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.ps-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem 0;
}

.ps-title-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  outline: none;
  padding: 0;
}

.ps-title-input:focus {
  color: var(--text);
}

.ps-save-status {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Tiptap editor mount */
.ps-editor-mount {
  padding: 0.5rem 1rem 0.75rem;
}

/* The ProseMirror contenteditable region */
.ps-editor {
  min-height: 5rem;
  outline: none;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
  caret-color: var(--accent);
}

.ps-editor p { margin: 0.3em 0; }
.ps-editor p:first-child { margin-top: 0; }
.ps-editor p:last-child  { margin-bottom: 0; }
.ps-editor ul, .ps-editor ol { padding-left: 1.4em; margin: 0.3em 0; }
.ps-editor li  { margin: 0.15em 0; }
.ps-editor strong { font-weight: 600; }
.ps-editor em  { font-style: italic; }
.ps-editor h1, .ps-editor h2, .ps-editor h3 {
  margin: 0.5em 0 0.25em;
  font-weight: 600;
  line-height: 1.25;
}

/* Placeholder — shown on empty unfocused editor */
.ps-editor[data-placeholder]:empty::before,
.ps-editor.is-editor-empty .is-empty::before {
  content: attr(data-placeholder);
  color: #b0a89e;
  pointer-events: none;
  float: left;
  height: 0;
}

.ps-hint {
  padding: 0 1rem 0.65rem;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0;
}

/* ==========================================================================
   Sources panel
   ========================================================================== */

.sources-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* --- Toolbar (Add sources) --- */

.sources-toolbar {
  display: flex;
  align-items: center;
}

.add-sources-dropdown {
  position: relative;
}

/* <summary> styled as a small action button */
.add-sources-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.add-sources-btn::-webkit-details-marker { display: none; }

.add-sources-btn:hover,
.add-sources-dropdown[open] .add-sources-btn {
  background: var(--accent-subtle-bg);
  border-color: var(--accent-subtle-border);
  color: var(--accent);
}

.add-sources-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  padding: 0.25rem;
  min-width: 11rem;
}

.add-sources-option {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  font-size: 0.8rem;
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s ease;
}

.add-sources-option:hover {
  background: var(--surface-muted);
}

/* --- Source list --- */

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* --- Source card --- */

.source-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: visible; /* allow delete popover to escape */
}

.source-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.875rem 1rem 0.75rem;
}

.source-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

/* Three-column body */
.source-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border-top: 1px solid var(--border);
}

.source-col {
  padding: 0.75rem 1rem;
  min-width: 0;
  overflow: hidden;
}

.source-col + .source-col {
  border-left: 1px solid var(--border);
}

.source-col-heading {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.source-col-empty {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

/* Rendered markdown in summary column */
.source-col-markdown {
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text);
}

.source-col-markdown p            { margin: 0.3em 0; }
.source-col-markdown p:first-child { margin-top: 0; }
.source-col-markdown p:last-child  { margin-bottom: 0; }
.source-col-markdown ul,
.source-col-markdown ol            { padding-left: 1.2em; margin: 0.3em 0; }
.source-col-markdown li            { margin: 0.15em 0; }
.source-col-markdown strong        { font-weight: 600; }
.source-col-markdown h1, .source-col-markdown h2,
.source-col-markdown h3, .source-col-markdown h4 {
  font-size: 0.8rem;
  font-weight: 600;
  margin: 0.4em 0 0.2em;
}

.source-col-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text);
  padding: 0;
  margin: 0;
}

.source-col-list li {
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.35;
}

.source-col-list li:last-child { border-bottom: none; }

/* --- Delete popover --- */

.source-delete-menu {
  position: relative;
  flex-shrink: 0;
}

.source-delete-menu > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1;
  transition: color 0.12s ease, background 0.12s ease;
}

.source-delete-menu > summary::-webkit-details-marker { display: none; }

.source-delete-menu > summary:hover {
  color: var(--danger);
  background: #fff0f0;
}

.source-delete-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 0.2rem);
  z-index: 10;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
  padding: 0.2rem;
  white-space: nowrap;
}

.source-delete-confirm {
  display: block;
  width: 100%;
  padding: 0.3rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  font-size: 0.8rem;
  color: var(--danger);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s ease;
}

.source-delete-confirm:hover {
  background: #fff0f0;
}

/* ==========================================================================
   Synthesis panel
   ========================================================================== */

.synthesis-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* --- Header: tabs + toolbar --- */

.synthesis-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  flex-shrink: 0;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.synthesis-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  flex: 1;
  min-width: 0;
}

.synthesis-tab {
  display: inline-block;
  background: none;
  border: none;
  padding: 0.2rem 0;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.12s ease, border-color 0.12s ease;
  white-space: normal;
  word-break: break-word;
  max-width: 16rem;
  line-height: 1.35;
  text-align: left;
}

.synthesis-tab:hover {
  color: var(--text);
}

.synthesis-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Toolbar / New synthesis button (mirrors add-sources) --- */

.synthesis-toolbar {
  flex-shrink: 0;
}

.new-synthesis-dropdown {
  position: relative;
}

.new-synthesis-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}

.new-synthesis-btn::-webkit-details-marker { display: none; }

.new-synthesis-btn:hover,
.new-synthesis-dropdown[open] .new-synthesis-btn {
  background: var(--accent-subtle-bg);
  border-color: var(--accent-subtle-border);
  color: var(--accent);
}

.new-synthesis-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  right: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  padding: 0.5rem;
  min-width: 16rem;
  max-width: 22rem;
}

/* Source picker list inside the dropdown */

.synthesis-source-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  max-height: 14rem;
  overflow-y: auto;
  margin-bottom: 0.5rem;
}

.synthesis-picker-item {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.3rem 0.35rem;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s ease;
}

.synthesis-picker-item:hover {
  background: var(--surface-muted);
}

.synthesis-picker-item input[type="checkbox"] {
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.synthesis-picker-empty {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.25rem 0.35rem;
  margin: 0;
}

.synthesis-go-btn {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  background: var(--accent);
  border: none;
  border-radius: 5px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #fff;
  cursor: pointer;
  transition: background 0.12s ease, opacity 0.12s ease;
}

.synthesis-go-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.synthesis-go-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* --- Body area --- */

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

.synthesis-save-row {
  display: flex;
  justify-content: flex-end;
  min-height: 1.25rem;
  flex-shrink: 0;
  margin-bottom: 0.25rem;
}

.synthesis-save-status {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

/* Tiptap editor mount */
.synthesis-editor-mount {
  flex: 1;
  min-height: 0;
}

/* The ProseMirror contenteditable region */
.synthesis-editor {
  min-height: 12rem;
  outline: none;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text);
  caret-color: var(--accent);
}

.synthesis-editor p { margin: 0.35em 0; }
.synthesis-editor p:first-child { margin-top: 0; }
.synthesis-editor p:last-child  { margin-bottom: 0; }
.synthesis-editor ul, .synthesis-editor ol { padding-left: 1.4em; margin: 0.35em 0; }
.synthesis-editor li  { margin: 0.2em 0; }
.synthesis-editor strong { font-weight: 600; }
.synthesis-editor em  { font-style: italic; }
.synthesis-editor h1, .synthesis-editor h2, .synthesis-editor h3 {
  margin: 0.6em 0 0.3em;
  font-weight: 600;
  line-height: 1.25;
}
.synthesis-editor blockquote {
  border-left: 3px solid var(--border);
  margin: 0.5em 0;
  padding-left: 0.9em;
  color: var(--muted);
}

/* Empty / pending / failed states */

.synthesis-empty-state,
.synthesis-pending-state,
.synthesis-failed-state {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0;
  padding: 0.25rem 0;
}

.synthesis-pending-hint {
  font-size: 0.8rem;
  color: var(--muted);
  display: block;
  margin-top: 0.4rem;
}

.synthesis-failed-state {
  color: var(--danger);
}

/* ==========================================================================
   Products Panel
   ========================================================================== */

.products-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}



/* ==========================================================================
   Responsive — breakpoints stubbed for future mobile work
   ========================================================================== */
@media (max-width: 1024px) {
  :root {
    --chat-width: 28%;
    --sidebar-width: 200px;
  }
}

@media (max-width: 768px) {
  /*
    On mobile the three-column layout collapses.
    The chat pane is hidden by default; tabs become primary navigation.
    TODO: implement mobile layout.
  */
  .app-body {
    grid-template-columns: var(--sidebar-collapsed-width) 1fr 0;
  }

  .app-body:has(#sidebar-toggle:checked) {
    grid-template-columns: var(--sidebar-collapsed-width) 1fr 0;
  }

  .chat-pane {
    display: none;
  }

  .message-form {
    width: 90%;
  }
}

/* ==========================================================================
   Landing page
   ========================================================================== */
.landing-body {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.landing-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.landing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
  height: var(--header-height);
  background: rgba(255, 253, 249, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.landing-logo {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.landing-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.landing-user-name {
  font-size: 0.875rem;
  color: var(--muted);
}

/* Main */
.landing-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5rem 1.5rem 4rem;
  gap: 4rem;
}

/* Hero */
.landing-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 560px;
  gap: 1.5rem;
}

.landing-headline {
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
}

.landing-sub {
  font-size: 1.0625rem;
  color: var(--muted);
  line-height: 1.65;
  max-width: 480px;
}

.landing-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.5rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  margin-top: 0.5rem;
}

.landing-cta-btn:hover {
  background: #fffaf4;
  border-color: #cdc6ba;
  box-shadow: 0 2px 8px rgba(31, 29, 24, 0.1);
}

.landing-google-icon {
  flex-shrink: 0;
}

/* Features */
.landing-features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  max-width: 820px;
  width: 100%;
}

.landing-feature {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow-xs);
}

.landing-feature-icon {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
  line-height: 1;
}

.landing-feature h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.landing-feature p {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
}

/* Footer */
.landing-footer {
  padding: 1.5rem;
  text-align: center;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .landing-features {
    grid-template-columns: 1fr;
  }

  .landing-main {
    padding: 3rem 1.25rem 3rem;
    gap: 2.5rem;
  }
}
