:root {
  color-scheme: light;
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-strong: #f8fafb;
  --text: #172026;
  --muted: #65717a;
  --line: #d7dee3;
  --accent: #1f7a6d;
  --accent-strong: #145a51;
  --info: #2f5f9f;
  --warning: #b7791f;
  --success: #2f7d50;
  --danger: #a33b3b;
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.workspace {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(24, 38, 48, 0.08);
}

.upload-panel {
  padding: 20px;
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 18px;
}

p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.brand-subline {
  display: block;
  margin-top: 8px;
  color: #33515b;
  font-size: 13px;
  font-weight: 700;
}

.drop-zone {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px dashed #9caab3;
  border-radius: 8px;
  background: var(--surface-strong);
}

.drop-zone.is-dragging {
  border-color: var(--accent);
  background: #edf8f5;
}

.drop-zone input {
  width: 100%;
}

.drop-content {
  display: grid;
  gap: 4px;
}

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

.file-card,
.pdf-preview-card {
  margin-top: 14px;
}

.file-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #b9d5cc;
  border-radius: 8px;
  background: #f2fbf8;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 56px;
  border-radius: 6px;
  background: #d84b4b;
  color: white;
  font-size: 12px;
  font-weight: 900;
}

.file-card strong,
.file-card span,
.file-card em {
  display: block;
  overflow-wrap: anywhere;
}

.file-card span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.file-card em {
  margin-top: 4px;
  color: var(--success);
  font-size: 13px;
  font-style: normal;
  font-weight: 800;
}

.pdf-preview-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.pdf-preview-card iframe {
  width: 100%;
  height: 210px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.is-hidden {
  display: none;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

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

.status-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 18px;
}

.upload-message {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  color: var(--muted);
  line-height: 1.45;
}

.upload-message.error {
  border-color: #dfaaaa;
  background: #fff3f3;
  color: #8f2f2f;
}

.upload-message.success {
  border-color: #8cc9b6;
  background: #edf8f5;
  color: #244a45;
}

.status-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.status-grid span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.status-grid strong {
  overflow-wrap: anywhere;
}

.page-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.page-chip {
  max-width: 100%;
  padding: 7px 9px;
  border-radius: 6px;
  background: #e7efed;
  color: #244a45;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.index-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-head span,
.result-toolbar span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.step-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.step-item {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  font-size: 13px;
}

.result-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

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

.result-toolbar button {
  min-width: 82px;
  min-height: 34px;
}

pre {
  margin: 0;
  padding: 18px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: 14px/1.55 Consolas, Monaco, monospace;
  color: #243038;
}

.query-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  min-height: 430px;
  padding-bottom: 18px;
}

.query-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px;
}

