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

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: #f7f6f3;
  color: #111;
  display: flex;
  flex-direction: column;
}

/* ── App shell ──────────────────────────────────────────────── */

#app {
  display: flex;
  flex: 1;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* ── Left sidebar ───────────────────────────────────────────── */

#sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #0e1f3d;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease;
}

#sidebar.collapsed { width: 52px; }

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 0.75rem 0.6rem;
  flex-shrink: 0;
  min-width: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
}

.logo-mark {
  color: #fff;
  flex-shrink: 0;
  opacity: 0.9;
  display: block;
}

.logo-wordmark {
  font-family: 'Raleway', sans-serif;
  font-size: 0.76rem;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
  letter-spacing: 0.2em;
}

#sidebar-toggle {
  background: none;
  border: none;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, transform 0.2s ease;
}
#sidebar-toggle:hover { color: rgba(255,255,255,0.8); background: none; }
#sidebar.collapsed #sidebar-toggle { transform: rotate(180deg); }

/* Hide labels when collapsed */
.sidebar-label {
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.15s, max-width 0.2s;
  max-width: 160px;
}
#sidebar.collapsed .sidebar-label {
  opacity: 0;
  max-width: 0;
  pointer-events: none;
}

.create-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.25rem 0.6rem 0.6rem;
  padding: 0.48rem 0.7rem;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  color: rgba(255,255,255,0.85);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.15s;
  flex-shrink: 0;
}
.create-btn:hover { background: rgba(255,255,255,0.16); }
#sidebar.collapsed .create-btn { justify-content: center; padding: 0.48rem 0; margin: 0.25rem 0.4rem 0.6rem; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  padding: 0.15rem 0.5rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.52rem 0.7rem;
  border: none;
  border-radius: 6px;
  background: none;
  color: rgba(255,255,255,0.5);
  font-size: 0.83rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
  width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.9); }
.nav-item.active { background: rgba(255,255,255,0.11); color: #fff; }
.nav-item svg { flex-shrink: 0; }
#sidebar.collapsed .nav-item { justify-content: center; padding: 0.52rem 0; }

.sidebar-footer {
  flex-shrink: 0;
  padding: 0.5rem;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.9);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Main area ──────────────────────────────────────────────── */

#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* ── Top bar ────────────────────────────────────────────────── */

#topbar {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: #fff;
  border-bottom: 1px solid #e0ddd8;
}

.topbar-left { flex-shrink: 0; }

