/* === Structured note templates (features/structured-templates.js) === */

/* Sections a layout leaves out. */
.vf-tpl-hidden { display: none !important; }

/* A custom text section in the editor. */
.vf-sblock-custom .vf-list-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.vf-sblock.vf-half .vf-list-title { flex-wrap: wrap; }
.vf-sec-hide {
  margin-inline-start: auto; width: 24px; height: 24px; border: 0; border-radius: 6px; background: none;
  color: var(--text-tertiary); font-size: 16px; line-height: 1; cursor: pointer;
}
.vf-sec-hide:hover { background: var(--bg-secondary); color: var(--text); }
.vf-custom-text { width: 100%; }

/* "＋ Add section" under the notes. */
.vf-sec-tools { margin: 2px 0 10px; }
.vf-sec-add-wrap { position: relative; display: inline-block; }
.vf-sec-add {
  border: 1px dashed var(--border); border-radius: 8px; background: none; color: var(--primary);
  padding: 5px 12px; font: 600 12.5px var(--font); cursor: pointer;
}
.vf-sec-add:hover { border-color: var(--primary); background: var(--primary-light); }
/* The button sits at the start of the line: open the menu from there, never off-screen. */
.vf-sec-add-menu {
  min-width: 220px; max-width: min(320px, calc(100vw - 24px));
  inset-inline-start: 0; inset-inline-end: auto;
  max-height: min(60vh, 440px); overflow-y: auto;
}

/* Templates menu heading. */
.ntm-menu-head { padding: 6px 12px 2px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-tertiary); }