.query-suggestions strong {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.query-suggestions button,
.query-history button,
.citation-card button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.query-suggestions button:hover,
.query-history button:hover,
.citation-card button:hover {
  border-color: var(--accent);
  background: #edf8f5;
  color: var(--accent-strong);
}

.details-panel {
  grid-column: 1 / -1;
  min-height: auto;
}

.details-panel details {
  padding: 16px 18px;
}

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

.details-panel pre {
  max-height: 360px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.query-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 0 18px;
}

.feedback-form {
  display: none;
  grid-template-columns: 84px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 0 18px;
}

.query-form input,
.feedback-form input,
.feedback-form select {
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.answer-box,
.citation-list,
.retrieved-chunks {
  margin: 0 18px;
}

.confidence-badge {
  justify-self: start;
  margin: 0 18px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.confidence-badge.high {
  border-color: #94cfaa;
  background: #eef9f2;
  color: var(--success);
}

.confidence-badge.medium {
  border-color: #e8c77d;
  background: #fff8e8;
  color: var(--warning);
}

.confidence-badge.low {
  border-color: #dfaaaa;
  background: #fff3f3;
  color: var(--danger);
}

.answer-box {
  min-height: 210px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  line-height: 1.55;
  white-space: pre-wrap;
  font-size: 17px;
}

.citation-list {
  display: grid;
  gap: 10px;
}

.retrieved-chunks {
  display: none;
}

.citation-card,
.chunk-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.citation-card strong,
.chunk-card strong {
  display: block;
  margin-bottom: 6px;
}

.chunk-card p,
.citation-card p {
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding: 10px 0;
  }

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

  .result-panel {
    min-height: 55vh;
  }

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

.dashboard-panel {
  grid-column: 1 / -1;
  display: grid;
  gap: 0;
  padding-bottom: 0;
}

.advanced-dashboard {
  padding: 16px 18px 18px;
}

.advanced-dashboard summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 800;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px 0 0;
}

.metric-section {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.metric-section h2 {
  font-size: 16px;
}

.timeline-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #edf1f3;
}

.timeline-item span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 800;
}

.timeline-item.pending span {
  background: #d7dee3;
}

.timeline-item.current span {
  background: var(--info);
  animation: pulse 1.2s ease-in-out infinite;
}

.timeline-item.done span {
  background: var(--success);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

.comparison-table {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 70px 70px;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 6px;
  background: white;
  border: 1px solid var(--line);
  font-size: 13px;
}

.table-head {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
}

.table-row.winner {
  border-color: var(--accent);
  background: #edf8f5;
}

.table-row.winner span:first-child::before {
  content: "Winner ";
  color: var(--accent-strong);
  font-weight: 800;
}

.winner-badge {
  padding: 5px 8px;
  border: 1px solid #b9d5cc;
  border-radius: 999px;
  background: #edf8f5;
  color: var(--accent-strong) !important;
  font-weight: 900;
}

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

.stat-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

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

.stat-grid strong {
  font-size: 18px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.answer-card {
  display: grid;
  gap: 10px;
}

.answer-card > span {
  margin: 0 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.citation-title {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.citation-file-badge {
  display: grid !important;
  place-items: center;
  width: 38px;
  height: 42px;
  margin: 0 !important;
  border-radius: 6px;
  background: #d84b4b;
  color: white !important;
  font-size: 11px !important;
  font-weight: 900;
}

.citation-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.citation-card span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.citation-meta span {
  margin: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.citation-card button {
  display: inline-flex;
  align-items: center;
  margin: 0;
}

.retrieval-section,
.recommendation-section {
  margin: 14px 0 0;
}

.retrieved-chunks {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
}

.chunk-card summary {
  display: grid;
  grid-template-columns: 44px 150px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  cursor: pointer;
}

.chunk-card summary span {
  color: var(--accent-strong);
  font-weight: 800;
}

.chunk-summary-scores {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chunk-card summary em {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.chunk-card p strong {
  margin-top: 12px;
}

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

.chunk-scores span {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--muted);
  font-size: 12px;
}

.chunk-scores strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
}

.recommendation-box {
  margin-top: 10px;
  padding: 14px;
  border-radius: 8px;
  background: #edf8f5;
  color: #244a45;
  font-weight: 700;
}

.recommendation-box strong,
.recommendation-box span {
  display: block;
}

.recommendation-box span {
  margin-top: 5px;
  font-size: 18px;
}

.recommendation-box p {
  margin-top: 10px;
}

.recommendation-box ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.recommendation-box li {
  margin-top: 4px;
}

.crag-box {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.crag-box strong {
  font-size: 22px;
}

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

.crag-box.good {
  border-color: #8cc9b6;
  background: #edf8f5;
}

.crag-box.bad {
  border-color: #dfaaaa;
  background: #fff3f3;
}

.pipeline-viz {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.pipeline-viz div {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.pipeline-viz span {
  width: 1px;
  height: 12px;
  margin-left: 18px;
  background: var(--line);
  position: relative;
}

.pipeline-viz span::after {
  content: "";
  position: absolute;
  left: -4px;
  bottom: -1px;
  width: 8px;
  height: 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}

.hallucination-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

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

.hallucination-card strong {
  font-size: 20px;
}

.hallucination-card em {
  grid-column: 1 / -1;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-style: normal;
  font-weight: 900;
}

.hallucination-card.good {
  border-color: #94cfaa;
  background: #eef9f2;
}

.hallucination-card.bad {
  border-color: #dfaaaa;
  background: #fff3f3;
}

.history-panel {
  grid-column: 1 / -1;
}

.query-history {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 18px;
}

.query-history > span {
  color: var(--muted);
  font-size: 14px;
}

.page-chip.is-active {
  outline: 3px solid rgba(31, 122, 109, 0.22);
  border: 1px solid var(--accent);
  background: #dff4ee;
}

.empty-state {
  padding: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

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

  .chunk-card summary {
    grid-template-columns: 1fr;
  }

  .chunk-scores,
  .hallucination-card {
    grid-template-columns: 1fr;
  }
}