.workspace-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: none;
  font-size: 0.87rem;
  font-weight: 600;
  color: #111;
  font-family: inherit;
  cursor: pointer;
  padding: 0.3rem 0.45rem;
  border-radius: 5px;
  transition: background 0.12s;
}
.workspace-dropdown-btn:hover { background: #f0ede8; }

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.topbar-link {
  background: none;
  border: none;
  font-size: 0.8rem;
  color: #999;
  font-family: inherit;
  cursor: pointer;
  padding: 0.25rem 0.45rem;
  border-radius: 4px;
  transition: color 0.12s;
}
.topbar-link:hover { color: #333; background: none; }

.analytics-btn {
  background: none;
  border: none;
  color: #999;
  padding: 0.25rem 0.45rem;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.12s;
}
.analytics-btn:hover { color: #111; }

/* ── Language selector ──────────────────────────────────────── */

.lang-dropdown {
  position: relative;
  margin-left: 0.4rem;
}
.lang-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 0.25rem 0.35rem;
  cursor: pointer;
  line-height: 1;
  transition: border-color 0.15s, background 0.15s;
}
.lang-btn .fi {
  width: 20px;
  height: 15px;
  border-radius: 2px;
  display: block;
}
.lang-btn:hover {
  border-color: #d5d2cc;
  background: #f5f4f1;
}
.lang-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border: 1px solid #e0ddd8;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  padding: 0.3rem;
  min-width: 140px;
  z-index: 200;
}
.lang-menu.open { display: block; }
.lang-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  background: none;
  border: none;
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  font-size: 0.82rem;
  color: #333;
  text-align: left;
  white-space: nowrap;
  transition: background 0.12s;
}
.lang-option .fi {
  width: 20px;
  height: 15px;
  border-radius: 2px;
  flex-shrink: 0;
}
.lang-option:hover { background: #f5f4f1; }
.lang-option.active { background: #eef0f7; font-weight: 500; color: #0e1f3d; }

@media (max-width: 640px) {
  .lang-dropdown { display: none; }
}

/* ── Domain toggle ──────────────────────────────────────────── */

.domain-toggle {
  display: flex;
  border: 1px solid #d5d2cc;
  border-radius: 6px;
  overflow: hidden;
}
.domain-btn {
  background: none;
  border: none;
  color: #888;
  padding: 0.28rem 0.8rem;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.domain-btn + .domain-btn { border-left: 1px solid #d5d2cc; }
.domain-btn:hover  { color: #111; background: #f5f3ef; }
.domain-btn.active { color: #0e1f3d; background: #e5ecf8; font-weight: 600; }

/* ── Workspace ──────────────────────────────────────────────── */

#workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 1rem;
  gap: 1rem;
}

/* ── Chat panel ─────────────────────────────────────────────── */

#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fff;
  border: 1px solid #d5d2cc;
  border-radius: 8px;
  overflow: hidden;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}

.msg-user      { align-self: flex-end; }
.msg-assistant { align-self: flex-start; }

.msg-label {
  font-size: 0.67rem;
  font-weight: 600;
  color: #999;
  margin-bottom: 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.msg-content {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.6;
}

.msg-user .msg-content {
  background: #1c3d7a;
  color: #fff;
  border-bottom-right-radius: 3px;
}

.msg-assistant .msg-content {
  background: #eeecf0;
  color: #111;
  border-bottom-left-radius: 3px;
}

/* Markdown in AI messages */
.msg-assistant .msg-content h1,
.msg-assistant .msg-content h2,
.msg-assistant .msg-content h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0.8rem 0 0.3rem;
}
.msg-assistant .msg-content h1:first-child,
.msg-assistant .msg-content h2:first-child,
.msg-assistant .msg-content h3:first-child { margin-top: 0; }
.msg-assistant .msg-content p { margin-bottom: 0.5rem; }
.msg-assistant .msg-content p:last-child { margin-bottom: 0; }
.msg-assistant .msg-content ul,
.msg-assistant .msg-content ol { padding-left: 1.25rem; margin-bottom: 0.5rem; }
.msg-assistant .msg-content li { margin-bottom: 0.2rem; }
.msg-assistant .msg-content strong { font-weight: 600; }

/* Typing indicator */
.msg-typing {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  min-height: 2rem;
}

.dot {
  width: 6px;
  height: 6px;
  background: #bbb;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.6; }
  40%            { transform: translateY(-5px); opacity: 1; }
}

/* Chat form */
#chat-form {
  flex: none;
  border-top: 1px solid #e0ddd8;
  padding: 0.75rem;
  background: #f9f8f5;
}

#chat-form textarea {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  resize: none;
  font-family: inherit;
  background: #fff;
  margin-bottom: 0.5rem;
}

#chat-form textarea:focus {
  outline: none;
  border-color: #1c3d7a;
}

.form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#status {
  font-size: 0.8rem;
  color: #888;
}

button {
  padding: 0.45rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: #1c3d7a;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

button:hover    { background: #163162; }
button:disabled { background: #aaa; cursor: not-allowed; }

/* ── Right panel ────────────────────────────────────────────── */

#right-panel {
  flex: 0 0 420px;
  display: flex;
  min-height: 0;
  position: relative;
  transition: flex-basis 0.2s ease;
}

#right-panel.collapsed {
  flex: 0 0 20px;
}

#right-panel-toggle {
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: #fff;
  border: 1px solid #d5d2cc;
  border-radius: 4px;
  width: 20px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #bbb;
  padding: 0;
  transition: color 0.12s, background 0.12s;
  box-shadow: -1px 0 4px rgba(0,0,0,0.06);
}
#right-panel-toggle:hover { color: #555; background: #f5f3ef; }
#right-panel.collapsed #right-panel-toggle svg { transform: rotate(180deg); }
#right-panel.collapsed #results-panel { display: none; }

/* ── Results panel ──────────────────────────────────────────── */

#results-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#tab-bar {
  display: flex;
  border-bottom: 2px solid #d5d2cc;
  flex-shrink: 0;
}

#tab-bar .tab {
  flex: 1;
  padding: 0.55rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: none;
  color: #888;
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

#tab-bar .tab:hover { color: #444; border-color: #e0ded9; border-bottom-color: transparent; }

#tab-bar .tab.active {
  color: #1c3d7a;
  border-color: #d5d2cc;
  border-bottom-color: #1c3d7a;
  background: none;
}

.tab-pane {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.25rem 1rem 0;
  min-height: 0;
}

/* ── Cards ──────────────────────────────────────────────────── */

