:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9dee5;
  --brand: #294c7a;
  --brand-strong: #16365c;
  --soft: #edf3fa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.chat-home {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #111111;
  --muted: #6f7785;
  --line: #dedede;
  --brand: #2e5339;
  --brand-strong: #1f3a28;
  --soft: #eaf0ec;
  --accent: #2e5339;
  --accent-hover: #24422d;
  --accent-tint: #eaf0ec;
  --accent-text: #1f3a28;
  --accent-border: rgba(46, 83, 57, 0.35);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.ingestion-page { --ingestion: #2e5339; background: #f7f7f5; }
.ingestion-shell { width: min(980px, calc(100% - 32px)); margin: 0 auto; padding: 48px 0 72px; }
.ingestion-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.ingestion-header h1 { margin: 10px 0 6px; font-size: clamp(28px, 4vw, 42px); }
.ingestion-header p, .ingestion-feed p { color: var(--muted); }
.back-link { color: var(--ingestion); font-weight: 600; text-decoration: none; }
.ingestion-status { color: var(--muted); white-space: nowrap; font-size: 13px; padding-top: 20px; }
#liveDot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #3d8b58; margin-right: 6px; }
.ingestion-note { background: #eaf0ec; border-left: 4px solid var(--ingestion); padding: 14px 16px; border-radius: 4px; margin-bottom: 18px; }
.ingestion-feeds { display: grid; gap: 14px; }
.ingestion-feed { background: white; border: 1px solid #dedede; border-radius: 10px; padding: 20px; }
.ingestion-feed.planned { opacity: .7; }
.ingestion-feed-top { display: flex; justify-content: space-between; gap: 16px; }
.ingestion-feed h2 { font-size: 17px; margin-bottom: 4px; }
.feed-state { align-self: flex-start; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 600; background: #eaf0ec; color: #1f3a28; }
.progress-track { height: 8px; background: #edf0ed; border-radius: 20px; overflow: hidden; margin: 18px 0 7px; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--ingestion); transition: width .3s ease; }
.progress-caption { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; }
.progress-caption strong { color: var(--ink); }
.ingestion-feed dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0 0; padding-top: 14px; border-top: 1px solid #eee; }
.ingestion-feed dt { color: var(--muted); font-size: 12px; }.ingestion-feed dd { margin: 2px 0 0; font-weight: 600; }
@media (max-width: 620px) { .ingestion-header { display: block; }.ingestion-status { padding-top: 14px; }.ingestion-feed dl { grid-template-columns: 1fr; } }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  letter-spacing: 0;
}

.topbar p,
.muted {
  color: var(--muted);
}

nav {
  display: flex;
  gap: 8px;
}

.nav-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  text-decoration: none;
}

.nav-link:hover {
  border-color: var(--brand);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 12px;
}

button:hover {
  border-color: var(--brand);
}

button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.55;
}

.tab.active,
.toolbar button {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

main {
  padding: 20px 28px 28px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 22px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 320px;
}

.members-panel {
  overflow: hidden;
}

.toolbar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: white;
}

textarea {
  resize: vertical;
}

.member-list {
  max-height: calc(100vh - 238px);
  overflow: auto;
}

.member-item {
  width: 100%;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 10px 12px;
}

.member-item.active {
  background: var(--soft);
}

.member-item img,
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--soft);
}

.member-name {
  font-weight: 700;
}

.member-meta {
  color: var(--muted);
  font-size: 13px;
}

.detail {
  padding: 18px;
}

