:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #647084;
  --line: #dce3ee;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --soft: #e9f5f3;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

.hidden {
  display: none !important;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef5f6;
}

.auth-card {
  width: min(460px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 55px rgba(15, 23, 42, 0.12);
}

.auth-card h1 {
  margin: 0;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-tabs button {
  border: 0;
}

.auth-tabs button.active {
  background: var(--primary);
  color: #fff;
}

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

.auth-form.active {
  display: grid;
}

.auth-message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
}

.auth-message.success {
  color: var(--primary-dark);
}

.user-chip {
  max-width: 220px;
  padding: 8px 10px;
  border-radius: 999px;
  color: #d6f4ef;
  border: 1px solid rgba(255, 255, 255, 0.25);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--primary);
}

.topbar {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  background: #0b2f37;
  color: #fff;
}

.topbar h1,
.case-head h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0;
}

.topbar .eyebrow {
  color: #aad6d0;
}

.status {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 8px 12px;
  color: #d6f4ef;
  font-weight: 700;
  min-width: 190px;
  text-align: center;
}

.status.locked {
  border-color: #fecaca;
  background: #fff1f2;
  color: #b42318;
}

.status.ready {
  border-color: #7dd3c7;
  background: #ecfdf8;
  color: #115e59;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.view-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
}

.view-switch button {
  border: 0;
  background: transparent;
  color: #d6f4ef;
  padding: 7px 12px;
}

.view-switch button.active {
  background: #fff;
  color: #0b2f37;
}

.api-unlock {
  display: flex;
  gap: 6px;
  align-items: center;
}

.api-unlock input {
  width: 112px;
  height: 38px;
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.api-unlock input::placeholder {
  color: #b9d8d3;
}

.api-unlock button {
  height: 38px;
  border-color: rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #d6f4ef;
}

.llm-ready .api-unlock button {
  background: #fff;
  color: #0b2f37;
  cursor: default;
}

.llm-locked .api-unlock button {
  border-color: #fca5a5;
  background: #fff1f2;
  color: #b42318;
}

.llm-ready .api-unlock input {
  border-color: #7dd3c7;
  background: rgba(236, 253, 248, 0.16);
}

.llm-locked .topbar {
  box-shadow: inset 0 -3px 0 #b42318;
}

.llm-ready .topbar {
  box-shadow: inset 0 -3px 0 #14b8a6;
}

.toast {
  position: fixed;
  top: 92px;
  right: 22px;
  z-index: 20;
  max-width: 380px;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: 0 12px 35px rgba(15, 23, 42, 0.18);
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: #7dd3c7;
  background: #ecfdf8;
  color: var(--primary-dark);
}

.toast.error {
  border-color: #f3b4ae;
  background: #fff5f5;
  color: var(--danger);
}

.layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.sidebar,
.workspace {
  min-height: calc(100vh - 118px);
}

.sidebar,
.viewer,
.report-panel,
.agent-panel,
.task-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sidebar {
  padding: 14px;
  overflow: auto;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
}

.disease-title {
  margin: 16px 0 8px;
  color: var(--muted);
  font-weight: 700;
}

.case-card {
  width: 100%;
  display: block;
  text-align: left;
  margin-bottom: 8px;
  background: #fff;
}

.case-card.active {
  border-color: var(--primary);
  background: var(--soft);
}

.case-card strong {
  display: block;
  margin-bottom: 3px;
}

.case-card span {
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.task-panel {
  padding: 14px;
}

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

.student-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
}

.analytics-box {
  color: var(--text);
  line-height: 1.65;
}

.analytics-box p {
  margin: 8px 0;
}

.score-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.score-row span {
  border: 1px solid #b9e5df;
  border-radius: 999px;
  padding: 6px 9px;
  background: #f0fbf8;
  color: var(--primary-dark);
  font-weight: 700;
}

.teacher-dashboard {
  margin-top: 14px;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 14px;
}

.analytics-table th,
.analytics-table td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.analytics-table th {
  background: #f8fafc;
}

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

.panel-title h2 {
  margin: 0;
  font-size: 18px;
}

.panel-title.compact {
  margin-bottom: 10px;
}

.case-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.case-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toggle {
  color: var(--muted);
  white-space: nowrap;
}

.toggle input {
  width: auto;
}

.viewer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 14px;
  min-height: 470px;
}

