#templates-panel .template-create-actions{display:flex;flex-wrap:wrap;gap:8px;margin:0 0 20px}
#templates-panel .template-document{min-width:0;padding:0;background:var(--brand-tint)}
#templates-panel .template-edit-layout{grid-template-columns:minmax(0,1fr) 248px}
#templates-panel #template-document-editor{position:relative;height:760px;min-width:0;color:var(--brand-ink);font:14px/1.5 Arial,sans-serif}
#templates-panel #template-document-editor>.docx-editor{height:100%;min-height:0}
#templates-panel .template-placeholder-panel{max-height:760px;overflow:auto;padding:16px}
#templates-panel .template-placeholder-panel>p{line-height:1.6}
#templates-panel .template-placeholders{gap:6px}
#templates-panel .template-placeholders button{cursor:grab;padding:8px 10px;min-height:36px}
#templates-panel .template-placeholders button:active{cursor:grabbing}
#templates-panel .template-placeholders button:disabled{cursor:default}
#templates-panel .template-spacing{margin-top:16px;padding-top:12px}
#templates-panel .template-spacing label{margin:5px 0;font-size:12px;line-height:1.35}
#templates-panel .template-spacing legend{margin-bottom:4px;line-height:1.4}
#templates-panel .template-toolbar{position:static}
#templates-panel #template-draft-name-field input{min-width:140px;max-width:260px}
#templates-panel .docx-editor input,#templates-panel .docx-editor select,#templates-panel .docx-editor textarea{margin:0}
#templates-panel .document-editor-frame{display:flex;flex-direction:column;min-height:0;min-width:0;max-width:100%;overflow:hidden}
#templates-panel .document-editor-frame>.template-document-viewport{flex:1;min-height:0;min-width:0;overflow:auto}
@media(max-width:900px){#templates-panel .template-edit-layout{grid-template-columns:1fr}#templates-panel .template-placeholder-panel{max-height:none;border-left:0;border-top:1px solid var(--color-edge);display:grid;grid-template-columns:1fr 1fr;gap:18px}#templates-panel .template-placeholder-panel>h3,#templates-panel .template-placeholder-panel>p,#templates-panel .template-placeholders{grid-column:1/-1}#templates-panel .template-placeholders{display:grid;grid-template-columns:repeat(2,minmax(0,1fr))}#templates-panel .template-placeholder-panel>p{margin:0}#templates-panel .template-spacing{margin:0}#templates-panel #template-document-editor{height:640px}}
@media(max-width:480px){#templates-panel .template-placeholder-panel{padding:14px;gap:12px}#templates-panel .template-spacing label{font-size:12px}#templates-panel .template-actions{flex-wrap:wrap}#templates-panel .template-placeholders button{min-height:44px}}

#templates-panel .template-drop-cursor{position:absolute;z-index:5;width:2px;background:var(--color-accent);pointer-events:none;box-shadow:0 0 0 1px #fff}
#templates-panel .template-drop-cursor::before,#templates-panel .template-drop-cursor::after{content:"";position:absolute;left:-2px;width:6px;height:2px;background:inherit}
#templates-panel .template-drop-cursor::before{top:0}
#templates-panel .template-drop-cursor::after{bottom:0}

#templates-panel .docx-text-highlight-overlay:has(.report-field-block){mix-blend-mode:normal}
#templates-panel .report-field-block{container-type:size;border-radius:4px;background:#eaf1f5;box-shadow:inset 0 0 0 1px #bfd0da;overflow:hidden}
#templates-panel .report-field-block.docx-text-highlight--active{background:#f2c66d;box-shadow:inset 0 0 0 1px #b27b22}
#templates-panel .report-field-block::after{content:var(--report-field-label);position:absolute;inset:0;display:flex;align-items:center;justify-content:center;white-space:nowrap;overflow:hidden;color:#315f78;font-family:Arial,sans-serif;font-weight:600;font-size:clamp(6px,75cqh,13px);line-height:1}
#templates-panel .report-field-findings{--report-field-label:"Findings"}
#templates-panel .report-field-impression{--report-field-label:"Impression"}
#templates-panel .report-field-technique{--report-field-label:"Technique"}
#templates-panel .report-field-patient_name{--report-field-label:"Patient name"}
#templates-panel .report-field-date_of_birth{--report-field-label:"Date of birth"}
#templates-panel .report-field-referring_physician{--report-field-label:"Referring physician"}
#templates-panel .report-field-patient_id{--report-field-label:"Patient ID"}
#templates-panel .report-field-date_of_study{--report-field-label:"Date of study"}
#templates-panel .report-field-exam_title{--report-field-label:"Exam title"}
#templates-panel .report-field-clinical_history{--report-field-label:"Clinical history"}
#templates-panel .report-field-comparison{--report-field-label:"Comparison"}
#templates-panel .report-field-review_flags{--report-field-label:"Review flags"}

#templates-panel .template-page-heading{align-items:flex-start;gap:16px;margin-bottom:16px}
#templates-panel .template-page-heading>div{max-width:780px;flex:1 1 420px}
#templates-panel .template-page-heading h2{margin-bottom:8px}
#templates-panel #template-intro{font-size:13px;line-height:1.7;margin:0;max-width:85ch}
#templates-panel #download-starter-template{border-color:transparent;background:transparent;color:var(--color-muted);padding:6px 0;font-size:12px;min-height:32px;border-radius:6px}
#templates-panel #download-starter-template:hover{color:var(--color-ink)}
#templates-panel .template-create-actions .button{min-height:44px;gap:8px;padding:10px 14px;font-size:13px;border-radius:10px}
#templates-panel #create-blank-template{color:var(--color-ink);border-color:var(--color-edge);background:var(--color-surface)}
#templates-panel #create-blank-template:hover{color:var(--color-ink);border-color:var(--color-muted);background:var(--color-raised)}
#templates-panel #toggle-template-upload[aria-expanded="true"]{color:var(--color-accent);border-color:var(--color-accent);background:var(--brand-tint)}
#templates-panel .template-upload{margin:0 0 20px;border-radius:12px}
#templates-panel .template-upload form{padding:18px}
@media(max-width:600px){#templates-panel .template-page-heading{gap:8px}#templates-panel .template-page-heading>div{flex-basis:100%}#templates-panel .template-create-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr))}#templates-panel #toggle-template-upload{grid-column:1/-1}#templates-panel .template-create-actions .button{justify-content:center}}

/* Document chrome shares one neutral palette from the command bar to the ruler. */
#template-editor {
  --editor-surface: light-dark(#fff, #25282d);
  --editor-canvas: light-dark(#eef0f3, #191c21);
  --editor-toolbar: light-dark(#f7f8fa, #30343b);
  --editor-edge: light-dark(#d6dae0, #414750);
  --editor-ink: light-dark(#252b33, #ecedf0);
  --editor-muted: light-dark(#58626f, #b7bec9);
  --editor-selected: light-dark(#dce9fa, #384d68);
  --editor-selected-ink: light-dark(#194d87, #e0edff);
  background: var(--editor-surface);
  border-color: var(--editor-edge);
  border-radius: 10px;
}
#templates-panel .template-toolbar {
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  background: var(--editor-surface);
  border-color: var(--editor-edge);
  border-radius: 10px 10px 0 0;
}
#template-editor .template-picker label { color: var(--editor-muted); margin-bottom: 3px; }
#template-editor .template-picker :is(input,select),
#template-editor .template-actions .button.secondary {
  background: var(--editor-surface);
  border-color: var(--editor-edge);
  color: var(--editor-ink);
}
#template-editor .template-actions { gap: 4px; }
#template-editor .template-actions .button,
#template-editor .template-picker :is(input,select) {
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}
#template-editor .template-icon-button { width: 34px; height: 34px; border-radius: 6px; color: var(--editor-muted); }
#template-editor .template-actions :is(.secondary,.template-icon-button):enabled:hover { background: var(--editor-toolbar); }
#template-editor #save-template { background: light-dark(#245996, #3c679c); color: white; border-color: transparent; }
#template-editor .template-placeholder-panel { background: var(--editor-surface); border-color: var(--editor-edge); color: var(--editor-ink); }
#template-editor .template-placeholder-panel .muted { color: var(--editor-muted); }
#template-editor .template-placeholders button {
  color: var(--editor-ink);
  background: var(--editor-surface);
  border-color: var(--editor-edge);
  border-radius: 5px;
}
#template-editor .template-placeholders button:enabled:hover { background: var(--editor-selected); }
#templates-panel .template-document,
#template-editor .template-document-viewport { background: var(--editor-canvas); }
#template-editor .docx-editor {
  --doc-toggle-active-bg: var(--editor-selected);
  --doc-toggle-active-fg: var(--editor-selected-ink);
}
#template-editor .docx-menubar { background: var(--editor-surface); padding-inline: 10px; color: var(--editor-ink); }
#template-editor .docx-toolbar {
  margin: 0;
  padding: 5px 12px;
  border-block: 1px solid var(--editor-edge);
  border-radius: 0;
  background: var(--editor-toolbar);
}
#template-editor .docx-ruler-frame { background: var(--editor-canvas); padding-block: 6px; }
@media (pointer: coarse) {
  #template-editor .template-actions button { min-height: 44px; min-width: 44px; }
}
