/* ── Reset & Base ──────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', Arial, sans-serif;
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  background: #fff; color: #333;
}

/* ── Navigation bar ───────────────────────────────────────────── */
#main-nav {
  all: initial;
  display: flex !important; align-items: center !important; gap: 0 !important;
  background: #ffffff !important; padding: 0 32px !important;
  height: 73px !important; min-height: 73px !important; max-height: 73px !important;
  box-sizing: border-box !important; margin: 0 !important;
  font-family: 'Segoe UI', Arial, sans-serif !important;
  line-height: 1 !important; flex-shrink: 0 !important;
  border-bottom: 1px solid #e0e0e0 !important;
  width: 100% !important;
}
#nav-logo {
  all: initial;
  display: flex !important; align-items: center !important;
  margin-right: auto !important; cursor: pointer !important;
}
#nav-logo img {
  height: 28px !important; width: auto !important;
}
#nav-links {
  all: initial;
  display: flex !important; align-items: center !important; gap: 4px !important;
  margin-left: auto !important;
}
#main-nav .nav-item {
  all: initial;
  font-family: 'Segoe UI', Arial, sans-serif !important;
  font-size: 13px !important; font-weight: 600 !important;
  padding: 8px 18px !important; margin: 0 !important;
  color: #888 !important; text-decoration: none !important;
  border-radius: 6px !important;
  transition: background 0.15s, color 0.15s !important;
  line-height: 1 !important; box-sizing: border-box !important;
  cursor: pointer !important;
}
#main-nav .nav-item:hover { background: #f5f5f5 !important; color: #333 !important; }
#main-nav .nav-active {
  color: #457b9d !important; font-weight: 700 !important;
  background: transparent !important;
}

/* ── Modal ────────────────────────────────────────────────────── */
#modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 9999;
  align-items: center; justify-content: center;
}
#modal-overlay.show { display: flex; }
#modal-box {
  background: #fff; border-radius: 10px;
  width: 70vw; max-width: 820px; max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
#modal-header {
  padding: 16px 22px 12px; border-bottom: 1px solid #eee;
  display: flex; align-items: center; justify-content: space-between;
}
#modal-title { font-size: 0.95rem; font-weight: 700; color: #333; }
#modal-close {
  background: none; border: none; font-size: 1.3rem;
  cursor: pointer; color: #999; padding: 0 4px;
}
#modal-close:hover { color: #333; }
#modal-body {
  padding: 18px 22px; overflow-y: auto; flex: 1;
  font-size: 0.85rem; color: #444; line-height: 1.7;
}
.modal-date {
  font-size: 0.78rem; color: #888; margin-bottom: 12px;
}

