:root {
  --sa-accent: #0f7d72;
  --sa-accent-dark: #0b5e56;
  --sa-bg: #eef3f4;
  --sa-card: #ffffff;
  --sa-text: #102534;
  --sa-muted: #5b6b78;
  --sa-border: #d4dee6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--sa-text);
  background: linear-gradient(160deg, #e9f1f0 0%, #eef3f4 40%, #e7eef2 100%);
  min-height: 100vh;
}

.sa-header {
  background: var(--sa-card);
  border-bottom: 1px solid var(--sa-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.sa-header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.sa-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.sa-saved {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--sa-accent-dark);
  background: #e4f3f0;
  border: 1px solid #bfe3dd;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.sa-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.25rem;
}
.sa-form { display: flex; flex-direction: column; gap: 1rem; }

.sa-card {
  background: var(--sa-card);
  border: 1px solid var(--sa-border);
  border-radius: 14px;
  padding: 1.1rem 1.2rem;
  box-shadow: 0 1px 2px rgba(16, 37, 52, 0.04);
}

.sa-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--sa-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.4rem;
}
.sa-input {
  width: 100%;
  font-size: 1rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--sa-border);
  border-radius: 9px;
  background: #fbfdfd;
  color: var(--sa-text);
}
.sa-input:focus {
  outline: none;
  border-color: var(--sa-accent);
  box-shadow: 0 0 0 3px rgba(15, 125, 114, 0.14);
}
.sa-hint { margin: 0.45rem 0 0; font-size: 0.78rem; color: var(--sa-muted); }

