:root {
  color: #f7f7f4;
  background: #080906;
  font-family: Inter, system-ui, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --canvas: #080906;
  --canvas-soft: #10110d;
  --surface-card: #14150f;
  --surface-strong: #24251d;
  --hairline: #2a2b22;
  --hairline-soft: #202119;
  --hairline-strong: #424336;
  --ink: #f7f7f4;
  --body: #cfccc0;
  --muted: #a8a397;
  --muted-soft: #777267;
  --primary: #f54e00;
  --primary-active: #ff6a24;
  --on-primary: #ffffff;
  --thinking: #dfa88f;
  --grep: #9fc9a2;
  --read: #9fbbe0;
  --edit: #c0a8dd;
  --done: #c08532;
  --success: #1f8a65;
  --error: #ff6b92;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  background: var(--canvas);
  overflow: hidden;
}

#root {
  width: 100%;
  height: 100%;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

.app-shell {
  height: 100vh;
  background:
    radial-gradient(circle at 18% 10%, rgba(245, 78, 0, 0.13), transparent 24rem),
    radial-gradient(circle at 88% 4%, rgba(159, 187, 224, 0.13), transparent 22rem),
    linear-gradient(180deg, #0b0c08 0%, var(--canvas) 48%, #070806 100%);
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 72px;
  border-bottom: 1px solid var(--hairline);
  background: rgba(8, 9, 6, 0.9);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 28px;
  z-index: 20;
}

.brand,
.status-strip,
.panel-heading,
.citation-top,
.tabs,
.primary-button,
.icon-button {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(245, 78, 0, 0.48);
  background: var(--surface-card);
  color: var(--primary);
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.brand h1 {
  color: var(--ink);
  font-size: 24px;
  line-height: 1.22;
  font-weight: 400;
  letter-spacing: -0.36px;
}

.brand p,
.panel-heading p,
.stage-header p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.status-strip {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-strip span {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--hairline);
  background: rgba(20, 21, 15, 0.82);
  color: var(--body);
  padding: 0 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
}

.workspace {
  width: 100%;
  max-width: 1680px;
  min-height: 0;
  height: calc(100vh - 72px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(520px, 1fr) minmax(340px, 390px);
  grid-template-areas: "left stage right";
  gap: 16px;
  padding: 18px 24px 24px;
  overflow: hidden;
}

.left-rail,
.right-rail {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.left-rail {
  grid-area: left;
}

.right-rail {
  grid-area: right;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-color: var(--hairline-strong) transparent;
  scrollbar-width: thin;
}

.panel {
  border: 1px solid var(--hairline);
  background: var(--surface-card);
  border-radius: 12px;
  color: var(--body);
}

.source-panel,
.qa-panel,
.trace-panel,
.answer-panel,
.citations-panel {
  padding: 16px;
}

.source-panel,
.source-list,
.qa-panel,
.trace-panel,
.citations-panel {
  flex: 0 0 auto;
}

.source-list {
  flex: 1 1 auto;
}

.source-list,
.answer-panel {
  min-height: 0;
  overflow: auto;
}

.citations-panel {
  overflow: visible;
}

.source-list {
  padding: 8px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}

.panel-heading h2,
.stage-header h2 {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: 0;
}

.tabs {
  gap: 4px;
  padding: 4px;
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  margin-bottom: 14px;
}

.tabs button {
  flex: 1;
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--body);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 500;
}

.tabs button.active {
  background: var(--surface-strong);
  color: var(--ink);
  border: 1px solid var(--hairline-strong);
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  margin: 12px 0 6px;
}

input,
textarea {
  width: 100%;
  color: var(--ink);
  background: var(--canvas-soft);
  border: 1px solid var(--hairline-strong);
  border-radius: 8px;
  outline: none;
  caret-color: var(--primary);
}

input {
  height: 44px;
  padding: 0 14px;
  font-size: 14px;
}

textarea {
  min-height: 112px;
  resize: vertical;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
}

.primary-button,
.icon-button {
  border-radius: 8px;
  justify-content: center;
}

.primary-button {
  width: 100%;
  min-height: 44px;
  gap: 8px;
  margin-top: 14px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 14px;
  line-height: 1;
  font-weight: 500;
}

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

.primary-button:disabled {
  opacity: 0.62;
  cursor: wait;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--hairline-strong);
  background: var(--canvas-soft);
  color: var(--ink);
}

.source-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 30px;
  align-items: start;
  gap: 10px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--hairline-soft);
}

