:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-strong: #fdf8ea;
  --text: #202322;
  --muted: #66706c;
  --line: #dce1dc;
  --accent: #0f766e;
  --accent-strong: #0b5e58;
  --warn: #b45309;
  --danger: #a33b3b;
  --shadow: 0 12px 40px rgba(39, 48, 44, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 76px;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dataset-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.dataset-option {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.dataset-option.active {
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent-strong);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  max-width: 920px;
  font-size: 22px;
  line-height: 1.25;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

.thread-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
}

.filters {
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.input,
.select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

.input:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.thread-list {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.thread-item {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.thread-item:hover {
  background: #fff;
  border-color: var(--line);
}

.thread-item.active {
  background: var(--panel);
  border-color: rgba(15, 118, 110, 0.36);
  box-shadow: var(--shadow);
}

.thread-title {
  font-weight: 750;
  line-height: 1.25;
}

.thread-subtitle,
.thread-date {
  color: var(--muted);
  font-size: 12px;
}

.thread-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 180px;
  border: 1px solid rgba(15, 118, 110, 0.25);
  border-radius: 999px;
  color: var(--accent-strong);
  background: rgba(15, 118, 110, 0.08);
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pager {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.detail-panel {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.detail-view {
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  gap: 18px;
}

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

.summary-band,
.link-panel,
.submission-panel,
.evidence {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.summary-band {
  padding: 18px;
  background: var(--panel-strong);
}

.summary-band p {
  margin: 0;
  color: #303833;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.fact-grid > div {
  min-height: 76px;
  display: grid;
  align-content: start;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.fact-grid span,
.linked-row span,
.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.fact-grid strong,
.linked-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.link-panel {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.submission-panel {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-title strong {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.review-action-summary {
  display: grid;
  gap: 8px;
}

.action-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.action-summary-grid > div {
  min-height: 72px;
  display: grid;
  align-content: start;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.action-summary-grid span,
.action-summary-grid small {
  color: var(--muted);
  font-size: 12px;
}

.action-summary-grid strong {
  overflow-wrap: anywhere;
}

.risk-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.risk-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(176, 96, 39, 0.25);
  background: rgba(176, 96, 39, 0.08);
  color: #7c3f1d;
  font-size: 12px;
  font-weight: 700;
}

.risk-chip.low {
  border-color: rgba(15, 118, 110, 0.22);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent-strong);
}

.apply-report {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.report-block {
  min-width: 0;
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.report-block span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.report-block pre {
  max-height: 280px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  color: #303833;
}

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

.suggestion-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.suggestion-item,
.muted-box {
  min-height: 74px;
  display: grid;
  align-content: start;
  gap: 3px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
}

.suggestion-item.selectable {
  cursor: pointer;
}

.suggestion-item.selectable:hover {
  border-color: rgba(15, 118, 110, 0.45);
  background: rgba(15, 118, 110, 0.06);
}

.suggestion-item span,
.suggestion-item small,
.muted-box {
  color: var(--muted);
  font-size: 12px;
}

.suggestion-item strong {
  overflow-wrap: anywhere;
}

.form-grid {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 120px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
  font: inherit;
}

.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.linked-row {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.combo {
  position: relative;
}

.deal-results {
  position: absolute;
  z-index: 10;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.deal-option {
  width: 100%;
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.deal-option:hover,
.deal-option.selected {
  background: rgba(15, 118, 110, 0.08);
}

.deal-option small {
  color: var(--muted);
}

.action-row,
.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 750;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button.primary {
  background: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary {
  border-color: var(--line);
}

.button.secondary:hover,
.button.ghost:hover {
  background: #f0f3ef;
}

.button.ghost {
  color: var(--danger);
}

.evidence {
  padding: 14px 16px;
}

.evidence summary {
  cursor: pointer;
  font-weight: 750;
}

.evidence ul {
  margin: 12px 0 0;
  padding-left: 20px;
}

.evidence li + li {
  margin-top: 8px;
}

.empty-state {
  height: 100%;
  min-height: 420px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #202322;
  color: #fff;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

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

  .thread-panel {
    min-height: 420px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar,
  .detail-panel {
    padding: 16px;
  }

  .filters,
  .fact-grid {
    grid-template-columns: 1fr;
  }

  .detail-head,
  .linked-row {
    display: grid;
  }
}
