:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #5c6a72;
  --line: #d8e0e3;
  --surface: #ffffff;
  --band: #f5f7f2;
  --accent: #1f6f78;
  --accent-2: #b35b3a;
  --accent-3: #798b3d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #fbfcfb;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

[hidden] {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(31, 111, 120, 0.08), rgba(245, 247, 242, 0.92)),
    #fbfcfb;
}

.auth-panel {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 28px;
  box-shadow: 0 18px 50px rgba(23, 32, 38, 0.12);
}

.auth-panel h1 {
  margin-bottom: 22px;
}

.auth-panel label,
.auth-panel input,
.auth-panel button {
  width: 100%;
}

.auth-panel .action {
  margin-top: 14px;
}

.auth-error {
  min-height: 20px;
  margin-top: 12px;
  color: #9b3e2c;
  font-size: 13px;
  font-weight: 700;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 32px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 252, 251, 0.96);
  backdrop-filter: blur(10px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
}

h3 {
  font-size: 16px;
  line-height: 1.3;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  gap: 6px;
  border: 1px solid var(--line);
  padding: 4px;
  background: var(--surface);
}

.tab,
.action {
  min-height: 36px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}

.tab {
  padding: 0 14px;
}

.tab.active {
  border-color: #c8d4d7;
  background: #eaf2f2;
  color: #124f57;
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-color: var(--line);
  background: var(--surface);
}

main {
  padding: 24px 32px 44px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.metric,
.insight-panel,
.model-card,
.reason-box {
  border: 1px solid var(--line);
  background: var(--surface);
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1.1;
}

.band {
  margin-top: 20px;
  padding: 22px;
  background: var(--band);
  border: 1px solid #e1e7de;
}

.section-heading,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.overview-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 18px;
  align-items: stretch;
}

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

.notice {
  border: 1px solid var(--line);
  background: var(--surface);
}

.primary {
  border-color: #164f56;
  background: var(--accent);
  color: #fff;
}

pre {
  min-height: 80px;
  overflow: auto;
  margin: 14px 0 0;
  padding: 12px;
  background: #172026;
  color: #f5f7f2;
  font: 13px Consolas, "Courier New", monospace;
  white-space: pre-wrap;
}

.notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  color: var(--muted);
}

.compact-notice {
  margin: 14px 0 0;
}

.sheet-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

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

.sheet-wrap {
  max-height: 60vh;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--surface);
}

.sheet-table {
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.sheet-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
}

.sheet-table th,
.sheet-table td {
  padding: 0;
  border-right: 1px solid var(--line);
}

.sheet-table th {
  padding: 9px 10px;
}

.sheet-table td:first-child,
.sheet-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 52px;
  width: 52px;
  text-align: center;
  background: #f3f6f6;
}

.sheet-table td:first-child {
  background: #ffffff;
}

.sheet-input {
  width: 150px;
  min-width: 150px;
  height: 36px;
  border: 0;
  padding: 0 8px;
  background: transparent;
  color: var(--ink);
  font: 13px Arial, Helvetica, sans-serif;
}

.sheet-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: #f4fbfb;
}

.delete-row {
  width: 32px;
  height: 28px;
  border: 1px solid var(--line);
  background: #fff;
  color: #9b3e2c;
  cursor: pointer;
}

canvas {
  display: block;
  width: 100%;
  height: 320px;
  border: 1px solid var(--line);
  background: var(--surface);
}

#responseScatter {
  height: 380px;
}

.insight-panel {
  padding: 18px;
}

.insight-panel p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
}

dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  margin: 18px 0 0;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 700;
}

.patient-grid,
.model-grid,
.figure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.patient-card,
.model-card,
.figure-card {
  border: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}

.patient-card {
  padding: 14px;
}

.patient-card strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  background: #edf3df;
  color: #526322;
  font-size: 12px;
  font-weight: 700;
}

.ratio-bar {
  display: grid;
  grid-template-columns: 64px 1fr 44px;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.track {
  height: 8px;
  background: #e8ecee;
}

.fill {
  height: 100%;
  background: var(--accent);
}

.toolbar {
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select,
input {
  min-height: 36px;
  min-width: 220px;
  border: 1px solid var(--line);
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  text-transform: none;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f3f6f6;
  color: #3c4a50;
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #edf5f5;
}

.num {
  font-variant-numeric: tabular-nums;
}

.reason-box {
  margin-top: 14px;
  padding: 16px;
  color: var(--muted);
  line-height: 1.5;
}

.model-card {
  padding: 16px;
}

.model-card h3 {
  margin-bottom: 12px;
}

.metric-list {
  display: grid;
  gap: 8px;
  font-size: 14px;
}

.metric-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.metric-list span {
  color: var(--muted);
}

.metric-list strong {
  max-width: 55%;
  overflow-wrap: anywhere;
  text-align: right;
}

.figure-card img {
  width: 100%;
  display: block;
  background: #fff;
}

.figure-card h3 {
  padding: 12px 14px;
}

@media (max-width: 860px) {
  .app-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs {
    overflow-x: auto;
  }

  main {
    padding: 18px;
  }

  .summary-grid,
  .overview-layout,
  .chart-grid,
  .sheet-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
    flex-direction: column;
  }

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

  select,
  input {
    min-width: 100%;
  }
}
