:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --panel-soft: #f1f2ee;
  --ink: #171717;
  --muted: #6f716f;
  --line: #e1e2dd;
  --line-strong: #c9cbc4;
  --green: #4f9d55;
  --green-soft: #e7f3e4;
  --orange: #f06435;
  --orange-soft: #fff0ea;
  --blue: #4d8fd7;
  --blue-soft: #e9f2fb;
  --red: #c63d32;
  --console: #050505;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
  overflow: hidden;
}

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

.topbar {
  min-height: 62px;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto minmax(300px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-copy {
  min-width: 0;
}

.mark {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.docs-nav-button {
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0 12px;
  color: var(--ink);
  background: #f4f0e8;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.docs-nav-button:hover {
  border-color: var(--line-strong);
  background: #ece5d8;
}

.workspace-nav {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mode-tabs {
  padding: 4px;
  display: flex;
  gap: 4px;
  background: #f1f1ef;
  border-radius: 8px;
}

.tab {
  border: 0;
  border-radius: 6px;
  padding: 9px 20px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}

.tab.active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.status-strip {
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.status-strip strong {
  color: var(--ink);
}

.language-switch {
  height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 3px;
  background: #f1f1ef;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.language-switch button {
  min-width: 38px;
  height: 24px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 850;
  cursor: pointer;
}

.language-switch button.active {
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.result-export-button {
  height: 34px;
  padding: 0 14px;
  color: #ffffff;
  background: #090909;
  border: 0;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  cursor: pointer;
  white-space: nowrap;
}

.result-export-button:hover:not(:disabled) {
  background: #222222;
}

.result-export-button:disabled {
  color: #909090;
  background: #e5e5e1;
  cursor: not-allowed;
}

.auth-top-button {
  max-width: 190px;
  height: 34px;
  padding: 0 12px;
  overflow: hidden;
  color: #ffffff;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #090909;
  border: 0;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.auth-top-button:hover {
  background: #222222;
}

.auth-top-button.signed-in {
  color: var(--ink);
  background: #f1f1ef;
  border: 1px solid var(--line-strong);
}

.auth-top-button.is-hidden {
  display: none;
}

.ready-dot {
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
}

.is-busy .ready-dot {
  background: var(--orange);
}

.studio-fallback-banner {
  min-height: 44px;
  padding: 10px 18px;
  color: #4d3f11;
  background: #fff7d8;
  border-bottom: 1px solid #ead99a;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.35;
  text-align: center;
  overflow: hidden;
}

.studio-fallback-banner-content {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  max-width: 100%;
  white-space: nowrap;
  will-change: transform;
}

.studio-fallback-banner.is-marquee .studio-fallback-banner-content {
  animation: studio-banner-pan var(--studio-banner-duration, 14s) ease-in-out infinite alternate;
}

.studio-fallback-banner.is-marquee:hover .studio-fallback-banner-content {
  animation-play-state: paused;
}

.studio-fallback-banner a {
  color: #175f8d;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@keyframes studio-banner-pan {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(calc(-1 * var(--studio-banner-overflow, 0px)));
  }
}

@media (prefers-reduced-motion: reduce) {
  .studio-fallback-banner.is-marquee .studio-fallback-banner-content {
    animation: none;
    transform: translateX(0);
  }
}

.shell {
  height: calc(100dvh - 106px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, clamp(360px, 42vw, 620px)) minmax(420px, 1fr);
  overflow: hidden;
}

.left-pane {
  min-width: 0;
  min-height: 0;
  padding: 26px;
  background:
    radial-gradient(circle at 0 0, rgba(77, 143, 215, 0.06), transparent 34%),
    linear-gradient(0deg, rgba(0, 0, 0, 0.02), transparent 60%),
    var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
  scrollbar-gutter: stable;
}

.right-pane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) clamp(150px, 23vh, 230px);
  background: var(--bg);
  overflow: hidden;
}

body[data-view="results"] .shell,
body[data-view="citations"] .shell,
body[data-view="history"] .shell {
  grid-template-columns: minmax(0, 1fr);
}

body[data-view="results"] .left-pane,
body[data-view="citations"] .left-pane,
body[data-view="history"] .left-pane,
body[data-view="results"] .log-panel,
body[data-view="citations"] .log-panel,
body[data-view="history"] .log-panel {
  display: none;
}

body[data-view="results"] .right-pane,
body[data-view="citations"] .right-pane,
body[data-view="history"] .right-pane {
  grid-template-rows: minmax(0, 1fr);
}

body[data-view="results"] .workflow,
body[data-view="citations"] .workflow,
body[data-view="history"] .workflow {
  padding: 26px;
}

.query-section,
.config-section {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(12, 12, 12, 0.42);
}

.modal-overlay.is-hidden {
  display: none;
}

.auth-modal,
.config-modal {
  position: relative;
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
}

.auth-modal {
  width: min(640px, 100%);
}

.config-modal {
  width: min(520px, 100%);
}

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

.config-modal-content h2 {
  margin-right: 34px;
}

.config-modal-list {
  display: grid;
  gap: 10px;
  max-height: min(52vh, 420px);
  overflow: auto;
}

.config-modal-check {
  padding: 12px;
  background: #fff8f7;
  border: 1px solid #efb7a6;
  border-radius: 8px;
}

.config-modal-check strong,
.config-modal-check span {
  display: block;
  overflow-wrap: anywhere;
}

.config-modal-check span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  color: var(--muted);
  background: #f1f1ef;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--ink);
  background: #ffffff;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.oauth-actions {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.oauth-button {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}

.oauth-button:hover {
  background: #f7f7f5;
}

.oauth-icon {
  width: 20px;
  height: 20px;
  display: block;
  fill: #171717;
  flex: 0 0 auto;
}

.modelscope-icon {
  border-radius: 5px;
  object-fit: contain;
}

.auth-divider {
  position: relative;
  margin: 10px 0;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.auth-divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--line);
}

.auth-divider span {
  position: relative;
  padding: 0 9px;
  background: var(--panel);
}

.auth-actions,
.auth-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-secondary-actions {
  margin-top: 10px;
}

.auth-user {
  justify-content: space-between;
  min-width: 0;
  padding: 12px;
  background: #f8f8f6;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-user > div:first-child {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.auth-user strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.auth-user-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-identity-overview {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  margin-bottom: 12px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-identity-overview strong {
  font-size: 13px;
}

.auth-identity-overview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.auth-identity-overview th,
.auth-identity-overview td {
  padding: 7px 0;
  border-top: 1px solid #ececea;
  vertical-align: middle;
}

.auth-identity-overview th {
  color: var(--muted);
  font-weight: 750;
  text-align: left;
}

.auth-identity-overview td {
  text-align: right;
}

.identity-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
}

.identity-status.connected {
  color: #1f5e3b;
  background: var(--green-soft);
}

.identity-status.uid {
  max-width: min(280px, 58vw);
  min-height: auto;
  padding: 4px 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  text-align: left;
}

.identity-status.missing {
  color: #66501d;
  background: #fff4cc;
}

.linked-account-panel {
  display: grid;
  gap: 10px;
  margin: 0 0 12px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.linked-account-head {
  display: grid;
  gap: 3px;
}

.linked-account-head strong {
  font-size: 13px;
}

.linked-account-head span,
.linked-account-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.linked-account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid #ececea;
}

.linked-account-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.linked-account-copy strong {
  font-size: 13px;
}

.linked-account-state {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.linked-account-state button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.auth-verification {
  display: grid;
  gap: 8px;
  padding: 14px;
  margin-bottom: 12px;
  background: #f8f8f6;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-verification.success {
  background: var(--green-soft);
  border-color: #bcd8b8;
}

.auth-verification strong {
  overflow-wrap: anywhere;
}

.auth-verification p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.auth-progress {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
  background: #f8f8f6;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-progress strong {
  display: block;
  overflow-wrap: anywhere;
}

.auth-progress p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #ddddda;
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
}

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

.auth-message {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.auth-message.error {
  padding: 10px 12px;
  color: #8f2d1c;
  background: #fff3ef;
  border: 1px solid #efb7a6;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 750;
}

.auth-hint {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.link-button {
  justify-self: start;
  width: fit-content;
  padding: 0;
  color: #246d92;
  background: transparent;
  border: 0;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.link-button:hover {
  color: var(--ink);
  text-decoration: underline;
}

.query-section {
  padding: 18px;
}

.config-section {
  margin-top: 18px;
  padding: 18px;
}

.section-kicker {
  color: var(--orange);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.section-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

h2 {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

.privacy-pill {
  padding: 6px 10px;
  color: #3f7f43;
  background: var(--green-soft);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

textarea {
  width: 100%;
  min-height: 96px;
  margin-top: 12px;
  padding: 14px;
  resize: vertical;
  color: var(--ink);
  background: #fbfbfa;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
  line-height: 1.5;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(77, 143, 215, 0.16);
}

textarea.is-invalid,
input.is-invalid,
select.is-invalid {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(198, 61, 50, 0.14);
}

.discipline-picker {
  margin-top: 10px;
}

.discipline-picker summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fbfbfa;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
}

.discipline-picker summary::-webkit-details-marker {
  display: none;
}

.discipline-picker summary span {
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.discipline-picker summary small {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.discipline-picker[open] summary {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(77, 143, 215, 0.16);
}

.discipline-menu {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.discipline-options {
  max-height: 260px;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 3px;
}

.discipline-domain {
  display: grid;
  gap: 5px;
}

.discipline-domain-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.discipline-option {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #fbfbfa;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

.discipline-option input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.discipline-option span {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
}

.empty-mini {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.discipline-menu .utility-button {
  width: 100%;
  margin-top: 10px;
}

.primary-button {
  width: 100%;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: #090909;
  font-weight: 850;
  cursor: pointer;
}

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

.query-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px 112px;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

.query-actions .secondary-button {
  width: 100%;
  height: 48px;
  white-space: nowrap;
}

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

.config-group {
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
}

.config-group:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}

.config-group-title {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

.oauth-source-note {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  padding: 12px;
  color: var(--muted);
  background: #f7f7f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
}

.oauth-source-note strong {
  color: var(--ink);
  font-size: 13px;
}

.openalex-key-guide {
  width: 100%;
  min-width: 0;
  padding: 12px;
  color: var(--muted);
  background: #f8faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
}

.openalex-key-guide.span-2 {
  grid-column: span 2;
}

.openalex-key-guide strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 13px;
}

.openalex-key-guide ol {
  margin: 0;
  padding-left: 18px;
}

.openalex-key-guide li + li {
  margin-top: 3px;
}

.openalex-key-guide a {
  color: var(--blue);
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.config-mode-switch {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.config-mode-switch label {
  min-width: 0;
  display: grid;
  grid-template-columns: 18px minmax(120px, 0.42fr) minmax(0, 1fr);
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
  min-height: 58px;
  padding: 12px 14px;
  background: #f7f7f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.config-mode-switch label:has(input:checked),
.config-mode-switch label.is-active {
  background: #ffffff;
  border-color: var(--line-strong);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.config-mode-switch input {
  width: 15px;
  height: 15px;
  margin: 0;
}

.config-mode-switch span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.2;
}

.config-mode-switch small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.config-mode-panel {
  padding: 14px;
  background: #fbfbfa;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quick-start-config,
.modelscope-config {
  position: relative;
  min-height: 220px;
}

.requires-auth-body {
  transition: filter 0.18s ease, opacity 0.18s ease;
}

.quick-login-overlay {
  position: absolute;
  inset: 44px 14px 14px;
  z-index: 2;
  display: none;
  place-items: center;
  padding: 22px;
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(7px);
}

.quick-login-overlay > div {
  display: grid;
  gap: 8px;
  max-width: 360px;
}

.quick-login-overlay strong {
  font-size: 18px;
  line-height: 1.2;
}

.quick-login-overlay span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.quick-login-overlay .primary-inline-button {
  margin-top: 14px;
}

.auth-locked .requires-auth-body,
.email-unbound .quick-start-config .requires-auth-body,
.modelscope-locked .modelscope-config-body {
  filter: blur(2px);
  opacity: 0.38;
  pointer-events: none;
}

body[data-config-mode="quick"].auth-locked .quick-start-config .quick-login-overlay,
body[data-config-mode="quick"].email-unbound .quick-start-config .quick-login-overlay,
body[data-config-mode="modelscope"].auth-locked .modelscope-config .quick-login-overlay,
body[data-config-mode="modelscope"].modelscope-locked .modelscope-config .quick-login-overlay {
  display: grid;
}

.advanced-config {
  display: none;
  gap: 14px;
}

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

.advanced-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.mode-pill {
  flex: 0 0 auto;
  padding: 6px 9px;
  color: #246d92;
  background: var(--blue-soft);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.advanced-block {
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.advanced-block + .advanced-block {
  margin-top: 12px;
}

.advanced-block-title {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.quick-start-config,
.modelscope-config,
.advanced-config {
  display: none;
}

body[data-config-mode="quick"] .quick-start-config {
  display: block;
}

body[data-config-mode="modelscope"] .modelscope-config {
  display: block;
}

body[data-config-mode="own"] .advanced-config,
body[data-config-mode="advanced"] .advanced-config {
  display: block;
}

.hidden-control {
  display: none;
}

.field,
.toggle-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field.span-2 {
  grid-column: span 2;
}

.model-pool-summary {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 12px;
  background: #fbfbfa;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.model-pool-summary.span-2 {
  grid-column: span 2;
}

.model-pool-summary span {
  color: #555855;
  font-size: 12px;
  font-weight: 750;
}

.model-pool-summary strong,
.model-pool-summary small {
  overflow-wrap: anywhere;
}

.model-pool-summary small {
  color: var(--muted);
  line-height: 1.45;
}

.source-summary {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 12px;
  background: #fbfbfa;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.source-summary.span-2 {
  grid-column: span 2;
}

.source-summary span {
  color: #555855;
  font-size: 12px;
  font-weight: 750;
}

.source-summary strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.2;
}

.source-summary small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.config-advanced {
  margin-top: 14px;
  border-top: 1px solid var(--line);
}

.config-advanced summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}

.config-advanced summary::-webkit-details-marker {
  display: none;
}

.config-advanced summary span {
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

.config-advanced summary small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.35;
  text-align: right;
}

.config-advanced summary::after {
  content: "+";
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #f4f4f2;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-weight: 900;
}

.config-advanced[open] summary::after {
  content: "-";
}

.config-advanced-body {
  display: grid;
  gap: 12px;
  padding-top: 14px;
}

.toggle-field.span-2 {
  grid-column: span 2;
}

.field.is-hidden,
.source-field.is-hidden {
  display: none;
}

.field span,
.toggle-field span {
  color: #555855;
  font-size: 12px;
  font-weight: 750;
}

.field-hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

input,
select {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  color: var(--ink);
  background: #fbfbfa;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
}

.toggle-field {
  height: 42px;
  margin-top: 23px;
  flex-direction: row;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fbfbfa;
}

.toggle-field input {
  width: 16px;
  height: 16px;
}

.workflow {
  min-height: 0;
  padding: 26px 26px 20px;
  overflow: auto;
  scrollbar-gutter: stable;
}

.workflow-card {
  margin-bottom: 18px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
}

.workflow-card.processing-card {
  border-color: #f2a184;
}

.workflow-card.error-card {
  border-color: #d77770;
}

.card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.card-title span {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 900;
}

h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.status-badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 6px;
  color: #477c48;
  background: var(--green-soft);
  font-size: 11px;
  font-weight: 850;
}

.status-badge.waiting {
  color: #74766f;
  background: #ecedea;
}

.status-badge.processing {
  color: #d74e25;
  background: var(--orange-soft);
}

.status-badge.error {
  color: var(--red);
  background: #fff0ef;
}

.status-badge.empty {
  color: #8b6a1f;
  background: #fff6da;
}

.status-badge.ready {
  color: #276a8d;
  background: var(--blue-soft);
}

.card-description {
  margin: 18px 0;
  color: var(--muted);
  line-height: 1.55;
}

.empty-state,
.error-box {
  padding: 14px;
  color: var(--muted);
  background: #f6f6f4;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}

.error-box {
  color: var(--red);
  border-style: solid;
  background: #fff8f7;
}

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

.chip-list span {
  padding: 8px 12px;
  color: #62655f;
  background: #f0f0ee;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 18px;
  background: #f7f7f5;
  border-radius: 8px;
}

.metric-row div {
  text-align: center;
}

.metric-row strong {
  display: block;
  font-size: 28px;
}

.metric-row span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

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

.iteration-row {
  padding: 14px;
  background: #f8f8f6;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.iteration-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.iteration-meta strong {
  color: var(--ink);
}

.action-pill {
  padding: 4px 7px;
  border-radius: 6px;
  color: #5a5d55;
  background: #ecedea;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.action-pill.broaden {
  color: #246d92;
  background: var(--blue-soft);
}

.action-pill.narrow {
  color: #d74e25;
  background: var(--orange-soft);
}

.action-pill.repair {
  color: #7b4fa0;
  background: #f1e8f8;
}

.action-pill.simplify {
  color: #7b4fa0;
  background: #f1e8f8;
}

.action-pill.sanitize {
  color: #7b4fa0;
  background: #f1e8f8;
}

.action-pill.accept,
.action-pill.accept_low,
.action-pill.accept_high {
  color: #477c48;
  background: var(--green-soft);
}

code {
  display: block;
  margin-top: 9px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #222420;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.iteration-row p {
  margin: 10px 0 0;
  color: var(--muted);
}

.next-query,
.final-query {
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}

.next-query span,
.final-query span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.candidate-preview {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.candidate-preview > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.candidate-row {
  margin-top: 8px;
  padding: 10px;
  background: #f8f8f6;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.candidate-row strong,
.candidate-row small {
  display: block;
  overflow-wrap: anywhere;
}

.candidate-row strong {
  font-size: 13px;
  line-height: 1.35;
}

.candidate-row small {
  margin-top: 4px;
  color: var(--muted);
}

.paper-list {
  border-top: 1px solid var(--line);
}

.paper-row {
  border-bottom: 1px solid var(--line);
}

.paper-row summary {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 15px 0;
  cursor: pointer;
  list-style: none;
}

.paper-row summary::-webkit-details-marker {
  display: none;
}

.score {
  padding: 5px 7px;
  text-align: center;
  color: #1f5e3b;
  background: var(--green-soft);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 850;
}

.paper-title {
  font-weight: 800;
  line-height: 1.35;
}

.paper-body {
  padding: 0 0 15px 70px;
  color: var(--muted);
  line-height: 1.45;
}

.paper-body p {
  margin: 0 0 8px;
}

.paper-body a {
  color: #246d92;
  font-weight: 750;
  text-decoration: none;
}

.paper-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.workspace-view {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
  padding: 22px;
}

.workspace-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.workspace-header h2 {
  font-size: 22px;
}

.view-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.result-jump-actions,
.results-toolbar,
.citation-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.result-jump-actions {
  margin-top: 14px;
}

.primary-inline-button,
.secondary-button {
  min-height: 36px;
  padding: 0 13px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}

.primary-inline-button {
  color: #ffffff;
  background: #090909;
  border: 0;
}

.secondary-button {
  color: var(--ink);
  background: #f4f4f2;
  border: 1px solid var(--line-strong);
}

.secondary-button.compact {
  min-height: 32px;
  padding: 0 10px;
}

.citation-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.results-toolbar {
  padding: 12px;
  background: #f7f7f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
}

.results-toolbar input,
.results-toolbar select,
.citation-toolbar select {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  padding: 0 10px;
}

.results-toolbar input {
  flex: 1 1 260px;
}

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

.review-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.review-row summary {
  display: grid;
  grid-template-columns: 24px 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
  cursor: pointer;
}

.paper-select {
  width: 16px;
  height: 16px;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.history-list,
.history-detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.history-sidebar {
  display: grid;
  gap: 8px;
}

.history-list {
  display: grid;
  overflow: hidden;
}

.history-list-placeholder {
  min-height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.history-detail-warning {
  margin-bottom: 12px;
  padding: 10px 12px;
  color: #7a4b08;
  background: #fff8e8;
  border: 1px solid #efd9a8;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.35;
}

.history-run-button {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 14px;
  text-align: left;
  background: #ffffff;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.history-run-button:hover,
.history-run-button.active {
  background: #f7f7f5;
}

.history-run-button strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.history-run-button span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.history-detail-panel {
  min-width: 0;
  padding: 16px;
}

.history-detail-head {
  display: grid;
  gap: 8px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.history-detail-head h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

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

.history-meta span {
  padding: 5px 8px;
  color: var(--muted);
  background: #f3f3f1;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 750;
}

.history-query {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
}

.history-query p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.history-query span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.history-query code {
  white-space: pre-wrap;
  word-break: break-word;
  padding: 10px;
  background: #f6f6f4;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.history-event-list {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.history-event-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.history-event-row span:last-child {
  overflow-wrap: anywhere;
}

.citation-summary-grid .metric-row {
  margin-bottom: 14px;
}

.citation-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 14px;
  align-items: stretch;
}

.citation-map-panel,
.citation-detail,
.seed-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.citation-map-panel {
  min-width: 0;
  overflow: hidden;
}

.citation-toolbar {
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f7f7f5;
}

.citation-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.legend-dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 50%;
  margin-right: 5px;
}

.legend-dot.result { background: var(--orange); }
.legend-dot.seed { background: var(--blue); }
.legend-dot.forward { background: var(--green); }
.legend-dot.backward { background: #8a64b7; }

.citation-graph {
  min-height: 460px;
  background:
    radial-gradient(circle at 1px 1px, rgba(0, 0, 0, 0.08) 1px, transparent 0),
    #fbfbfa;
  background-size: 18px 18px;
}

.citation-graph svg {
  width: 100%;
  height: 100%;
  min-height: 460px;
  display: block;
  cursor: grab;
  touch-action: none;
}

.citation-graph svg:active {
  cursor: grabbing;
}

.citation-edge {
  stroke: #9da29b;
  stroke-width: 1.7;
  marker-end: url(#arrow);
}

.citation-graph marker path {
  fill: #9da29b;
}

.citation-node {
  cursor: grab;
}

.citation-node:active {
  cursor: grabbing;
}

.citation-node circle {
  stroke: #ffffff;
  stroke-width: 2;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.16));
}

.citation-node text {
  text-anchor: middle;
  fill: #333333;
  font-size: 10px;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 3px;
}

.citation-node.result circle { fill: var(--orange); }
.citation-node.seed circle { fill: var(--blue); }
.citation-node.forward circle { fill: var(--green); }
.citation-node.backward circle { fill: #8a64b7; }
.citation-node.candidate circle { fill: var(--muted); }

.citation-node.selected circle {
  stroke: #000000;
  stroke-width: 3;
}

.citation-detail {
  padding: 16px;
  color: var(--muted);
  line-height: 1.45;
}

.citation-detail h3 {
  margin: 5px 0 10px;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.25;
}

.detail-kicker {
  color: var(--orange);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.seed-list {
  margin-top: 14px;
  padding: 14px;
}

.seed-list h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.seed-row {
  width: 100%;
  display: grid;
  gap: 3px;
  text-align: left;
  padding: 10px 0;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.seed-row strong {
  color: var(--ink);
}

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

.log-panel {
  min-height: 0;
  height: 100%;
  color: #d8d8d8;
  background: var(--console);
  border-top: 1px solid #202020;
  overflow: hidden;
}

.log-header {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  color: #8d8d8d;
  border-bottom: 1px solid #1f1f1f;
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
}

.log-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.utility-button {
  min-width: 0;
  height: 22px;
  padding: 0 8px;
  color: #d8d8d8;
  background: #161616;
  border: 1px solid #2d2d2d;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.utility-button:hover:not(:disabled) {
  border-color: #4d4d4d;
  background: #202020;
}

.utility-button:disabled {
  color: #5b5b5b;
  cursor: not-allowed;
}

#logOutput {
  height: calc(100% - 34px);
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  color: #bfbfbf;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  scrollbar-gutter: stable;
}

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

  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    padding: 14px;
  }

  .workspace-nav,
  .mode-tabs,
  .status-strip {
    justify-self: stretch;
  }

  .workspace-nav {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

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

  .shell {
    height: auto;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .left-pane {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .right-pane {
    height: calc(100dvh - 24px);
    min-height: 640px;
  }
}

@media (max-width: 620px) {
  .left-pane,
  .workflow {
    padding: 16px;
  }

  body[data-view="results"] .workflow,
  body[data-view="citations"] .workflow,
  body[data-view="history"] .workflow {
    padding: 16px;
  }

  .field-grid,
  .metric-row {
    grid-template-columns: 1fr;
  }

  .config-mode-switch label {
    grid-template-columns: 18px minmax(0, 1fr);
  }

  .config-mode-switch small {
    grid-column: 2;
  }

  .query-actions {
    grid-template-columns: 1fr 1fr;
  }

  .query-actions .primary-button {
    grid-column: span 2;
  }

  .field.span-2 {
    grid-column: span 1;
  }

  .openalex-key-guide.span-2 {
    grid-column: span 1;
  }

  .model-pool-summary.span-2 {
    grid-column: span 1;
  }

  .paper-row summary {
    grid-template-columns: 1fr;
  }

  .review-row summary {
    grid-template-columns: 24px 1fr;
  }

  .review-row .score {
    grid-column: 2;
  }

  .citation-layout {
    grid-template-columns: 1fr;
  }

  .history-layout {
    grid-template-columns: 1fr;
  }

  .citation-graph,
  .citation-graph svg {
    min-height: 360px;
  }

  .paper-body {
    padding-left: 0;
  }

  .topbar {
    gap: 12px;
  }

  .workspace-nav,
  .mode-tabs {
    width: 100%;
  }

  .mode-tabs {
    overflow-x: auto;
  }

  .brand-title {
    font-size: 17px;
  }

  .tab {
    padding: 8px 12px;
  }

  .log-header {
    padding: 0 10px;
    font-size: 10px;
  }

  .log-actions {
    gap: 4px;
  }

  .utility-button {
    padding: 0 5px;
    font-size: 9px;
  }

  .linked-account-row {
    grid-template-columns: 1fr;
  }

  .linked-account-state {
    justify-content: flex-start;
  }

  .auth-modal {
    padding: 18px;
  }
}
