:root {
  color-scheme: light;
  --ink: #1f1f23;
  --muted: #75656a;
  --line: #ead8d8;
  --panel: #ffffff;
  --wash: #f7eeee;
  --accent: #b91c1c;
  --accent-2: #ef4444;
  --deep: #7f1d1d;
  --soft-red: #fff1f2;
  --paper: #fffdfd;
  --warn: #b45309;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  background: var(--wash);
  color: var(--ink);
}

body.auth-locked .sidebar,
body.auth-locked main {
  filter: blur(14px);
  transform: scale(1.01);
  pointer-events: none;
  user-select: none;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 36%, rgba(185, 28, 28, 0.18), transparent 34%),
    rgba(31, 31, 35, 0.38);
  backdrop-filter: blur(12px);
}

.auth-gate.hidden {
  display: none;
}

.auth-card {
  width: min(420px, 100%);
  padding: 30px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 10px;
  background: rgba(255, 253, 253, 0.88);
  box-shadow: 0 28px 90px rgba(127, 29, 29, 0.24), 0 10px 30px rgba(15, 23, 42, 0.16);
}

.auth-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 10px;
  color: #fff;
  font-weight: 900;
  background: linear-gradient(135deg, var(--deep), var(--accent));
  box-shadow: 0 14px 32px rgba(185, 28, 28, 0.24);
}

.auth-kicker {
  display: block;
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.auth-card h2 {
  margin-bottom: 8px;
  font-size: 25px;
  line-height: 1.12;
}

.auth-card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.auth-form {
  display: grid;
  gap: 9px;
  margin-top: 24px;
}

.auth-form label {
  color: #5f5054;
  font-size: 12px;
  font-weight: 900;
}

.auth-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.auth-input-row input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  font: inherit;
  outline: none;
}

.auth-input-row input:focus {
  border-color: rgba(185, 28, 28, 0.55);
  box-shadow: 0 0 0 4px rgba(185, 28, 28, 0.1);
}

.auth-input-row button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
}

.auth-error {
  color: var(--accent);
  font-weight: 800;
}

.auth-error.hidden {
  display: none;
}

button,
.upload-label {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.is-clicked,
.upload-label.is-clicked {
  transform: translateY(1px) scale(0.99);
  background: #fee2e2;
}

button.is-done,
.upload-label.is-done {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--soft-red);
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #334155;
}

.primary:hover {
  background: #991b1b;
  border-color: #991b1b;
}

.secondary:hover,
.upload-label:hover {
  border-color: #f3b4b4;
  background: var(--soft-red);
  color: var(--accent);
}

.sidebar {
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: #fffafa;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.brand {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: center;
}

.mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--deep);
  color: #fff;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

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

.brand p,
small,
.lab-card span {
  color: var(--muted);
  font-size: 12px;
}