.profile-head {
  display: flex;
  gap: 14px;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.profile-head .avatar {
  width: 72px;
  height: 72px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.section {
  min-width: 0;
}

.section h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.role-groups {
  display: grid;
  gap: 12px;
}

.role-section {
  display: grid;
  gap: 7px;
}

.role-section h4 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 8px;
}

.section-head h3 {
  margin: 0;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.pager button {
  padding: 5px 8px;
}

.pill-list,
.interest-list,
.contrib-list {
  display: grid;
  gap: 8px;
}

.pill,
.interest,
.contribution {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.pill-type {
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.interest {
  font-size: 14px;
}

.contribution p {
  margin: 6px 0 8px;
}

.contribution a {
  color: var(--brand-strong);
  font-weight: 700;
  text-decoration: none;
}

.search-panel,
.ask-panel {
  grid-column: 1 / -1;
  padding-bottom: 12px;
}

.search-meta {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px 0;
}

.search-panel .contrib-list {
  padding: 12px;
}

.ask-panel {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
}

.ask-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 160px minmax(160px, auto) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.ask-filters label,
.chat-composer label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.scope-chip {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
}

.scope-chip button {
  padding: 3px 7px;
  margin-left: 4px;
}

.ask-filters > button,
.chat-composer button {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

.ask-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  min-height: 360px;
  overflow: hidden;
}

.ask-body:has(.ask-member-panel.hidden) {
  grid-template-columns: minmax(0, 1fr) 0;
}

.chat-thread {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
  max-height: calc(100vh - 310px);
  overflow: auto;
}

.chat-message {
  display: flex;
}

.user-message {
  justify-content: flex-end;
}

.assistant-message {
  justify-content: flex-start;
}

.message-bubble {
  max-width: min(840px, 86%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}

.user-message .message-bubble {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

.assistant-message .message-bubble {
  display: grid;
  gap: 10px;
}

.message-details {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.message-details summary {
  color: var(--brand-strong);
  cursor: pointer;
  font-weight: 700;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.answer-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
}

.answer-box p {
  margin: 0 0 12px;
}

.answer-box p:last-child {
  margin-bottom: 0;
}

.answer-section {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.answer-section:last-child {
  margin-bottom: 0;
}

.answer-section h3 {
  margin: 0;
  color: var(--brand);
  font-size: 14px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mp-name-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent-text, var(--brand-strong));
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 0;
  text-decoration: underline;
}

.ask-member-panel {
  border-left: 1px solid var(--line);
  background: #f8fafc;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  transform: translateX(0);
  transition: transform 160ms ease;
  overflow: hidden;
}

.ask-member-panel.hidden {
  display: block;
  transform: translateX(100%);
  pointer-events: none;
  visibility: hidden;
}

.ask-member-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.ask-member-panel-head > div {
  display: grid;
  gap: 2px;
}

.ask-member-panel-head button {
  width: 32px;
  height: 32px;
  padding: 0;
}

.ask-member-cards {
  display: grid;
  gap: 10px;
  align-content: start;
  overflow: auto;
  padding: 12px;
}

.ask-member-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
}

.ask-member-card.pulse {
  animation: cardPulse 900ms ease;
}

.ask-member-card-head {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.ask-member-card-head img {
  width: 48px;
  height: 48px;
  border: 3px solid var(--line);
  border-radius: 999px;
  object-fit: cover;
  background: #eef2f7;
}

.ask-member-card-head div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.ask-member-card-head span {
  color: var(--muted);
  font-size: 12px;
}

.ask-member-card-section {
  display: grid;
  gap: 4px;
}

.ask-member-card a {
  color: var(--brand-strong);
  font-weight: 800;
  text-decoration: none;
}

@keyframes cardPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(47, 74, 122, 0.38);
  }
  100% {
    box-shadow: 0 0 0 12px rgba(47, 74, 122, 0);
  }
}

/* Chat-first homepage */

.chat-home {
  height: 100vh;
  overflow: hidden;
  background: #f7f8fb;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  display: grid;
  gap: 18px;
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 24px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

.auth-brand {
  display: grid;
  gap: 3px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  border-radius: 8px;
  background: var(--soft);
  padding: 4px;
}

.auth-tabs button {
  border: 0;
  background: transparent;
  font-weight: 800;
}

.auth-tabs button.active {
  background: #fff;
  color: var(--accent-text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-name-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.auth-error {
  border: 1px solid #f3c15f;
  border-radius: 8px;
  background: #fff8e6;
  color: #7a4a00;
  padding: 10px 12px;
}

.chat-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 0px;
  height: 100vh;
  min-height: 0;
  transition: grid-template-columns 220ms ease;
}

.chat-shell.rail-open {
  grid-template-columns: 220px minmax(0, 1fr) 320px;
}

.chat-sidebar,
.sources-panel,
.mp-profile-panel {
  background: #fff;
  border-color: var(--line);
}

.chat-sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 16px;
  padding: 18px;
  border-right: 1px solid var(--line);
  min-height: 0;
}

.chat-brand h1 {
  font-size: 22px;
}

.chat-brand p,
.sources-head p {
  color: var(--muted);
  font-size: 13px;
}

.primary-action {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
  font-weight: 800;
}

.primary-action:hover,
.home-input-row button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.chat-history {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
}

.chat-history h2 {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.chat-history-list {
  display: grid;
  gap: 6px;
  align-content: start;
  overflow: auto;
}

.chat-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  border-radius: 8px;
}

.chat-history-item,
.chat-history-edit,
.side-nav {
  display: grid;
  gap: 2px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 9px 10px;
  text-align: left;
  text-decoration: none;
}

.chat-history-row:hover,
.chat-history-row.active,
.side-nav:hover {
  background: var(--soft);
}

.chat-history-row .chat-history-item:hover {
  background: transparent;
}

.chat-history-edit {
  padding: 7px 10px;
}

.chat-title-input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 2px 5px;
}

.chat-history-item span,
.chat-history-edit span,
.side-nav span {
  color: var(--muted);
  font-size: 12px;
}

.chat-edit-button,
.chat-delete-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-right: 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  opacity: 0;
  padding: 0;
}

.chat-history-row:hover .chat-edit-button,
.chat-history-row:hover .chat-delete-button,
.chat-edit-button:focus-visible,
.chat-delete-button:focus-visible {
  opacity: 1;
}

.chat-edit-button:hover,
.chat-delete-button:hover {
  background: rgba(46, 83, 57, 0.12);
  color: var(--accent-text);
}

.side-nav.disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.chat-sidebar-footer {
  display: grid;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.admin-nav {
  display: grid;
  gap: 4px;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.admin-nav p {
  margin: 0 10px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.data-freshness {
  display: grid;
  gap: 2px;
  margin: 0 0 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}

.data-freshness strong { color: var(--ink); font-size: 12px; }
.data-freshness.updating strong { color: var(--accent); }
.data-freshness.error { background: #fff5f5; }

.freshness-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.42);
}

.freshness-modal.hidden { display: none; }

.freshness-dialog {
  width: min(480px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 0;
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.24);
}
.freshness-dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.freshness-dialog-head h2 { font: 600 18px/1.2 "Source Serif 4", Georgia, serif; }
.freshness-dialog-head button { border: 0; padding: 0 4px; font-size: 24px; line-height: 1; }
.freshness-dialog-content { padding: 20px; }
.freshness-stage { margin-bottom: 16px; color: var(--accent-text); font-weight: 700; }
.freshness-progress { display: grid; gap: 6px; margin: 0 0 18px; padding: 12px; border-radius: 8px; background: var(--soft); }
.freshness-progress div { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.freshness-progress progress { width: 100%; height: 9px; accent-color: var(--accent); }
.freshness-progress small { color: var(--muted); }
.freshness-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; }
.freshness-details div { min-width: 0; }
.freshness-details dt { color: var(--muted); font-size: 11px; }
.freshness-details dd { margin: 2px 0 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 600; }
.freshness-error { margin: 16px 0 0; border-radius: 6px; background: #fff5f5; color: #8a1c1c; padding: 10px; font-size: 12px; }

.account-chip {
  display: grid;
  gap: 2px;
  padding: 2px 10px 8px;
}

.account-chip strong {
  font-size: 13px;
}

.account-chip span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-main {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.mobile-chat-topbar {
  display: none;
}

.home-chat-thread {
  display: grid;
  align-content: start;
  gap: 34px;
  overflow: auto;
  padding: 32px max(40px, calc((100% - 860px) / 2)) 32px max(24px, calc((100% - 860px) / 2));
  min-height: 0;
  scrollbar-color: rgba(46, 83, 57, 0.34) transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.home-chat-thread::-webkit-scrollbar {
  width: 10px;
}

.home-chat-thread::-webkit-scrollbar-track {
  background: transparent;
}

.home-chat-thread::-webkit-scrollbar-thumb {
  background: rgba(46, 83, 57, 0.28);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

.home-chat-thread::-webkit-scrollbar-thumb:hover {
  background: rgba(46, 83, 57, 0.45);
  border: 3px solid transparent;
  background-clip: content-box;
}

.home-empty {
  align-self: center;
  justify-self: center;
  display: grid;
  gap: 8px;
  max-width: 520px;
  color: var(--muted);
  text-align: center;
}

.home-empty h2 {
  color: var(--ink);
  font-size: 32px;
}

.home-message {
  display: flex;
  padding-block: 2px;
}

.home-message.user {
  justify-content: flex-end;
}

.home-message.assistant {
  justify-content: flex-start;
}

.home-bubble {
  max-width: min(760px, 88%);
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 18px;
  line-height: 1.55;
  margin: -14px -16px;
  padding: 13px 15px;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.home-message.user .home-bubble {
  background: transparent;
}

.home-message:hover .home-bubble {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.home-message.selected .home-bubble {
  border-color: var(--accent-border);
  background: var(--accent-tint);
  color: var(--ink);
  box-shadow: none;
}

.home-message.error .home-bubble {
  border-color: #f3c15f;
  background: #fff8e6;
  color: #7a4a00;
}

.home-answer-section {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.home-answer-section:last-child,
.home-bubble p:last-child {
  margin-bottom: 0;
}

.home-answer-section h3 {
  margin: 0;
  color: var(--accent-text);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
}

.home-bubble p {
  margin: 0 0 12px;
}

.home-citation {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 900;
  padding: 0 1px;
}

.typed-citation {
  display: inline-flex;
  align-items: center;
  min-width: 24px;
  min-height: 18px;
  justify-content: center;
  border: 1px solid currentColor;
  border-radius: 5px;
  padding: 0 4px;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 900;
  line-height: 16px;
  letter-spacing: 0.02em;
  vertical-align: 1px;
}

.citation-type-contribution { color: #175cd3; background: #eff8ff; }
.citation-type-written-question { color: #6941c6; background: #f4f3ff; }
.citation-type-division { color: #b42318; background: #fef3f2; }
.citation-type-edm { color: #027a48; background: #ecfdf3; }
.citation-type-legislation { color: #b54708; background: #fffaeb; }
.citation-type-profile { color: #0e7090; background: #ecfdff; }

.home-composer {
  display: grid;
  padding: 14px max(24px, calc((100% - 860px) / 2)) 18px;
  background: rgba(247, 248, 251, 0.95);
  border-top: 1px solid var(--line);
}

.home-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.home-input-row textarea {
  min-height: 54px;
  resize: none;
}

.chat-home .home-input-row textarea:focus,
.chat-home button:focus-visible,
.chat-home a:focus-visible {
  border-color: var(--accent);
  outline: 3px solid var(--accent-border);
  outline-offset: 2px;
}

.home-input-row button {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 800;
}

.right-rail {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.chat-shell:not(.rail-open) .right-rail {
  border-left: 0;
}

.sources-panel,
.mp-profile-panel {
  position: absolute;
  inset: 0;
  width: 320px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
}

.mp-profile-panel {
  transform: translateX(100%);
  transition: transform 220ms ease;
  z-index: 2;
}

.mp-profile-panel.open {
  transform: translateX(0);
}

.sources-head,
.mp-profile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.sources-head button {
  display: none;
}

.sources-head .rail-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.mp-profile-back {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 6px 10px;
  font-weight: 700;
  cursor: pointer;
}

.reopen-sources-tab {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 20;
  writing-mode: vertical-rl;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  padding: 14px 8px;
  cursor: pointer;
  box-shadow: -4px 0 10px rgba(15, 23, 42, 0.08);
}

.reopen-sources-tab.hidden {
  display: none;
}

.mp-profile-content {
  display: grid;
  gap: 18px;
  align-content: start;
  overflow: auto;
  padding: 16px;
}

.mp-profile-card {
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
}

.mp-profile-avatar {
  width: 84px;
  height: 84px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--soft);
}

.mp-profile-card h3 {
  font-size: 18px;
}

.mp-profile-content h4 {
  margin-bottom: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.sources-content {
  display: grid;
  gap: 18px;
  align-content: start;
  overflow: auto;
  padding: 16px;
}

.sources-content h3 {
  margin-bottom: 10px;
  font-size: 14px;
}

.home-source-list,
.mentioned-mp-list {
  display: grid;
  gap: 10px;
}

.home-source-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.home-source-card.selected,
.mentioned-mp-card.selected {
  border-color: var(--accent-border);
  background: var(--accent-tint);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

.home-source-card.source-card-contribution { border-left: 3px solid #175cd3; }
.home-source-card.source-card-written-question { border-left: 3px solid #6941c6; }
.home-source-card.source-card-division { border-left: 3px solid #b42318; }
.home-source-card.source-card-edm { border-left: 3px solid #027a48; }
.home-source-card.source-card-legislation { border-left: 3px solid #b54708; }
.home-source-card.source-card-profile { border-left: 3px solid #0e7090; }

.source-marker {
  color: var(--accent, var(--brand-strong));
  font-size: 19px;
  font-weight: 900;
  line-height: 1;
}

.home-source-card p {
  margin: 6px 0;
  color: #344054;
  font-size: 13px;
}

.home-source-card a {
  color: var(--brand-strong);
  font-weight: 800;
  text-decoration: none;
}

.mentioned-mp-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.mentioned-mp-card img {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--soft);
}

.mentioned-mp-card div {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.mentioned-mp-card span {
  color: var(--muted);
  font-size: 12px;
}

.drawer-backdrop,
.sources-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.42);
}

.drawer-backdrop.hidden,
.sources-backdrop.hidden {
  display: none;
}

.citation {
  color: var(--brand-strong);
  font-weight: 800;
  text-decoration: none;
}

.citation.missing {
  color: #9a3412;
}

.warnings {
  display: grid;
  gap: 6px;
  border: 1px solid #f3c15f;
  border-radius: 8px;
  background: #fff8e6;
  color: #7a4a00;
  padding: 10px 12px;
  font-weight: 700;
}

.source-list {
  display: grid;
  gap: 8px;
}

.source-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.source-item p {
  margin: 6px 0 8px;
}

.source-item a {
  color: var(--brand-strong);
  font-weight: 700;
  text-decoration: none;
}

.ask-stats {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  padding-top: 10px;
}

.compact {
  padding: 8px 0;
}

.hidden {
  display: none;
}

.empty,
.error,
.loading {
  padding: 18px;
  color: var(--muted);
}

/* ── Clusters ─────────────────────────────────────────────────────────────── */

.clusters-panel {
  grid-column: 1 / -1;
  padding-bottom: 12px;
}

.clusters-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.clusters-toolbar input {
  flex: 1;
}

.clusters-toolbar select {
  width: auto;
}

.cluster-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
}

.cluster-empty {
  grid-column: 1 / -1;
  padding: 18px;
  color: var(--muted);
}

.cluster-card {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel);
  cursor: pointer;
  text-align: left;
}

.cluster-card:hover {
  border-color: var(--brand);
}

.cluster-card.active {
  border-color: var(--brand);
  background: var(--soft);
}

.cluster-label {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 5px;
}

.cluster-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.cluster-bar-track {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.cluster-bar-fill {
  height: 100%;
  background: var(--brand);
  border-radius: 2px;
}

.cluster-detail {
  grid-column: 1 / -1;
  background: var(--soft);
  border: 1px solid var(--brand);
  border-radius: 8px;
  padding: 18px;
}

.cluster-detail h3 {
  margin-bottom: 5px;
}

.cluster-detail-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.cluster-detail-desc {
  margin: 0 0 14px;
}

.cluster-detail .contrib-list {
  margin-top: 12px;
}

@media (max-width: 1060px) {
  .cluster-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

/* ── Map ──────────────────────────────────────────────────────────────────── */

.map-panel {
  grid-column: 1 / -1;
  padding: 0;
  overflow: hidden;
}

.map-controls {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.map-filter-wrap {
  position: relative;
  max-width: 480px;
}

.map-filter-wrap input {
  padding-right: 42px;
}

.map-party-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}

.map-party-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.map-party-controls button {
  padding: 5px 8px;
}

.map-party-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.map-party-option input {
  width: auto;
  margin: 0;
}

.map-filter-clear {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
}

.map-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 12;
  display: grid;
  gap: 4px;
  max-height: 320px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(23, 32, 42, 0.14);
}

.map-suggestion-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
}

.map-suggestion-item:hover {
  background: var(--soft);
}

.map-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 72vh;
}

.map-canvas-wrap {
  position: relative;
  min-height: 72vh;
  background: #1a1a2e;
}

.map-canvas {
  display: block;
  width: 100%;
  height: 72vh;
  background: #1a1a2e;
}

.map-loading {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 8;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(8, 12, 24, 0.85);
  color: #f8fafc;
  padding: 9px 14px;
  backdrop-filter: blur(8px);
}

.map-tooltip {
  position: absolute;
  z-index: 9;
  min-width: 180px;
  max-width: 260px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(10, 14, 28, 0.94);
  color: #f8fafc;
  padding: 10px 12px;
  pointer-events: none;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

.map-tooltip strong {
  display: block;
  margin-bottom: 4px;
}

.map-legend {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 8;
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(10, 14, 28, 0.82);
  color: #e5e7eb;
  font-size: 12px;
  backdrop-filter: blur(8px);
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.map-side-panel {
  width: 300px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
  overflow: auto;
}

.map-side-head {
  position: relative;
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.map-side-close {
  position: absolute;
  top: 0;
  right: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
}

.map-side-avatar {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--soft);
}

.map-view-profile {
  display: inline-block;
  margin-top: 16px;
  color: var(--brand-strong);
  font-weight: 700;
  text-decoration: none;
}

/* ──────────────────────────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout,
  .profile-grid {
    grid-template-columns: 1fr;
  }

  .ask-filters,
  .chat-composer {
    grid-template-columns: 1fr;
  }

  .ask-body,
  .ask-body:has(.ask-member-panel.hidden) {
    grid-template-columns: 1fr;
  }

  .ask-member-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 360px;
  }

  .member-list {
    max-height: 420px;
  }

  .map-shell {
    grid-template-columns: 1fr;
  }

  .map-side-panel {
    width: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 768px) {
  .drawer-backdrop:not(.hidden),
  .sources-backdrop:not(.hidden) {
    display: block;
  }

  .chat-home {
    height: 100dvh;
  }

  .chat-shell {
    display: grid;
    grid-template-columns: 1fr;
    height: 100dvh;
  }

  .chat-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 45;
    width: min(82vw, 320px);
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 18px 0 36px rgba(15, 23, 42, 0.18);
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  .chat-main {
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100dvh;
  }

  .mobile-chat-topbar {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: #fff;
  }

  .mobile-chat-topbar strong {
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .home-chat-thread {
    padding: 18px 12px;
  }

  .home-empty h2 {
    font-size: 26px;
  }

  .home-bubble {
    max-width: 94%;
  }

  .home-composer {
    padding: 10px 12px 12px;
  }

  .chat-shell.rail-open {
    grid-template-columns: 1fr;
  }

  .right-rail {
    display: contents;
  }

  .sources-panel,
  .mp-profile-panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    z-index: 50;
    height: min(70dvh, 620px);
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    transform: translateY(104%);
    transition: transform 180ms ease;
    box-shadow: 0 -18px 40px rgba(15, 23, 42, 0.2);
  }

  .mp-profile-panel {
    z-index: 55;
  }

  .sources-panel.open,
  .mp-profile-panel.open {
    transform: translateY(0);
  }

  .sources-head,
  .mp-profile-head {
    padding: 14px 16px;
  }

  .sources-head button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
  }

  .sources-head .rail-collapse-btn,
  .reopen-sources-tab {
    display: none;
  }

  .sources-content {
    padding: 14px;
  }
}
