.clinic-settings-tabs { flex-wrap: wrap; }
#settings-panel-templates,#templateCentral,.template-central-panel { min-width: 0; }
.template-central-panel .panel-head { flex-wrap: wrap; gap: 12px; }
.template-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 18px 0; }
.template-editing-fields { border: 0; padding: 0; margin: 0; min-width: 0; }
.template-card { border: 1px solid #dfe9e5; border-radius: 10px; padding: 16px; margin: 16px 0; min-width: 0; }
.template-toolbar,.template-preview-controls,.template-document-heading,.template-rule-fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0; }
.template-document-heading > label,.template-rule-fields > label { flex: 1 1 240px; min-width: 0; }
.template-document-heading input:not([type=checkbox]),.template-document-heading select,.template-rule-fields select { width: 100%; }
.template-toolbar button,.template-variables button { font-size: 11px; }
.template-editor { border: 1px solid #cdded7; border-radius: 8px; overflow: hidden; background: #fff; margin: 12px 0; }
.template-toolbar { padding: 8px 10px; margin: 0; background: #f3f8f6; border-bottom: 1px solid #dfe9e5; gap: 10px; align-items: stretch; }
.template-ribbon-group { display: flex; flex-direction: column; justify-content: flex-start; gap: 4px; padding-right: 10px; border-right: 1px solid #cdded7; min-width: 0; }
.template-ribbon-group:last-child { padding-right: 0; border-right: 0; }
.template-ribbon-row { display: flex; gap: 4px; align-items: center; min-height: 30px; }
.template-toolbar select { height: 30px; min-height: 30px; padding: 3px 5px; border: 1px solid #cdded7; border-radius: 4px; background: white; font: 14px Calibri,Arial,sans-serif; }
.template-toolbar .template-font-control { width: 148px; }
.template-toolbar .template-size-control { width: 54px; }
.template-toolbar .template-case-control { width: 55px; }
.template-toolbar .template-spacing-control { width: 70px; }
.template-toolbar .template-icon-button { display: inline-flex; flex: 0 0 32px; align-items: center; justify-content: center; width: 32px; height: 30px; padding: 4px; font: 16px Georgia,serif; }
.template-icon-button sub,.template-icon-button sup { font-size: 10px; position: relative; }
.template-icon-button sub { top: 4px; }
.template-icon-button sup { top: -4px; }
.template-font-color-icon { font: bold 17px Georgia,serif; border-bottom: 3px solid #c00000; line-height: 19px; }
.template-style-group select { min-width: 105px; height: 64px; text-align: center; }
.template-icon-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.template-icon-button[aria-pressed="true"] { background: #d7eee5; border-color: #4c9a8b; color: #155e4e; }
.template-variables { padding: 10px; border-bottom: 1px solid #dfe9e5; background: #f3f8f6; }
.template-variables p { margin: 6px 0 0; font-size: 11px; }
.template-category-row { display: flex; align-items: center; flex-wrap: nowrap; gap: 6px; overflow-x: auto; padding: 2px 0 5px; }
.template-category-row .button { flex: 0 0 auto; min-height: 34px; padding: 6px 8px; border-radius: 5px; font: 14px Calibri,Arial,sans-serif; white-space: nowrap; }
.template-category-row .button[aria-expanded="true"],.template-category-row .button[aria-pressed="true"] { background: #d7eee5; border-color: #4c9a8b; color: #155e4e; }
.template-field-menu { position: fixed; inset: auto; margin: 0; padding: 4px 0; box-sizing: border-box; max-width: calc(100vw - 16px); overflow-y: auto; border: 1px solid #b7c8c2; border-radius: 0 5px 5px 5px; background: #fff; color: #202124; box-shadow: 0 5px 16px #102f3833; }
.template-field-menu:popover-open { display: flex; flex-direction: column; }
.template-field-menu button { flex-shrink: 0; width: 100%; min-height: 34px; padding: 7px 14px; border: 0; border-radius: 0; text-align: left; font: 14px/1.35 Calibri,Arial,sans-serif; color: inherit; background: #fff; white-space: normal; overflow-wrap: anywhere; }
.template-field-menu button:hover,.template-field-menu button:focus-visible { background: #d7eee5; outline: 2px solid #4c9a8b; outline-offset: -2px; }
.template-color-menu section,.template-color-menu details { padding: 8px 12px; border-top: 1px solid #e3e7e5; }
.template-color-menu h4 { margin: 0 0 8px; font-size: 13px; }
.template-color-grid { display: grid; grid-template-columns: repeat(10,minmax(0,1fr)); gap: 4px; }
.template-color-menu .template-color-grid button { min-height: 24px; height: 24px; padding: 1px; border: 1px solid #e2e5e3; }
.template-color-grid span { display: block; width: 100%; height: 100%; }
.template-color-menu summary { cursor: pointer; font-size: 14px; }
.template-color-menu label { display: block; margin-top: 10px; font-size: 13px; }
.template-color-menu input { display: block; width: 100%; margin: 5px 0; padding: 7px; font: 14px monospace; }
.template-condition-menu { padding: 12px; gap: 8px; }
.template-condition-menu h4,.template-condition-menu p { margin: 0; }
.template-condition-menu p { font-size: 12px; line-height: 1.4; }
.template-condition-menu label { display: grid; gap: 4px; min-width: 0; font-size: 13px; }
.template-condition-menu input:not([type=checkbox]),.template-condition-menu select,.template-condition-menu textarea { width: 100%; min-width: 0; padding: 6px; font-size: 13px; box-sizing: border-box; }
.template-condition-menu textarea,.template-condition-menu output { font-family: monospace; overflow-wrap: anywhere; }
.template-condition-controls { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.template-condition-controls > label:first-child,.template-condition-controls > .template-condition-not { grid-column: 1 / -1; }
.template-condition-controls .template-condition-not { display: flex; align-items: center; }
.template-condition-menu [hidden] { display: none !important; }
[data-template-condition-error] { color: #a53131; }
.template-rich-text { min-height: 360px; max-height: 70vh; overflow: auto; padding: 30px; color: #202124; font: 12pt/1.65 Calibri,Arial,sans-serif; overflow-wrap: anywhere; }
.template-rich-text font[size="1"] { font-size: 8pt; }
.template-rich-text font[size="2"] { font-size: 10pt; }
.template-rich-text font[size="3"] { font-size: 12pt; }
.template-rich-text font[size="4"] { font-size: 14pt; }
.template-rich-text font[size="5"] { font-size: 18pt; }
.template-rich-text font[size="6"] { font-size: 24pt; }
.template-rich-text font[size="7"] { font-size: 36pt; }
.template-rich-text:focus { outline: 2px solid #4c9a8b; outline-offset: -2px; }
.template-rich-text h1 { font-size: 22pt; }
.template-rich-text h2 { font-size: 16pt; }
.template-rich-text h3 { font-size: 14pt; }
.template-rich-text table { border-collapse: collapse; width: 100%; }
.template-rich-text td,.template-rich-text th { border: 1px solid #cdded7; padding: 6px; }
.template-rich-text ul,.template-rich-text ol { padding-left: 26px; }
[data-template-error] { color: #a53131; white-space: pre-wrap; }
.modal.template-preview-modal { display: flex; flex-direction: column; width: min(1200px,calc(100vw - 32px)); height: 94vh; max-height: 94vh; overflow: hidden; }
.template-preview-modal #modalForm { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.template-preview-modal #modalForm > .form-grid { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; gap: 0; }
.template-preview-notice { margin: 0 0 12px; padding: 10px 14px; border-radius: 6px; color: #78521d; background: #fff5e5; font-size: 13px; }
.template-preview { display: block; width: 100%; flex: 1; min-height: 0; border: 1px solid #cdded7; border-radius: 6px; background: #fff; }
.template-preview-modal .modal-head h2 { font-size: 20px; }
.template-preview-modal .modal-head p { font-size: 13px; }
@media (max-width: 650px) {
  .template-central-panel { padding: 12px; }
  .template-rich-text { padding: 12px; font-size: 14px; }
  .template-card { padding: 10px; }
  .template-toolbar .template-icon-button { height: 34px; }
  .template-preview-controls > label { width: 100%; }
  .modal.template-preview-modal { padding: 14px; }
}
.template-image-controls {display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:10px;background:#eef4f2;border:1px solid #cbd8d1}
.template-image-controls[hidden],.template-image-frame[hidden] {display:none}
.template-image-controls>span {flex-basis:100%;font-size:12px}
.template-image-controls label {display:flex;align-items:center;gap:4px;font-size:12px}
.template-image-controls input {width:76px}
.template-image-frame {position:fixed;z-index:1300;border:2px solid #2780cc;cursor:move;touch-action:none}
.template-image-handle {position:absolute;width:12px;height:12px;padding:0;background:#fff;border:1px solid #2780cc;touch-action:none}
.template-image-handle.nw {left:-6px;top:-6px;cursor:nwse-resize}
.template-image-handle.ne {right:-6px;top:-6px;cursor:nesw-resize}
.template-image-handle.sw {left:-6px;bottom:-6px;cursor:nesw-resize}
.template-image-handle.se {right:-6px;bottom:-6px;cursor:nwse-resize}
.template-rich-text img {user-select:none}
.template-editor:is([data-editor-id="header"],[data-editor-id="footer"]) .template-rich-text {min-height:140px}
