:root {
  --chat-width: min(460px, 42vw);
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #fff;
  --text: #16181d;
  --muted: #6b7079;
  --line: #e0e4e9;
  --blue: #2563eb;
  --green: #14804a;
  --red: #b42318;
  --amber: #9a5b05;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

button {
  display: inline-flex;
  min-height: 38px;
  padding: 0 13px;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd1d8;
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

button.compact {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  font-weight: 400;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid #cbd1d8;
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 104px;
  resize: vertical;
  line-height: 1.5;
}

:is(button, input, select, textarea):focus-visible {
  outline: 3px solid rgb(37 99 235 / 18%);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

a {
  color: var(--blue);
}

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

h1 {
  font-size: 18px;
}

h2 {
  font-size: 23px;
}

h3 {
  margin-bottom: 8px;
  font-size: 14px;
}

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

.helper {
  font-size: 12px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
}

.header-inner {
  display: grid;
  grid-template-columns: auto minmax(240px, 520px) auto;
  max-width: 1440px;
  margin: auto;
  padding: 14px 24px;
  align-items: center;
  gap: 24px;
}

.search {
  background: var(--bg);
}

.toolbar,
.toolbar-actions,
.tabs,
.review-lanes,
.pill-row,
.source-links,
.review-verdicts,
.submit-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-avatar {
  width: 34px;
  height: 34px;
  justify-self: end;
  font-size: 12px;
  font-weight: 700;
}

.field,
.quality-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.page {
  width: min(1180px, calc(100% - 40px));
  margin: auto;
  padding: 28px 0 64px;
}

.loading-page {
  display: grid;
  min-height: calc(100vh - 63px);
  padding: 40px 20px;
  place-items: center;
}

.loading-content {
  display: grid;
  max-width: 420px;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #dbe3f1;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

body.initial-load .search,
body.initial-load .profile-avatar {
  visibility: hidden;
}

.queue-header,
.candidate-list {
  display: grid;
}

.queue-header {
  gap: 15px;
  margin-bottom: 18px;
}

.tabs {
  border-bottom: 1px solid var(--line);
}

.review-lanes {
  display: flex;
  width: fit-content;
  padding: 4px;
  gap: 4px;
  border-radius: 10px;
  background: #eef0f3;
}

.lane {
  padding: 7px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.lane.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(20 25 35 / 10%);
}

.tab {
  padding: 0 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  border-bottom-color: var(--text);
  color: var(--text);
}

.count,
.filter-count,
.pill {
  border-radius: 999px;
  font-size: 12px;
}

.count {
  padding: 2px 7px;
  background: #eef0f3;
}

.toolbar,
.submit-row {
  justify-content: space-between;
  gap: 16px;
}

.sort-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.sort-field select {
  min-width: 170px;
}

.filter-count {
  padding: 1px 6px;
  background: var(--text);
  color: white;
}

.filter-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  padding: 14px;
  align-items: end;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.candidate-list {
  gap: 12px;
}

.candidate-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.candidate-card.expanded,
.candidate-card.chat-selected {
  border-color: #8cacef;
}

.candidate-card.chat-selected {
  box-shadow: 0 0 0 2px rgb(37 99 235 / 10%);
}

.card-chat-select {
  position: absolute;
  top: 25px;
  left: 18px;
  z-index: 2;
  width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 16px;
}

.card-chat-select[aria-pressed="true"] {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.card-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  width: 100%;
  padding: 17px 18px 17px 60px;
  align-items: start;
  gap: 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  font-weight: 400;
}

.person-avatar {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 50%;
  background: #eef1f5;
  color: #445064;
}

.card-body {
  min-width: 0;
}

.card-title {
  display: block;
  margin: 5px 0;
  font-size: 16px;
}

.card-context,
.pill-row,
.source-links,
.review-verdicts {
  flex-wrap: wrap;
}

.card-context {
  display: flex;
  margin-bottom: 9px;
  gap: 5px 12px;
  color: var(--muted);
  font-size: 13px;
}

.card-evidence {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card-side {
  display: grid;
  justify-items: end;
  gap: 9px;
}

.pill {
  padding: 2px 8px;
  background: #eff1f4;
  color: #4e5560;
}

.pill.signal {
  background: #eef4ff;
  color: #2855a2;
}

.pill.valid {
  background: #eaf8f0;
  color: var(--green);
}

.pill.false {
  background: #fff0ee;
  color: var(--red);
}

.pill.missing {
  background: #fff6e8;
  color: var(--amber);
}

.chevron {
  color: var(--muted);
  font-size: 18px;
}

.expanded .chevron {
  transform: rotate(180deg);
}

.card-details {
  display: grid;
  padding: 18px 18px 18px 78px;
  gap: 18px;
  border-top: 1px solid var(--line);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 22px;
}

.evidence-list {
  margin: 0;
  padding-left: 18px;
}

.evidence-list li {
  margin-bottom: 8px;
  color: #343941;
  line-height: 1.5;
}

.evidence-list.supporting li::marker {
  color: var(--green);
}

.signal-metadata {
  display: flex;
  margin: 4px 0;
  flex-wrap: wrap;
  gap: 4px 12px;
  color: var(--muted);
  font-size: 12px;
}

.quality-panel,
.review-summary {
  padding: 16px;
  border: 1px solid #cfdbf2;
  border-radius: 13px;
  background: #f8faff;
}

.review-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.decision-field {
  width: min(220px, 45%);
}

.signal-reviews {
  margin: 12px 0;
}

.signal-review {
  display: grid;
  grid-template-columns: 1fr minmax(190px, 42%);
  padding: 10px 0;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #dce5f4;
}

.signal-review:last-child {
  border-bottom: 0;
}

.error {
  margin-top: 7px;
  color: var(--red);
  font-size: 12px;
}

.review-summary {
  display: grid;
  gap: 12px;
  border-color: #cfe6d8;
  background: #f8fcfa;
}

.review-note {
  padding-top: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.empty {
  padding: 72px 20px;
  color: var(--muted);
  text-align: center;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: none;
  padding: 11px 14px;
  border-radius: 10px;
  background: #1c222c;
  color: white;
}

.toast.show {
  display: block;
}

.chat-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  min-height: 48px;
  padding: 0 17px;
  gap: 9px;
  border-color: #1c4fc7;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  box-shadow: 0 10px 30px rgb(24 46 91 / 24%);
}

.chat-launcher.has-selection {
  box-shadow: 0 10px 30px rgb(24 46 91 / 24%), 0 0 0 4px rgb(37 99 235 / 12%);
}

body.dragging-candidates .chat-launcher,
body.dragging-candidates .chat-panel {
  outline: 4px solid rgb(37 99 235 / 28%);
  outline-offset: 4px;
}

body.dragging-candidates .chat-launcher {
  transform: translateY(-4px) scale(1.04);
}

.chat-launcher svg {
  width: 21px;
  fill: none;
  stroke: currentcolor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  width: var(--chat-width);
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.chat-header {
  display: flex;
  padding: 18px;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.chat-header h2 {
  font-size: 18px;
}

.chat-heading-row,
.chat-header-actions,
.chat-compose-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-heading-row {
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.chat-header-actions {
  flex-shrink: 0;
}

.chat-scope {
  display: flex;
  margin-top: 9px;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-scope-chip {
  min-height: 28px;
  padding: 3px 8px;
  gap: 6px;
  border-color: #bfd0f5;
  border-radius: 999px;
  background: #eef4ff;
  color: #2855a2;
  font-size: 11px;
}

.chat-scope-chip span {
  font-size: 15px;
  line-height: 1;
}

.chat-messages {
  display: flex;
  min-height: 0;
  padding: 20px 18px 10px;
  overflow-y: auto;
  flex-direction: column;
  gap: 13px;
}

.chat-message {
  display: grid;
  max-width: 88%;
  padding: 11px 13px;
  gap: 5px;
  border-radius: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-message.user {
  align-self: end;
  background: var(--blue);
  color: white;
}

.chat-message.assistant {
  align-self: start;
  border: 1px solid var(--line);
  background: var(--bg);
}

.chat-message.error-message {
  align-self: start;
  border: 1px solid #f0c8c3;
  background: #fff7f6;
  color: var(--red);
}

.chat-message-meta {
  color: inherit;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.7;
}

.chat-thinking {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chat-thinking span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentcolor;
  animation: chat-pulse 1s infinite ease-in-out;
  opacity: 0.45;
}

.chat-thinking span:nth-child(2) {
  animation-delay: 120ms;
}

.chat-thinking span:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes chat-pulse {
  50% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

.chat-welcome {
  display: grid;
  padding: 4px 18px 16px;
  gap: 7px;
}

.chat-suggestions {
  display: grid;
  margin-top: 7px;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.chat-suggestions button {
  min-height: 54px;
  padding: 9px 10px;
  justify-content: start;
  color: #34435c;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
}

.chat-form {
  display: grid;
  padding: 14px 18px 18px;
  gap: 9px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.chat-form textarea {
  min-height: 82px;
  resize: none;
}

.chat-compose-row {
  justify-content: space-between;
}

body.chat-open .page,
body.chat-open .app-header {
  padding-right: calc(var(--chat-width) + 24px);
}

@media (max-width: 720px) {
  .header-inner {
    grid-template-columns: 1fr auto;
    padding: 14px;
    gap: 8px;
  }

  .search {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .page {
    width: calc(100% - 24px);
    padding-top: 20px;
  }

  .toolbar,
  .submit-row {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    display: grid;
  }

  .sort-field,
  .sort-field select {
    width: 100%;
  }

  .filter-panel,
  .detail-grid,
  .signal-review {
    grid-template-columns: 1fr;
  }

  .review-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .decision-field {
    width: 100%;
  }

  .card-summary {
    grid-template-columns: auto 1fr;
    padding: 15px 15px 15px 56px;
  }

  .card-chat-select {
    top: 23px;
    left: 14px;
  }

  .card-side {
    grid-column: 2;
    justify-items: start;
  }

  .card-details {
    padding: 18px 15px 15px;
  }

  .chat-launcher {
    right: 12px;
    bottom: 12px;
  }

  .chat-panel {
    width: 100%;
    border-left: 0;
  }

  .chat-header {
    padding: 14px;
  }

  .chat-header-actions {
    gap: 0;
  }

  .chat-messages {
    padding-right: 14px;
    padding-left: 14px;
  }

  .chat-welcome,
  .chat-form {
    padding-right: 14px;
    padding-left: 14px;
  }

  .chat-suggestions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner,
  .chat-thinking span {
    animation: none;
  }
}

.chat-message-content > :first-child { margin-top: 0; }
.chat-message-content > :last-child { margin-bottom: 0; }
.chat-message-content p,
.chat-message-content ul,
.chat-message-content ol { margin: 0 0 0.75em; }
.chat-message-content ul,
.chat-message-content ol { padding-left: 1.5em; }
.chat-message-content h1,
.chat-message-content h2,
.chat-message-content h3,
.chat-message-content h4,
.chat-message-content h5,
.chat-message-content h6 {
  margin: 0.75em 0 0.35em;
  font-size: 1em;
  line-height: 1.3;
}
.chat-message-content a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 900px) {
  body.chat-open .page,
  body.chat-open .app-header {
    padding-right: 0;
  }

  .chat-panel {
    width: 100%;
  }
}