.sa-fields { min-height: 80px; }
.sa-placeholder {
  margin: 0;
  color: var(--sa-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 1.5rem 0;
  border: 1px dashed var(--sa-border);
  border-radius: 10px;
}

.sa-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.sa-btn {
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
}
.sa-btn-primary { background: var(--sa-accent); color: #fff; }
.sa-btn-primary:hover { background: var(--sa-accent-dark); }
.sa-btn-primary:disabled { opacity: 0.55; cursor: default; }
.sa-btn-ghost { background: transparent; color: var(--sa-muted); border-color: var(--sa-border); }
.sa-btn-ghost:hover { background: #f1f5f6; }

/* Marker type selector + body diagram. Colours match the document renderer
   (TYPE_RGB in bodyDiagramPng.js) so on-screen == generated document. */
.sa-types { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.sa-type {
  font-size: 0.82rem; font-weight: 600; padding: 0.35rem 0.7rem;
  border: 1px solid var(--sa-border); border-radius: 999px;
  background: #fff; color: var(--sa-muted); cursor: pointer;
}
.sa-type[data-type="wound"].is-active { background: rgb(47,116,149); border-color: rgb(47,116,149); color: #fff; }
.sa-type[data-type="pressureInjury"].is-active { background: rgb(191,111,48); border-color: rgb(191,111,48); color: #fff; }
.sa-type[data-type="stoma"].is-active { background: rgb(47,143,89); border-color: rgb(47,143,89); color: #fff; }
.sa-type[data-type="catheter"].is-active { background: rgb(123,83,182); border-color: rgb(123,83,182); color: #fff; }

.sa-body {
  position: relative; display: inline-block; max-width: 320px; margin: 0 auto;
  width: 100%; text-align: center; cursor: crosshair; user-select: none;
}
.sa-body-img { display: block; width: 100%; height: auto; pointer-events: none; }
.sa-markers { position: absolute; inset: 0; pointer-events: none; }
.sa-marker {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  color: #fff; font: 700 11px/22px system-ui, sans-serif; text-align: center;
}
.sa-marker[data-type="wound"] { background: rgb(47,116,149); }
.sa-marker[data-type="pressureInjury"] { background: rgb(191,111,48); }
.sa-marker[data-type="stoma"] { background: rgb(47,143,89); }
.sa-marker[data-type="catheter"] { background: rgb(123,83,182); }

.sa-marker-list { margin: 0.7rem 0 0; padding-left: 1.2rem; font-size: 0.85rem; color: var(--sa-text); }
.sa-marker-list li { margin-bottom: 0.3rem; }
.sa-marker-list .sa-ml-type { color: var(--sa-muted); }
.sa-marker-list .sa-ml-input {
  margin-left: 0.4rem; padding: 0.15rem 0.4rem; font-size: 0.82rem;
  border: 1px solid var(--sa-border); border-radius: 6px; min-width: 120px;
}
.sa-marker-list .sa-ml-remove {
  margin-left: 0.4rem; border: none; background: none; color: #b0182a;
  cursor: pointer; font-size: 0.82rem;
}

/* Schema-driven sections (standalone-form.js). */
.saf-section { margin-bottom: 1.2rem; }
.saf-section + .saf-section { border-top: 1px solid var(--sa-border); padding-top: 1.1rem; }
.saf-section-title { margin: 0 0 0.9rem; font-size: 1rem; font-weight: 700; color: var(--sa-text); }
.saf-note { margin: -0.4rem 0 0.9rem; font-size: 0.82rem; color: var(--sa-muted); }
.saf-field { margin-bottom: 0.95rem; }
.saf-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--sa-text); margin-bottom: 0.4rem; }
.saf-req { color: #b0182a; }
.saf-input { width: 100%; font-size: 0.98rem; padding: 0.55rem 0.65rem; border: 1px solid var(--sa-border); border-radius: 9px; background: #fbfdfd; color: var(--sa-text); font-family: inherit; }
.saf-input:focus { outline: none; border-color: var(--sa-accent); box-shadow: 0 0 0 3px rgba(15,125,114,0.14); }
textarea.saf-input { min-height: 4.5rem; resize: vertical; }
.saf-unit-row { display: flex; align-items: center; gap: 0.5rem; }
.saf-unit { font-size: 0.85rem; color: var(--sa-muted); white-space: nowrap; }
.saf-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.4rem 0.9rem; }
.saf-check { display: flex; align-items: center; gap: 0.5rem; font-size: 0.92rem; color: var(--sa-text); cursor: pointer; padding: 0.15rem 0; }
.saf-check input { width: 1.05rem; height: 1.05rem; accent-color: var(--sa-accent); }
.saf-cits { margin-top: 0.5rem; }
.saf-group { margin: 0.2rem 0 0.6rem; padding: 0.7rem 0.8rem; border-left: 3px solid var(--sa-accent); background: #f3f8f8; border-radius: 0 9px 9px 0; }
.saf-rows { display: flex; flex-direction: column; gap: 0.45rem; margin-bottom: 0.5rem; }
.saf-row { display: flex; gap: 0.4rem; align-items: center; }
.saf-row .saf-input { flex: 1; }
.saf-row-rm { flex: 0 0 auto; width: 2rem; height: 2rem; border: 1px solid var(--sa-border); background: #fff; border-radius: 8px; color: #b0182a; font-size: 1.1rem; line-height: 1; cursor: pointer; }
.saf-add { font-size: 0.85rem; font-weight: 600; color: var(--sa-accent-dark); background: transparent; border: 1px dashed var(--sa-border); border-radius: 8px; padding: 0.4rem 0.8rem; cursor: pointer; }
.saf-add:hover { background: #f1f5f6; }

/* Admin submissions table. */
.sa-table { width: 100%; border-collapse: collapse; background: var(--sa-card); border: 1px solid var(--sa-border); border-radius: 12px; overflow: hidden; font-size: 0.9rem; }
.sa-table th, .sa-table td { text-align: left; padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--sa-border); }
.sa-table th { background: #f3f8f8; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--sa-muted); }
.sa-table tr:last-child td { border-bottom: none; }
.sa-tlink { color: var(--sa-accent-dark); font-weight: 600; margin-right: 0.8rem; text-decoration: none; }
.sa-tlink:hover { text-decoration: underline; }
.sa-edit-banner { background: #fff6e6; border: 1px solid #f0d8a8; color: #7a5a12; padding: 0.6rem 0.9rem; border-radius: 9px; margin-bottom: 1rem; font-size: 0.9rem; font-weight: 600; }

.sa-status { margin: 0.3rem 0 0; font-size: 0.88rem; text-align: right; min-height: 1.2em; }
.sa-status.is-error { color: #b0182a; }
.sa-status.is-ok { color: var(--sa-accent-dark); }