.card {
  background: #fff;
  border: 1px solid #d5d2cc;
  border-left: 3px solid #1c3d7a;
  border-radius: 6px;
  padding: 0.85rem;
  margin-bottom: 0.65rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.source-badge {
  font-size: 0.68rem;
  font-weight: 700;
  color: #1c3d7a;
  background: #e5ecf8;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
}

.rank-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: #dcfce7;
  color: #166534;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.via-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}
.via-vector { background: #f0f0f0; color: #666; }
.via-graph  { background: #f3eaff; color: #6b21a8; }

.score {
  font-size: 0.68rem;
  color: #aaa;
  margin-left: auto;
}

.path {
  font-size: 0.75rem;
  font-weight: 600;
  color: #1c3d7a;
  margin-bottom: 0.35rem;
  word-break: break-word;
}

.article-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1a1a2e;
  margin-bottom: 0.3rem;
}

.via-reason {
  font-size: 0.7rem;
  color: #888;
  margin-bottom: 0.35rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.45rem;
}

.chip {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
  font-size: 0.67rem;
  font-weight: 600;
}

.chip-law        { background: #e5ecf8; color: #1c3d7a; }
.chip-type       { background: #f0fdf4; color: #15803d; }
.chip-year       { background: #f5f5f5; color: #555;    }
.chip-parties    { background: #fff7ed; color: #92400e; }
.chip-obligation { background: #fef3c7; color: #78350f; font-style: italic; }
.chip-subject    { background: #f3e8ff; color: #6b21a8; }

.excerpt {
  font-size: 0.8rem;
  color: #333;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pdf-link {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: #666;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.pdf-link:hover { color: #0e1f3d; }

.graph-ctx {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.graph-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
}

.graph-label { color: #999; white-space: nowrap; }

.tag {
  display: inline-block;
  padding: 0.08rem 0.4rem;
  border-radius: 4px;
  font-size: 0.67rem;
  font-weight: 500;
}

.tag-law  { background: #e5ecf8; color: #1c3d7a; }
.tag-case { background: #fef3e8; color: #b45309; }

.no-results { font-size: 0.85rem; color: #aaa; }

/* ── Sources / manifest tab ─────────────────────────────────── */

.manifest-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 1.1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid #e0ddd8;
}

.manifest-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #0e1f3d;
}

.manifest-total {
  font-size: 0.75rem;
  color: #999;
}

.manifest-section {
  margin-bottom: 1.25rem;
}

.manifest-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.manifest-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #888;
}

.manifest-section-count {
  font-size: 0.68rem;
  font-weight: 600;
  color: #fff;
  background: #1c3d7a;
  padding: 0.05rem 0.45rem;
  border-radius: 99px;
}

.manifest-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid #f0ede8;
}

.manifest-row:last-child { border-bottom: none; }

.manifest-name {
  font-size: 0.8rem;
  color: #222;
  line-height: 1.4;
  word-break: break-word;
  flex: 1;
}

a.manifest-name {
  color: #1c3d7a;
  text-decoration: none;
  text-underline-offset: 2px;
}

a.manifest-name:hover { text-decoration: underline; }

.manifest-count {
  font-size: 0.7rem;
  color: #aaa;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Modal ──────────────────────────────────────────────────── */

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

#modal-overlay[hidden] { display: none; }

#modal {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.75rem 1.75rem 1.5rem;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.22);
}

#modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1rem;
  color: #aaa;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  line-height: 1;
}
#modal-close:hover { background: #f0f0f0; color: #333; }

.modal-path {
  font-size: 0.75rem;
  font-weight: 600;
  color: #1c3d7a;
  margin-bottom: 0.25rem;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0e1f3d;
  margin-bottom: 0.6rem;
  line-height: 1.35;
}

.modal-excerpt {
  font-size: 0.845rem;
  color: #222;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #eee;
}

/* Card clickability */
.card {
  cursor: pointer;
  transition: box-shadow 0.12s, border-left-color 0.12s;
}
.card:hover {
  border-left-color: #2d5abf;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.card.is-pinned {
  border-left-color: #c8960c;
  background: #fffdf5;
}

/* Vote buttons */
.vote-row {
  display: flex;
  gap: 0.2rem;
  margin-left: 0.3rem;
  flex-shrink: 0;
}
.vote-btn {
  background: none;
  border: 1px solid #ddd;
  padding: 0.1rem 0.4rem;
  font-size: 0.75rem;
  color: #bbb;
  cursor: pointer;
  border-radius: 3px;
  line-height: 1.4;
  min-width: 1.6rem;
  text-align: center;
  font-weight: 400;
}
.vote-btn:hover { border-color: #aaa; color: #666; background: #f5f5f5; }
.vote-btn.vote-accept.voted { background: #dcfce7; border-color: #4ade80; color: #15803d; }
.vote-btn.vote-reject.voted { background: #fee2e2; border-color: #f87171; color: #b91c1c; }

/* Modal vote row */
.modal-vote-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
}
.modal-vote-label {
  font-size: 0.78rem;
  color: #888;
}

/* Pin button */
.pin-btn {
  background: none;
  border: none;
  padding: 0.1rem 0.35rem;
  font-size: 0.8rem;
  color: #ccc;
  cursor: pointer;
  border-radius: 3px;
  line-height: 1;
  margin-left: 0.2rem;
  flex-shrink: 0;
}
.pin-btn:hover    { color: #1c3d7a; background: #f0f0f0; }
.pin-btn.is-pinned { color: #c8960c; }

/* ── Responsive ─────────────────────────────────────────────── */

.mobile-indicator { display: none; }

/* Settings gear: hidden on desktop */
.topbar-settings-btn { display: none; }

/* Swipe dots: hidden on desktop */
.workspace-swipe-dots { display: none; }

/* Mobile shortcuts: hidden everywhere except mobile home */
#mobile-shortcuts { display: none; }

/* Mobile tab bar: hidden on desktop */
#mobile-tab-bar { display: none; }

/* Mobile history view: hidden by default (JS-managed) */
#mobile-history-view { display: none; }

@media (min-width: 641px) and (max-width: 1024px) {
  #sidebar { width: 52px; }
  #sidebar .sidebar-label { opacity: 0; max-width: 0; pointer-events: none; }
  #sidebar #sidebar-toggle { transform: rotate(180deg); }
  #sidebar .create-btn { justify-content: center; padding: 0.48rem 0; margin: 0.25rem 0.4rem 0.6rem; }
  #sidebar .nav-item { justify-content: center; padding: 0.52rem 0; }
  #right-panel { flex: 0 0 340px; }
}

@media (max-width: 640px) {
  html, body { overflow-x: hidden; }

  /* Hide desktop sidebar — bottom tab bar handles nav */
  #sidebar { display: none; }

  /* Topbar: compact, show settings gear */
  #topbar { padding: 0 0.75rem; }
  .topbar-link { display: none; }
  .analytics-btn { display: none; }
  .topbar-settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: rgba(255,255,255,0.75);
    cursor: pointer;
    padding: 0.3rem;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
  }
  .topbar-settings-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }

  /* Main area: column with tab bar at bottom */
  #main-area { padding-bottom: 0; }

  /* Workspace: horizontal slide between chat and sources */
  #workspace {
    flex-direction: column;
    padding: 0;
    gap: 0;
    overflow: clip;
    position: relative;
  }

  #chat-panel {
    flex: 1;
    min-height: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
  }

  #right-panel {
    flex: 1;
    min-height: 0;
  }

  #right-panel-toggle { display: none; }

  #chat-panel,
  #right-panel {
    position: absolute;
    inset: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
  }

  #workspace.show-chat    #chat-panel   { transform: translateX(0); }
  #workspace.show-chat    #right-panel  { transform: translateX(100%); }
  #workspace.show-sources #chat-panel   { transform: translateX(-100%); }
  #workspace.show-sources #right-panel  { transform: translateX(0); }

  /* Swipe dots inside workspace */
  .workspace-swipe-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 5px 0 6px;
    flex-shrink: 0;
    background: #f7f6f3;
    border-top: 1px solid #e5e2dc;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
  }
  .mobile-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ccc;
    transition: background 0.2s, transform 0.2s;
  }
  .mobile-dot.active { background: #1c3d7a; transform: scale(1.3); }

  /* Only show swipe dots when in chatting + results visible state */
  #workspace:not(.results-ready) .workspace-swipe-dots { display: none; }

  /* Sources panel: tab pane padding */
  .tab-pane { padding: 0.75rem 0.5rem; }

  /* Mobile history view: full-height scrollable */
  #mobile-history-view {
    flex: 1;
    flex-direction: column;
    overflow-y: auto;
    background: #faf9f7;
    min-height: 0;
  }

  .mvh-header {
    padding: 1.25rem 1.1rem 0.75rem;
    border-bottom: 1px solid #e8e5df;
    flex-shrink: 0;
  }

  .mvh-title {
    font-size: 1rem;
    font-weight: 700;
    color: #111;
    margin: 0;
  }

  .mvh-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
  }

  .mvh-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.1rem;
    border-bottom: 1px solid #f0ede8;
    cursor: pointer;
    transition: background 0.1s;
  }
  .mvh-item:hover { background: #f5f3ef; }
  .mvh-item-name {
    flex: 1;
    font-size: 0.85rem;
    color: #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mvh-item-time {
    font-size: 0.72rem;
    color: #aaa;
    flex-shrink: 0;
  }
  .mvh-empty {
    padding: 2rem 1.1rem;
    font-size: 0.83rem;
    color: #aaa;
    text-align: center;
  }

  /* Workflows view on mobile */
  #workflows-view { padding: 1.25rem 1rem; }
  .wfv-grid { grid-template-columns: repeat(2, 1fr); }
  .wfv-header { max-width: 100%; }

  /* Mobile bottom tab bar */
  #mobile-tab-bar {
    display: flex;
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid #e0ddd8;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mob-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0.5rem 0.25rem 0.4rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #aaa;
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 500;
    transition: color 0.15s;
  }
  .mob-tab:hover { color: #555; }
  .mob-tab.active { color: #0e1f3d; }
  .mob-tab.active svg { stroke: #0e1f3d; }

  /* Mobile home: centered, input pinned to bottom */
  #chat-panel:not(.chatting) {
    display: flex;
    flex-direction: column;
    padding: 0;
  }
  #chat-panel:not(.chatting) #home-header {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem 0.5rem;
  }
  #chat-panel:not(.chatting) #chat-form {
    order: 10;
    padding: 0 0.75rem 0.5rem;
    border-top: 1px solid #e8e5df;
  }
  #chat-panel:not(.chatting) #home-pills {
    order: 9;
    padding: 0.5rem 0.75rem 0;
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  #chat-panel:not(.chatting) #home-pills::-webkit-scrollbar { display: none; }
  #chat-panel:not(.chatting) #home-workflows { display: none; }
  #chat-panel:not(.chatting) #home-action-row { display: none; }

  /* Mobile shortcuts: shown on mobile home state */
  #chat-panel:not(.chatting) #mobile-shortcuts {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 0 0.4rem;
    justify-content: center;
    flex-wrap: wrap;
  }
  .mob-shortcut-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: #f5f3ef;
    border: 1px solid #e0ddd8;
    border-radius: 20px;
    padding: 0.38rem 0.75rem;
    font-family: inherit;
    font-size: 0.75rem;
    color: #444;
    cursor: pointer;
    white-space: nowrap;
  }
  .mob-shortcut-btn:hover { background: #edeae4; }
}

/* ── Phase 2: Home screen ───────────────────────────────────── */

/* Home state: scrollable column, content centered */
#chat-panel:not(.chatting) {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 2rem 2.5rem;
}