.patient-panel {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.patient-panel strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.patient-panel small {
  display: block;
  margin-top: 3px;
  line-height: 1.25;
  max-height: 31px;
  overflow: hidden;
  color: #8a7373;
}

.eyebrow,
.section-title {
  color: #9f6a6a;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tree {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 4px 2px 0;
  scrollbar-width: thin;
  scrollbar-color: #d9aaaa transparent;
}

.tree-group {
  margin-bottom: 3px;
}

.tree-node {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 7px 8px;
  min-height: 30px;
  color: #334155;
  font-weight: 700;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-node:hover,
.tree-node.active {
  background: var(--soft-red);
  color: var(--accent);
}

.tree-children {
  margin-left: 10px;
  padding-left: 7px;
  border-left: 1px solid #ead7d7;
}

.lab-card {
  flex: 0 0 auto;
  display: grid;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #5f1111;
  background: linear-gradient(135deg, #5f1111 0%, #8f1616 52%, #1f1f23 100%);
  color: #fff;
  line-height: 1.25;
  box-shadow: 0 10px 22px rgba(127, 29, 29, 0.22);
}

.lab-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.lab-monogram {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.lab-card strong,
.lab-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lab-card span {
  color: #ffdada;
}

.lab-credit-btn {
  min-height: 30px;
  width: 100%;
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #ffdada;
  font-size: 11px;
  font-weight: 800;
}

.lab-credit-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

main {
  height: 100vh;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 56px;
  min-height: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  overflow: hidden;
}

h2 {
  margin-top: 2px;
  font-size: 18px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--soft-red);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.workbench {
  min-height: 0;
  min-width: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 24vw, 360px);
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}

.signal-stage {
  min-width: 0;
  min-height: 0;
  height: 100%;
  flex: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 92px;
  gap: 8px;
  overflow: hidden;
}

.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  min-height: 0;
  padding: 8px;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.summary {
  min-width: 0;
  min-height: 0;
  height: 92px;
  display: grid;
  grid-template-columns: 100px minmax(0, 1.15fr) 330px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.summary-head {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.scale-badge {
  display: inline-flex;
  max-width: 100%;
  width: 100%;
  justify-content: center;
  padding: 5px 6px;
  border-radius: 6px;
  background: var(--soft-red);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

dl {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 0.95fr) minmax(0, 1.15fr);
  gap: 8px;
  margin: 0;
  min-width: 0;
}

dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 7px;
  min-width: 0;
}

.metric-grid div,
.slider-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  min-width: 0;
  background: #ffffff;
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 16px;
  line-height: 1.2;
  color: var(--deep);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.control-head,
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.control-head {
  flex: 0 0 auto;
  padding: 0 2px 6px;
  border-bottom: 1px solid var(--line);
}

.control-head strong {
  display: block;
  margin-top: 3px;
  font-size: 16px;
  line-height: 1.1;
}

.status-pill,
.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 22px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--soft-red);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.status-pill[data-tone="done"] {
  background: #dcfce7;
  color: #166534;
}

.control-section {
  flex: 0 0 auto;
  display: grid;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.action-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tool-button {
  width: 100%;
  min-height: 29px;
  border-color: #e7c7c7;
  background: #ffffff;
  color: #334155;
  font-size: 12px;
  line-height: 1.15;
  transition: transform 120ms ease, background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.tool-button:hover {
  border-color: #e89999;
  background: var(--soft-red);
  color: var(--accent);
}

.tool-button:active,
.tool-button.is-clicked {
  transform: translateY(1px) scale(0.99);
  background: #fee2e2;
}

.tool-button.is-done {
  border-color: #b91c1c;
  color: #b91c1c;
  background: #fff1f2;
}

.tool-button.is-working {
  opacity: 0.75;
}

.tool-button.subtle {
  min-height: 30px;
}

.tool-button.wide {
  min-height: 30px;
}

.fwave-tool input {
  width: 100%;
  accent-color: var(--accent);
}

.fwave-tool small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.feature-section,
.stats-section,
.fft-section {
  min-height: 0;
  flex: 1 1 0;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr);
}

.feature-section {
  min-height: 104px;
}

.stats-section {
  min-height: 122px;
  flex-grow: 1;
}

.fft-section {
  min-height: 134px;
  flex-grow: 1;
  grid-template-rows: auto 104px;
}

.fft-chart {
  width: 100%;
  height: 104px;
  min-height: 104px;
  border: 1px solid #f0d5d5;
  border-radius: 7px;
  background: #fffafa;
}

.fwave-tool:not(.hidden) ~ .feature-section {
  min-height: 68px;
  flex-grow: 0.65;
}

.fwave-tool:not(.hidden) ~ .stats-section {
  min-height: 84px;
  flex-grow: 0.75;
}

.fwave-tool:not(.hidden) ~ .fft-section {
  min-height: 102px;
  grid-template-rows: auto 76px;
}

.fwave-tool:not(.hidden) ~ .fft-section .fft-chart {
  height: 76px;
  min-height: 76px;
}

.feature-list,
.stats-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 5px;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: #d9aaaa transparent;
}

.feature-list p,
.stats-list p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.feature-item,
.stats-item {
  display: grid;
  gap: 3px;
  padding: 6px 7px;
  border: 1px solid #f0d5d5;
  border-radius: 7px;
  background: #fffafa;
}

.feature-item strong,
.stats-item strong {
  font-size: 13px;
}

.feature-item span,
.stats-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.stat-table {
  display: grid;
  gap: 4px;
}

.stat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.stat-row b {
  color: var(--deep);
  font-size: 11px;
  white-space: nowrap;
}

.export-section {
  flex: 0 0 auto;
}

.export-section select {
  width: 100%;
  height: 28px;
  border: 1px solid #e7c7c7;
  border-radius: 6px;
  background: #fff;
  color: #334155;
  font: inherit;
  font-weight: 700;
  padding: 0 8px;
}

.slider-block {
  margin: 0;
  height: 74px;
  align-self: center;
}

.slider-block label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.slider-block input {
  width: 100%;
  accent-color: var(--accent);
  margin-top: 9px;
}

.hidden {
  display: none;
}

.report-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 31, 35, 0.38);
}

.credits-modal {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 31, 35, 0.42);
}

.credits-modal.hidden {
  display: none;
}

.credits-shell {
  width: min(900px, 100%);
  max-height: min(760px, 100%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #ead8d8;
  border-radius: 10px;
  background: #fffdfd;
}

.credits-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fffafa;
}

.credits-body {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 14px;
  padding: 16px;
}

.copyright-note {
  display: grid;
  gap: 7px;
  padding: 13px 14px;
  border: 1px solid #efcaca;
  border-radius: 8px;
  background: #fff5f5;
}

.copyright-note span {
  color: var(--deep);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.copyright-note p {
  color: #5f4b4f;
  font-size: 13px;
  line-height: 1.5;
}

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

.team-person {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid #f0d5d5;
  border-radius: 8px;
  background: #ffffff;
}

.team-person strong {
  color: #1f2937;
  font-size: 13px;
  line-height: 1.3;
}

.team-person em {
  width: fit-content;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--soft-red);
  color: var(--deep);
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.team-person span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.report-modal.hidden {
  display: none;
}

.report-shell {
  width: min(1180px, 100%);
  height: min(820px, 100%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #fffdfd;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.report-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fffafa;
}

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

.report-body {
  overflow: auto;
  padding: 14px;
  display: grid;
  gap: 14px;
}

.report-block {
  display: grid;
  gap: 8px;
}

.report-block h3 {
  margin: 0;
  font-size: 15px;
  color: var(--deep);
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: #fff;
}

.report-table th,
.report-table td {
  border: 1px solid #d8c6c6;
  padding: 5px 6px;
  text-align: left;
  vertical-align: top;
}

.report-table th {
  background: #e5e5e5;
  color: #1f2937;
  font-weight: 800;
}

.report-table td.abnormal {
  background: #ff9a9a;
  color: #7f1d1d;
  font-weight: 900;
}

.report-patient {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

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

  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    max-height: none;
  }

  main {
    height: auto;
  }

  .signal-stage {
    grid-template-rows: 58vh auto;
  }

  .workbench {
    grid-template-columns: 1fr;
    padding: 10px;
    overflow: visible;
  }

  .control-panel {
    height: auto;
  }

  .summary {
    height: auto;
    grid-template-columns: 1fr;
    align-items: stretch;
    overflow: visible;
  }

  dl {
    grid-template-columns: 1fr;
  }

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

  .team-list {
    grid-template-columns: 1fr;
  }

  .credits-head {
    align-items: flex-start;
  }
}
