:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #65736f;
  --paper: #f7f8f4;
  --surface: #ffffff;
  --line: #dbe2dd;
  --green: #1f6b5a;
  --green-dark: #134a3f;
  --rust: #a45336;
  --gold: #d7a856;
  --blue: #365d7c;
  --danger: #9a3412;
  --shadow: 0 20px 50px rgba(23, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 20px;
  align-items: center;
  min-height: 72px;
  padding: 0 clamp(18px, 3vw, 38px);
  background: rgba(247, 248, 244, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: white;
  background: var(--green);
  border-radius: 8px;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.topnav {
  display: inline-flex;
  gap: 8px;
}

.topnav a {
  padding: 8px 10px;
  color: var(--muted);
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.topnav a:hover,
.topnav a:focus-visible {
  color: var(--green-dark);
  background: #e8f1ed;
}

.shell {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(420px, 1fr) minmax(280px, 340px);
  gap: 18px;
  width: min(1480px, calc(100% - 32px));
  margin: 18px auto 42px;
  align-items: start;
}

.side-panel,
.report-panel {
  display: grid;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel,
.model-panel,
.study-panel,
.report-panel .panel {
  padding: 20px;
}

.panel-heading h1,
.panel-heading h2,
.panel-title-row h2 {
  margin: 0;
  letter-spacing: 0;
}

.panel-heading h1 {
  font-size: 1.75rem;
  line-height: 1.08;
}

.panel-heading h2,
.panel-title-row h2 {
  font-size: 1.18rem;
}

.panel-heading.wide {
  margin-bottom: 18px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--rust);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-line,
.form-status {
  color: var(--muted);
  font-size: 0.9rem;
}

.status-line {
  margin: 16px 0;
  padding: 10px 12px;
  background: #f3f6f4;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: #edf1ee;
  border-radius: 8px;
}

.segment {
  min-height: 38px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-weight: 800;
}

.segment.is-active {
  color: var(--green-dark);
  background: white;
  box-shadow: 0 1px 4px rgba(23, 33, 31, 0.08);
}

.stack {
  display: grid;
  gap: 12px;
}

.model-config-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #f2f8f5;
  border: 1px solid #cfe3db;
  border-radius: 8px;
}

.model-config-summary strong,
.model-config-summary small {
  display: block;
}

.model-config-summary small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.45;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

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

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 107, 90, 0.14);
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  min-height: 42px;
  border-radius: 6px;
  font-weight: 900;
}

.primary-button {
  color: white;
  background: var(--green);
  border: 1px solid var(--green);
}

.primary-button:hover {
  background: var(--green-dark);
}

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

.secondary-button {
  color: var(--green-dark);
  background: #eaf4f0;
  border: 1px solid #c7ddd5;
}

.compact-button {
  min-height: 36px;
  padding: 0 12px;
}

.ghost-button {
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  padding: 0 13px;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  color: var(--blue);
  background: #eef5f9;
  border: 1px solid #d5e5ed;
  font-size: 1.1rem;
}

.icon-button.is-refreshing {
  animation: progress-spin 0.8s linear infinite;
  cursor: wait;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  color: var(--blue);
  background: #edf5fa;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 900;
}

.workspace {
  display: grid;
  gap: 18px;
}

.study-visual {
  height: clamp(168px, 15vw, 220px);
  overflow: hidden;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

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

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.type-fieldset {
  grid-column: 1 / -1;
}

.type-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.type-card {
  min-height: 94px;
  padding: 13px;
  text-align: left;
  color: var(--ink);
  background: #f7faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.type-card strong,
.type-card small {
  display: block;
}

.type-card small {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.45;
}

.type-card.is-active {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 107, 90, 0.12);
}

.inline-fieldset {
  display: flex;
  gap: 12px;
  align-items: end;
}

.radio-line {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-height: 42px;
  color: var(--ink);
  font-weight: 800;
}

.radio-line input {
  width: 16px;
  min-height: 16px;
}

.submit-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 12px;
  align-items: center;
}

.submit-row .primary-button {
  min-width: 132px;
}

.progress-status {
  display: none;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  max-width: 100%;
  padding: 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1.35;
  background: #f7faf8;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.progress-status.is-visible {
  display: inline-flex;
}

.progress-status::before {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--green);
  content: "";
}

.progress-status.is-running::before {
  border: 2px solid rgba(31, 107, 90, 0.22);
  border-top-color: var(--green);
  background: transparent;
  animation: progress-spin 0.8s linear infinite;
}

.progress-status.is-success {
  color: var(--green-dark);
  background: #eaf4f0;
  border-color: #c7ddd5;
}

.progress-status.is-error {
  color: var(--danger);
  background: #fff7ed;
  border-color: rgba(154, 52, 18, 0.28);
}

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

.report-list {
  display: grid;
  gap: 10px;
  min-height: 120px;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  background: #f6f8f6;
  border: 1px dashed #cfd8d3;
  border-radius: 8px;
  line-height: 1.65;
}

.report-item {
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 13px;
  text-align: left;
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.report-item strong {
  font-size: 0.95rem;
  line-height: 1.35;
}

.report-item small {
  color: var(--muted);
}

.report-item:hover,
.report-item:focus-visible {
  border-color: var(--green);
}

.report-viewer {
  position: fixed;
  inset: 22px;
  z-index: 20;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(23, 33, 31, 0.22);
}

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

.viewer-toolbar h2 {
  margin: 0;
  font-size: 1.05rem;
}

.viewer-actions {
  display: inline-flex;
  gap: 10px;
  align-items: center;
}

#reportFrame {
  width: 100%;
  height: 100%;
  border: 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: 360px;
  padding: 12px 14px;
  color: white;
  background: var(--green-dark);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.is-error {
  color: var(--danger);
}

[hidden] {
  display: none !important;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 320px minmax(0, 1fr);
  }

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

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .topnav {
    grid-column: 1 / -1;
    justify-content: space-between;
  }

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

  .study-grid,
  .type-options {
    grid-template-columns: 1fr;
  }

  .inline-fieldset,
  .submit-row {
    align-items: stretch;
    flex-direction: column;
  }

  .progress-status {
    width: 100%;
  }

  .model-config-summary {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .viewer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .report-viewer {
    inset: 8px;
  }
}