/* Hide messages and chat footer in home state */
#messages                    { display: none; }
.form-footer                 { display: none; }

/* Chat state: restore panel layout */
#chat-panel.chatting         { overflow: hidden; }
#chat-panel.chatting #messages       { display: flex; flex: 1; }
#chat-panel.chatting .form-footer    { display: flex; }
#chat-panel.chatting #home-header    { display: none; }
#chat-panel.chatting #home-action-row { display: none; }
#chat-panel.chatting #home-pills     { display: none; }
#chat-panel.chatting #home-workflows { display: none; }

/* Chat state: restore form styling */
#chat-panel.chatting #chat-form {
  border: none;
  border-top: 1px solid #e0ddd8;
  border-radius: 0;
  background: #f9f8f5;
  padding: 0.75rem;
  max-width: none;
  margin: 0;
  overflow: visible;
}
#chat-panel.chatting #chat-form textarea {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  min-height: unset;
}
#chat-panel.chatting #chat-form textarea:focus {
  border-color: #1c3d7a;
}

/* ── Home header: brand mark ── */

#home-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3.5rem 0 2rem;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}

.home-brand-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 1.75rem;
}

.home-brand-title {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.home-star {
  color: #c8102e;
  font-size: 0.72rem;
  line-height: 1;
}

.home-wordmark {
  font-family: 'Raleway', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  color: #0e1f3d;
}

/* Context buttons */
.home-context-btns {
  display: flex;
  gap: 0.5rem;
}

.home-ctx-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.8rem;
  border: 1px solid #d5d2cc;
  border-radius: 6px;
  background: none;
  color: #666;
  font-size: 0.8rem;
  font-weight: 400;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.home-ctx-btn:hover { background: #f5f3ef; color: #111; border-color: #bbb; }
.home-ctx-btn.vault-active { border-color: #0e1f3d; color: #0e1f3d; }

/* Vault dropdown */
.vault-dropdown { position: relative; }
.vault-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: #fff;
  border: 1px solid #e0ddd8;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  padding: 0.3rem;
  min-width: 160px;
  z-index: 200;
}
.vault-menu.open { display: block; }
.vault-option {
  display: block;
  width: 100%;
  background: none;
  border: none;
  border-radius: 5px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  color: #333;
  text-align: left;
  white-space: nowrap;
  transition: background 0.12s;
}
.vault-option:hover { background: #f5f4f1; }
.vault-option.active { background: #eef0f7; font-weight: 500; color: #0e1f3d; }

/* ── Home form: unified input box ── */

#chat-panel:not(.chatting) #chat-form {
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
  border: 1px solid #d5d2cc;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  flex-shrink: 0;
  padding: 0;
  border-top: 1px solid #d5d2cc;
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
}

#chat-panel:not(.chatting) #chat-form textarea {
  border: none;
  border-bottom: 1px solid #e8e5e0;
  border-radius: 0;
  padding: 1rem 1.1rem;
  font-size: 0.93rem;
  margin-bottom: 0;
  min-height: 80px;
  background: #fff;
}
#chat-panel:not(.chatting) #chat-form textarea:focus {
  outline: none;
  border-color: #e8e5e0;
}

/* Home action row */
#home-action-row {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: #fafaf8;
  gap: 0.4rem;
}

