:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-muted: #f9fafb;
  --text: #172033;
  --muted: #697386;
  --line: #d8dee8;
  --primary: #1f6feb;
  --primary-dark: #1557b0;
  --teal: #087f7a;
  --amber: #b7791f;
  --rose: #c2414b;
  --green: #237a4b;
  --shadow: 0 18px 40px rgba(20, 31, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--primary);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.brand h1,
.brand p,
.section-heading h2,
.panel-title h2,
.empty-state h2,
.result-section h2 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
  word-break: keep-all;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

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

.status-pill,
.risk-badge,
.small-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-pill.ok {
  border-color: rgba(35, 122, 75, 0.35);
  color: var(--green);
  background: #eef8f2;
}

.status-pill.warn {
  border-color: rgba(183, 121, 31, 0.35);
  color: var(--amber);
  background: #fff8e8;
}

.token-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.token-field input {
  width: 150px;
  height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.app-shell {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 18px;
}

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

.history-panel {
  align-self: start;
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 112px);
  overflow: hidden;
}

.panel-title,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-title h2,
.section-heading h2 {
  font-size: 16px;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 178px);
  overflow: auto;
  padding: 14px;
}

.history-item {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.history-item:hover,
.history-item:focus-visible {
  border-color: rgba(31, 111, 235, 0.45);
  outline: none;
}

.history-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--text);
  font-weight: 650;
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 0.92fr) minmax(460px, 1.08fr);
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.input-panel {
  overflow: hidden;
}

.field-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1fr;
  gap: 12px;
  padding: 18px 18px 0;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

input,
select {
  min-height: 40px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
  min-height: 118px;
  padding: 10px 11px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(31, 111, 235, 0.2);
  border-color: rgba(31, 111, 235, 0.6);
}

.stacked,
.upload-zone,
.toggle-grid,
.privacy-note,
.form-actions {
  margin: 16px 18px 0;
}

.upload-zone {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px dashed #b9c3d2;
  border-radius: 8px;
  background: var(--panel-muted);
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.file-picker span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 160px;
  min-height: 38px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--teal);
  font-weight: 650;
}

.file-list {
  display: grid;
  gap: 8px;
}