.viewer {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.phase-tabs {
  display: flex;
  gap: 8px;
  padding: 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.phase-tabs button {
  white-space: nowrap;
}

.phase-tabs button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.image-stage {
  min-height: 420px;
  display: grid;
  place-items: center;
  padding: 14px;
  background: #111827;
  color: #cbd5e1;
}

.image-pair {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: center;
}

.image-pair.single {
  grid-template-columns: minmax(0, 1fr);
}

.image-pair.single .image-card img {
  max-height: 70vh;
}

.image-card {
  min-width: 0;
}

.image-card p {
  margin: 0 0 8px;
  color: #dbeafe;
  font-size: 14px;
}

.image-card img {
  width: 100%;
  max-height: 63vh;
  object-fit: contain;
  background: #000;
  border-radius: 6px;
}

.report-panel {
  padding: 14px;
  overflow: auto;
}

.report-panel h3 {
  margin: 0 0 12px;
}

.report-images {
  display: grid;
  gap: 12px;
}

.report-images img {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.agent-panel {
  padding: 14px;
}

.role-view {
  display: none;
}

.role-view.active {
  display: block;
}

body[data-view="student"] .teacher-only {
  display: none !important;
}

body[data-view="student"] .viewer-grid {
  grid-template-columns: minmax(0, 1fr);
}

body[data-view="teacher"] .viewer-grid {
  grid-template-columns: minmax(0, 1fr) 310px;
}

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

.task-grid label,
.wide-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.task-grid input,
.wide-field textarea {
  color: var(--text);
  font-weight: 400;
}

.wide-field {
  margin-top: 10px;
}

.wide-field textarea {
  min-height: 78px;
}

.competency {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.competency span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: #fff;
}

.competency span.ok {
  border-color: #7dd3c7;
  background: var(--soft);
  color: var(--primary-dark);
}

.student-actions,
.teacher-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.student-actions button,
.teacher-actions button {
  min-height: 40px;
}

.student-actions button.active,
.teacher-actions button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.student-actions button.active:hover,
.teacher-actions button.active:hover {
  background: var(--primary-dark);
}

.teacher-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
}

.teacher-tools {
  min-width: 0;
}

.agent-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.agent-tabs {
  display: none;
}

.agent-tabs button.active,
.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

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

textarea {
  min-height: 118px;
  resize: vertical;
}

.quick-prompts {
  display: grid;
  gap: 8px;
  align-content: start;
}

.agent-actions {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

#busy {
  color: var(--muted);
}

pre {
  white-space: pre-wrap;
  margin: 12px 0 0;
  padding: 14px;
  min-height: 170px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  line-height: 1.6;
}

.interaction-box {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.interaction-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.interaction-head strong {
  color: var(--primary-dark);
}

.interaction-log {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
  padding-right: 4px;
}

.log-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}

.log-item.ai {
  border-color: #b9e5df;
  background: #f0fbf8;
}

.log-item.student {
  border-color: #dbe4f0;
  background: #f8fafc;
}

.log-item.teacher {
  border-color: #c7d2fe;
  background: #f5f7ff;
}

.log-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.log-text {
  white-space: pre-wrap;
  line-height: 1.55;
}

.empty-log {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1050px) {
  .layout,
  .viewer-grid,
  .prompt-grid,
  .task-grid,
  .teacher-grid,
  .student-grid {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .workspace {
    min-height: auto;
  }

  .case-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .image-pair {
    grid-template-columns: 1fr;
  }
}