.home-action-btns {
  display: flex;
  flex: 1;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.home-action-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: 1px solid #d5d2cc;
  color: #666;
  font-size: 0.76rem;
  font-weight: 400;
  font-family: inherit;
  padding: 0.25rem 0.55rem;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.home-action-btn:hover { background: #eeece8; color: #111; }

#home-ask-btn {
  background: #1c3d7a;
  color: #fff;
  border: none;
  padding: 0.38rem 1.2rem;
  border-radius: 6px;
  font-size: 0.83rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s;
}
#home-ask-btn:hover { background: #163162; }
#home-ask-btn:disabled { background: #aaa; cursor: not-allowed; }

/* ── Source pills ── */

#home-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.85rem 0 0;
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
}

.home-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.7rem;
  border: 1px solid #d5d2cc;
  border-radius: 99px;
  background: none;
  color: #666;
  font-size: 0.76rem;
  font-weight: 400;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.home-pill:hover { border-color: #1c3d7a; color: #1c3d7a; background: none; }
.pill-add { color: #bbb; font-size: 0.8rem; }
.home-pill:hover .pill-add { color: #1c3d7a; }

/* ── Workflow cards ── */

#home-workflows {
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
  padding-top: 1.75rem;
}

.home-workflows-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  margin-bottom: 0.7rem;
}

.home-workflows-scroll {
  display: flex;
  gap: 0.65rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: #d5d2cc transparent;
}

.workflow-card {
  flex-shrink: 0;
  width: 162px;
  background: #fff;
  border: 1px solid #d5d2cc;
  border-radius: 8px;
  padding: 0.9rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  transition: box-shadow 0.12s, border-color 0.12s;
}
.workflow-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-color: #bbb; }

.wf-icon { color: #777; flex-shrink: 0; }
.wf-title { font-size: 0.83rem; font-weight: 600; color: #111; line-height: 1.3; }
.wf-meta  { display: flex; align-items: center; gap: 0.4rem; margin-top: auto; padding-top: 0.25rem; }
.wf-badge {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.wf-draft  { background: #e5ecf8; color: #1c3d7a; }
.wf-output { background: #f0fdf4; color: #15803d; }
.wf-review { background: #fef3c7; color: #78350f; }
.wf-steps  { font-size: 0.69rem; color: #bbb; }

/* ── Workflows full-view (Phase 7) ── */

#workflows-view {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: #faf9f7;
  min-height: 0;
}

.wfv-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 860px;
}

.wfv-title-row {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.wfv-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #111;
  margin: 0;
}

.wfv-view-all {
  background: none;
  border: none;
  font-size: 0.78rem;
  color: #1c3d7a;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.wfv-view-all:hover { color: #0e1f3d; }

.wfv-search-wrap {
  position: relative;
  max-width: 320px;
}

.wfv-search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: #aaa;
  pointer-events: none;
}

.wfv-search-input {
  width: 100%;
  padding: 0.42rem 0.75rem 0.42rem 2rem;
  font-family: inherit;
  font-size: 0.82rem;
  border: 1px solid #d5d2cc;
  border-radius: 7px;
  background: #fff;
  color: #111;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.wfv-search-input:focus { border-color: #1c3d7a; }

.wfv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 0.9rem;
  max-width: 860px;
}

.wfv-card {
  background: #fff;
  border: 1px solid #d5d2cc;
  border-radius: 10px;
  padding: 1.1rem 1rem 0.9rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  transition: box-shadow 0.12s, border-color 0.12s;
  min-height: 120px;
}
.wfv-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,0.09); border-color: #aaa; }

.wfv-card .wf-icon { color: #6b7280; }
.wfv-card .wf-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #111;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.wfv-card .wf-meta { margin-top: auto; padding-top: 0.3rem; }

/* Extract badge */
.wf-extract { background: #f3e8ff; color: #6b21a8; }

/* Right panel: hidden until first response with results or reasoning starts */
#right-panel                 { display: none; }
#right-panel.results-visible { display: flex; }

/* ── Phase 3: Sidebar content ───────────────────────────────── */

.sidebar-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0.5rem 0.5rem;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

#sidebar.collapsed .sidebar-content { display: none; }

/* Section labels (static headers + details summaries) */
.sidebar-section-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.25rem 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.3);
  cursor: default;
  list-style: none;
  user-select: none;
}

/* details summary inherits .sidebar-section-label and is clickable */
details.sidebar-details > summary.sidebar-section-label {
  cursor: pointer;
  margin-top: 0.35rem;
}
details.sidebar-details > summary.sidebar-section-label::-webkit-details-marker { display: none; }
details.sidebar-details > summary.sidebar-section-label:hover { color: rgba(255,255,255,0.55); }

.sidebar-chevron {
  flex-shrink: 0;
  transition: transform 0.18s ease;
  transform: rotate(0deg);
}
details.sidebar-details[open] > summary .sidebar-chevron { transform: rotate(90deg); }

.sidebar-details-body {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  padding-bottom: 0.25rem;
}

/* Items inside details sections (templates, favourites) */
.sidebar-item-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: rgba(255,255,255,0.55);
  font-size: 0.79rem;
  font-weight: 400;
  font-family: inherit;
  padding: 0.35rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s, color 0.12s;
}
.sidebar-item-btn:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.9); }

/* History list */
.sidebar-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  margin-bottom: 0.25rem;
}

.history-empty {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.2);
  padding: 0.3rem 0.5rem 0.5rem;
  font-style: italic;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.5rem;
  border-radius: 5px;
  cursor: default;
  transition: background 0.12s;
  min-width: 0;
}
.history-item:hover { background: rgba(255,255,255,0.07); }

