:root {
  --bg: #f6f7f9;
  --ink: #1c2430;
  --muted: #647084;
  --line: #d7dde7;
  --panel: #ffffff;
  --accent: #0f766e;
  --warn: #9a5b00;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 1px solid #0b5f59;
  background: var(--accent);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}

button.secondary {
  color: var(--accent);
  background: white;
}

.shell {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.workspace,
.qa,
.view,
.analysisWorkbench {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 17px;
}

.viewTabs {
  display: inline-flex;
  gap: 6px;
  width: fit-content;
  background: #e8edf3;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 16px;
}

.tabButton {
  border: 0;
  color: var(--muted);
  background: transparent;
  padding: 8px 14px;
}

.tabButton.active {
  color: white;
  background: var(--accent);
}

.view {
  display: none;
}

.view.active {
  display: grid;
}

.viewHeader {
  display: grid;
  gap: 4px;
}

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

.workspace {
  grid-template-columns: 1fr;
  align-items: start;
  min-width: 0;
}

.filters,
.panel,
.askBox {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

.filters,
.askBox {
  display: grid;
  gap: 12px;
}

.filters {
  position: sticky;
  top: 0;
  z-index: 5;
  width: 100%;
  max-width: 100%;
  grid-template-columns: minmax(260px, 2fr) minmax(150px, 1fr) minmax(140px, 1fr) minmax(140px, 1fr) 150px;
  align-items: end;
  box-shadow: 0 8px 18px rgba(31, 41, 55, 0.08);
}

.filters button {
  min-height: 38px;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

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

textarea {
  min-height: 72px;
  resize: vertical;
}

.panelHead {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.chunkList,
#criteria {
  display: grid;
  gap: 10px;
}

.tableWrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.clausesTable {
  width: 100%;
  min-width: 1780px;
  border-collapse: collapse;
}

.clausesTable th,
.clausesTable td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.clausesTable th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
}

.clausesTable tr:hover td {
  background: #fbfcfe;
}

.clausesTable tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
}

.strong {
  font-weight: 750;
  min-width: 180px;
}

.subtle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.smallCell {
  min-width: 260px;
  max-width: 360px;
  color: var(--muted);
}

.textCell {
  min-width: 360px;
  max-width: 520px;
  line-height: 1.4;
}

.tagCell {
  min-width: 190px;
}

.jsonCell {
  min-width: 240px;
  max-width: 320px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  color: #465466;
  white-space: pre-wrap;
  word-break: break-word;
}

.sourceCell {
  min-width: 112px;
}

.sourceCell .secondary {
  padding: 5px 8px;
  margin-bottom: 6px;
}

.sourceCell a {
  display: inline-block;
  margin-left: 6px;
}

.chunk {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}

.chunkTitle {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 750;
}

.meta,
.tags {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

.tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  margin: 4px 4px 0 0;
  background: #f9fafb;
}

.effect-exclusion {
  color: #b42318;
}

.effect-limit,
.effect-duty {
  color: var(--warn);
}

.excerpt {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.45;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.actions a,
.actions button {
  font-size: 13px;
}

.buttonRow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.analysisWorkbench {
  align-items: start;
  min-width: 0;
}

.analysisSearch {
  position: sticky;
  top: 0;
  z-index: 10;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr) minmax(170px, 220px) auto;
  align-items: end;
  box-shadow: 0 10px 24px rgba(31, 41, 55, 0.1);
}

.analysisSearch textarea {
  min-height: 58px;
  max-height: 118px;
}

.analysisSearch .buttonRow {
  align-content: end;
  justify-content: end;
  min-width: 210px;
}

.analysisSearch .buttonRow button {
  width: 100%;
  min-height: 38px;
}

.analysisBody {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.agentSidebar {
  position: sticky;
  top: 110px;
  max-height: calc(100vh - 130px);
  overflow: auto;
}

.agentSidebar .analysis {
  margin-bottom: 0;
}

.agentSidebar .agentSummary {
  grid-template-columns: 1fr;
}

.agentSidebar .agentSummary strong {
  font-size: 18px;
}

.agentSidebar .liveHead {
  display: grid;
  gap: 4px;
}

.agentSidebar .agentBuckets {
  gap: 8px;
}

.agentSidebar .agentBucket {
  padding: 10px;
}

.agentSidebar .bucketHead {
  display: grid;
}

.agentSidebar .chunkList {
  display: none;
}

.analysisMain {
  min-width: 0;
}

.answerPanel {
  overflow: hidden;
}

.qa {
  grid-template-columns: 420px 1fr;
  align-items: start;
}

.analysis {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
  line-height: 1.5;
  margin: 10px 0 18px;
}

.analysis table {
  width: 100%;
  border-collapse: collapse;
}

.analysis th,
.analysis td {
  border: 1px solid var(--line);
  padding: 7px;
  vertical-align: top;
}

.agentSummary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.agentSummary > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
}

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

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

.agentBuckets {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.liveAgent {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
  margin: 10px 0;
}

.liveHead {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.agentStepList {
  display: grid;
  gap: 8px;
  max-height: min(520px, calc(100vh - 260px));
  overflow: auto;
  margin: 0;
  padding-left: 22px;
}

.agentStepList.compact {
  max-height: 280px;
  margin-top: 10px;
}

.agentStep {
  border-left: 3px solid #cbd5e1;
  padding: 7px 0 7px 10px;
  color: #344054;
  font-size: 13px;
}

.agentStep.tool_call_start {
  border-left-color: var(--accent);
}

.agentStep.error {
  border-left-color: #b42318;
  color: #b42318;
}

.agentEventType {
  display: inline-block;
  min-width: 112px;
  color: var(--muted);
  font-weight: 750;
  text-transform: capitalize;
}

.agentArgs {
  margin-top: 5px;
  color: var(--muted);
  word-break: break-word;
}

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

.bucketHead {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

.bucketHead h3 {
  margin: 0;
  font-size: 15px;
}

.bucketStatus {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.bucketStatus.complete {
  background: #dcfce7;
  color: #166534;
}

.bucketStatus.incomplete {
  background: #fef3c7;
  color: #92400e;
}

.groupGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.groupPill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  font-size: 12px;
}

.groupPill.required {
  font-weight: 750;
}

.groupPill.found {
  border-color: #86efac;
  color: #166534;
}

.groupPill.missing {
  border-color: #fcd34d;
  color: #92400e;
}

.steps {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.missingBox {
  border: 1px solid #fcd34d;
  border-radius: 8px;
  background: #fffbeb;
  color: #92400e;
  padding: 10px;
  margin: 10px 0;
  font-size: 13px;
}

.retrievedTable {
  min-width: 1500px;
}

.comparisonTable {
  width: 100%;
  min-width: 1280px;
  border-collapse: collapse;
  background: white;
}

.comparisonTable th,
.comparisonTable td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  line-height: 1.45;
}

.comparisonTable th {
  position: sticky;
  top: 0;
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
}

.insurerFinding {
  border-bottom: 1px solid #eef2f7;
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.insurerFinding:last-child {
  border-bottom: 0;
  padding-bottom: 0;
  margin-bottom: 0;
}

.sourceLinks {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

button.mini {
  padding: 3px 7px;
  font-size: 12px;
  border-radius: 999px;
}

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

dialog {
  width: min(1100px, 92vw);
  max-height: 88vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: auto;
}

.dialogHead {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: white;
  border-bottom: 1px solid var(--line);
  padding: 12px;
}

#sourceBody {
  padding: 12px;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

mark {
  background: #fff1a8;
  padding: 0 2px;
}

.sourceHighlight {
  display: inline;
  background: #fff0a6;
  box-shadow: 0 0 0 2px rgba(154, 91, 0, 0.14);
}

@media (max-width: 900px) {
  .workspace,
  .qa,
  .filters,
  .analysisSearch,
  .analysisBody {
    grid-template-columns: 1fr;
  }

  .analysisSearch {
    position: static;
  }

  .analysisSearch .buttonRow {
    justify-content: stretch;
  }

  .agentSidebar {
    position: static;
    max-height: none;
  }
}
