:root {
  --ink: #173b59;
  --muted: #6c8297;
  --line: #d5e1eb;
  --canvas: #edf3f8;
  --card: #ffffff;
  --accent: #0b65aa;
  --accent-soft: #e8f3fb;
  --success: #167c59;
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
}

body::before {
  content: "";
  display: block;
  height: 4px;
  background: linear-gradient(90deg, #084d82, #1677ba 55%, #56a9d8);
}

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

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

.topbar,
.query-card,
.progress-card,
.results-card,
.report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 2px 9px rgba(26, 62, 91, .045);
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 102px;
  padding: 22px 28px 20px;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(115deg, #0d4f83 0%, #0b659f 62%, #147bb8 100%);
  box-shadow: 0 4px 12px rgba(20, 73, 108, .14);
}
.topbar::after {
  content: "";
  position: absolute;
  right: 28px;
  bottom: 0;
  left: 28px;
  height: 1px;
  background: rgba(255, 255, 255, .28);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12);
}
.brand-mark svg {
  width: 29px;
  height: 29px;
  fill: none;
  stroke: #e5f5ff;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .12em;
}
.topbar .eyebrow { color: #80bce2; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; color: #fff; font-size: clamp(27px, 3vw, 37px); letter-spacing: .01em; }
h2 { margin: 0; font-size: 20px; }
.subtitle { margin-bottom: 0; color: rgba(239, 248, 255, .82); }
.query-heading p { margin-bottom: 0; color: var(--muted); }

.service-status {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 5px;
  padding: 8px 12px;
  color: rgba(255, 255, 255, .86);
  background: rgba(255, 255, 255, .1);
  font-size: 14px;
}
.service-status.online { color: #d9f7e8; background: rgba(30, 157, 105, .22); }
.service-status.error { color: #ffe5e2; background: rgba(170, 57, 49, .25); }

.query-card, .progress-card { margin-top: 12px; padding: 20px 22px; }
.mode-switch {
  display: inline-flex;
  gap: 4px;
  margin: 0;
  padding: 4px;
  border: 1px solid #cbdce9;
  border-radius: 8px;
  background: #f2f7fb;
}
.mode-tab {
  border: 0;
  border-radius: 5px;
  padding: 8px 13px;
  color: #58728c;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}
.mode-tab.is-active { color: #fff; background: var(--accent); box-shadow: 0 1px 3px rgba(11, 101, 170, .2); }
.query-heading, .query-actions, .section-title, .progress-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.query-heading { align-items: start; }
.query-heading > div:first-child { flex: 1; }
.query-heading h2,
.section-title h2 {
  padding-left: 10px;
  border-left: 3px solid var(--accent);
}

.sample-select {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 285px;
  color: #58728c;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}
select, input[type="number"] {
  border: 1px solid #c2d5e4;
  border-radius: 5px;
  padding: 9px 11px;
  color: var(--ink);
  background: #f6f9fc;
  box-shadow: none;
  transition: border-color .2s ease, background-color .2s ease, box-shadow .2s ease;
}
select {
  width: 100%;
  min-height: 40px;
  padding-right: 38px;
  cursor: pointer;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #5d86aa 50%),
    linear-gradient(135deg, #5d86aa 50%, transparent 50%),
    linear-gradient(90deg, transparent 0 82%, #e5eff7 82% 100%);
  background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px, 0 0;
  background-size: 5px 5px, 5px 5px, 100% 100%;
  background-repeat: no-repeat;
}
select:hover, input[type="number"]:hover {
  border-color: #8eb8da;
  background-color: #f1f7fc;
}
select:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(10, 105, 183, .12), 0 4px 10px rgba(26, 62, 91, .05);
}
select option { color: var(--ink); background: #fff; }
select option:disabled { color: #9aaab8; background: #f1f4f6; }

.query-input-shell {
  position: relative;
  margin: 16px 0;
}

textarea {
  width: 100%;
  min-height: 142px;
  margin: 0;
  resize: vertical;
  border: 1px solid #cddce8;
  border-radius: 6px;
  padding: 13px 14px 67px;
  color: var(--ink);
  line-height: 1.65;
  outline: none;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10, 105, 183, .12); }

.keyword-panel {
  position: absolute;
  right: 11px;
  bottom: 11px;
  left: 11px;
  overflow: hidden;
  pointer-events: none;
}
.keyword-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 52px;
  overflow: hidden;
}
.keyword-tag {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 2px 7px;
  border: 1px solid #c9dff0;
  border-radius: 5px;
  color: #2870a8;
  background: rgba(237, 246, 252, .96);
  font-size: 11px;
  line-height: 1.35;
}

.buttons { display: flex; gap: 8px; }
.query-controls {
  display: flex;
  align-items: end;
  gap: 10px;
}
.limit-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #58728c;
  font-size: 12px;
  font-weight: 700;
}
.limit-control { min-width: 112px; }
.limit-control input { width: 100%; }
select:disabled { cursor: wait; color: #8ca0b0; background-color: #f0f5f8; }
.button, .icon-button {
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 700;
}
.button-primary { color: #fff; background: var(--accent); box-shadow: 0 2px 4px rgba(11, 101, 170, .18); }
.button-primary:disabled { cursor: wait; opacity: .62; }
.button-secondary, .icon-button { color: #425d74; background: #fff; border-color: var(--line); }
.icon-button:not(:disabled):hover, .button-secondary:hover { color: var(--accent); border-color: #9fc8ea; background: var(--accent-soft); }
.icon-button:disabled { cursor: not-allowed; color: #a7b7c4; background: #f7f9fa; }

.progress-card { padding: 16px 22px; border-left: 3px solid #b8d5e9; }
.progress-topline { font-size: 14px; }
.progress-topline span { color: var(--accent); font-weight: 750; }
.progress-track { height: 7px; margin: 12px 0; overflow: hidden; border-radius: 999px; background: #e7eef4; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #0a69b7, #3c9de5); transition: width .25s ease; }
.stage-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#stageList > span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  background: #f3f7fa;
  font-size: 14px;
  text-align: center;
  transition: color .2s ease, background-color .2s ease, border-color .2s ease;
}
#stageList > span.active { color: var(--accent); background: var(--accent-soft); font-weight: 700; }
#stageList > span.done { color: var(--success); background: #eaf7f1; }
.stage-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
}
.stage-label { padding: 0; color: inherit; background: transparent; font-size: inherit; text-align: left; }
.stream-meta { min-height: 19px; margin: 10px 0 0; color: var(--muted); font-size: 13px; }

.llm-output {
  margin-top: 11px;
  overflow: hidden;
  border: 1px solid #dce8f0;
  border-radius: 9px;
  background: #f8fbfd;
}

.llm-output-title {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 31px;
  padding: 0 11px;
  border-bottom: 1px solid #dce8f0;
  color: #52718c;
  font-size: 12px;
  font-weight: 700;
}

.llm-output-title #streamOutputMeta {
  margin-left: auto;
  color: #91a4b5;
  font-size: 11px;
  font-weight: 400;
}

.llm-live-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #9eb2c3;
}

.llm-output.is-live .llm-live-dot {
  background: #2b9b70;
  box-shadow: 0 0 0 4px rgba(43, 155, 112, .12);
  animation: llmPulse 1.2s ease-in-out infinite;
}

@keyframes llmPulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

#streamOutput {
  height: 112px;
  margin: 0;
  overflow: auto;
  padding: 10px 11px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #55718a;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Consolas, "Noto Sans SC", monospace;
  scrollbar-color: #a9bdcc transparent;
  scrollbar-width: thin;
}

.llm-output.is-live #streamOutput { color: #365f80; }

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

.results-card, .report-card { min-width: 0; padding: 18px; }
.report-card { position: sticky; top: 14px; }
.section-title { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
#resultMeta { color: var(--muted); font-size: 12px; text-align: right; }
.report-actions { display: flex; gap: 7px; }

.results-empty, .report-empty {
  display: grid;
  min-height: 260px;
  place-items: center;
  border: 1px dashed #c7d8e5;
  border-radius: 6px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: #fbfdff;
}
.result-list { display: grid; gap: 0; border-top: 1px solid var(--line); }
.result-item { padding: 15px 5px 16px; border-bottom: 1px solid var(--line); background: #fff; }
.result-item h3 { margin: 0 0 5px; color: #174f7e; font-size: 16px; }
.result-item p { margin: 8px 0 0; color: #516b80; line-height: 1.65; font-size: 13px; }
.result-item .original-label { margin-top: 12px; color: #7890a3; font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.result-meta { color: var(--muted); font-size: 12px; }
.tag { display: inline-block; margin: 9px 6px 0 0; padding: 3px 7px; border-radius: 999px; color: #2370a9; background: #edf6fc; font-size: 11px; }

/* The report box is the only scroll container. The document itself is normal flow. */
.report-box {
  height: clamp(330px, calc(100vh - 248px), 720px);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  scrollbar-color: #a8bdce transparent;
  scrollbar-width: thin;
}
.report-box:has(.report-empty:not([hidden])) { border-style: dashed; }
.report-empty[hidden] { display: none; }
.report-document {
  display: block;
  overflow: visible;
  padding: 24px 24px 30px;
  color: #243c51;
  font-size: 14px;
  line-height: 1.8;
  word-break: break-word;
}
.report-document h1, .report-document h2, .report-document h3 { color: #173b58; line-height: 1.4; }
.report-document h1 { margin: 0 0 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line); font-size: 20px; }
.report-document h2 { margin: 25px 0 10px; color: var(--accent); font-size: 16px; }
.report-document h3 { margin: 18px 0 8px; font-size: 15px; }
.report-document p { margin: 0 0 12px; }
.report-document ul { margin: 0 0 12px; padding-left: 1.35em; }
.report-document strong { color: #173b58; }

@media (max-width: 980px) {
  .content-grid { grid-template-columns: 1fr; }
  .report-card { position: static; }
  .report-box { height: min(600px, 70vh); }
}
@media (max-width: 620px) {
  .app-shell { width: min(100% - 20px, 1440px); padding-top: 10px; }
  .topbar, .query-card, .progress-card, .results-card, .report-card { padding: 16px; }
  .topbar, .query-heading, .query-actions { align-items: stretch; flex-direction: column; }
  .topbar-actions { align-items: stretch; flex-direction: column; }
  .mode-switch { align-self: flex-start; }
  .query-controls { align-items: stretch; flex-direction: column; }
  .stage-list { grid-template-columns: 1fr 1fr; }
  .sample-select { display: grid; gap: 5px; }
  .sample-select select { margin-left: 0; width: 100%; }
  .report-document { padding: 18px; }
}
