:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #67717a;
  --line: #dce2df;
  --accent: #197278;
  --accent-strong: #0d4f55;
  --warn: #b85c38;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: #102a2d;
  color: white;
  padding: 24px;
}
.brand {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 36px;
}
nav { display: grid; gap: 8px; }
nav a {
  color: #e8f2ef;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 6px;
}
nav a:hover { background: rgba(255,255,255,.12); }
.content { padding: 32px; overflow-x: auto; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
h1, h2 { margin: 0; }
h1 { font-size: 34px; }
h2 { font-size: 20px; margin-bottom: 14px; }
.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin: 0 0 8px;
}
.button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 6px;
  padding: 11px 16px;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}
.button:hover { background: var(--accent-strong); }
.button.secondary {
  background: #e8f2ef;
  color: var(--accent-strong);
}
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.search-panel form {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  align-items: end;
  gap: 12px;
}
.search-panel button,
.inline-form button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 20px;
}
.tabs a {
  background: #e8f2ef;
  color: var(--accent-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  text-decoration: none;
  font-weight: 700;
}
.patient-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.patient-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.patient-summary div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.patient-summary span {
  display: block;
  font-size: 22px;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.patient-summary p {
  color: var(--muted);
  margin: 6px 0 0;
}
.patient-tabs {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding: 10px;
}
.tab-button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 12px;
}
.tab-button.is-active {
  background: #e8f2ef;
  border-color: var(--line);
  color: var(--accent-strong);
}
.tab-panel {
  display: none;
  padding: 18px;
}
.tab-panel.is-active {
  display: block;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.metrics div, .grid > div, .form-panel, section:not(.grid):not(.metrics) {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.metrics span { font-size: 32px; font-weight: 700; }
.metrics p { color: var(--muted); margin: 6px 0 0; }
.grid { display: grid; gap: 16px; margin-bottom: 20px; }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; }
td a { color: var(--accent-strong); font-weight: 700; }
.form-panel { display: grid; gap: 16px; max-width: 1050px; }
.form-panel section,
.form-section {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}
.form-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.score-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  font: inherit;
  color: var(--ink);
  background: white;
}
.checks { display: flex; flex-wrap: wrap; gap: 16px; }
.checks label { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.checks input { width: auto; }
.score-input {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) auto;
  gap: 6px;
}
.score-input button {
  border: 1px solid var(--line);
  background: #e8f2ef;
  color: var(--accent-strong);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0 10px;
}
.clinical-test-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
}
.clinical-test-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px;
}
.clinical-test-item small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}
.clinical-test-item input { width: auto; }
.record {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
}
.record p { color: var(--muted); margin: 8px 0 0; }
.visit-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
  background: #fff;
}
.visit-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.section-head form {
  display: flex;
  align-items: center;
  gap: 12px;
}
.section-head label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.section-head input { width: auto; }
.section-head button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.record pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  margin: 10px 0 0;
}
.inline-form {
  display: grid;
  gap: 14px;
}
.entry-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  margin-bottom: 16px;
  padding: 0;
}
.entry-panel summary {
  cursor: pointer;
  font-weight: 700;
  padding: 14px 16px;
  color: var(--accent-strong);
}
.entry-panel[open] summary {
  border-bottom: 1px solid var(--line);
}
.entry-panel .inline-form {
  padding: 16px;
}
.compact-tests {
  max-height: 360px;
  overflow: auto;
}
.modality-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.modality-fields {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 14px;
}
.modality-fields.is-active {
  display: block;
}
.modality-fields.side-managed > .form-grid {
  display: none;
}
.modality-fields.side-managed > [data-field-group] {
  display: none;
}
.modality-fields h3 {
  margin: 0 0 12px;
}
.diagnostic-checklist-note {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  line-height: 1.45;
  margin-bottom: 12px;
  padding: 12px;
}
.diagnostic-checklist-note strong {
  color: var(--accent-strong);
}
.diagnostic-checklist-note small {
  display: block;
  color: var(--muted);
  margin-top: 6px;
}
.safety-gate {
  border: 1px solid #c8a44d;
  border-radius: 8px;
  background: #fffaf0;
  margin: 18px 0;
  padding: 14px 16px;
}
.safety-gate legend {
  color: #6d4d00;
  font-weight: 700;
  padding: 0 8px;
}
.red-flag-checks,
.required-checks {
  align-items: flex-start;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.safety-alert,
.intake-status.needs-action {
  border: 1px solid #b42318;
  border-left-width: 5px;
  border-radius: 8px;
  background: #fff4f2;
  color: #7a271a;
  margin: 12px 0;
  padding: 12px 14px;
}
.safety-alert ul,
.intake-status ul {
  margin-bottom: 0;
}
.intake-status.is-ready {
  border-left: 4px solid #27845b;
  background: #f0faf5;
  margin: 12px 0;
  padding: 10px 12px;
}
.side-measurement-panels {
  display: grid;
  gap: 12px;
}
.side-measurement-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  padding: 14px;
}
.side-measurement-panel h4,
.side-timeline-title {
  margin: 0 0 10px;
  color: var(--accent-strong);
}
.side-field-group {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}
.side-field-group h5 {
  color: var(--ink);
  font-size: 15px;
  margin: 0 0 10px;
}
.side-measurement-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 14px;
}
.side-timeline-title {
  margin-top: 14px;
}
.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.attachment-list a {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #e8f2ef;
  color: var(--accent-strong);
  font-weight: 700;
  padding: 6px 8px;
  text-decoration: none;
}
.dicom-upload {
  margin-top: 12px;
}
.timeline {
  display: grid;
  gap: 10px;
}
.timeline-item {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.timeline-date {
  color: var(--muted);
  font-weight: 700;
}
.timeline-body p {
  margin: 6px 0 0;
  color: var(--muted);
}
.score-bar {
  width: 100%;
  max-width: 320px;
  height: 8px;
  background: #eef4f2;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.score-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}
.scale-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 31, 35, .42);
  padding: 24px;
}
.scale-modal.is-open { display: flex; }
.scale-dialog {
  width: min(880px, 100%);
  max-height: min(760px, 92vh);
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0,0,0,.22);
  overflow: hidden;
}
.scale-dialog-head,
.scale-dialog-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.scale-description {
  color: var(--muted);
  margin: 6px 0 0;
}
.scale-dialog-foot {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}
.scale-dialog-body {
  overflow: auto;
  padding: 18px;
  background: #f8faf9;
}
.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  font-size: 22px;
}
.scale-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  margin: 8px 0 12px;
}
.scale-section-title::before {
  content: "";
  width: 4px;
  height: 24px;
  border-radius: 999px;
  background: var(--accent);
}
.scale-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(220px, 340px) 58px;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  margin-bottom: 10px;
  color: var(--ink);
}
.scale-question {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  font-weight: 700;
}
.scale-question b {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #e8f2ef;
  color: var(--accent-strong);
}
.scale-control {
  display: grid;
  gap: 8px;
}
.scale-labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.scale-labels small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}
.scale-row em {
  grid-column: 2 / 4;
  color: var(--accent-strong);
  font-style: normal;
  font-weight: 700;
  text-align: center;
}
.scale-row input { padding: 0; }
.scale-row output {
  display: grid;
  place-items: center;
  width: 48px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}