.source-row:last-child {
  border-bottom: 0;
}

.modality-dot,
.mini-dot {
  display: grid;
  place-items: center;
  color: #15150f;
  border: 1px solid rgba(247, 247, 244, 0.16);
}

.modality-dot {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.mini-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.text {
  background: var(--grep);
}

.url {
  background: var(--read);
}

.pdf {
  background: var(--done);
  color: var(--on-primary);
}

.image {
  background: var(--edit);
}

.audio {
  background: var(--thinking);
}

.video {
  background: var(--surface-strong);
  color: var(--ink);
}

.query {
  background: var(--primary);
  color: var(--on-primary);
}

.source-title {
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

.source-summary {
  margin-top: 4px;
  color: var(--body);
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-meta {
  width: fit-content;
  margin-top: 7px;
  border: 1px solid var(--hairline);
  border-radius: 9999px;
  color: var(--muted);
  background: var(--canvas-soft);
  padding: 3px 8px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  line-height: 1.4;
}

.source-actions {
  display: grid;
  gap: 6px;
}

.delete-source {
  width: 30px;
  height: 30px;
  border: 1px solid var(--hairline);
  color: var(--body);
  background: var(--canvas-soft);
  border-radius: 6px;
  display: grid;
  place-items: center;
}

.delete-source:hover {
  color: var(--error);
  border-color: var(--error);
}

.delete-source:disabled {
  opacity: 0.62;
  cursor: wait;
}

.source-list-heading {
  padding: 6px 8px 0;
}

.qa-panel {
  border-color: rgba(245, 78, 0, 0.38);
  flex: 0 0 auto;
}

.question-box {
  min-height: 82px;
}

.file-preview {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 4px 8px;
  align-items: center;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--canvas-soft);
  padding: 10px;
}

.file-preview svg {
  color: var(--primary);
  grid-row: span 2;
}

.file-preview span {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-preview strong {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.inline-status {
  margin-top: 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px;
  color: var(--body);
  background: var(--canvas-soft);
  font-size: 13px;
  line-height: 1.45;
}

.inline-status.success {
  border-color: rgba(31, 138, 101, 0.48);
}

.inline-status.error {
  border-color: rgba(255, 107, 146, 0.58);
  color: #ffd3df;
}

.space-stage {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--hairline);
  background:
    radial-gradient(circle at 58% 36%, rgba(245, 78, 0, 0.18), transparent 22rem),
    linear-gradient(180deg, rgba(20, 21, 15, 0.94), rgba(8, 9, 6, 0.98));
  border-radius: 12px;
}

.space-stage::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(247, 247, 244, 0.08);
  border-radius: 10px;
  pointer-events: none;
  z-index: 1;
}

.stage-header {
  position: absolute;
  z-index: 3;
  inset: 0 0 auto 0;
  min-height: 78px;
  padding: 18px 18px 0;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.stage-header h2 {
  font-size: 26px;
  line-height: 1.25;
  font-weight: 400;
  letter-spacing: -0.325px;
}

.stage-tools {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.modality-key {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  max-width: 380px;
  color: var(--muted);
}

.modality-key-item {
  min-height: 18px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: 0.58px;
  text-transform: uppercase;
}

.modality-key-item::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--body);
}

.key-text::before {
  background: var(--grep);
}

.key-image::before {
  background: var(--edit);
}

.key-audio::before {
  background: var(--thinking);
}

.key-video::before {
  background: var(--ink);
}

.key-pdf::before {
  background: var(--done);
}

.key-query::before {
  background: var(--primary);
}

.space-readout {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  border: 1px solid rgba(247, 247, 244, 0.08);
  border-radius: 9999px;
  background: rgba(16, 17, 13, 0.72);
  padding: 6px;
}

.space-readout span {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  color: var(--body);
  background: rgba(247, 247, 244, 0.04);
  padding: 0 10px;
  font-size: 11px;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: 0.58px;
  text-transform: uppercase;
}

.space-readout span:last-child {
  color: var(--ink);
  background: rgba(245, 78, 0, 0.14);
  border: 1px solid rgba(245, 78, 0, 0.28);
}

.vector-canvas {
  position: absolute;
  inset: 0;
}

.hover-card {
  position: absolute;
  right: 24px;
  top: 96px;
  width: 286px;
  border: 1px solid var(--hairline-strong);
  background: rgba(20, 21, 15, 0.96);
  border-radius: 12px;
  padding: 14px;
  z-index: 5;
}

.hover-card strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  margin-top: 8px;
}

.hover-card span,
.hover-card p {
  color: var(--body);
  font-size: 13px;
  line-height: 1.45;
}

.hover-card span {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
}

.hover-card p {
  margin-top: 8px;
}

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

.trace-row {
  border: 1px solid var(--hairline);
  background: var(--canvas-soft);
  border-radius: 8px;
  padding: 10px;
}

.trace-row:nth-child(1) span {
  background: var(--thinking);
}

.trace-row:nth-child(2) span {
  background: var(--read);
}

.trace-row:nth-child(3) span {
  background: var(--done);
  color: var(--on-primary);
}

.trace-row span {
  display: inline-flex;
  width: fit-content;
  border-radius: 9999px;
  color: #15150f;
  font-size: 11px;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  padding: 4px 10px;
}

.trace-row p,
.answer-box p,
.citation-row p,
.empty-state {
  color: var(--body);
  font-size: 13px;
  line-height: 1.5;
}

.trace-row p {
  margin-top: 6px;
}

.answer-box {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  border: 1px solid var(--hairline);
  background: linear-gradient(180deg, rgba(16, 17, 13, 0.98), rgba(13, 14, 10, 0.98));
  border-radius: 12px;
  padding: 16px;
  max-height: 280px;
  overflow: auto;
}

.prominent-answer {
  min-height: 128px;
}

.answer-content {
  display: grid;
  gap: 12px;
}

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

.answer-content h3 {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
}

.answer-content p,
.answer-content li {
  color: var(--body);
  font-size: 15px;
  line-height: 1.5;
}

.answer-content ul {
  margin: 0;
  padding-left: 17px;
  display: grid;
  gap: 7px;
}

.answer-box svg {
  color: var(--primary);
  margin-top: 2px;
}

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

.citation-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--hairline-strong);
  background: linear-gradient(180deg, rgba(16, 17, 13, 0.98), rgba(12, 13, 10, 0.98));
  border-radius: 8px;
  padding: 13px;
}

