:root {
  --bg: #f7f8f8;
  --surface: #ffffff;
  --surface-soft: #f4f6f6;
  --ink: #1f2328;
  --muted: #68717d;
  --line: #e3e6e8;
  --accent: #256f79;
  --accent-strong: #174e56;
  --mint: #e8f5ef;
  --blue-soft: #eef5f6;
  --amber-soft: #fff7e7;
  --shadow: 0 24px 70px rgba(24, 31, 38, 0.08);
  --soft-shadow: 0 10px 34px rgba(24, 31, 38, 0.055);
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-lg: 17px;
  --text-xl: 22px;
  --text-2xl: 28px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  zoom: 0.8;
  background:
    radial-gradient(circle at 50% -20%, rgba(37, 111, 121, 0.08), transparent 34%),
    var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  column-gap: 26px;
  row-gap: 0;
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 22px 42px;
}

.topbar {
  flex: 0 0 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 2px 22px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #20252b;
  color: white;
}

.brand-mark img {
  width: 25px;
  height: 25px;
  display: block;
}

.topbar h1 {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.workspace {
  flex: 1 1 0;
  max-width: 880px;
  min-width: 0;
  align-self: start;
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  align-items: start;
  gap: 18px;
  margin: 0;
}

.query-card,
.answer-panel,
.results-panel,
.notice {
  align-self: start;
  background: var(--surface);
  border: 1px solid rgba(227, 230, 232, 0.96);
  border-radius: 20px;
  box-shadow: var(--soft-shadow);
}

.query-card {
  padding: 0;
  overflow: visible;
  box-shadow: var(--shadow);
}

.query-card-header,
.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.query-card-header {
  padding: 24px 24px 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0;
}

.composer-shell {
  margin: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.field-label {
  display: block;
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 750;
}

.composer-shell > .field-label:first-child {
  margin-top: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: var(--text-base);
  outline: none;
  padding: 12px 13px;
}

textarea {
  height: 82px;
  min-height: 82px;
  resize: vertical;
  line-height: 1.45;
  font-size: var(--text-lg);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 111, 121, 0.1);
}

.scope-box {
  border: 0;
  border-radius: 14px;
  background: var(--surface-soft);
  padding: 8px 9px 9px;
}

.scope-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 30px;
  margin-bottom: 7px;
}

.scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e9f4ff;
  color: #1b5f89;
  font-size: var(--text-sm);
  font-weight: 750;
}

.scope-all {
  background: var(--blue-soft);
  color: var(--accent-strong);
}

.scope-sector {
  background: var(--amber-soft);
  color: #795711;
}

.scope-sub_industry {
  background: #f1edff;
  color: #5b4b9a;
}

.scope-chip button {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  color: currentColor;
  font-size: var(--text-xs);
  font-weight: 800;
}

.autocomplete {
  position: relative;
}

.scope-box input {
  border: 0;
  border-radius: 10px;
  background: white;
  padding: 10px 11px;
}

.scope-box input:focus {
  box-shadow: none;
}

.autocomplete-menu {
  position: absolute;
  z-index: 40;
  inset: calc(100% + 6px) 0 auto 0;
  overflow: hidden;
  max-height: 292px;
  overflow-y: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 22px 54px rgba(24, 31, 38, 0.16);
}

.scope-group-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 12px 5px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: var(--text-xs);
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scope-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
  text-align: left;
}

.scope-option:hover {
  background: var(--blue-soft);
}

.scope-option strong,
.scope-option span {
  display: block;
}