.scale-choice-list {
  display: grid;
  gap: 10px;
}
.scale-choice-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 14px;
}
.scale-choice-row input {
  width: auto;
  margin-top: 4px;
}
.scale-choice-row small {
  display: block;
  color: var(--muted);
  line-height: 1.35;
  margin-top: 4px;
}
.scale-result {
  color: var(--accent-strong);
  font-weight: 700;
}
.compact { margin-bottom: 12px; }
.compact > div { padding: 14px; }
.compact h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.compact p { margin: 6px 0; color: var(--muted); }
.test-grid {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.test-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px 90px 90px;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.test-row:last-child { border-bottom: 0; }
.test-head {
  background: #eef4f2;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.test-row small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}
.test-row label {
  align-items: center;
  justify-items: center;
}
.test-row input { width: auto; }
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  margin: 0;
}
.safety-banner {
  margin: 0 0 20px;
  padding: 14px 16px;
  border: 1px solid #c87500;
  border-left-width: 5px;
  border-radius: 8px;
  background: #fff7e6;
  color: #583600;
  line-height: 1.45;
}
.test-mode-banner {
  background: #7a271a;
  border-radius: 8px;
  color: #fff;
  margin: 0 0 18px;
  padding: 12px 16px;
}
.status-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  background: #eef1f3;
  color: #43515c;
}
.status-chip.verified { background: #dff3e7; color: #17633b; }
.status-chip.rejected { background: #fde5e5; color: #9d2929; }
.status-chip.draft { background: #fff1d6; color: #865100; }
.safety-note { color: #865100; font-size: 13px; line-height: 1.4; }

body.login-page {
  display: block;
  min-height: 100vh;
  background: linear-gradient(135deg, #102a2d 0%, #197278 100%);
}
.login-card {
  max-width: 420px;
  margin: 8vh auto;
  background: var(--panel);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
}
.login-form { display: grid; gap: 14px; margin-top: 20px; }
.login-form label { display: grid; gap: 6px; font-weight: 700; }
.login-form input {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.login-hint, .login-note { color: var(--muted); font-size: 14px; line-height: 1.45; }
.alert {
  padding: 12px 14px;
  border-radius: 6px;
  margin: 14px 0;
}
.alert.error { background: #fde5e5; color: #9d2929; }
.alert.success { background: #dff3e7; color: #17633b; }
.user-panel {
  margin: -12px 0 24px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 4px;
  font-size: 14px;
}
.user-panel span { color: #b8d4cf; }
.logout-form { margin-top: 24px; }
.logout-form .button { width: 100%; }
.inline-form {
  display: grid;
  gap: 8px;
  min-width: 260px;
}
.inline-form label { display: grid; gap: 4px; font-size: 13px; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .metrics, .two, .three, .form-grid, .score-grid, .clinical-test-grid, .patient-summary { grid-template-columns: 1fr; }
  .patient-header { display: grid; }
  .search-panel form, .timeline-item { grid-template-columns: 1fr; }
  .scale-row { grid-template-columns: 1fr; }
  .scale-row small { grid-column: auto; }
  .test-row { grid-template-columns: minmax(160px, 1fr) 80px 70px 80px; }
  .content { padding: 20px; }
}