/* Manager: the template builder (templates · section cards · settings + add) */
.modal.modal-wide.stm-modal { max-width: 1240px; width: 96%; }
.stm { display: grid; grid-template-columns: 210px minmax(0, 1fr) 340px; gap: 18px; min-height: 420px; }
.stm-side { display: flex; flex-direction: column; gap: 8px; border-inline-end: 1px solid var(--border-light, var(--border)); padding-inline-end: 14px; }
.stm-side-head, .stm-group-title, .stm-lbl { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-tertiary); }
.stm-group-title { margin: 16px 0 6px; }
.stm-list { display: flex; flex-direction: column; gap: 2px; }
.stm-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: var(--radius-sm, 4px); background: none; color: var(--text);
  font: 14px var(--font); text-align: start; cursor: pointer;
}
.stm-item:hover { background: var(--bg-secondary); }
.stm-item.on { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.stm-new { align-self: flex-start; padding: 5px 12px; font-size: 12.5px; }
.stm-default { margin-top: auto; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-secondary); }
.stm-default select { width: 100%; }
.stm-main { min-width: 0; max-height: 68vh; overflow: auto; padding-inline-end: 4px; }
.stm-name { width: 100%; font-size: 17px; font-weight: 600; padding: 8px 10px; }
.stm-help, .stm-ro { margin: 8px 0 0; font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; }
.stm-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 0 10px; font-size: 12px; color: var(--text-secondary); }
.stm-legend b { font-weight: 700; }
.stm-c-fill { color: var(--success); }
.stm-c-ask { color: var(--warning); }
.stm-c-empty { color: var(--text-secondary); }
.stm-rows { display: flex; flex-direction: column; gap: 6px; }
.stm-card {
  display: flex; align-items: center; gap: 2px; padding: 2px 6px 2px 4px;
  border: 1px solid var(--border-light, var(--border)); border-radius: var(--radius, 6px); background: var(--surface);
}
.stm-card.on { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 18%, transparent); }
.stm-card-after { border-style: dashed; }
.stm-card-main {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 8px 6px;
  border: 0; background: none; color: var(--text); font: 14px var(--font); text-align: start; cursor: pointer;
}
.stm-card-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.stm-card-name { font-weight: 600; }
.stm-card-hint { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stm-badge { flex: none; font: 500 11px/14px var(--mono, monospace); color: var(--text-secondary); background: var(--bg-secondary); border-radius: 3px; padding: 2px 6px; white-space: nowrap; }
.stm-carrytxt { flex: none; width: 66px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.stm-half { flex: none; width: 14px; font-size: 12px; color: var(--text-tertiary); }
.stm-icon { flex: none; width: 28px; height: 28px; border: 0; border-radius: var(--radius-sm, 4px); background: none; color: var(--text-secondary); font: 600 14px/1 var(--font); cursor: pointer; }
.stm-icon:hover { background: var(--bg-secondary); color: var(--text); }
.stm-panel { min-width: 0; max-height: 68vh; overflow: auto; border-inline-start: 1px solid var(--border-light, var(--border)); padding-inline-start: 16px; display: flex; flex-direction: column; gap: 18px; }
.stm-set, .stm-pal { display: flex; flex-direction: column; gap: 12px; }
.stm-set { padding-bottom: 16px; border-bottom: 1px solid var(--border-light, var(--border)); }
.stm-set-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.stm-field { display: flex; flex-direction: column; gap: 6px; }
.stm-field input[type="text"], .stm-field input[type="number"], .stm-field select { width: 100%; }
.stm-fl { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.stm-row2 { display: flex; flex-wrap: wrap; gap: 14px; }
.stm-inline { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.stm-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.stm-opt-add { display: flex; gap: 6px; }
.stm-opt-add input { flex: 1 1 auto; min-width: 0; }
.stm-opt-add .btn-secondary { padding: 4px 12px; font-size: 12.5px; }
.stm-muted { font-size: 12.5px; color: var(--text-tertiary); }
.stm-types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stm-type {
  display: flex; flex-direction: column; gap: 2px; padding: 9px 11px; text-align: start; cursor: pointer;
  border: 1px solid var(--border-light, var(--border)); border-radius: var(--radius, 6px); background: var(--surface); color: var(--text); font: 13px var(--font);
}
.stm-type:hover { border-color: var(--primary); background: var(--primary-light); }
.stm-type-name { font-weight: 600; }
.stm-type-desc { font-size: 11.5px; line-height: 1.35; color: var(--text-tertiary); }
.stm-foot { gap: 8px; }

@media (max-width: 1000px) {
  .stm { grid-template-columns: minmax(0, 1fr) 320px; }
  .stm-side { grid-column: 1 / -1; border-inline-end: 0; border-bottom: 1px solid var(--border-light, var(--border)); padding: 0 0 12px; }
  .stm-list { flex-direction: row; flex-wrap: wrap; }
  .stm-item { width: auto; }
}
@media (max-width: 720px) {
  .stm { grid-template-columns: 1fr; }
  .stm-main, .stm-panel { max-height: none; overflow: visible; }
  .stm-panel { border-inline-start: 0; padding-inline-start: 0; border-top: 1px solid var(--border-light, var(--border)); padding-top: 14px; }
  .stm-carrytxt { width: auto; }
}

/* ── Visit editor: typed sections ───────────────────────────────────────── */
/* Half-width sections sit side by side. */
#visit-notes-structured { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 20px; }
#visit-notes-structured.hidden { display: none; }
#visit-notes-structured > * { grid-column: 1 / -1; min-width: 0; }
#visit-notes-structured > .vf-sblock.vf-half { grid-column: auto; }
@media (max-width: 720px) { #visit-notes-structured > .vf-sblock.vf-half { grid-column: 1 / -1; } }

.vf-req { margin-inline-start: 3px; color: var(--warning); font-weight: 700; }
.vf-carry-note {
  display: flex; align-items: flex-start; gap: 8px; margin: 0 0 12px; padding: 9px 12px;
  border-radius: var(--radius-sm, 4px); background: var(--bg-secondary); color: var(--text-secondary); font-size: 13px; line-height: 1.45;
}
.vf-carry-note svg { flex: none; margin-top: 2px; }
.vf-carry-note strong { color: var(--text); }
.vf-ok {
  margin-inline-start: 8px; display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border: 0; border-radius: var(--radius-sm, 4px);
  background: none; color: var(--success); font: 600 12px var(--font); text-transform: none; letter-spacing: 0; cursor: pointer; white-space: nowrap;
}
.vf-ok:hover { background: var(--bg-secondary); }
.vf-ok-done { margin-inline-start: 8px; color: var(--text-tertiary); font-size: 12px; font-weight: 600; text-transform: none; letter-spacing: 0; }

.vfw { margin-top: 2px; }
.vfw-tags, .vfw-check, .vfw-meas, .vfw-scorewrap { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.vfw-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 9px; border: 1px solid var(--border);
  border-radius: var(--radius-chip, 3px); background: var(--surface); color: var(--text); font-size: 13px; line-height: 18px;
}
.vfw-x { border: 0; background: none; color: var(--text-tertiary); font: 600 14px/1 var(--font); padding: 2px 4px; border-radius: 3px; cursor: pointer; }
.vfw-x:hover { background: var(--bg-secondary); color: var(--text); }
.vfw-tag-in { flex: 1 1 140px; min-width: 120px; padding: 4px 8px !important; font-size: 13px !important; }
.vfw-sug {
  padding: 3px 9px; border: 1px dashed var(--border); border-radius: var(--radius-chip, 3px); background: none;
  color: var(--primary); font: 13px/18px var(--font); cursor: pointer;
}
.vfw-sug:hover { border-color: var(--primary); background: var(--primary-light); }
.vfw-check { flex-direction: column; align-items: stretch; gap: 4px; }
.vfw-ci { display: flex; align-items: center; gap: 8px; }
.vfw-ci input[type="checkbox"] { flex: none; width: 18px; height: 18px; margin: 0; }
.vfw-ct { flex: 1 1 auto; min-width: 0; padding: 5px 8px !important; }
.vfw-ct.done { text-decoration: line-through; color: var(--text-tertiary); }
.vfw-add { align-self: flex-start; border: 0; background: none; color: var(--primary); font: 600 12.5px var(--font); padding: 4px 6px; border-radius: var(--radius-sm, 4px); cursor: pointer; }
.vfw-add:hover { background: var(--primary-light); }
.vfw-meas { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; align-items: start; }
.vfw-m { display: flex; flex-direction: column; gap: 3px; margin: 0; }
.vfw-ml { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.vfw-mrow { display: flex; align-items: baseline; gap: 4px; }
.vfw-mrow input { width: 100%; min-width: 0; font-family: var(--mono, monospace); }
.vfw-mu { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; }
.vfw-last { font: 11px var(--mono, monospace); color: var(--text-tertiary); }
.vfw-seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: var(--radius-sm, 4px); overflow: hidden; }
.vfw-seg button {
  border: 0; border-inline-start: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
  font: 500 12.5px/16px var(--font); padding: 6px 11px; cursor: pointer;
}
.vfw-seg button:first-child { border-inline-start: 0; }
.vfw-seg button[aria-pressed="true"] { background: var(--primary-light); color: var(--text); font-weight: 600; }
.vfw-seg button:disabled { cursor: default; opacity: .6; }
.vfw-score button { min-width: 32px; padding: 6px 0; font-family: var(--mono, monospace); }
.vfw-scorewrap .vfw-mrow input { width: 70px; }

/* Earlier prescriptions in a visit's list. */
.rx-prev-tag { display: inline-block; margin-inline-start: 6px; padding: 0 7px; border-radius: 999px; background: var(--bg-secondary); color: var(--text-secondary); font-size: 11px; font-weight: 600; vertical-align: 1px; }
.vf-carried { margin-inline-start: 8px; padding: 1px 8px; border-radius: 999px; background: var(--primary-light); color: var(--primary); font-size: 11px; font-weight: 600; text-transform: none; letter-spacing: 0; white-space: nowrap; }

/* Under the note: hidden sections one tap away, and "Customise sections" (features/note-sections.js). */
.vf-bottom-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 4px; }
.vf-bt-wrap { position: relative; margin-inline-start: auto; }
.vf-bt-custom { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--text-secondary); font: 600 12.5px var(--font); padding: 5px 8px; border-radius: 8px; cursor: pointer; }
.vf-bt-custom:hover { background: var(--bg-secondary); color: var(--text); }
.vf-bt-menu { min-width: 280px; padding: 10px 12px; inset-inline-end: 0; inset-inline-start: auto; bottom: calc(100% + 4px); top: auto; }
.vf-bt-title { font-weight: 700; font-size: 13.5px; color: var(--text); }
.vf-bt-help { margin: 2px 0 8px; font-size: 12px; color: var(--text-secondary); line-height: 1.45; }
.vf-bt-row { display: flex; align-items: center; gap: 4px; padding: 4px 0; }
.vf-bt-row label { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.vf-bt-move { width: 28px; height: 28px; border: 1px solid var(--border-light, var(--border)); border-radius: 6px; background: var(--surface); color: var(--text-secondary); cursor: pointer; }
.vf-bt-move:disabled { opacity: .35; cursor: default; }
.vf-bt-foot { display: flex; justify-content: flex-end; margin-top: 8px; }
.vf-bt-foot .btn-secondary { padding: 4px 12px; font-size: 12.5px; }

/* Unsigned drafts in the chart rail (features/visit-drafts.js) and unsigned visits. */
.ch-tag-warn { color: var(--warning, #b45309); }
.ch-draft-card-shared { margin-top: 6px; border-style: dashed; }
.ch-unsigned { display: inline-block; padding: 0 7px; border-radius: 999px; background: var(--warning-light, #fef3c7); color: var(--warning, #b45309); font-size: 11px; font-weight: 700; }

/* Structured block on top of the Note templates window. */
.stm-ntm-acts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0 2px; }
.ntm-sep-line { height: 1px; background: var(--border-light, var(--border)); margin: 14px 0 12px; }

/* Quick review controls (features/review-controls.js) */
.rv-row { flex-wrap: wrap; }
.rv-row .linerow-input { flex: 1 1 220px; }
.rv-row .medrow-name { flex: 1 1 180px; }
.rv-seg { flex: none; display: inline-flex; align-self: center; border: 1px solid var(--border); border-radius: var(--radius-sm, 4px); overflow: hidden; }
.rv-seg button {
  border: 0; border-inline-start: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
  font: 500 12px/16px var(--font); padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.rv-seg button:first-child { border-inline-start: 0; }
.rv-seg button:hover { background: var(--bg-secondary); color: var(--text); }
.rv-seg button[aria-pressed="true"] { background: var(--primary-light); color: var(--text); font-weight: 600; }
.rv-seg button[data-v="worse"][aria-pressed="true"], .rv-seg button[data-v="stop"][aria-pressed="true"] { color: var(--warning); }
/* Stop does what "→ Past" did. */
.rv-row .medrow-move-btn { display: none; }
.rv-phrases { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.rv-phrases-l { font-size: 12px; color: var(--text-tertiary); margin-inline-end: 2px; }
@media (max-width: 720px) { .rv-seg { order: 5; } }
.rv-edit { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 0; border-radius: var(--radius-sm, 4px); background: none; color: var(--text-tertiary); cursor: pointer; }
.rv-edit:hover { background: var(--bg-secondary); color: var(--text); }
.rv-ed { flex: 1 1 100%; display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border-light, var(--border)); border-radius: var(--radius, 6px); background: var(--surface); }
.rv-ed-head { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.rv-ed-head span { font-size: 12px; color: var(--text-tertiary); }
.rv-ed-rows { display: flex; flex-direction: column; gap: 4px; }
.rv-ed-row { display: flex; align-items: center; gap: 6px; }
.rv-ed-in { flex: 1 1 auto; min-width: 0; padding: 5px 8px !important; font-size: 13px !important; }
.rv-ed-add { display: flex; gap: 6px; }
.rv-ed-add input { flex: 1 1 auto; min-width: 0; padding: 5px 8px; font-size: 13px; }
.rv-ed-add .btn-secondary { padding: 4px 12px; font-size: 12.5px; }
.rv-ed-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rv-ed-foot .btn-primary { padding: 5px 14px; font-size: 12.5px; }
