/* Manas Clinic forms. One stylesheet for patient, kiosk, staff and editor pages. */
:root {
  --brand: #18aeb3;
  --brand-dk: #1f5568;
  --brand-dkr: #17414f;
  --tint: #e8f7f7;
  --ink: #1c2426;
  --muted: #5d6a6d;
  --line: #d3dcdd;
  --bg: #f3f6f6;
  --err: #b3261e;
  --ok: #1c5c34;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 40, 45, .06), 0 2px 8px rgba(20, 40, 45, .04);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  padding: 0 16px 40px;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand-dk); }

/* ---------- top bar ---------- */
.topbar {
  margin: 0 -16px 24px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 3px solid var(--brand);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-in {
  max-width: 760px;
  margin: 0 auto;
  min-height: 64px;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.wide .topbar-in, .wide main, .wide footer { max-width: 1120px; }
.logo { display: block; height: 52px; width: auto; filter: brightness(1.05); }
.toplinks { display: flex; align-items: center; gap: 18px; font-size: 14px; }
.toplinks a { text-decoration: none; font-weight: 600; }
.toplinks a:hover { text-decoration: underline; }
.helpline { font-size: 14px; color: var(--muted); text-align: right; line-height: 1.3; }
.helpline a { font-weight: 600; text-decoration: none; white-space: nowrap; }

/* ---------- page and cards ---------- */
main { display: block; max-width: 760px; margin: 0 auto; }
.sheet, .card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sheet > header { padding: 22px 32px 16px; border-bottom: 3px solid var(--brand); }
.sheet section { padding: 22px 32px; border-bottom: 1px solid var(--line); }
.sheet section:last-of-type { border-bottom: 0; }
h1 { font-family: Cambria, Georgia, serif; font-size: 26px; line-height: 1.25; margin: 0 0 6px; }
h2 { font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--brand-dk); margin: 0 0 14px; }
h3 { font-size: 15px; margin: 8px 0 6px; }
.hint { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.done { padding: 32px; }
footer { max-width: 760px; margin: 24px auto 0; text-align: center; font-size: 13px; color: var(--muted); line-height: 1.7; }

/* ---------- form fields ---------- */
.notice { margin: 0; padding: 12px 14px; background: var(--tint); border-radius: 6px; font-size: 14px; }
.prose { font-size: 15px; }
.prose p { margin: 0 0 8px; }
.prose ul { margin: 0 0 8px; padding-left: 22px; }
.prose li { margin-bottom: 4px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; min-width: 0; }
.full, fieldset.field { grid-column: 1 / -1; }
label { font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.opt { font-weight: 400; color: var(--muted); }
input, select, textarea {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid #c4cfd0;
  border-radius: 6px;
  background: #fff;
  color: inherit;
  width: 100%;
  min-height: 44px;
}
input[type="date"] { -webkit-appearance: none; appearance: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
[aria-invalid="true"] { border-color: var(--err); }
.err { color: var(--err); font-size: 13px; margin-top: 4px; }
.err:empty { display: none; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 8px; }
.choices { display: flex; gap: 10px; }
.choice { display: flex; align-items: center; gap: 7px; margin: 0; padding: 8px 18px; border: 1px solid #c4cfd0; border-radius: 6px; cursor: pointer; background: #fff; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--tint); }
.choice input, .checkline input { width: 22px; min-height: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--brand); }
.checkline { display: flex; align-items: center; gap: 10px; font-weight: 400; margin: 0; cursor: pointer; }
.checks { display: flex; flex-direction: column; gap: 10px; }
/* Rating scales: one row of equal buttons; the selected number is filled in. */
.choices.scale { display: grid; grid-template-columns: repeat(var(--options, 5), minmax(0, 1fr)); gap: 6px; max-width: 460px; }
.choices.scale .choice { position: relative; justify-content: center; padding: 0; min-height: 48px; font-weight: 600; }
.choices.scale .choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choices.scale .choice:has(input:checked) { background: var(--brand-dk); border-color: var(--brand-dk); color: #fff; }
.choices.scale .choice:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 1px; }
.scaleends { display: flex; justify-content: space-between; max-width: 460px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.sigwrap { position: relative; border: 1px solid #c4cfd0; border-radius: 6px; background: #fdfdfd; overflow: hidden; }
.sigwrap.invalid { border-color: var(--err); }
.sigwrap canvas { display: block; width: 100%; height: 170px; touch-action: none; cursor: crosshair; }
.sigline { position: absolute; left: 24px; right: 24px; bottom: 38px; border-bottom: 1px solid var(--line); pointer-events: none; }
.sigplaceholder { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; font-size: 13px; color: var(--muted); pointer-events: none; }
.sigtools { display: flex; justify-content: flex-end; margin-top: 8px; }

/* ---------- buttons and messages ---------- */
.submit, .btn {
  font: inherit; font-weight: 600; min-height: 44px; padding: 10px 22px;
  border: 1px solid var(--brand-dk); border-radius: 6px; background: var(--brand-dk); color: #fff; cursor: pointer;
}
.submit:hover, .btn:hover { background: var(--brand-dkr); }
.submit:disabled, .btn:disabled { opacity: .6; cursor: progress; }
.submit.large { font-size: 22px; padding: 22px 56px; }
.submit.secondary, .btn.secondary { background: #fff; color: var(--brand-dk); }
.submit.secondary:hover, .btn.secondary:hover { background: var(--tint); }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: 13px; }
.btn.danger { background: #fff; color: var(--err); border-color: #e4b4b0; }
.btn.danger:hover { background: #fdf2f1; }
.link { background: none; border: 0; padding: 4px 2px; font: inherit; font-size: 14px; color: var(--brand-dk); text-decoration: underline; cursor: pointer; }
.actions { padding: 22px 32px 30px; display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.actions .summary { flex-basis: 100%; }
.actionsrow { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 16px; }
section > .actionsrow:first-of-type { margin-top: 0; }
.summary { padding: 12px 14px; border-left: 3px solid var(--err); background: #fdf2f1; font-size: 14px; border-radius: 0 6px 6px 0; }
.summary ul { margin: 6px 0 0; padding-left: 20px; }
.statusbox { padding: 10px 14px; border-left: 3px solid var(--brand); background: var(--tint); font-size: 14px; margin: 10px 0; border-radius: 0 6px 6px 0; }

/* ---------- patient pages ---------- */
.welcome { text-align: center; padding-block: 80px; }
.thanks { color: var(--brand-dk); font-weight: 600; }
.checklist { list-style: none; margin: 20px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.formbtn { width: 100%; min-height: 52px; padding: 12px 16px; font: inherit; font-weight: 600; text-align: left; background: var(--tint); border: 1px solid var(--brand); border-radius: 6px; color: var(--brand-dk); cursor: pointer; }
.formbtn:hover { background: #d9f1f1; }
.isdone { padding: 12px 16px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.sheet .tablewrap td, .sheet .tablewrap th { min-width: 70px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #e7ecec; color: var(--muted); white-space: nowrap; }
.badge.complete { background: #dff2e6; color: var(--ok); }
.badge.partial, .badge.sending { background: #e3f0f5; color: #1b5068; }
.badge.pending { background: #f3eee0; color: #6b5310; }
.badge.email_waiting { background: #fbe3e1; color: var(--err); }

/* ---------- staff page ---------- */
.pagehead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin: 4px 0 18px; }
.pagehead p { margin: 0; color: var(--muted); font-size: 14px; }
.card { padding: 20px 24px; margin-bottom: 18px; }
.card > h2 { display: flex; align-items: center; gap: 10px; }
.step { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--brand-dk); color: #fff; font-size: 12px; letter-spacing: 0; }
.cardgrid { display: grid; grid-template-columns: 3fr 2fr; gap: 18px; align-items: start; }
.cardgrid .card { margin-bottom: 0; height: 100%; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px 18px; }
.formgrid .checkline { padding: 6px 8px; border-radius: 6px; font-size: 15px; }
.formgrid .checkline:has(input:checked) { background: var(--tint); }
.cardtools { display: flex; gap: 14px; margin-top: 10px; font-size: 14px; }
.linkresult { margin-top: 16px; padding: 14px; background: var(--tint); border-radius: 6px; }
.linkrow { display: flex; gap: 8px; }
.linkrow input { flex: 1; min-width: 0; }
.listtools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--muted); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--brand-dk); border-color: var(--brand-dk); color: #fff; }
.chip .count { opacity: .8; font-weight: 400; margin-left: 4px; }
.search { max-width: 240px; min-height: 36px; padding: 6px 10px; font-size: 14px; }
.patients td { padding-block: 12px; }
.patients .who { font-weight: 600; }
.progress { height: 6px; background: #e4eaea; border-radius: 3px; overflow: hidden; margin: 4px 0 6px; max-width: 220px; }
.progress span { display: block; height: 100%; background: var(--brand); }
.formstatus { list-style: none; margin: 4px 0; padding: 0; font-size: 13px; }
.formstatus li { padding: 1px 0 1px 20px; text-indent: -20px; }
.formstatus .mark { display: inline-block; width: 20px; text-indent: 0; }
.formstatus .is-done .mark { color: var(--ok); font-weight: 700; }
.formstatus .is-waiting { color: var(--muted); }
.formnote { font-size: 12px; color: var(--muted); }
.actionscell { white-space: nowrap; }
.actionscell > * { display: block; width: 100%; margin-bottom: 6px; text-align: center; }

/* ---------- form editor ---------- */
.editor .sheet { max-width: 900px; margin: 0 auto; }
.fieldcard { border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; margin: 10px 0; background: #fcfdfd; }
.sectioncard { background: #f7fafa; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.cardhead .tools { display: flex; gap: 6px; flex: none; }
.kind { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-dk); }
.sectiontitle { font-weight: 600; }
.titleinput { font-size: 20px; font-weight: 600; }
.actionsrow.sticky { position: sticky; top: 67px; z-index: 2; background: #fff; padding: 12px 32px; margin: 0; border-bottom: 1px solid var(--line); }
.previewpane { padding: 16px; background: var(--bg); border-top: 3px solid var(--brand); }
.versions { margin: 0; padding-left: 20px; font-size: 14px; }
.badge + .badge { margin-left: 6px; }

/* ---------- tablets and smaller ---------- */
@media (max-width: 900px) {
  .cardgrid { grid-template-columns: 1fr; }
}

/* ---------- phones ---------- */
@media (max-width: 620px) {
  .topbar { margin-bottom: 14px; }
  .topbar-in { min-height: 52px; }
  .logo { height: 40px; }
  .toplinks { gap: 12px; font-size: 13px; }
  .helpline { font-size: 12px; }
  h1 { font-size: 22px; }
  .sheet > header, .sheet section, .actions, .done { padding-left: 18px; padding-right: 18px; }
  .sheet > header { padding-top: 18px; padding-bottom: 14px; }
  .card { padding: 16px 16px; }
  .grid { grid-template-columns: 1fr; }
  .actions .submit { width: 100%; padding-block: 14px; }
  .actions .cancel { width: 100%; text-align: center; }
  .choices:not(.scale) .choice { flex: 1; justify-content: center; }
  .actionsrow.sticky { padding: 10px 18px; top: 55px; }
  .search { max-width: none; }
  /* Tables become one card per row, each cell labelled with its column. */
  .tablewrap table, .tablewrap tbody, .tablewrap tr, .tablewrap td { display: block; width: 100%; }
  .tablewrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tablewrap tr { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; padding: 8px 12px; background: #fff; }
  .tablewrap td { border: 0; padding: 3px 0; }
  .tablewrap td:empty { display: none; }
  .sheet .tablewrap td { display: flex; gap: 10px; min-width: 0; }
  .sheet .tablewrap td[data-label]::before { content: attr(data-label); flex: 0 0 38%; color: var(--muted); font-size: 13px; }
  .sheet .tablewrap td[data-label=""]::before { content: none; }
  .actionscell { white-space: normal; padding-top: 8px !important; }
  .actionscell > * { display: inline-block; width: auto; margin: 0 6px 6px 0; }
}
