/* ── Reset & Base ──────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; 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: 'Helvetica Neue', Helvetica, 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: 'Helvetica Neue', Helvetica, 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;
}
#nav-always {
  display: flex !important; align-items: center !important; gap: 4px !important;
  margin-left: 8px !important;
}
#nav-burger {
  all: initial; display: none !important;
  cursor: pointer; padding: 6px !important;
  color: #666;
  align-items: center !important; justify-content: center !important;
}
#nav-burger:hover { color: #457b9d; }
#main-nav.nav-compact {
  height: 50px !important; min-height: 50px !important; max-height: 50px !important;
  border-bottom: 1px solid #eee !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; }
.chip-formation { background: #f0e8f5; color: #7a5a8a; }
.chip-book      { background: #f5f0e8; color: #8a7a4a; }
#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-article   { background: #e8f5e8; color: #4a8a4a; }
.doc-source-video     { background: #f5e8e8; color: #c46040; }
.doc-source-formation { background: #f0e8f5; color: #7a5a8a; }
.doc-source-book      { background: #f5f0e8; color: #8a7a4a; }
.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;
}
a.facet-title-link {
  display: inline-flex; align-items: center; gap: 5px;
  color: #888; text-decoration: none;
  transition: color 0.15s;
}
a.facet-title-link svg { opacity: 0.55; transition: opacity 0.15s, transform 0.15s; }
a.facet-title-link:hover { color: #457b9d; }
a.facet-title-link:hover svg { opacity: 1; transform: translate(1px, -1px); }
.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 page (full-height column) ──────────────────────────── */
.login-body {
  background: #fff; overflow: hidden;
}
.login-page {
  display: flex; flex-direction: column;
  align-items: center;
  width: 100%; max-width: 320px;
  margin: 0 auto;
  height: 100vh; height: 100dvh;
  padding: 0 24px;
}
.login-top {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding-top: 25vh; padding-bottom: 44px;
}
.login-logo { height: 88px; width: auto; max-width: 88px; object-fit: contain; }
.login-brand {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 1.1rem; font-weight: 300; color: #1a1a2e;
  letter-spacing: 0.06em;
}
.login-center { width: 100%; }
.login-error {
  background: #fef2f2; color: #b91c1c;
  font-size: 0.82rem; padding: 8px 14px;
  border-radius: 6px; margin-bottom: 16px; text-align: center;
}
.login-invitation-badge {
  background: #f0f4ff; color: #4a5478;
  font-size: 0.85rem; padding: 8px 14px;
  border-radius: 6px; margin-bottom: 4px; text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.05em;
}
.login-form {
  display: flex; flex-direction: column; gap: 12px;
}
.login-input {
  padding: 12px 14px; width: 100%; box-sizing: border-box;
  background: transparent; border: none;
  border-bottom: 1.5px solid #ddd;
  font-size: 1rem; font-family: inherit; outline: none;
  letter-spacing: 0.02em; color: #333;
  transition: border-color 0.2s;
}
.login-input::placeholder { color: #bbb; }
.login-input:focus {
  border-bottom-color: #457b9d;
}
/* Browser autofill background creeps past the underline style — keep the
 * autofilled inputs aligned with the same horizontal padding. */
.login-input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px #f0f4f8 inset;
  -webkit-text-fill-color: #333;
  padding-left: 14px !important;
}
.login-btn {
  padding: 14px 20px; background: #457b9d; color: #fff;
  border: none; border-radius: 10px; font-size: 0.95rem;
  font-weight: 600; cursor: pointer; transition: background 0.15s;
  width: 100%;
}
.login-btn:hover { background: #3a6a89; }
.login-bottom {
  margin-top: auto; padding-bottom: 32px;
}
.login-switch {
  margin-top: 16px; text-align: center;
  font-size: 0.85rem; color: #888;
}
.login-switch a {
  color: #457b9d; text-decoration: none; font-weight: 500;
}
.login-switch a:hover { text-decoration: underline; }
.login-guest-notice {
  background: #fef9e7; color: #92600a;
  font-size: 0.82rem; padding: 8px 14px;
  border-radius: 6px; margin-bottom: 16px; text-align: center;
}
.login-admin-link {
  color: #d0d0d0; transition: color 0.15s;
}
.login-admin-link:hover { color: #457b9d; }

/* ── Profile page ────────────────────────────────────────────── */
.profile-page {
  padding: 32px 48px; max-width: 640px; margin: 0 auto;
}
@media (max-width: 768px) {
  .profile-page {
    padding: 20px 16px; max-width: 100%;
    width: 100%; box-sizing: border-box;
    overflow-x: hidden;
  }
  .profile-section { overflow-wrap: break-word; word-break: break-word; }
  .profile-context { overflow-wrap: break-word; word-break: break-word; }
  .profile-form input, .profile-form select { width: 100%; box-sizing: border-box; }
}
.profile-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 28px;
}
.profile-header-left {
  display: flex; align-items: center; gap: 12px;
}
.profile-back {
  color: #666; transition: color 0.12s;
  display: flex; align-items: center;
}
.profile-back:hover { color: #457b9d; }
.profile-page h1 {
  font-size: 1.5rem; font-weight: 700; margin: 0; color: #1a1a2e;
}
.profile-section {
  margin-bottom: 32px; padding-bottom: 24px;
  border-bottom: 1px solid #eee;
}
.profile-section:last-child { border-bottom: none; }
.profile-section h2 {
  font-size: 1rem; font-weight: 600; color: #457b9d;
  margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.04em;
}
.profile-form {
  display: flex; flex-direction: column; gap: 14px;
}
.profile-form-row {
  display: flex; gap: 16px;
}
.profile-form-row > label { flex: 1; }
@media (max-width: 480px) {
  .profile-form-row { flex-direction: column; gap: 14px; }
}
.profile-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.85rem; color: #666; font-weight: 500;
}
.profile-form input, .profile-form select {
  padding: 10px 0; border: none; border-bottom: 1.5px solid #ddd;
  font-size: 0.95rem; font-family: inherit; outline: none;
  background: transparent; color: #333; transition: border-color 0.2s;
}
.profile-form input:focus, .profile-form select:focus {
  border-bottom-color: #457b9d;
}
.profile-form input:disabled { color: #aaa; }
.profile-btn {
  padding: 10px 20px; background: #457b9d; color: #fff;
  border: none; border-radius: 8px; font-size: 0.9rem;
  font-weight: 600; cursor: pointer; transition: background 0.15s;
  align-self: flex-start; margin-top: 8px;
}
.profile-btn:hover { background: #3a6a89; }
.profile-btn-secondary {
  background: transparent; color: #457b9d;
  border: 1.5px solid #457b9d; text-decoration: none;
}
.profile-btn-secondary:hover { background: #f0f6fa; }
.profile-btn-danger {
  background: #dc2626; color: #fff;
}
.profile-btn-danger:hover { background: #b91c1c; }
.profile-readonly {
  font-size: 0.95rem; color: #333; line-height: 1.6;
}
.profile-conf { color: #888; font-size: 0.85rem; }
.profile-context {
  background: #f8f9fa; padding: 18px 20px; border-radius: 8px;
  font-size: 0.9rem; color: #555; line-height: 1.7;
}
.profile-context p { margin-bottom: 10px; }
.profile-context p:last-child { margin-bottom: 0; }
.profile-hint {
  font-size: 0.8rem; color: #999; margin-top: 8px;
}
.profile-toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: #16a34a; color: #fff; padding: 10px 24px;
  border-radius: 8px; font-size: 0.9rem; font-weight: 500;
  opacity: 0; transition: opacity 0.3s; z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.profile-toast.show { opacity: 1; }
.profile-danger { margin-top: 16px; }
.profile-syntheses { display: flex; flex-direction: column; gap: 8px; }
.synthesis-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; background: #f8f9fa; border-radius: 8px;
  font-size: 0.9rem; gap: 12px;
}
.synthesis-item-info {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.synthesis-item-title {
  font-weight: 600; color: #333;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.synthesis-item-date { font-size: 0.8rem; color: #999; }
/* ── Custom dialog (replaces native confirm/alert) ─────────────── */
.app-dialog-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s;
  padding: 20px;
}
.app-dialog-overlay.show { opacity: 1; }
.app-dialog {
  background: #fff; border-radius: 12px;
  max-width: 440px; width: 100%;
  padding: 24px 26px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: scale(0.95); transition: transform 0.15s;
}
.app-dialog-overlay.show .app-dialog { transform: scale(1); }
.app-dialog-title {
  font-size: 1.05rem; font-weight: 700; color: #1d3557;
  margin-bottom: 8px;
}
.app-dialog-message {
  font-size: 0.95rem; color: #444; line-height: 1.5;
  margin-bottom: 22px; white-space: pre-wrap;
}
.app-dialog-actions {
  display: flex; justify-content: flex-end; gap: 10px;
}
.app-dialog-btn {
  padding: 9px 18px; border: none; border-radius: 6px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.app-dialog-btn:focus { outline: 2px solid #457b9d; outline-offset: 2px; }
.app-dialog-cancel { background: #e9ecef; color: #495057; }
.app-dialog-cancel:hover { background: #dee2e6; }
.app-dialog-ok { background: #457b9d; color: #fff; }
.app-dialog-ok:hover { background: #386384; }
.app-dialog-ok.app-dialog-danger { background: #e63946; }
.app-dialog-ok.app-dialog-danger:hover { background: #c12c39; }

.synthesis-item-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Admin user list ───────────────────────────────────────── */
.user-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; background: #f8f9fa; border-radius: 8px;
  margin-bottom: 8px; gap: 12px;
}
.user-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.user-email { font-weight: 600; color: #1d3557; font-size: 0.92rem; }
.user-meta { font-size: 0.78rem; color: #8089a8; font-style: italic; }
.user-role-admin {
  display: inline-block;
  background: #e63946; color: #fff;
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  padding: 2px 7px; border-radius: 4px;
  letter-spacing: 0.05em; vertical-align: middle; margin-left: 6px;
}
.user-actions { flex-shrink: 0; display: flex; align-items: center; }
.user-self-tag {
  font-size: 0.7rem; color: #8089a8; font-style: italic;
  padding: 4px 8px; background: #fff; border: 1px dashed #d6def5;
  border-radius: 5px;
}
.user-delete {
  padding: 7px 9px; background: #e9ecef; color: #6c757d;
  border: none; border-radius: 5px; cursor: pointer;
  display: flex; align-items: center; transition: background 0.15s, color 0.15s;
}
.user-delete:hover { background: #e63946; color: #fff; }

/* ── Invitations (admin section) ───────────────────────────── */
.profile-invitations { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.profile-invitations:empty { display: none; }
.invitation-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: #f8f9fa; border-radius: 8px;
  font-size: 0.9rem; gap: 12px;
}
.invitation-item.invitation-used { opacity: 0.55; }
.invitation-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.invitation-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700; color: #1d3557; letter-spacing: 0.05em;
  background: #fff; padding: 4px 10px; border-radius: 5px;
  border: 1px solid #e0e0e0;
}
.invitation-status { font-size: 0.78rem; color: #8089a8; text-transform: uppercase; letter-spacing: 0.04em; }
.invitation-actions { display: flex; gap: 8px; flex-shrink: 0; }
.invitation-actions button {
  padding: 6px 10px; background: #457b9d; color: #fff;
  border: none; border-radius: 5px; cursor: pointer;
  font-size: 0.8rem; display: flex; align-items: center; gap: 4px;
}
.invitation-actions button:hover { background: #386384; }
.invitation-actions button.invitation-delete { background: #e9ecef; color: #6c757d; padding: 6px 8px; }
.invitation-actions button.invitation-delete:hover { background: #e63946; color: #fff; }
.synthesis-item button {
  padding: 8px; background: #457b9d; color: #fff;
  border: none; border-radius: 6px;
  cursor: pointer; display: flex; align-items: center;
  flex-shrink: 0;
}
.synthesis-item button:hover { background: #3a6a89; }
.synthesis-item button.synthesis-delete { background: #e9ecef; color: #6c757d; }
.synthesis-item button.synthesis-delete:hover { background: #e63946; color: #fff; }

/* ── 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: row;
  flex: 1; overflow: hidden;
}
#conversation-sidebar {
  width: 280px; min-width: 280px;
  background: #f8f9fa; border-right: 1px solid #e8e8e8;
  display: flex; flex-direction: column;
  overflow: hidden;
}
#sidebar-new-btn {
  margin: 14px 14px 8px; padding: 10px 16px;
  background: #457b9d; color: #fff; border: none;
  border-radius: 8px; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
#sidebar-new-btn:hover { background: #3a6a89; }
#sidebar-list {
  flex: 1; overflow-y: auto; padding: 0 8px 14px;
}
.sidebar-item {
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: 8px; cursor: pointer;
  transition: background 0.12s;
}
.sidebar-item:hover { background: #eef1f4; }
.sidebar-item-active { background: #e2e8f0; }
.sidebar-item-preview {
  font-size: 0.85rem; color: #333;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.4;
}
.sidebar-item-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 4px;
}
.sidebar-item-meta span {
  font-size: 0.75rem; color: #999;
}
.sidebar-delete {
  background: none; border: none; color: #ccc;
  font-size: 1.1rem; cursor: pointer; padding: 0 4px;
  line-height: 1; transition: color 0.12s;
}
.sidebar-delete:hover { color: #dc2626; }
.sidebar-empty {
  padding: 20px 14px; text-align: center;
  font-size: 0.85rem; color: #aaa;
}
#sidebar-toggle {
  display: none;
  position: absolute; left: 8px; top: 56px; z-index: 10;
  background: #fff; border: 1px solid #ddd; border-radius: 6px;
  padding: 6px 8px; cursor: pointer; color: #666;
  transition: color 0.12s;
}
#sidebar-toggle:hover { color: #457b9d; }

@media (max-width: 768px) {
  /* Nav: collapse to compact + burger */
  #main-nav {
    height: 50px !important; min-height: 50px !important; max-height: 50px !important;
    padding: 0 12px !important;
  }
  #main-nav #nav-links { display: none !important; }
  #main-nav #nav-burger { display: flex !important; margin-right: 6px !important; }

  /* Sidebar: overlay style */
  #conversation-sidebar {
    display: none;
    position: fixed; left: 0; top: 50px; bottom: 0;
    z-index: 100; width: 280px;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }
  #conversation-sidebar.sidebar-open { display: flex; }
  #sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.3); z-index: 99;
  }
  #sidebar-overlay.open { display: block; }

  /* Chat: fill viewport, no overflow */
  #chat-page {
    flex: 1; overflow: hidden;
    height: calc(100dvh - 50px);
  }
  #chat-main {
    display: flex; flex-direction: column;
    flex: 1; overflow: hidden;
    height: 100%;
  }
  #chat-messages {
    flex: 1; min-height: 0; overflow-y: auto;
  }
  #chat-input-area {
    flex-shrink: 0;
  }
}
#chat-main {
  display: flex; flex-direction: column;
  flex: 1; min-width: 0; min-height: 0;
}
#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: 300; 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: 88%; border: 1px solid #e8e8e8;
}
/* Thumbs sit in the empty space to the right of the assistant bubble.
 * Always visible, never overlap the text. Vertically aligned to the top. */
.chat-msg-assistant { align-items: flex-start; gap: 6px; }
.msg-actions {
  display: flex; flex-direction: column; gap: 2px;
  flex-shrink: 0; padding-top: 6px;
}
.msg-thumb {
  background: transparent; border: none;
  width: 26px; height: 26px; padding: 5px;
  border-radius: 5px; cursor: pointer;
  color: #b8b8b8; transition: background 0.15s, color 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.msg-thumb svg { width: 14px; height: 14px; }
.msg-thumb:hover { background: rgba(0,0,0,0.05); color: #555; }
.msg-thumb.msg-thumb-up.active { color: #2a9d8f; background: rgba(42,157,143,0.12); }
.msg-thumb.msg-thumb-down.active { color: #e63946; background: rgba(230,57,70,0.12); }
.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, .profile-context ul, #synthesis-content ul {
  margin: 6px 0 10px 0; padding-left: 28px;
}
.msg-content li, .profile-context li, #synthesis-content li { margin-bottom: 4px; }
.msg-content li:last-child, .profile-context li:last-child, #synthesis-content li:last-child {
  margin-bottom: 0;
}
.msg-content strong { font-weight: 700; }
.msg-content table, .profile-context table, #synthesis-content table {
  border-collapse: collapse; margin: 8px 0; font-size: 0.86rem;
}
.msg-content th, .msg-content td,
.profile-context th, .profile-context td,
#synthesis-content th, #synthesis-content td {
  border: 1px solid #d8dde4; padding: 6px 10px;
  text-align: left; vertical-align: top;
}
.msg-content th, .profile-context th, #synthesis-content th {
  background: #f3f5f8; font-weight: 700;
}
/* Once markdown is rendered, don't preserve whitespace literally */
.msg-content:has(h3), .msg-content:has(strong), .msg-content:has(ul), .msg-content:has(table) {
  white-space: normal;
}

/* Typing indicator */
.typing-status {
  font-size: 0.85em;
  color: #888;
  font-style: italic;
  margin-bottom: 6px;
}
.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-input-actions {
  display: flex; gap: 8px; align-items: flex-end;
}
#chat-send {
  padding: 10px 14px; background: #457b9d; color: #fff;
  border: none; border-radius: 8px; font-size: 0.84rem;
  font-weight: 600; cursor: pointer; transition: background 0.15s;
  display: flex; align-items: center; justify-content: center;
}
#chat-send:hover { background: #3a6a89; }
#chat-send:disabled { background: #b0c4d0; cursor: not-allowed; }
#chat-mic {
  padding: 10px 12px; background: #f0f4f8; color: #457b9d;
  border: 1.5px solid #ccc; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#chat-mic:hover { background: #e4ebf2; }
#chat-mic:disabled { opacity: 0.5; cursor: not-allowed; }
#chat-mic.recording {
  background: #d64545; color: #fff; border-color: #d64545;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214, 69, 69, 0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(214, 69, 69, 0); }
}
@media (max-width: 768px) {
  #chat-input-area { flex-direction: column; }
  #chat-input { flex: none; width: 100%; }
  .chat-input-actions { justify-content: flex-end; }
}

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

/* ── Synthesis button ──────────────────────────────────────────── */
#btn-synthesis, #btn-synthesis-nav {
  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, #btn-synthesis-nav:hover { background: #f0f6fa; }
#btn-synthesis:disabled, #btn-synthesis-nav:disabled { color: #b0c4d0; border-color: #b0c4d0; cursor: not-allowed; }
#btn-synthesis-nav {
  align-self: center; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  padding: 6px 14px; font-size: 0.78rem;
}

/* ── 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; flex-direction: column; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
#synthesis-title-row {
  display: flex; align-items: center; justify-content: space-between;
}
#synthesis-title {
  font-weight: 700; font-size: 1rem; color: #1d3557;
}

#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 p:empty { display: none; }
#synthesis-content ul { margin: 6px 0 12px 0; padding-left: 22px; }
#synthesis-content ul br { display: none; }
#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; }
  #synthesis-download { width: 100%; text-align: center; }
}
