:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --line: #e5e3df;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --soft: #9a9a9a;
  --accent: #8b3a2b;
  --accent-soft: #f4e6e0;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

header {
  height: 52px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
header .brand { display: flex; align-items: center; gap: 10px; }
.env-badge {
  padding: 2px 10px; border-radius: 10px;
  background: #fef3c7; border: 1px solid #f0c869; color: #92600a;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  white-space: nowrap;
}
header h1 { margin: 0; font-size: 16px; font-weight: 600; }
header h1 em { font-style: normal; color: var(--accent); font-weight: 500; }
header .user { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.user-pic { width: 26px; height: 26px; border-radius: 50%; }
.logout-form { margin: 0; }
.logout {
  border: 1px solid var(--line); background: var(--surface); border-radius: 5px;
  padding: 4px 10px; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer;
}
.logout:hover { color: var(--ink); border-color: var(--ink); }

.top-nav { display: flex; gap: 8px; }
.nav-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 5px;
  padding: 5px 12px; font-size: 12px; color: var(--muted); text-decoration: none;
}
.nav-btn:hover { color: var(--ink); border-color: var(--ink); }

/* HearAid sync chip (header) + status modal */
.sync-chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer;
}
.sync-chip:hover { color: var(--ink); border-color: var(--soft); }
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #4a6b4e; flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(74, 107, 78, 0.15);
}
.sync-dot.pending { background: var(--soft); box-shadow: 0 0 0 3px rgba(154, 154, 154, 0.15); }
.sync-sub { font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.sync-h {
  font-size: 11px; font-weight: 600; color: var(--soft); text-transform: uppercase;
  letter-spacing: 0.04em; margin: 18px 0 8px;
}
.sync-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.sync-cell { background: var(--surface); padding: 10px 12px; }
.sync-k { font-size: 11px; color: var(--soft); }
.sync-v { font-size: 17px; font-weight: 600; color: var(--ink); margin-top: 2px; }
.sync-v.warn { color: #855a12; }
.sync-foot { font-size: 11px; color: var(--soft); margin: 16px 0 0; }

.app { display: grid; grid-template-columns: 320px 1fr; min-height: calc(100vh - 52px); }

/* Sidebar */
aside {
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex; flex-direction: column;
  position: sticky; top: 52px; height: calc(100vh - 52px);
}
.search { padding: 16px; border-bottom: 1px solid var(--line); }
.search input {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; background: var(--bg); outline: none;
}
.search input:focus { border-color: var(--accent); }
.search-row { display: flex; gap: 8px; align-items: stretch; }
.search-row input { flex: 1; min-width: 0; }
.adv-toggle {
  flex: none; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); font: inherit; font-size: 13px; color: var(--muted);
  cursor: pointer; white-space: nowrap;
}
.adv-toggle:hover { color: var(--ink); border-color: var(--ink); }
/* Advanced-search modal field grid (two columns; DOB spans the full width). */
.adv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.adv-grid .adv-wide { grid-column: 1 / -1; }
.adv-grid input {
  min-width: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 13px; background: var(--bg); outline: none;
}
.adv-grid input:focus { border-color: var(--accent); }
.status-filter {
  width: 100%; margin-top: 10px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 13px; color: var(--ink); background: var(--bg); outline: none;
}
.status-filter:focus { border-color: var(--accent); }
.add-patient {
  width: 100%; margin-top: 10px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); font: inherit; font-size: 13px; color: var(--muted);
  cursor: pointer; text-align: left;
}
.add-patient:hover { color: var(--ink); border-color: var(--ink); }
.list { flex: 1; overflow-y: auto; padding: 8px; }
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 6px; cursor: pointer;
  text-decoration: none; color: inherit;
}
.row:hover { background: var(--bg); }
.row.active { background: var(--accent-soft); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600; color: var(--muted); flex-shrink: 0;
}
.row.active .avatar { background: var(--accent); color: #fff; border-color: var(--accent); }
.row .name { font-size: 13px; font-weight: 500; }
.row .sub { font-size: 11px; color: var(--soft); margin-top: 1px; }
.row .meta { flex: 1; min-width: 0; }
.pill {
  font-size: 10px; padding: 2px 7px; border-radius: 999px;
  color: var(--muted); background: var(--bg); border: 1px solid var(--line);
}
.pill.active   { color: #4a6b4e; background: #eaf0e8; border-color: #d4dccf; }
.pill.follow   { color: #8a5a1d; background: #f5e8d0; border-color: #e4d3b1; }
.pill.new      { color: #3b5b6a; background: #e2ebef; border-color: #c7d6dd; }
.pill.inactive { color: #6b6b6b; background: #ececec; border-color: #dcdcdc; }

/* Main */
main { padding: 32px 40px; max-width: 980px; position: relative; }
.detail-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.detail-head-main { flex: 1; min-width: 0; }
.add-doc { flex-shrink: 0; white-space: nowrap; }
h2.client { margin: 0 0 4px; font-size: 28px; font-weight: 600; letter-spacing: -0.01em; }
.detail-head .subline { margin-bottom: 0; }
.subline { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.chips {
  display: flex; flex-wrap: wrap; gap: 24px;
  padding: 16px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  margin-bottom: 32px;
}
.chip-label { font-size: 11px; color: var(--soft); text-transform: uppercase; letter-spacing: 0.04em; }
.chip-value { font-size: 14px; margin-top: 2px; }
.empty { color: var(--soft); }

/* Full HearAid record — collapsible read-only section of extended client fields */
.ha-record { margin: 0 0 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.ha-record > summary {
  cursor: pointer; padding: 12px 16px; font-size: 13px; font-weight: 500;
  color: var(--muted); list-style: none; user-select: none;
}
.ha-record > summary::-webkit-details-marker { display: none; }
.ha-record > summary::before { content: "▸ "; color: var(--soft); }
.ha-record[open] > summary::before { content: "▾ "; }
.ha-record > summary:hover { color: var(--ink); }
.ha-groups { padding: 4px 16px 18px; display: grid; gap: 18px; }
.ha-group h4 {
  margin: 0 0 8px; font-size: 11px; font-weight: 600; color: var(--soft);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.ha-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 24px; }
.ha-label { font-size: 11px; color: var(--soft); }
.ha-value { font-size: 13px; color: var(--ink); margin-top: 1px; white-space: pre-wrap; word-break: break-word; }
.ha-value.warn { color: #855a12; font-weight: 500; }

section { margin-bottom: 32px; }
section h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--ink); }
section h3 span { color: var(--soft); font-weight: 400; margin-left: 6px; }

.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.doc {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  position: relative; overflow: hidden;
}
.doc:hover { border-color: var(--soft); }
.doc-icon {
  position: relative; width: 44px; height: 44px; border-radius: 6px; background: var(--bg);
  display: grid; place-items: center; color: var(--muted); flex-shrink: 0; overflow: hidden;
}
/* Client-generated preview; sits over the type glyph and is removed by app.js
   if it fails to load, revealing the glyph beneath. */
.doc-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.doc-body { flex: 1; min-width: 0; }
/* Single-line, ellipsised — keeps cards uniform instead of growing tall when a
   title or meta line is long. */
.doc-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 11px; color: var(--soft); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Actions overlay the right edge on hover instead of taking flex space (which
   previously squeezed the title down to one word per line). */
.doc-actions {
  position: absolute; top: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 4px; padding: 0 12px 0 28px;
  background: linear-gradient(to right, transparent, var(--surface) 24px);
  opacity: 0; transition: opacity .12s;
}
.doc:hover .doc-actions { opacity: 1; }
.doc-actions .btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 4px;
  padding: 4px 8px; font: inherit; font-size: 11px; color: var(--muted);
  cursor: pointer; text-decoration: none;
}
.doc-actions .btn:hover { color: var(--ink); border-color: var(--ink); }
.doc-actions .btn-danger:hover { color: #b3261e; border-color: #b3261e; }
.removed-note { font-size: 12px; color: var(--soft); margin: 2px 0 8px; }
.removed h3 span { color: #b3261e; }

/* Provenance markers */
.tag-manual {
  font-size: 10px; font-weight: 500; vertical-align: middle;
  padding: 1px 6px; border-radius: 999px; margin-left: 4px;
  color: var(--accent); background: var(--accent-soft); border: 1px solid #e7cdc4;
}
.notice {
  background: var(--accent-soft); border: 1px solid #e7cdc4; color: #7a3526;
  border-radius: 6px; padding: 8px 12px; font-size: 12px; margin-bottom: 20px;
}
/* Collision warning — a file number (MRN) shared by more than one patient.
   Amber, distinct from the accent-toned provenance notice. */
.notice.warn { background: #fbf1d8; border-color: #e8d28f; color: #855a12; }
.dup-badge {
  font-size: 10px; font-weight: 500; vertical-align: middle;
  padding: 1px 6px; border-radius: 999px; margin-left: 4px; white-space: nowrap;
  color: #855a12; background: #fbf1d8; border: 1px solid #e8d28f;
}
/* Provisional-entry notice carries an inline "Link to patient record" action. */
.notice-link { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.notice-link .link-record { flex: none; padding: 5px 12px; font-size: 12px; }

/* Link-to-record modal: search box + synced-record candidate list. */
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.modal input[type="search"] {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); outline: none;
}
.modal input[type="search"]:focus { border-color: var(--accent); }
.link-candidates { list-style: none; margin: 12px 0 0; padding: 0; max-height: 320px; overflow-y: auto; }
.link-candidates li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.link-candidates .lc-name { font-size: 14px; color: var(--ink); }
.link-candidates .lc-meta { font-size: 12px; color: var(--soft); margin-top: 2px; }
.link-candidates form { margin: 0; flex: none; }
.link-candidates .btn-primary { padding: 6px 14px; }
#link-results .hint, #link-results .empty { display: block; margin-top: 12px; font-size: 12px; }

/* Add-patient form */
.pform { display: flex; flex-direction: column; gap: 16px; max-width: 460px; margin-top: 8px; }
.pform label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.pform .hint { color: var(--soft); font-weight: 400; text-transform: none; }
.pform input, .pform select {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); outline: none;
}
.pform input:focus, .pform select:focus { border-color: var(--accent); }
.form-error {
  background: #fdecea; border: 1px solid #f5c6c0; color: #8a2c1d;
  border-radius: 6px; padding: 8px 12px; font-size: 12px;
}
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.btn-primary {
  padding: 9px 18px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 500; cursor: pointer;
}
.btn-primary:hover { background: #76301f; border-color: #76301f; }
.btn-secondary {
  padding: 9px 16px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--muted); font: inherit; text-decoration: none; cursor: pointer;
}
.btn-secondary:hover { color: var(--ink); border-color: var(--ink); }

/* htmx indicator rules — normally injected inline by htmx, but our CSP blocks
   that (see app.html), so we ship them here. */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

/* Add-document modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 16, 14, 0.45);
  align-items: flex-start; justify-content: center; padding: 8vh 16px;
}
.modal-overlay.is-open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  width: 480px; max-width: 100%; padding: 24px 24px 20px;
  box-shadow: 0 12px 40px rgba(20, 16, 14, 0.25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close {
  border: none; background: none; font-size: 22px; line-height: 1;
  color: var(--soft); cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }
.modal .pform { margin-top: 0; max-width: none; }
.file-chosen {
  font-size: 12px; color: var(--muted); margin-top: -8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.upload-preview { margin-top: -4px; }
.upload-preview.is-loading { font-size: 12px; color: var(--soft); }
.upload-preview img {
  display: block; max-width: 100%; max-height: 180px;
  border: 1px solid var(--line); border-radius: 6px;
}

/* Encrypted-export modal */
.modal p { font-size: 13px; color: var(--muted); margin: 0 0 14px; line-height: 1.5; }
.modal p.hint { font-size: 12px; color: var(--soft); }
.export-pass { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.export-pass code {
  flex: 1; font-size: 15px; letter-spacing: 0.5px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  user-select: all; overflow-wrap: anywhere;
}

/* Drag-to-upload overlay over the patient view */
.drop-hint {
  display: none; position: absolute; inset: 0; z-index: 40; pointer-events: none;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(141, 60, 40, 0.06);
  border: 2px dashed var(--accent); border-radius: 10px;
}
#main.drag-over .drop-hint { display: flex; }
.drop-hint-inner {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 22px; font-size: 14px; font-weight: 500; color: var(--accent);
  box-shadow: 0 6px 20px rgba(20, 16, 14, 0.12);
}

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 40px 36px; width: 360px; max-width: calc(100vw - 32px); text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.login-card h1 em { font-style: normal; color: var(--accent); font-weight: 500; }
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.login-env {
  display: inline-block; margin: 6px 0 0; padding: 2px 10px; border-radius: 10px;
  background: #fef3c7; border: 1px solid #f0c869; color: #92600a;
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
}
.login-error {
  background: #fdecea; border: 1px solid #f5c6c0; color: #8a2c1d;
  border-radius: 6px; padding: 8px 12px; font-size: 12px; margin: 0 0 16px;
}
.google-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 10px 16px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink); font-weight: 500; text-decoration: none;
}
.google-btn:hover { border-color: var(--soft); background: var(--bg); }
.login-foot { color: var(--soft); font-size: 11px; margin: 18px 0 0; }

/* --- Batch A: document view toggle, list mode, multi-file preview, responsive --- */

/* Detail-head action cluster (view toggle + add-document) */
.detail-head-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.doc-view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.doc-view-toggle button {
  border: 0; background: var(--surface); color: var(--soft); cursor: pointer;
  padding: 6px 10px; font-size: 14px; line-height: 1;
}
.doc-view-toggle button + button { border-left: 1px solid var(--line); }
.doc-view-toggle button:hover { color: var(--ink); }
.doc-view-toggle button.active { background: var(--bg); color: var(--accent); }

/* List view: one document per full-width row instead of the card grid */
body.doc-list .docs { grid-template-columns: 1fr; gap: 4px; }
body.doc-list .doc { padding: 8px 12px; }
body.doc-list .doc-icon { width: 32px; height: 32px; }

/* Multi-file upload preview strip */
.upload-preview { display: flex; flex-wrap: wrap; gap: 6px; }
.upload-preview.is-loading { display: block; }

/* --- Responsive / mobile --- */
@media (max-width: 760px) {
  header { flex-wrap: wrap; height: auto; min-height: 52px; padding: 6px 14px; gap: 6px 12px; }
  header h1 { font-size: 15px; }
  /* Keep the nav reachable on phones — it wraps to its own line rather than
     vanishing (it used to be display:none, which hid "Hearing room" entirely). */
  .top-nav { order: 3; flex-basis: 100%; }
  .app { grid-template-columns: 1fr; min-height: 0; }
  aside {
    position: static; height: auto; max-height: 42vh; overflow-y: auto;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  main { padding: 20px 16px; max-width: none; }
  .detail-head { flex-wrap: wrap; gap: 10px; }
  .chips { gap: 14px; }
  .docs { grid-template-columns: 1fr; }
  .ha-fields { grid-template-columns: 1fr 1fr; }
  .modal { width: calc(100vw - 24px); max-width: none; }
  /* Touch has no hover, so the per-card actions must always be visible. */
  .doc-actions { position: static; opacity: 1; background: none; padding: 8px 0 0; }
}

/* --- About this system --- */
.about { max-width: 760px; }
.about h2 { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.about h3 { margin: 28px 0 8px; font-size: 15px; font-weight: 600; color: var(--accent); }
.about .lead { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 8px; }
.about section ul { margin: 0; padding-left: 20px; }
.about section li { font-size: 14px; line-height: 1.7; color: var(--ink); }
.about .note-intro { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.about .note {
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 6px; padding: 14px 16px; margin: 12px 0;
}
.about .note h4 { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.about .note p { margin: 0 0 8px; font-size: 13px; line-height: 1.6; color: var(--ink); }
.about .note p:last-child { margin-bottom: 0; }
.about .note .caveat { color: var(--muted); font-style: italic; }

/* --- Sync admin --- */
.admin-sync { max-width: 1100px; }
.admin-sync h2 { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.admin-sync .lead { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 20px; max-width: 760px; }
.sync-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.sync-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 16px 18px; }
.sync-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; color: var(--accent); }
.sync-card .sync-h { margin: 16px 0 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--soft); }
.muted { color: var(--soft); font-weight: 400; }

.exceptions { margin-top: 28px; }
.exceptions h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.ex-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.ex-tab {
  padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 12px; color: var(--muted); text-decoration: none;
}
.ex-tab:hover { border-color: var(--ink); color: var(--ink); }
.ex-tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 500; }

.ex-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ex-table th {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--soft); font-weight: 600;
}
.ex-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ex-table tr:hover td { background: var(--bg); }
.ex-file { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.ex-kind { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.ex-missing { background: #fdeee0; color: #9a5a1a; }
.ex-ambiguous { background: #fbe2e0; color: #9a2b2b; }
.ex-orphan { background: #eee9f6; color: #5b3a8b; }

@media (max-width: 760px) {
  .sync-cards { grid-template-columns: 1fr; }
}

.list-cap { padding: 10px 12px; font-size: 11px; color: var(--soft); text-align: center; }
.list-count {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  padding: 6px 4px 8px; font-size: 11px; font-weight: 500; color: var(--soft);
}

/* ===== Clinical form wizard ============================================== */

.notice.ok { background: #e7f3ea; border-color: #b9ddc4; color: #2c6b3f; }

/* Forms list block on the patient detail */
.forms-section { margin-bottom: 28px; }
.forms-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.newform { display: flex; gap: 8px; margin: 0; }
.newform select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); outline: none;
}
.newform select:focus { border-color: var(--accent); }
.form-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.form-row {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface);
}
.form-row .doc-glyph { color: var(--muted); display: flex; }
.form-row-body { flex: 1; min-width: 0; }
.form-row-title { font-size: 14px; font-weight: 500; }
.form-row-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.form-row-meta.status-complete { color: #2c6b3f; }
.form-row-meta.status-patient_pending { color: #855a12; }
.form-row-actions { display: flex; gap: 8px; flex-shrink: 0; }
.form-row .btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 4px;
  padding: 5px 12px; font: inherit; font-size: 12px; color: var(--muted);
  cursor: pointer; text-decoration: none;
}
.form-row .btn:hover { color: var(--ink); border-color: var(--ink); }

/* Wizard */
.wizard { max-width: 720px; }
.wizard-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.wizard-head-handoff { margin-left: auto; flex-shrink: 0; }
.wizard-title h2 { margin: 0; }
.wizard-section {
  border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; background: var(--surface);
}
.wizard-section h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.role-tag {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 1px 7px; border-radius: 999px; color: var(--muted); background: var(--bg); border: 1px solid var(--line);
}
.wizard-section.role-patient h3 .role-tag { color: var(--accent); background: var(--accent-soft); border-color: #e7cdc4; }
.wizard-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

/* Generic field */
.ff { margin: 14px 0; }
.ff[hidden], .wizard-section[hidden] { display: none !important; }
.ff-label { font-size: 13px; font-weight: 500; color: var(--ink); margin-bottom: 6px; }
.ff-label .req, .ff-yesno .req { color: var(--accent); }
.ff-help { font-size: 12px; color: var(--soft); margin-top: 4px; }
.ff-input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); outline: none;
}
.ff-input:focus { border-color: var(--accent); }
textarea.ff-input { resize: vertical; }
.ff-choices { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.ff-opt, .ff-yesno, .ff-scale-opt { font-size: 14px; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.ff-scale { display: flex; gap: 16px; }
.ff-bilat { display: flex; gap: 12px; }
.ff-bilat label { flex: 1; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

/* Side-check: a present/absent tick with an optional ear side */
.ff-sidecheck { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.ff-side { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.ff-side select { width: auto; }

/* COSI grid */
.ff-cosi { display: flex; flex-direction: column; gap: 8px; }
.ff-cosi-row { display: flex; gap: 8px; align-items: center; }
.ff-cosi-order { flex: 0 0 48px; text-align: center; }
.ff-cosi-need { flex: 2; }
.ff-cosi-sel { flex: 1; min-width: 0; }

/* Score list (speech tests) */
.ff-scorelist { display: flex; flex-direction: column; gap: 8px; }
.sl-cond { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.sl-cond-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.sl-cond-item .ff-input { width: 130px; }
.sl-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sl-table td { padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.sl-n { color: var(--soft); font-size: 12px; width: 30px; text-align: right; }
.sl-text { min-width: 120px; }
.sl-resp .ff-input { min-width: 120px; }
.sl-mark { white-space: nowrap; width: 1%; color: var(--muted); font-size: 13px; }
.sl-num { width: 64px; display: inline-block; text-align: center; }
.sl-tick { display: inline-flex; align-items: center; gap: 4px; margin-right: 12px; cursor: pointer; }
.sl-cat { font-size: 12px; color: var(--soft); }
.sl-outof { font-size: 12px; color: var(--soft); }
.sl-total { font-weight: 600; }

/* Attachment prompts (KindUpload) */
.ff-upload { display: flex; flex-direction: column; gap: 6px; }
.ff-upload-cur { font-size: 13px; }
.ff-upload-cur a { color: var(--accent); }
.ff-upload-file { font-size: 13px; color: var(--muted); }

/* Locked (read-only) patient sections in the clinician wizard while the patient fills */
.wizard-section.locked { background: #f7f9fc; border-color: #dce4f0; }
.role-tag.live { color: #2e8b57; background: #e8f5ee; border-color: #bfe3cf; display: inline-flex; align-items: center; gap: 5px; }

/* Finalise "incomplete fields" warning + modal */
.btn-link { background: none; border: 0; padding: 0; margin-left: 6px; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }
.missing-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.missing-list li { border-bottom: 1px solid var(--line, #eee); }
.missing-list a { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 4px; color: var(--ink); text-decoration: none; }
.missing-list a:hover { background: var(--accent-soft, #f3e9e5); }
.missing-sec { font-size: 12px; color: var(--soft); white-space: nowrap; }
.field-flash { animation: fieldflash 1.6s ease-out; border-radius: 6px; }
@keyframes fieldflash {
  0%, 30% { box-shadow: 0 0 0 3px var(--accent, #b1543b); background: var(--accent-soft, #fbeee9); }
  100% { box-shadow: 0 0 0 0 transparent; background: transparent; }
}

/* Read-only live patient view */
.watch-live {
  background: #f3f6fb; border: 1px solid #d7e0ee; border-radius: 8px;
  padding: 12px 14px; margin-bottom: 14px;
}
.watch-live-status { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.watch-live .seg-progress { margin: 8px 0; }
.watch-live .hint { margin: 6px 0 10px; }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #2e8b57;
  display: inline-block; animation: livepulse 1.4s ease-in-out infinite;
}
@keyframes livepulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.fv-section { margin-bottom: 8px; }
.fv { padding: 5px 0; border-bottom: 1px solid var(--line, #eee); }
.fv-label { font-size: 12px; color: var(--soft); margin-bottom: 2px; }
.fv-val { font-size: 14px; color: var(--ink); white-space: pre-wrap; }
.fv-val.empty { color: var(--soft); }
.fv-sign { max-width: 260px; max-height: 90px; border: 1px solid var(--soft); border-radius: 6px; background: #fff; }
.fv-cosi { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.fv-cosi th, .fv-cosi td { border: 1px solid #dcdcdc; padding: 4px 6px; text-align: left; }
.fv-cosi th { background: #eef1f6; font-weight: 600; }
.fv-cosi td.empty, .fv-cosi .empty { color: var(--soft); }

/* Signature pad */
.ff-sign { display: inline-block; }
.ff-sign-canvas {
  width: 100%; max-width: 360px; height: 140px; border: 1px dashed var(--soft);
  border-radius: 8px; background: #fffdfb; touch-action: none; display: block;
}
.btn-small { padding: 4px 10px; font-size: 12px; margin-top: 8px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); cursor: pointer; }
.btn-small:hover { color: var(--ink); border-color: var(--ink); }

/* Handoff QR panel */
.handoff { display: flex; gap: 20px; align-items: flex-start; border: 1px solid var(--line);
  border-radius: 10px; padding: 16px 18px; margin-bottom: 18px; background: var(--accent-soft); }
.handoff-qr img.qr { display: block; border-radius: 8px; background: #fff; padding: 6px; }
.handoff-body h3 { margin: 0 0 6px; font-size: 15px; }
.handoff-body p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }

/* ===== Public patient page ============================================== */
.pub-body { background: var(--bg); min-height: 100vh; }
.pub-card { max-width: 640px; margin: 0 auto; padding: 24px 18px 64px; }
.pub-card h1 { font-size: 22px; font-weight: 600; }
.pub-card h1 em { font-style: normal; color: var(--accent); font-weight: 500; }
.pub-sub { font-size: 15px; color: var(--muted); margin-bottom: 20px; }
.pub-form .wizard-section { padding: 16px 16px; }
.pub-form .ff-input, .pub-form .ff-opt, .pub-form .ff-scale-opt { font-size: 16px; } /* touch-friendly */
.pub-form .wizard-actions { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.pub-msg { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px 24px; text-align: center; }
.pub-msg h2 { margin: 0 0 8px; }
.pub-msg p { color: var(--muted); margin: 0; }

/* Narrow screens (phones): stack the side-by-side field layouts vertically so
   inputs get full width instead of being squished into a single row. */
@media (max-width: 560px) {
  .ff-bilat { flex-direction: column; gap: 10px; }
  .ff-cosi-row { flex-direction: column; gap: 6px; }
  .ff-scale { flex-wrap: wrap; gap: 8px 18px; }
  .ff-choices { gap: 8px 14px; }
  .wizard-actions { flex-direction: column; align-items: stretch; }
  .wizard-actions .btn-primary, .wizard-actions .btn-secondary { text-align: center; }
  .handoff { flex-direction: column; align-items: center; text-align: center; }
}

/* ===== Form progress + step wizard ====================================== */

.form-row-sub { font-size: 11px; color: var(--soft); margin-top: 3px; }

/* Segmented progress bar — CSP-safe (no inline width), one cell per step. */
.seg-progress { display: flex; gap: 4px; margin-top: 6px; }
.seg-progress .seg {
  height: 6px; flex: 1; border-radius: 3px;
  background: var(--line); transition: background .2s;
}
.seg-progress .seg.filled { background: var(--accent); }

/* Patient page progress header */
.pub-progress { margin: 4px 0 18px; }
.pub-progress .seg-progress .seg { height: 8px; }
.pub-step-label { font-size: 12px; color: var(--muted); margin-top: 6px; font-weight: 500; }

/* Patient step navigation: Back on the left, Next/Submit on the right */
.pub-actions { justify-content: space-between; }
.pub-actions .btn-primary { margin-left: auto; }

/* Autosave status line */
.pub-saved { min-height: 18px; margin-top: 10px; font-size: 12px; color: var(--soft); text-align: center; }
.pub-saved.ok { color: #2c6b3f; }
.pub-saved.warn { color: #855a12; }

/* ===== Forms settings editor (Phase 1) ================================== */

.form-settings { max-width: 1000px; }
.form-settings h2 { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.form-settings .lead { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 20px; max-width: 760px; }
.fs-crumb { margin-bottom: 10px; }
.fs-crumb a { font-size: 13px; color: var(--muted); text-decoration: none; }
.fs-crumb a:hover { color: var(--ink); }
.fs-note { font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 0 0 16px; line-height: 1.5; }
.fs-saved { background: #e7f3ea; border: 1px solid #b9ddc4; color: #2c6b3f; border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 16px; }

.fs-badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }

/* Shared option lists (index page) */
.fs-lists-head { margin-top: 34px; }
.fs-lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.fs-list { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.fs-list-head { display: flex; align-items: center; gap: 8px; }
.fs-list-head h3 { margin: 0; font-size: 15px; }
.fs-list textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font: inherit; font-size: 13px; resize: vertical; }
.fs-list-actions { display: flex; justify-content: flex-end; }
.fs-saved { color: #2e8b57; font-size: 12px; font-weight: 600; }
.fs-list-locked { background: #f7f9fc; }
.fs-badge-locked { background: #eef1f6; color: var(--soft); }
.fs-list-values { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink); max-height: 180px; overflow-y: auto; }
.fs-list-values li { padding: 1px 0; }

.fs-index { width: 100%; border-collapse: collapse; font-size: 13px; }
.fs-index th { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--soft); font-weight: 600; }
.fs-index td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.fs-index .fs-name { font-weight: 600; }

.fs-section { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 14px 16px; margin-bottom: 16px; }
.fs-section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.fs-section-head h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--accent); }
.fs-intro { font-size: 12px; margin: 4px 0 10px; line-height: 1.5; }
.fs-role { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.fs-role select, .fs-fields select { font: inherit; font-size: 13px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--ink); }
.fs-fields select.fs-changed { border-color: var(--accent); }

.fs-fields { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.fs-fields th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--soft); font-weight: 600; }
.fs-fields td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.fs-fields tr:last-child td { border-bottom: none; }
.fs-req-col { text-align: center; width: 90px; }
.fs-field-label { font-weight: 500; }
.fs-fid { display: block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--soft); font-weight: 400; margin-top: 2px; }
.fs-help { display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 3px; }
.fs-kind-fixed { font-size: 12px; color: var(--muted); }

.fs-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.fs-save { font: inherit; font-size: 13px; font-weight: 500; padding: 8px 18px; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
.fs-save:hover { filter: brightness(1.08); }
.fs-reset { font: inherit; font-size: 13px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); cursor: pointer; }
.fs-reset:hover { border-color: var(--ink); color: var(--ink); }