.citation-row:hover {
  border-color: rgba(245, 78, 0, 0.58);
}

.citation-top {
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.citation-top span {
  min-width: 0;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.citation-top strong {
  flex: 0 0 auto;
  color: var(--ink);
  background: rgba(245, 78, 0, 0.16);
  border: 1px solid rgba(245, 78, 0, 0.38);
  border-radius: 9999px;
  padding: 3px 7px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
}

.citation-row p {
  margin-top: 9px;
  color: var(--body);
  font-size: 13.5px;
  line-height: 1.55;
}

.score-track {
  height: 4px;
  background: var(--surface-strong);
  border-radius: 9999px;
  overflow: hidden;
  margin: 10px 0 0;
}

.score-track div {
  height: 100%;
  background: var(--primary);
}

.empty-state {
  border: 1px dashed var(--hairline-strong);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
  background: var(--canvas-soft);
}

.spin {
  animation: spin 0.9s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spin {
    animation: none;
  }
}

@media (max-width: 1239px) {
  .workspace {
    height: calc(100vh - 72px);
    grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
    grid-template-rows: minmax(430px, 1fr) minmax(0, 0.72fr);
    grid-template-areas:
      "stage right"
      "left right";
    padding: 18px 18px 40px;
  }

  .space-stage {
    min-height: 430px;
  }

  .topbar {
    min-height: 72px;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
  }

  .status-strip {
    justify-content: flex-start;
  }
}

@media (max-width: 980px) {
  body {
    overflow-y: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .workspace {
    height: auto;
    overflow: visible;
    grid-template-columns: 1fr;
    grid-template-areas:
      "stage"
      "right"
      "left";
  }

  .left-rail,
  .right-rail {
    height: auto;
    overflow: visible;
  }

  .space-stage {
    height: 560px;
  }
}

@media (max-width: 720px) {
  .brand h1 {
    font-size: 20px;
  }

  .status-strip span {
    min-height: 34px;
  }

  .workspace {
    padding: 12px 12px 32px;
  }

  .space-stage {
    min-height: 520px;
  }

  .stage-header {
    position: relative;
    background: rgba(8, 9, 6, 0.84);
    padding: 14px;
    pointer-events: auto;
  }

  .stage-header,
  .stage-tools,
  .modality-key,
  .space-readout {
    flex-direction: column;
    align-items: flex-start;
    justify-items: start;
  }

  .vector-canvas {
    inset: 86px 0 0;
  }

  .hover-card {
    left: 16px;
    right: 16px;
    top: 112px;
    width: auto;
  }
}