/* ── Shared side panel ────────────────────────────────────────── */
#panel {
  width: 500px; min-width: 500px;
  background: #f7f7f8;
  border-left: 2px solid #e0e0e0;
  padding: 24px 22px;
  display: flex; flex-direction: column; gap: 0;
  overflow-y: auto; min-height: 0;
}
#panel > * { margin-top: 8px; }
#panel > *:first-child { margin-top: 0; }
#p-title { font-size: 1.05rem; color: #457b9d; font-weight: 700; line-height: 1.4; flex-shrink: 0; }
.pillar-chip {
  font-size: 0.68rem; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; vertical-align: middle; margin-left: 6px;
  white-space: nowrap;
}
.pillar-curiosite  { background: #e8f0f5; color: #457b9d; }
.pillar-relations  { background: #f0e8f5; color: #8b5cf6; }
.pillar-generosite { background: #e8f5e8; color: #4a8a4a; }
.divider { border: none; border-top: 1px solid #e0e0e0; margin: 32px 0 4px; display: none; }
#panel.panel-active .divider { display: block; margin-top: 32px; }
#p-desc { font-size: 0.87rem; color: #555; line-height: 1.6; flex-shrink: 0; }
#p-counts { display: flex; gap: 10px; flex-wrap: wrap; flex-shrink: 0; margin-top: 28px; }
.p-count-chip {
  font-size: 0.78rem; font-weight: 600; padding: 3px 9px;
  border-radius: 12px; white-space: nowrap;
}
.chip-total   { background: #e8f0f5; color: #3a6f8f; }
.chip-article { background: #e8f5e8; color: #4a8a4a; }
.chip-video   { background: #f5e8e8; color: #c46040; }
#p-words { font-size: 0.82rem; color: #777; margin-top: 10px; }


/* ── Tone summary ─────────────────────────────────────────────── */
#p-tones { flex-shrink: 0; margin-top: 16px; }
.tone-heading { font-size: 0.78rem; font-weight: 600; color: #666; margin-bottom: 6px; }
.tone-bar-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.tone-bar-label { font-size: 0.76rem; color: #555; min-width: 90px; text-align: right; }
.tone-bars { display: flex; flex-direction: column; gap: 2px; }
.tone-bar-line { display: flex; align-items: center; gap: 6px; }
.tone-bar { height: 17px; border-radius: 3px; background: #a8cce0; min-width: 0; }
.tone-bar-bg { height: 12px; border-radius: 2px; background: #ddd; min-width: 0; }
.tone-val-blue { font-size: 0.72rem; font-weight: 700; color: #3a6f8f; white-space: nowrap; }
.tone-val-grey { font-size: 0.68rem; color: #bbb; white-space: nowrap; }
.tone-bar-label.has-tip {
  cursor: help; position: relative;
  text-decoration: underline dotted #bbb; text-underline-offset: 2px;
}
.tone-bar-label.has-tip:hover::after {
  content: attr(data-tip);
  position: absolute; left: 100%; top: 50%; transform: translateY(-50%);
  margin-left: 8px; white-space: nowrap;
  background: #333; color: #fff; font-size: 0.72rem; font-weight: 400;
  padding: 5px 10px; border-radius: 5px;
  z-index: 100; pointer-events: none;
}

/* ── Document list (collapsible) ──────────────────────────────── */
.doc-row {
  display: flex; align-items: baseline; gap: 8px; padding: 5px 0;
  cursor: pointer;
}
.doc-row:hover { background: #f0f4f8; }
.doc-title { flex: 1; font-size: 0.82rem; color: #333; }
.doc-source {
  font-size: 0.68rem; font-weight: 600; padding: 1px 6px;
  border-radius: 4px; white-space: nowrap;
}
.doc-source-q { background: #e8f5e8; color: #4a8a4a; }
.doc-source-v { background: #f5e8e8; color: #c46040; }
.doc-words { font-size: 0.72rem; color: #999; white-space: nowrap; }
.docs-toggle {
  cursor: pointer; user-select: none; display: flex;
  align-items: center; gap: 6px; font-weight: 600;
  font-size: 0.82rem; color: #457b9d;
}
.docs-toggle:hover { color: #3a6f8f; }
.docs-arrow {
  display: inline-block; transition: transform 0.2s; font-size: 0.7rem;
}
.docs-arrow.open { transform: rotate(90deg); }
.docs-list { display: none; margin-top: 6px; }
.docs-list.open { display: block; max-height: 294px; overflow-y: auto; }
.docs-list::-webkit-scrollbar { width: 4px; }
.docs-list::-webkit-scrollbar-track { background: transparent; }
.docs-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
.docs-list::-webkit-scrollbar-thumb:hover { background: #aaa; }
.docs-list { scrollbar-width: thin; scrollbar-color: #ccc transparent; }

/* ── Mindmap page ─────────────────────────────────────────────── */
#map-wrap { flex: 1; overflow: hidden; position: relative; }
#map-wrap svg { display: block; }
line.link { stroke-linecap: round; pointer-events: none; }
.node { cursor: pointer; }
.node:hover circle { filter: brightness(1.15); }
#p-breadcrumb {
  font-size: 0.72rem; color: #8a8a8a; line-height: 1.6; display: none;
}
.bc-link { cursor: pointer; text-decoration: underline dotted; transition: color 0.15s; }
.bc-link:hover { color: #457b9d; }
#p-conv {
  font-size: 0.87rem; color: #555; line-height: 1.6;
  font-style: italic; flex-shrink: 0;
}
#p-docs { margin-top: 10px; }

/* ── Graph pages ──────────────────────────────────────────────── */
#main-content { display: flex; flex: 1; overflow: hidden; }
#mynetwork { flex: 1; background: white; }
#p-catdesc, #p-conviction {
  font-size: 0.84rem; color: #555; line-height: 1.6;
  font-style: italic; padding: 10px 14px;
  background: #f0eff4; border-left: 3px solid #457b9d;
  border-radius: 4px; display: none;
}
#p-concepts { display: flex; flex-wrap: wrap; gap: 6px; }
.concept-tag {
  font-size: 0.72rem; padding: 3px 10px; border-radius: 10px;
  background: #eee; color: #555; white-space: nowrap;
}
#p-connections { font-size: 0.82rem; color: #555; line-height: 1.7; }
.conn-heading {
  font-weight: 600; color: #457b9d; margin-top: 6px; margin-bottom: 2px;
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em;
}
.conn-item { padding: 1px 0; }
.conn-weight {
  display: inline-block; min-width: 28px; text-align: right;
  color: #999; font-size: 0.75rem; margin-right: 6px;
}

/* ── Heatmap page ─────────────────────────────────────────────── */
#main-heatmap { display: flex; flex: 1; overflow: hidden; }
#chart-wrap { flex: 1; overflow: hidden; }
.section-title { font-size: 1rem; font-weight: 700; line-height: 1.3; padding: 2px 0; }
.section-title.conv { color: #457b9d; }
.section-title.topic { color: #4a8a4a; }
.section-count {
  font-size: 0.72rem; font-weight: 600; padding: 1px 7px;
  border-radius: 10px; margin-left: 6px; vertical-align: middle;
}
.section-count.conv { background: #e8f0f5; color: #3a6f8f; }
.section-count.topic { background: #e8f5e8; color: #4a8a4a; }
.section-desc {
  font-size: 0.85rem; color: #555; line-height: 1.55;
  font-style: italic; padding: 8px 12px; border-radius: 4px; display: none;
}
.section-desc.conv { background: #f0eff4; border-left: 3px solid #457b9d; }
.section-desc.topic { background: #eef5ee; border-left: 3px solid #4a8a4a; }
.section-cross {
  text-align: center; font-size: 1.6rem; color: #333;
  font-weight: 400; padding: 0; line-height: 1; letter-spacing: 0.1em;
}
.relevance-score {
  font-size: 0.82rem; font-weight: 700; color: #457b9d;
}
.relevance-score.relevance-grey {
  color: #999;
}
.relevance-justification {
  font-size: 0.74rem; color: #666; line-height: 1.4; margin-top: 2px;
}
#p-stats { flex-shrink: 0; margin-top: 28px; }
.stats-pct {
  font-size: 0.74rem; color: #3a6f8f; font-weight: 600;
  line-height: 1.3; margin-bottom: 2px; white-space: nowrap;
}
.stats-chips { display: flex; gap: 10px; flex-wrap: wrap; }
.chip-docs { background: #f0eff4; color: #6b5b95; }
.docs-heading {
  font-weight: 600; color: #457b9d; margin-top: 6px; margin-bottom: 8px;
  font-size: 0.78rem; letter-spacing: 0.03em;
}
#p-context { font-size: 0.82rem; color: #555; line-height: 1.7; margin-top: 16px; }
.ctx-heading {
  font-weight: 600; color: #457b9d; margin-top: 8px; margin-bottom: 4px;
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em;
}
.ctx-bar-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.ctx-bar-label {
  font-size: 0.75rem; color: #555; min-width: 200px; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ctx-bar { height: 10px; border-radius: 3px; background: #a8cce0; min-width: 2px; }
.ctx-bar-val { font-size: 0.72rem; color: #999; min-width: 32px; }

/* ── Search page ─────────────────────────────────────────────── */
#search-page {
  display: flex; flex: 1; overflow: hidden;
}

/* Sidebar: search box + facets */
#search-sidebar {
  width: 420px; min-width: 420px;
  background: #f7f7f8;
  border-right: 2px solid #e0e0e0;
  padding: 20px 18px;
  display: flex; flex-direction: column; gap: 16px;
  overflow-y: auto;
}

#search-box {
  display: flex; gap: 8px;
}
#search-input {
  flex: 1; padding: 9px 14px;
  border: 1.5px solid #ccc; border-radius: 6px;
  font-size: 0.88rem; font-family: inherit;
  outline: none; transition: border-color 0.15s;
}
#search-input:focus { border-color: #457b9d; }
#search-btn {
  padding: 9px 16px;
  background: #457b9d; color: #fff; border: none; border-radius: 6px;
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
#search-btn:hover { background: #3a6a89; }

/* Stats */
#search-stats {
  display: flex; gap: 12px; align-items: baseline;
  font-size: 0.8rem; color: #666;
}
.stats-count { font-weight: 700; color: #457b9d; }
.stats-words { color: #999; }
.stats-empty { color: #999; font-style: italic; }

/* Facets */
#facets { display: flex; flex-direction: column; gap: 14px; }
.facet-group { }
.facet-title {
  font-size: 0.74rem; font-weight: 700; color: #888;
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.facet-items { display: flex; flex-direction: column; gap: 2px; }
.facet-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 10px; border-radius: 5px;
  cursor: pointer; transition: background 0.12s;
  font-size: 0.8rem; color: #555;
}
.facet-item:hover { background: #eee; }
.facet-active {
  background: #e0edf5 !important; color: #2a5f7d; font-weight: 600;
}
.facet-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.facet-count {
  font-size: 0.72rem; font-weight: 600; color: #aaa;
  min-width: 24px; text-align: right;
}
.facet-active .facet-count { color: #457b9d; }

/* Results area */
#search-results {
  flex: 1; overflow-y: auto;
  padding: 20px 28px;
  display: flex; flex-direction: column; gap: 12px;
}
.results-empty {
  color: #999; font-size: 0.88rem; font-style: italic;
  padding-top: 40px; text-align: center;
}

.search-result {
  padding: 14px 16px; border-radius: 8px;
  border: 1px solid #e8e8e8; background: #fff;
  cursor: pointer; transition: box-shadow 0.15s, border-color 0.15s;
}
.search-result:hover {
  border-color: #c0d6e4; box-shadow: 0 2px 10px rgba(69,123,157,.12);
}

.sr-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
}
.sr-date { font-size: 0.74rem; color: #999; }
.sr-words { font-size: 0.72rem; color: #bbb; margin-left: auto; }

.sr-title {
  font-size: 0.92rem; font-weight: 700; color: #333;
  line-height: 1.4; margin-bottom: 6px;
}

.sr-summary {
  font-size: 0.82rem; color: #666; line-height: 1.55;
  margin-bottom: 8px;
}

/* Highlights */
.sr-highlights { margin-bottom: 8px; }
.sr-highlight {
  display: flex; gap: 8px; align-items: baseline;
  padding: 3px 0; font-size: 0.8rem; line-height: 1.5;
}
.sr-hl-field {
  font-size: 0.68rem; font-weight: 600; color: #999;
  text-transform: uppercase; min-width: 52px; flex-shrink: 0;
}
.sr-hl-snippet { color: #555; }
.sr-hl-snippet mark {
  background: #fef3c7; color: #92400e;
  padding: 1px 2px; border-radius: 2px;
  font-weight: 600;
}

/* Tags row */
.sr-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.sr-tag {
  font-size: 0.68rem; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; white-space: nowrap;
}
.sr-tag-topic { background: #e8f5e8; color: #4a8a4a; }
.sr-tag-conv  { background: #e8f0f5; color: #3a6f8f; }

/* ── Login page ──────────────────────────────────────────────── */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: #f0f2f7;
}
.login-card {
  background: #fff; border-radius: 14px;
  padding: 48px 44px 40px; width: 440px;
  border: 1px solid #e8e8ee;
  text-align: center;
}
.login-title {
  font-size: 1.6rem; font-weight: 700; color: #1a1a2e;
  margin-bottom: 6px;
}
.login-subtitle {
  font-size: 0.88rem; color: #999;
  margin-bottom: 32px;
}
.login-error {
  background: #fef2f2; color: #b91c1c;
  font-size: 0.82rem; padding: 8px 14px;
  border-radius: 6px; margin-bottom: 16px;
}
.login-form {
  display: flex; flex-direction: column; gap: 16px;
  text-align: left;
}
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-label {
  font-size: 0.82rem; font-weight: 600; color: #333;
}
.login-input {
  padding: 12px 16px;
  background: #f0f0f8; border: none; border-radius: 8px;
  font-size: 0.9rem; font-family: inherit; outline: none;
  letter-spacing: 0.08em;
  transition: box-shadow 0.15s;
}
.login-input:focus { box-shadow: 0 0 0 2px rgba(99,102,241,.3); }
.login-btn {
  padding: 12px 20px; background: #6366f1; color: #fff;
  border: none; border-radius: 8px; font-size: 0.9rem;
  font-weight: 600; cursor: pointer; transition: background 0.15s;
}
.login-btn:hover { background: #5558e6; }
.login-request {
  display: inline-block; margin-top: 24px;
  font-size: 0.8rem; color: #999;
  text-decoration: underline dotted; text-underline-offset: 3px;
  transition: color 0.15s;
}
.login-request:hover { color: #6366f1; }

/* ── Admin page ──────────────────────────────────────────────── */
.admin-page { padding: 32px 48px; max-width: 800px; margin: 0 auto; }
.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.admin-header h1 { font-size: 1.2rem; color: #333; }
.admin-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.84rem;
}
.admin-table th {
  text-align: left; padding: 10px 12px;
  font-size: 0.72rem; font-weight: 700; color: #888;
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 2px solid #e0e0e0;
}
.admin-table td {
  padding: 10px 12px; border-bottom: 1px solid #f0f0f0;
  color: #555;
}
.code-cell {
  font-family: 'Courier New', monospace;
  font-weight: 700; letter-spacing: 0.1em; color: #333;
}
.status-badge {
  font-size: 0.72rem; font-weight: 600;
  padding: 2px 10px; border-radius: 10px;
}
.status-pending { background: #fef3c7; color: #92400e; }
.status-used    { background: #e8f5e8; color: #4a8a4a; }
.btn-delete {
  background: none; border: 1px solid #e0e0e0;
  color: #999; font-size: 0.76rem; padding: 4px 12px;
  border-radius: 5px; cursor: pointer; transition: all 0.15s;
}
.btn-delete:hover { border-color: #e74c3c; color: #e74c3c; }
.admin-logout {
  display: inline-block; margin-top: 28px;
  font-size: 0.8rem; color: #999;
  text-decoration: underline dotted; text-underline-offset: 3px;
}
.admin-logout:hover { color: #e74c3c; }

/* ── Chat page ──────────────────────────────────────────────────── */
#chat-page {
  display: flex; flex-direction: column;
  flex: 1; overflow: hidden;
}
#chat-main {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
}
#chat-messages {
  flex: 1; overflow-y: auto;
  padding: 24px 20px;
  display: flex; flex-direction: column; gap: 16px;
}
#chat-messages > * {
  width: 100%; max-width: 780px;
  margin-left: auto; margin-right: auto;
}
#chat-input-area {
  max-width: 780px; margin: 0 auto; width: 100%;
}
.chat-welcome {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; text-align: center; padding: 40px 20px;
}
.welcome-title {
  font-size: 1.3rem; font-weight: 700; color: #333; margin-bottom: 8px;
}
.welcome-subtitle {
  font-size: 0.88rem; color: #888; max-width: 480px; line-height: 1.55;
  margin-bottom: 24px;
}
.welcome-suggestions {
  display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 420px;
}
.suggestion-btn {
  background: #f7f7f8; border: 1px solid #e0e0e0; border-radius: 8px;
  padding: 10px 16px; font-size: 0.84rem; color: #555;
  cursor: pointer; text-align: left; transition: all 0.15s;
  font-family: inherit;
}
.suggestion-btn:hover {
  border-color: #457b9d; color: #457b9d; background: #f0f6fa;
}

/* Message bubbles */
.chat-msg { display: flex; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-assistant { justify-content: flex-start; }
.chat-msg-user .msg-bubble {
  background: #457b9d; color: #fff; border-radius: 12px 12px 2px 12px;
  padding: 10px 16px; max-width: 75%;
}
.chat-msg-assistant .msg-bubble {
  background: #f7f7f8; color: #333; border-radius: 12px 12px 12px 2px;
  padding: 10px 16px; max-width: 75%; border: 1px solid #e8e8e8;
}
.msg-content {
  font-size: 0.88rem; line-height: 1.6; white-space: pre-wrap;
}
/* Rendered markdown inside messages */
.msg-content h3, .msg-content h4 {
  margin: 12px 0 4px 0; font-size: 0.92rem; font-weight: 700;
}
.msg-content h3:first-child, .msg-content h4:first-child { margin-top: 0; }
.msg-content p { margin: 0 0 8px 0; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul { margin: 4px 0 8px 0; padding-left: 20px; }
.msg-content li { margin-bottom: 2px; }
.msg-content strong { font-weight: 700; }
/* Once markdown is rendered, don't preserve whitespace literally */
.msg-content:has(h3), .msg-content:has(strong), .msg-content:has(ul) {
  white-space: normal;
}

/* Typing indicator */
.typing-dots { display: flex; gap: 4px; padding: 4px 0; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #bbb; animation: typing-bounce 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Input area — layout props (max-width, margin) are above with chat-page */
#chat-input-area {
  display: flex; gap: 8px; padding: 12px 20px;
  border-top: 1px solid #e0e0e0; background: #fff;
  box-sizing: border-box;
}
#chat-input {
  flex: 1; padding: 10px 14px; border: 1.5px solid #ccc;
  border-radius: 8px; font-size: 0.88rem; font-family: inherit;
  resize: none; outline: none; transition: border-color 0.15s;
  min-height: 42px; max-height: 120px;
}
#chat-input:focus { border-color: #457b9d; }
#chat-send {
  padding: 10px 20px; background: #457b9d; color: #fff;
  border: none; border-radius: 8px; font-size: 0.84rem;
  font-weight: 600; cursor: pointer; transition: background 0.15s;
  align-self: flex-end;
}
#chat-send:hover { background: #3a6a89; }
#chat-send:disabled { background: #b0c4d0; cursor: not-allowed; }

.chat-msg-system .msg-bubble {
  background: #fef3c7; color: #92400e; border-radius: 8px;
  padding: 8px 14px; font-size: 0.82rem;
}

/* ── Synthesis button ──────────────────────────────────────────── */
#btn-synthesis {
  padding: 10px 16px; background: transparent; color: #457b9d;
  border: 1.5px solid #457b9d; border-radius: 8px; font-size: 0.84rem;
  font-weight: 600; cursor: pointer; transition: all 0.15s;
  align-self: flex-end; white-space: nowrap;
}
#btn-synthesis:hover { background: #f0f6fa; }
#btn-synthesis:disabled { color: #b0c4d0; border-color: #b0c4d0; cursor: not-allowed; }

/* ── Synthesis panel ───────────────────────────────────────────── */
#synthesis-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.3); z-index: 900;
}
#synthesis-overlay.open { display: block; }

#synthesis-panel {
  position: fixed; top: 0; right: -460px; width: 440px;
  height: 100vh; background: #fff; z-index: 1000;
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  display: flex; flex-direction: column;
  transition: right 0.3s ease;
}
#synthesis-panel.open { right: 0; }

#synthesis-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid #e0e0e0;
}
#synthesis-title {
  font-weight: 700; font-size: 1rem; color: #1d3557;
}
#synthesis-header div { display: flex; gap: 8px; }

#synthesis-download {
  padding: 6px 14px; background: #457b9d; color: #fff;
  border: none; border-radius: 6px; font-size: 0.8rem;
  font-weight: 600; cursor: pointer; transition: background 0.15s;
}
#synthesis-download:hover { background: #3a6a89; }

#synthesis-close {
  width: 32px; height: 32px; background: none; border: none;
  font-size: 1.3rem; color: #666; cursor: pointer; border-radius: 4px;
}
#synthesis-close:hover { background: #f0f0f0; }

#synthesis-content {
  flex: 1; overflow-y: auto; padding: 20px;
  font-size: 0.9rem; line-height: 1.7; color: #333;
  white-space: pre-wrap; font-family: inherit;
}
/* Rendered markdown in synthesis panel */
#synthesis-content h3 {
  margin: 20px 0 8px 0; font-size: 1rem; font-weight: 700;
  color: #1d3557; border-bottom: 1px solid #e8e8e8; padding-bottom: 4px;
}
#synthesis-content h3:first-child { margin-top: 0; }
#synthesis-content h4 { margin: 14px 0 6px 0; font-size: 0.92rem; font-weight: 700; }
#synthesis-content p { margin: 0 0 10px 0; }
#synthesis-content ul { margin: 6px 0 12px 0; padding-left: 22px; }
#synthesis-content li { margin-bottom: 4px; }
#synthesis-content strong { font-weight: 700; color: #1d3557; }
#synthesis-content:has(h3) { white-space: normal; }

@media (max-width: 600px) {
  #synthesis-panel { width: 100vw; right: -100vw; }
}
