:root {
  --ink: #17212b;
  --muted: #64717d;
  --brand: #116b78;
  --brand-dark: #0b4e59;
  --brand-soft: #eaf5f5;
  --line: #dce2e6;
  --line-dark: #bcc7cd;
  --surface: #ffffff;
  --canvas: #f5f6f7;
  --error: #a9271d;
  --error-soft: #fff1f0;
  --success: #1a744a;
  --radius: 12px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

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

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 100;
  padding: .7rem 1rem;
  color: white;
  background: var(--ink);
  border-radius: 7px;
}

.skip-link:focus { top: 1rem; }

.topbar {
  min-height: 62px;
  padding: 0 max(1.25rem, calc((100vw - 780px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: white;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  color: var(--ink);
  text-decoration: none;
  font-size: .91rem;
  font-weight: 700;
}

.page {
  width: min(780px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.5rem 0 5rem;
}

.workflow { margin-bottom: 1.5rem; }

.workflow ol {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  list-style: none;
}

.workflow li {
  position: relative;
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
}

.workflow li:not(:last-child)::after {
  content: "";
  height: 1px;
  margin: 0 .75rem;
  flex: 1;
  background: var(--line-dark);
}

.workflow-marker {
  width: 25px;
  height: 25px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  background: white;
  border: 1px solid var(--line-dark);
  border-radius: 50%;
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
}

.workflow li.active { color: var(--brand-dark); }

.workflow li.active .workflow-marker {
  color: white;
  background: var(--brand);
  border-color: var(--brand);
}

.workflow li.complete .workflow-marker {
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-color: #9ec8cc;
}

.workflow li.complete::after { background: #9ec8cc; }

.panel {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.form-header {
  padding: 1.6rem 1.75rem;
  border-bottom: 1px solid var(--line);
}

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

.form-header h1,
.patient-header h1,
.success-panel h1 {
  margin-bottom: .25rem;
  font-size: 1.45rem;
  line-height: 1.25;
  letter-spacing: -.015em;
}

.form-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: .89rem;
}

.form-body { padding: 1.75rem; }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.15rem;
}

.field { margin-bottom: 1.45rem; }
.field:last-child { margin-bottom: 0; }

.field label,
.question legend {
  display: block;
  margin-bottom: .55rem;
  color: #253442;
  font-weight: 650;
}

.field-help {
  margin: .4rem 0 0;
  color: var(--muted);
  font-size: .77rem;
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: .7rem .8rem;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

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

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(17, 107, 120, .12);
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--error);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.question {
  padding: 1.45rem 0;
  border: 0;
}

.question.first-question { padding-top: 0; border-top: 0; }

.question-number {
  display: inline-block;
  min-width: 1.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.choice-row,
.choice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem 1.5rem;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 1.5rem;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  padding: .25rem 0;
  color: #3b4853;
  cursor: pointer;
}

.choice input {
  width: 17px;
  height: 17px;
  margin: .16rem 0 0;
  flex: 0 0 auto;
  accent-color: var(--brand);
}

.choice span { line-height: 1.4; }

.other-field {
  max-width: 520px;
  margin: -.45rem 0 1rem 1.8rem;
}

.duration-grid {
  max-width: 410px;
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: .65rem;
}

.duration-grid .field { margin-bottom: 0; }

.patient-count-field { max-width: 360px; }

.number-control {
  width: 160px;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  overflow: hidden;
}

.number-control input {
  padding: .62rem .2rem;
  text-align: center;
  border: 0;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-radius: 0;
  -moz-appearance: textfield;
}

.number-control input::-webkit-outer-spin-button,
.number-control input::-webkit-inner-spin-button { margin: 0; appearance: none; }

.number-control button {
  padding: 0;
  color: var(--brand-dark);
  background: #f7f9f9;
  border: 0;
  cursor: pointer;
  font-size: 1.15rem;
}

.number-control button:hover { background: var(--brand-soft); }

.patient-header { margin-bottom: 1rem; }

.patient-header h1 { margin-bottom: .25rem; }

.patient-header p {
  margin: 0;
  color: var(--muted);
  font-size: .84rem;
}

.overline {
  display: block;
  margin-bottom: .18rem;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.patient-switcher {
  margin-bottom: .55rem;
  padding: .9rem 1rem;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.patient-switcher-heading {
  margin-bottom: .7rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.patient-switcher-heading strong { font-size: .82rem; }

.patient-switcher-heading span,
.patient-submit-note {
  color: var(--muted);
  font-size: .76rem;
}

.patient-submit-note {
  margin: 0 0 1rem;
  text-align: right;
}

.patient-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: .45rem;
}

.patient-tab {
  min-height: 46px;
  min-width: 110px;
  padding: .45rem .75rem;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: .05rem;
  color: var(--muted);
  background: white;
  border: 1px solid var(--line-dark);
  border-radius: 7px;
  cursor: pointer;
  font-size: .78rem;
  font-weight: 700;
}

.patient-tab-label {
  color: inherit;
  font-size: .8rem;
  font-weight: 750;
}

.patient-tab-status {
  color: inherit;
  font-size: .65rem;
  font-weight: 550;
}

.patient-tab.active {
  color: white;
  background: var(--brand);
  border-color: var(--brand);
}

.patient-tab.complete:not(.active) {
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-color: #9ec8cc;
}

.patient-tab.has-errors {
  color: var(--error);
  background: var(--error-soft);
  border-color: #d88e88;
}

.patient-tab.has-errors.active {
  color: white;
  background: var(--error);
}

.patient-card[hidden] { display: none; }

.form-section { padding: 0 1.75rem; }

.form-section + .form-section {
  border-top: 1px solid var(--line);
}

.form-section-header {
  margin: 0;
  padding: 1.25rem 0 .9rem;
  background: white;
  border-bottom: 1px solid var(--line);
}

.form-section-header h2 {
  margin: 0;
  font-size: .98rem;
}

.form-section-header p {
  margin: .2rem 0 0;
  color: var(--muted);
  font-size: .78rem;
}

.conditional-placeholder {
  margin: .25rem 0 1rem;
  padding: .8rem .9rem;
  display: flex;
  align-items: baseline;
  gap: .6rem;
  color: var(--muted);
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .8rem;
}

.conditional-placeholder strong {
  flex: 0 0 auto;
  color: #344451;
}

.conditional {
  margin: .4rem 0 1rem;
  padding: .1rem 1rem;
  background: #f1f7f7;
  border-left: 3px solid var(--brand);
}

.optional-label {
  display: inline-block;
  margin-left: .35rem;
  padding: .1rem .4rem;
  color: var(--muted);
  background: #eef2f3;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .02em;
  vertical-align: .08rem;
}

.field-error {
  margin: .6rem 0 0;
  color: var(--error);
  font-size: .78rem;
  font-weight: 650;
}

.question:has([aria-invalid="true"]),
.other-field:has([aria-invalid="true"]) {
  margin-right: -.75rem;
  margin-left: -.75rem;
  padding-right: .75rem;
  padding-left: .75rem;
  background: var(--error-soft);
  border-radius: 8px;
}

.actions {
  display: flex;
  gap: .75rem;
  margin-top: 1rem;
}

.actions.end { justify-content: flex-end; }
.actions.split { justify-content: space-between; }

.button {
  min-height: 42px;
  padding: .65rem 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: .85rem;
}

.button:disabled { cursor: wait; opacity: .65; }

.button.primary {
  color: white;
  background: var(--brand-dark);
}

.button.primary:hover { background: #073f48; }

.button.secondary {
  color: #33424f;
  background: white;
  border-color: var(--line-dark);
}

.alert {
  margin: 0 0 1rem;
  padding: .8rem .9rem;
  border-radius: 8px;
  font-size: .84rem;
}

.error-alert {
  color: var(--error);
  background: var(--error-soft);
  border: 1px solid #e9b9b5;
}

.error-alert ul { margin: .35rem 0 0; padding-left: 1.15rem; }

.review-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1.5rem;
}

.review-item {
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--line);
}

.review-label {
  display: block;
  margin-bottom: .18rem;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.review-list-title {
  margin: 0 0 .45rem;
  font-size: .9rem;
}

.review-patient {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .8rem 0;
  border-top: 1px solid var(--line);
}

.review-patient strong,
.review-patient span { display: block; }
.review-patient span { color: var(--muted); font-size: .78rem; }

.edit-patient {
  color: var(--brand-dark);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 700;
}

.spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.submit-button.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.success-panel {
  padding: 3.5rem 2rem;
  text-align: center;
}

.success-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 1rem;
  display: grid;
  place-items: center;
  color: white;
  background: var(--success);
  border-radius: 50%;
  font-size: 1.2rem;
}

.success-panel p {
  max-width: 480px;
  margin: .5rem auto 0;
  color: var(--muted);
}

.confirmation-code {
  width: fit-content;
  margin: 1.4rem auto;
  padding: .7rem 1rem;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: .06em;
}

/* Administration */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat { padding: 1.4rem; }
.stat span {
  display: block;
  color: var(--brand-dark);
  font-size: 2rem;
  font-weight: 750;
  line-height: 1;
}
.stat small { display: block; margin-top: .4rem; color: var(--muted); }

.section-card { padding: 1.75rem; }
.section-card .field:last-of-type { margin-bottom: 1.2rem; }

.admin-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.admin-heading h2 {
  margin: 0;
  font-size: 1.2rem;
}

.eyebrow {
  margin: 0 0 .2rem;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.hero { padding: 1rem 0 1.5rem; }
.hero h1 { margin: 0; font-size: 1.75rem; }
.hero > p:last-child { max-width: 620px; margin: .45rem 0 0; color: var(--muted); }

.admin-table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: .75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-size: .82rem;
}
th {
  color: var(--muted);
  font-size: .68rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

@media (max-width: 620px) {
  .topbar { padding: 0 1rem; }
  .brand { font-size: .82rem; }
  .page { width: min(100% - 1.2rem, 780px); padding-top: 1.5rem; }
  .form-header, .form-body { padding: 1.25rem; }
  .field-grid, .choice-grid, .review-details { grid-template-columns: 1fr; }
  .form-section { padding: 0 1.25rem; }
  .form-section-header { padding: 1rem 0 .8rem; }
  .conditional-placeholder { align-items: flex-start; flex-direction: column; gap: .2rem; }
  .workflow li {
    align-items: flex-start;
    flex-direction: column;
    gap: .25rem;
    font-size: .7rem;
  }
  .workflow li:not(:last-child)::after {
    position: absolute;
    top: 12px;
    left: 33px;
    width: calc(100% - 41px);
    margin: 0;
  }
  .patient-switcher-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: .15rem;
  }
  .patient-submit-note { text-align: left; }
  .duration-grid { grid-template-columns: 1fr 125px; }
  .actions.split { align-items: stretch; flex-direction: column-reverse; }
  .actions .button { width: 100%; }
  .admin-heading { align-items: stretch; flex-direction: column; }
}

/* Invitation and administration additions */
.patient-id-line { display:flex; flex-wrap:wrap; align-items:center; gap:.65rem; padding:1rem 1.75rem; border-bottom:1px solid var(--line); }
.patient-id-line > span { color:var(--muted); }
.patient-id-line strong { font-variant-numeric:tabular-nums; }
.review-patient-details { padding:1rem 0; border-top:1px solid var(--line); }
.review-patient-details summary { font-weight:700; cursor:pointer; }
dt { font-weight:600; margin-top:1rem; }
dd { margin:.25rem 0 .75rem; white-space:pre-wrap; overflow-wrap:anywhere; }
.admin-page { width:min(1240px,calc(100% - 2rem)); }
.admin-page .section-card { margin-bottom:1.5rem; }
.admin-page .admin-stats { grid-template-columns:repeat(3,minmax(0,1fr)); }
.inline-form { display:flex; align-items:end; flex-wrap:wrap; gap:1rem; }
.inline-form .field { margin-bottom:0 !important; max-width:200px; }
.admin-page .actions { margin:0; flex-wrap:wrap; }
.admin-page #new-links .actions { margin-top:.75rem; }
.row-actions { display:flex; gap:.7rem; align-items:center; }
#link-output { width:100%; margin:.5rem 0; font-size:.8rem; }
#draft-status { margin-bottom:1rem; }
#submitted-patients { margin-top:1rem; overflow-wrap:anywhere; }
.no-bleeds { padding-bottom:1rem; }
@media(max-width:620px) { .patient-id-line{padding:1rem 1.25rem;} .admin-page .stat{padding:1rem .5rem;} .admin-page .stat span{font-size:1.6rem;} }