.scope-option strong {
  overflow: hidden;
  font-size: var(--text-base);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scope-option span {
  margin-top: 3px;
  color: var(--muted);
  font-size: var(--text-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ask-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  position: relative;
}

.ask-row textarea {
  padding-right: 122px;
  padding-bottom: 44px;
}

.ask-button {
  position: absolute;
  right: 12px;
  bottom: 9px;
  min-width: 92px;
  min-height: 36px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: var(--text-sm);
  font-weight: 800;
}

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

.ask-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.advanced-panel {
  margin: 0 18px 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.advanced-panel summary {
  color: var(--muted);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 750;
}

.advanced-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.55fr 0.8fr 0.8fr;
  gap: 12px;
  margin-top: 12px;
  align-items: end;
}

.advanced-grid .field-label {
  margin-top: 0;
}

.pill-checks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pill-checks input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pill-checks span {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  color: #394759;
  font-weight: 750;
  font-size: var(--text-sm);
}

.pill-checks input:checked + span {
  border-color: #afd4cb;
  background: var(--mint);
  color: #175344;
}

.small-input {
  text-align: center;
}

.notice {
  padding: 13px 15px;
  border-color: #f2d27b;
  background: var(--amber-soft);
  color: #74510f;
}

.answer-panel,
.results-panel {
  padding: 22px;
}

.answer-empty,
.answer-text {
  margin-top: 16px;
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-wrap;
}

.answer-text {
  color: #223044;
  font-size: var(--text-lg);
}

.enhancement-list {
  display: grid;
  gap: 7px;
  padding-right: 2px;
}

.enhancement-item {
  display: grid;
  gap: 2px;
  padding: 7px 8px;
  border: 1px solid rgba(227, 230, 232, 0.82);
  border-radius: 9px;
  background: white;
}

.enhancement-item span {
  color: var(--accent-strong);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
}

.enhancement-item p {
  margin: 0;
  color: #5f6875;
  line-height: 1.32;
  font-size: var(--text-xs);
  font-weight: 650;
}

.answer-text p {
  margin: 0 0 10px;
}

.answer-text p:last-child {
  margin-bottom: 0;
}

.answer-text ul {
  margin: 8px 0 12px 20px;
  padding: 0;
}

.answer-text li {
  margin: 5px 0;
}

.answer-text h3,
.answer-text h4 {
  margin: 12px 0 7px;
  font-size: var(--text-lg);
}

.answer-text code {
  padding: 1px 4px;
  border-radius: 5px;
  background: var(--surface-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.inline-citation {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  min-height: 18px;
  margin: 0 1px;
  padding: 0 5px;
  border: 1px solid rgba(37, 111, 121, 0.16);
  border-radius: 999px;
  background: rgba(37, 111, 121, 0.08);
  color: var(--accent-strong);
  font-size: 0.68em;
  font-weight: 850;
  line-height: 1;
  vertical-align: 0.18em;
}

.inline-citation:hover {
  border-color: rgba(37, 111, 121, 0.32);
  background: rgba(37, 111, 121, 0.14);
}

.citation-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.citation {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #f3d893;
  border-radius: 999px;
  background: #fffaf0;
  color: #80621c;
  font-size: var(--text-xs);
  font-weight: 800;
}

.result-count {
  color: var(--muted);
  font-size: var(--text-sm);
}

.results-list {
  display: grid;
  gap: 16px;
  margin-top: 14px;
}

.source-form-group {
  display: grid;
  gap: 12px;
}

.source-form-group h3 {
  margin: 0;
  color: var(--accent-strong);
  font-size: var(--text-lg);
  letter-spacing: 0;
}

.source-file-group {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfcfc;
}

.source-file-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.source-file-heading h4 {
  margin: 0;
  font-size: var(--text-base);
}

.source-link {
  flex: 0 0 auto;
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--accent-strong);
  font-size: var(--text-xs);
  font-weight: 800;
  text-decoration: none;
}

.source-link:hover {
  background: var(--blue-soft);
}

.result-item {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.result-item.source-highlight {
  border-color: rgba(37, 111, 121, 0.45);
  background: #fbffff;
  box-shadow: 0 0 0 4px rgba(37, 111, 121, 0.12);
}

.result-summary {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 86px;
  gap: 14px;
  align-items: start;
  padding: 15px;
}

.rank {
  min-width: 38px;
  padding: 0 7px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--accent-strong);
  font-size: var(--text-xs);
  font-weight: 850;
}

.result-title {
  margin-bottom: 6px;
  font-size: var(--text-base);
  font-weight: 850;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: var(--text-xs);
}

.meta span {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
}

.snippet {
  color: #344256;
  font-size: var(--text-base);
  line-height: 1.5;
}

.toggle-text {
  align-self: center;
  min-height: 34px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: var(--text-xs);
  font-weight: 800;
}

.toggle-text:hover {
  background: var(--blue-soft);
}

.full-text {
  display: none;
  max-height: 460px;
  overflow: auto;
  padding: 15px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
  color: #29384b;
  line-height: 1.52;
  white-space: pre-wrap;
}

.loading {
  opacity: 0.72;
}

.process-drawer {
  flex: 0 0 292px;
  align-self: start;
  position: sticky;
  top: 18px;
  width: auto;
  z-index: 5;
}

.process-card {
  position: relative;
  padding: 16px;
  border: 1px solid rgba(219, 226, 234, 0.9);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(12px);
}

.process-header h2 {
  font-size: var(--text-2xl);
}

.process-steps {
  position: relative;
  display: grid;
  gap: 9px;
  margin-top: 13px;
}

.process-step {
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  color: var(--muted);
  opacity: 0.66;
  transition: opacity 180ms ease, transform 180ms ease;
}

.process-step:hover,
.process-step:focus {
  opacity: 1;
}

.process-step:focus {
  outline: none;
}

.process-step > span {
  position: relative;
  width: 23px;
  height: 23px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
}

.process-step > span::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 999px;
  background: var(--line);
  transition: transform 180ms ease, background 180ms ease;
}

.process-step:not(:last-child) > span::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 24px;
  width: 2px;
  height: 25px;
  background: var(--line);
}

.process-step strong {
  display: block;
  color: var(--ink);
  font-size: var(--text-sm);
}

.process-step small {
  display: block;
  margin-top: 2px;
  line-height: 1.35;
  font-size: var(--text-xs);
}

.process-step.active {
  opacity: 1;
  transform: translateX(-2px);
}

.process-step.active > span {
  border-color: var(--accent);
  box-shadow: 0 0 0 5px rgba(23, 107, 135, 0.12);
}

.process-step.active > span::after {
  background: var(--accent);
  animation: pulse-node 900ms ease-in-out infinite;
}

.process-step.complete {
  opacity: 0.95;
}

.process-step.complete > span {
  border-color: #8ec5b7;
  background: var(--mint);
}

.process-step.complete > span::after {
  background: #1b8067;
}

.process-detail {
  position: relative;
  display: grid;
  gap: 11px;
  margin-top: 13px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  opacity: 0.88;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.process-detail.is-changing {
  opacity: 0.35;
  transform: translateY(4px);
}

.process-detail p {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: var(--text-sm);
  font-weight: 850;
}

.process-detail span {
  display: block;
  color: #3c4b5f;
  font-size: var(--text-sm);
  line-height: 1.45;
}

.pipeline-output {
  display: none;
  position: absolute;
  left: calc(100% + 14px);
  top: 118px;
  z-index: 50;
  gap: 9px;
  width: 292px;
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 42px rgba(24, 31, 38, 0.14);
  backdrop-filter: blur(10px);
}

.pipeline-output::before {
  content: "";
  position: absolute;
  left: -9px;
  top: 32px;
  width: 16px;
  height: 16px;
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  transform: rotate(45deg);
}

.pipeline-output > * {
  position: relative;
  z-index: 1;
}

.pipeline-output[hidden] {
  display: none;
}

.pipeline-output p {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 750;
  letter-spacing: 0;
  text-transform: none;
}

.process-card.show-enhancement > .pipeline-output:not([hidden]) {
  display: grid;
}

@keyframes pulse-node {
  0%, 100% {
    transform: scale(0.84);
  }
  50% {
    transform: scale(1.18);
  }
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
    padding: 14px;
  }

  .ask-row,
  .advanced-grid {
    grid-template-columns: 1fr;
  }

  .workspace {
    margin-right: 0;
  }

  .process-drawer {
    position: static;
    width: auto;
    margin-top: 14px;
  }

  .pipeline-output {
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    width: 100%;
  }

  .pipeline-output::before {
    left: 24px;
    top: -9px;
    border: 0;
    border-left: 1px solid var(--line);
    border-top: 1px solid var(--line);
  }

  .ask-button {
    min-height: 46px;
  }

}

@media (max-width: 640px) {
  .query-card,
  .answer-panel,
  .results-panel {
    border-radius: 16px;
  }

  .query-card-header,
  .answer-panel,
  .results-panel {
    padding: 16px;
  }

  .composer-shell {
    margin: 12px;
    padding: 12px;
  }

  .pill-checks,
  .result-summary {
    grid-template-columns: 1fr;
  }

  .query-card-header,
  .panel-heading,
  .source-file-heading {
    flex-direction: column;
  }
}