.file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.file-name {
  overflow: hidden;
  color: var(--text);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-status {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.file-preview {
  grid-column: 1 / -1;
  max-height: 84px;
  overflow: hidden;
  padding: 9px;
  border-radius: 8px;
  background: var(--panel-muted);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

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

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 48px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
  color: var(--text);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.privacy-note {
  padding: 11px 12px;
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  color: #654400;
  background: #fff8e8;
  font-size: 13px;
  line-height: 1.55;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  padding-bottom: 18px;
}

.primary-button,
.secondary-button,
.icon-button,
.feedback-button {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 650;
}

.primary-button {
  min-width: 128px;
  color: #ffffff;
  background: var(--primary);
}

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

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

.secondary-button,
.icon-button,
.feedback-button {
  color: var(--text);
  background: #ffffff;
  border-color: var(--line);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.result-panel {
  min-height: 640px;
  padding: 18px;
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 600px;
  text-align: center;
}

.empty-state h2 {
  font-size: 20px;
}

.empty-state p {
  max-width: 420px;
  color: var(--muted);
  line-height: 1.6;
}

.loading-box {
  display: grid;
  place-content: center;
  min-height: 460px;
  color: var(--muted);
  text-align: center;
}

.result-stack {
  display: grid;
  gap: 14px;
}

.result-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.result-section h2 {
  font-size: 16px;
}

.risk-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.risk-badge.red {
  border-color: rgba(194, 65, 75, 0.35);
  color: var(--rose);
  background: #fff1f2;
}

.risk-badge.yellow {
  border-color: rgba(183, 121, 31, 0.35);
  color: var(--amber);
  background: #fff8e8;
}

.risk-badge.green {
  border-color: rgba(35, 122, 75, 0.35);
  color: var(--green);
  background: #eef8f2;
}

.plain-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.plain-list li {
  line-height: 1.55;
}

.info-grid {
  display: grid;
  gap: 10px;
}

.info-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.info-card strong {
  display: block;
  margin-bottom: 5px;
}

.finding-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.finding-table th,
.finding-table td {
  padding: 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

.finding-table th {
  color: var(--muted);
  background: var(--panel-muted);
  font-size: 12px;
}

.finding-table tr:last-child td {
  border-bottom: 0;
}

.recommendation {
  display: grid;
  gap: 10px;
}

.doctor-list {
  display: grid;
  gap: 8px;
}

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

.feedback-box {
  display: grid;
  gap: 10px;
}

.feedback-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.feedback-box textarea {
  min-height: 76px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.error-text {
  color: var(--rose);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .result-panel {
    min-height: 420px;
  }
}

@media (max-width: 900px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 12px 14px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 24px;
  }

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

  .brand p {
    font-size: 12px;
  }

  .top-actions {
    justify-content: flex-start;
    gap: 8px;
  }

  .status-pill,
  .risk-badge,
  .small-badge {
    min-height: 30px;
    white-space: normal;
  }

  .token-field {
    flex: 1 1 220px;
  }

  .token-field input {
    min-width: 0;
    flex: 1;
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .workspace {
    order: 1;
    gap: 12px;
  }

  .history-panel {
    order: 2;
    position: static;
    max-height: none;
  }

  .history-list {
    max-height: 240px;
  }

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

  .panel-title,
  .section-heading {
    padding: 14px;
  }

  .result-panel {
    min-height: 0;
    padding: 14px;
  }

  .empty-state,
  .loading-box {
    min-height: 260px;
  }

  .finding-table {
    display: block;
    border: 0;
    overflow: visible;
  }

  .finding-table thead {
    display: none;
  }

  .finding-table tbody,
  .finding-table tr,
  .finding-table td {
    display: block;
    width: 100%;
  }

  .finding-table tr {
    margin-bottom: 10px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
  }

  .finding-table td {
    min-height: 0;
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
  }

  .finding-table td::before {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
  }

  .finding-table td:nth-child(1)::before {
    content: "项目";
  }

  .finding-table td:nth-child(2)::before {
    content: "结果";
  }

  .finding-table td:nth-child(3)::before {
    content: "解释";
  }

  .finding-table td:nth-child(4)::before {
    content: "后续";
  }

  .finding-table td:last-child {
    border-bottom: 0;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
  }

  .brand {
    min-width: 0;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .top-actions,
  .token-field {
    width: 100%;
  }

  .token-field input {
    flex: 1;
  }

  .field-grid,
  .stacked,
  .upload-zone,
  .toggle-grid,
  .privacy-note,
  .form-actions {
    margin-left: 12px;
    margin-right: 12px;
  }

  .field-grid {
    padding-top: 12px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  input,
  select {
    min-height: 44px;
  }

  textarea {
    min-height: 104px;
  }

  .file-picker span,
  .primary-button,
  .secondary-button,
  .feedback-button {
    width: 100%;
    min-height: 44px;
  }

  .form-actions {
    display: grid;
    padding-bottom: 12px;
  }

  .toggle-row {
    min-height: 44px;
    padding: 10px 11px;
  }

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

  .file-name {
    white-space: normal;
    word-break: break-word;
  }

  .result-stack {
    gap: 10px;
  }

  .result-section {
    padding: 12px;
  }

  .info-card,
  .doctor-row {
    padding: 10px;
  }

  .plain-list {
    padding-left: 18px;
  }

  .panel-title,
  .section-heading,
  .result-panel {
    padding: 14px 12px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 10px;
  }

  .field-grid,
  .stacked,
  .upload-zone,
  .toggle-grid,
  .privacy-note,
  .form-actions {
    margin-left: 10px;
    margin-right: 10px;
  }

  .panel-title,
  .section-heading,
  .result-panel {
    padding: 12px 10px;
  }

  .brand p {
    display: none;
  }
}