.history-name {
  flex: 1;
  font-size: 0.79rem;
  color: rgba(255,255,255,0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.history-time {
  font-size: 0.67rem;
  color: rgba(255,255,255,0.25);
  white-space: nowrap;
  flex-shrink: 0;
}

.history-delete {
  background: none;
  border: none;
  padding: 0.1rem 0.25rem;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.25);
  cursor: pointer;
  border-radius: 3px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
  line-height: 1;
}
.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: #f87171; background: rgba(255,255,255,0.08); }

/* ── Phase 5: Message actions + follow-ups ──────────────────── */

.msg-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.msg-action-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: 1px solid #e0ddd8;
  color: #888;
  font-size: 0.73rem;
  font-weight: 400;
  font-family: inherit;
  padding: 0.22rem 0.6rem;
  border-radius: 5px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.msg-action-btn:hover  { border-color: #bbb; color: #333; background: #f5f3ef; }
.msg-action-btn.copied { border-color: #86efac; color: #166534; background: #f0fdf4; }
.msg-action-btn.dim    { color: #ccc; cursor: default; }
.msg-action-btn.dim:hover { border-color: #e0ddd8; color: #ccc; background: none; }


/* ── Phase 5: Input bar upgrade ─────────────────────────────── */

.footer-icons {
  display: flex;
  gap: 0.1rem;
  flex-shrink: 0;
}

.footer-icon-btn {
  background: none;
  border: none;
  color: #bbb;
  padding: 0.3rem 0.4rem;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color 0.12s, background 0.12s;
}
.footer-icon-btn:hover { color: #555; background: #eeece8; }

.footer-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

/* Client-ready Summary shortcut */
.sidebar-shortcut-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-top: 1px solid rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.4);
  font-size: 0.78rem;
  font-weight: 400;
  font-family: inherit;
  padding: 0.65rem 0.25rem 0.4rem;
  margin-top: 0.5rem;
  cursor: pointer;
  transition: color 0.12s;
}
.sidebar-shortcut-link:hover { color: rgba(255,255,255,0.75); background: none; }

/* ── Phase 6: Draft Editor ───────────────────────────────────── */

/* Right panel: editor-visible state */
#right-panel.editor-visible            { display: flex; }
#right-panel.editor-visible #editor-panel    { display: flex; }
#right-panel.editor-visible #results-panel   { display: none; }
#right-panel.collapsed #editor-panel         { display: none; }

#editor-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  background: #fff;
  border: 1px solid #d5d2cc;
  border-radius: 8px;
  overflow: hidden;
}

#editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 0.2rem;
  gap: 0.08rem;
  padding: 0.3rem 0.45rem;
  border-bottom: 1px solid #e0ddd8;
  background: #f9f8f5;
  flex-shrink: 0;
}

.editor-style-select {
  font-family: inherit;
  font-size: 0.72rem;
  color: #555;
  background: #fff;
  border: 1px solid #d5d2cc;
  border-radius: 4px;
  padding: 0.15rem 0.3rem;
  cursor: pointer;
  height: 24px;
  outline: none;
  flex-shrink: 0;
}
.editor-style-select:focus { border-color: #1c3d7a; }

.editor-sep {
  width: 1px;
  height: 16px;
  background: #e0ddd8;
  margin: 0 0.1rem;
  flex-shrink: 0;
  align-self: center;
}

.editor-tool-group {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.editor-toolbar-spacer {
  flex: 1;
  min-width: 0.2rem;
}

.editor-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  color: #666;
  font-size: 0.72rem;
  font-family: inherit;
  font-weight: 400;
  padding: 0.15rem 0.28rem;
  border-radius: 4px;
  cursor: pointer;
  height: 24px;
  min-width: 24px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.editor-tool-btn:hover  { background: #eeece8; color: #111; border-color: #d5d2cc; }
.editor-tool-btn.active { background: #e8ecf5; color: #1c3d7a; border-color: #c5d0e8; }
.editor-fmt { font-size: 0.78rem; }

.editor-uci-toggle {
  font-size: 0.69rem;
  padding: 0.15rem 0.45rem;
  white-space: nowrap;
}
.editor-uci-toggle.active { background: #fff8e6; color: #92400e; border-color: #fde68a; }


.editor-close-btn { color: #bbb; }
.editor-close-btn:hover { color: #c00; background: #fee2e2; border-color: #fca5a5; }

/* Editor body: editable content area */
#editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.1rem;
  font-size: 0.875rem;
  line-height: 1.7;
  color: #111;
  outline: none;
  min-height: 0;
}

#editor-body h1 { font-size: 1.05rem; font-weight: 700; margin: 0.9rem 0 0.4rem; }
#editor-body h2 { font-size: 0.93rem; font-weight: 700; margin: 0.8rem 0 0.35rem; }
#editor-body h3 { font-size: 0.86rem; font-weight: 600; margin: 0.7rem 0 0.3rem; }
#editor-body h1:first-child,
#editor-body h2:first-child,
#editor-body h3:first-child { margin-top: 0; }
#editor-body p { margin-bottom: 0.5rem; }
#editor-body p:last-child { margin-bottom: 0; }
#editor-body ul,
#editor-body ol { padding-left: 1.3rem; margin-bottom: 0.5rem; }
#editor-body li { margin-bottom: 0.15rem; }
#editor-body strong { font-weight: 600; }
#editor-body code {
  font-family: 'Courier New', monospace;
  font-size: 0.81rem;
  background: #f0ede8;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}
#editor-body a { color: #1c3d7a; text-underline-offset: 2px; }

/* UCI (tracked changes / redline) mode */
#editor-body.uci-mode ins {
  background: #dcfce7;
  color: #15803d;
  text-decoration: none;
  border-radius: 2px;
}
#editor-body.uci-mode del {
  background: #fee2e2;
  color: #b91c1c;
  text-decoration: line-through;
  border-radius: 2px;
}

/* Per-section priority badges */
.priority-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1;
  margin-right: 0.3rem;
  vertical-align: middle;
  cursor: help;
  user-select: none;
  flex-shrink: 0;
}
.priority-badge[data-priority="1"] { background: #fee2e2; color: #b91c1c; }
.priority-badge[data-priority="2"] { background: #fef3c7; color: #92400e; }
.priority-badge[data-priority="3"] { background: #f0f0f0; color: #666; }

