.template-center { min-height: 100%; }
.template-scope { width: 100%; min-height: 50px; padding: 9px 11px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--border); border-radius: 10px; text-align: left; background: var(--surface); }
.template-scope > span { display: flex; align-items: center; gap: 8px; }
.template-scope > span:first-child { min-width: 0; }
.template-scope > span:last-child { flex: 0 0 auto; color: var(--primary); font-size: 8px; font-weight: 700; }
.template-scope .icon { width: 15px; color: var(--muted); }
.template-scope > span:first-child > .icon { width: 28px; height: 28px; padding: 6px; border-radius: 7px; color: var(--primary); background: var(--primary-soft); }
.template-scope small, .template-scope strong { display: block; }
.template-scope small { color: var(--muted); font-size: 7px; }
.template-scope strong { margin-top: 3px; overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.template-toolbar { margin: 10px 0; display: flex; gap: 7px; flex-wrap: wrap; }
.template-toolbar > .search-field { width: 100%; }
.template-toolbar-actions { width: 100%; display: flex; justify-content: flex-end; gap: 7px; }
.template-toolbar-actions button, .template-selection-bar button, .template-detail-card footer button { min-height: 32px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; font-size: 8px; }
.template-toolbar-actions .icon, .template-selection-bar .icon, .template-detail-card footer .icon { width: 13px; }
.template-selection-bar { margin-bottom: 10px; padding: 8px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid #bfdbfe; border-radius: 9px; background: var(--primary-soft); }
.template-selection-bar strong { color: var(--primary); font-size: 9px; }
.template-selection-bar > span { display: flex; align-items: center; gap: 5px; }
.template-selection-bar > span > button:first-child { color: var(--muted); }
.template-master-detail { min-height: 0; display: grid; }
.template-list-panel, .template-detail-panel { min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.template-list-panel > header { min-height: 42px; padding: 8px 10px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.template-list-panel > header > span { display: flex; align-items: center; gap: 8px; }
.template-list-panel > header strong { font-size: 10px; }
.template-list-panel > header small { color: var(--muted); font-size: 8px; }
.template-check { width: 20px; height: 20px; flex: 0 0 auto; display: grid; place-items: center; border: 1px solid var(--border-strong); border-radius: 5px; color: white; background: var(--surface); }
.template-check.is-selected { border-color: var(--primary); background: var(--primary); }
.template-check .icon { width: 12px; }
.template-table-head { display: none; }
.template-row { min-height: 78px; padding: 9px 8px; display: grid; grid-template-columns: 20px minmax(0, 1fr) 28px; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); content-visibility: auto; contain-intrinsic-size: 0 78px; }
.template-row:last-child { border-bottom: 0; }
.template-row:hover, .template-row.is-active { background: var(--surface-subtle); }
.template-row-main { min-width: 0; display: grid; gap: 4px; text-align: left; }
.template-row-main > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-row-title { display: flex; align-items: center; gap: 5px; }
.template-row-title strong { overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.template-row-stats { color: var(--text); font-size: 8px; }
.template-row-meta { color: var(--muted); font-size: 7px; }
.template-row-more { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 7px; color: var(--muted); }
.template-row-more:hover { background: var(--surface); }
.template-row-more .icon { width: 15px; }
.template-empty { min-height: 180px; display: grid; place-items: center; align-content: center; gap: 5px; }
.template-empty strong { font-size: 11px; }
.template-empty span { color: var(--muted); font-size: 8px; }
.template-list-footer { min-height: 46px; padding: 7px 9px; display: flex; align-items: center; justify-content: center; border-top: 1px solid var(--border); }
.template-phone-more { min-height: 30px; padding: 0 10px; font-size: 8px; }
.template-phone-more:disabled { color: var(--muted); border-color: transparent; }
.template-pagination { display: none; align-items: center; gap: 7px; color: var(--muted); font-size: 8px; }
.template-pagination label { display: flex; align-items: center; gap: 4px; }
.template-pagination select { height: 27px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font-size: 8px; }
.template-pagination button { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 6px; }
.template-pagination button:disabled { opacity: .35; }
.template-pagination .icon { width: 12px; }
.template-detail-panel { display: none; overflow-y: auto; }
.template-detail-empty { min-height: 280px; display: grid; place-items: center; align-content: center; gap: 9px; color: var(--muted); }
.template-detail-empty .icon { width: 28px; height: 28px; }
.template-detail-empty strong { font-size: 10px; }
.template-detail-card > header { padding: 13px; display: grid; grid-template-columns: minmax(0, 1fr) 30px; gap: 10px; border-bottom: 1px solid var(--border); }
.template-detail-card > header > div { min-width: 0; }
.template-detail-card > header > button:last-child { width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); }
.template-detail-card h2 { margin: 7px 0 0; font-size: 14px; }
.template-detail-card header p { margin: 5px 0 0; color: var(--muted); font-size: 8px; line-height: 1.55; }
.template-detail-back { grid-column: 1 / -1; justify-self: start; display: inline-flex; align-items: center; gap: 5px; color: var(--text); font-size: 8px; }
.template-detail-back .icon { width: 13px; }
.template-summary { margin: 0; padding: 11px 13px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; border-bottom: 1px solid var(--border); }
.template-summary > div { min-width: 0; padding: 8px; border-radius: 7px; background: var(--surface-subtle); }
.template-summary dt { color: var(--muted); font-size: 7px; }
.template-summary dd { margin: 5px 0 0; overflow: hidden; font-size: 9px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.template-tags { padding: 11px 13px; display: grid; gap: 9px; border-bottom: 1px solid var(--border); }
.template-tags > div { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 7px; }
.template-tags strong { padding-top: 4px; font-size: 8px; }
.template-tags span { display: flex; gap: 5px; flex-wrap: wrap; }
.template-tags i { padding: 4px 6px; border-radius: 5px; color: var(--text); background: var(--surface-subtle); font-size: 7px; font-style: normal; }
.template-outline { padding: 12px 13px; }
.template-outline > h3 { margin: 0 0 9px; font-size: 10px; }
.template-outline-chapter { margin-bottom: 7px; padding: 9px; border: 1px solid var(--border); border-radius: 8px; }
.template-outline-chapter > header { display: flex; align-items: center; gap: 7px; }
.template-outline-chapter b { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 6px; color: var(--primary); background: var(--primary-soft); font-size: 7px; }
.template-outline-chapter strong { flex: 1; font-size: 9px; }
.template-outline-chapter header span { color: var(--muted); font-size: 7px; }
.template-outline-chapter > div { margin: 7px 0 0 27px; display: grid; gap: 4px; color: var(--muted); font-size: 7px; }
.template-detail-card > footer { position: sticky; bottom: 0; padding: 9px 12px; display: flex; justify-content: flex-end; gap: 6px; border-top: 1px solid var(--border); background: var(--surface); }
.template-sheet-options, .template-action-list { display: grid; gap: 6px; }
.template-sheet-options > button, .template-action-list > button { width: 100%; min-height: 58px; padding: 9px 10px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 9px; text-align: left; }
.template-sheet-options button > span, .template-action-list button > span { min-width: 0; flex: 1; }
.template-sheet-options strong, .template-sheet-options small, .template-action-list strong, .template-action-list small { display: block; }
.template-sheet-options strong, .template-action-list strong { font-size: 11px; }
.template-sheet-options small, .template-action-list small { margin-top: 4px; color: var(--muted); font-size: 8px; }
.template-sheet-options .icon, .template-action-list .icon { width: 15px; color: var(--muted); }
.template-sheet-options button.is-selected { border-color: #93c5fd; background: var(--primary-soft); }
.template-sheet-options button.is-selected > .icon { color: var(--primary); }
.template-action-list button > .icon:first-child { width: 30px; height: 30px; padding: 7px; border-radius: 7px; color: var(--primary); background: var(--primary-soft); }
.template-action-list button.is-danger strong, .template-action-list button.is-danger > .icon:last-child { color: var(--danger); }
.template-action-list button.is-danger > .icon:first-child { color: var(--danger); background: #fef2f2; }
.template-file-picker { min-height: 110px; padding: 16px; display: flex; align-items: center; justify-content: center; gap: 10px; border: 1px dashed var(--border-strong); border-radius: 10px; text-align: left; cursor: pointer; }
.template-import-guide { margin: 0 0 10px; color: var(--muted); font-size: 9px; line-height: 1.6; }
.template-file-picker > .icon { width: 28px; height: 28px; color: var(--primary); }
.template-file-picker strong, .template-file-picker small { display: block; }
.template-file-picker strong { font-size: 11px; }
.template-file-picker small { margin-top: 4px; color: var(--muted); font-size: 8px; }
.template-file-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.template-import-error { margin: 9px 0 0; color: var(--danger); font-size: 9px; }
.template-import-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 7px; }
.template-import-actions button { min-height: 34px; padding: 0 12px; font-size: 9px; }
.template-import-result { text-align: center; }
.template-result-icon { width: 42px; height: 42px; margin: auto; display: grid; place-items: center; border-radius: 50%; color: var(--success); background: #f0fdf4; }
.template-result-icon .icon { width: 20px; }
.template-import-result h3 { margin: 10px 0 12px; font-size: 15px; }
.template-import-result > div { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.template-import-result > div > span { padding: 10px; border-radius: 8px; background: var(--surface-subtle); }
.template-import-result small, .template-import-result strong { display: block; }
.template-import-result small { color: var(--muted); font-size: 8px; }
.template-import-result strong { margin-top: 5px; font-size: 17px; }
.template-import-result > section { margin-top: 9px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; text-align: left; }
.template-import-result > section strong { font-size: 9px; }
.template-import-result > section p { margin: 5px 0 0; color: var(--muted); font-size: 8px; line-height: 1.5; overflow-wrap: anywhere; }
.template-import-result > button { width: 100%; min-height: 36px; margin-top: 14px; }
.template-delete-confirm { text-align: center; }
.template-delete-confirm > span { width: 42px; height: 42px; margin: auto; display: grid; place-items: center; border-radius: 50%; color: var(--danger); background: #fef2f2; }
.template-delete-confirm > span .icon { width: 20px; }
.template-delete-confirm h3 { margin: 11px 0 6px; font-size: 15px; }
.template-delete-confirm p { margin: 0; color: var(--muted); font-size: 9px; line-height: 1.6; }
.template-delete-confirm > div { margin-top: 15px; display: flex; justify-content: center; gap: 7px; }
.template-copy-form .field { margin: 0; }
.template-copy-form > div { margin-top: 14px; display: flex; justify-content: flex-end; gap: 7px; }
.template-copy-form > div button { min-height: 34px; padding: 0 12px; font-size: 9px; }
.danger-button { min-height: 34px; padding: 0 12px; border-radius: 8px; color: #fff; background: var(--danger); font-size: 9px; font-weight: 700; }

.template-editor { min-height: 100%; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.template-editor > header { min-height: 56px; padding: 10px 12px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.template-editor > header > button { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 8px; }
.template-editor > header .icon { width: 13px; }
.template-editor > header > div { min-width: 0; flex: 1; }
.template-editor > header small { color: var(--muted); font-size: 7px; }
.template-editor > header h2 { margin: 3px 0 0; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.template-editor-steps { margin: 0; padding: 10px 14px; display: grid; grid-template-columns: 1fr 1fr; list-style: none; border-bottom: 1px solid var(--border); }
.template-editor-steps li { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 8px; }
.template-editor-steps li:last-child::before { height: 1px; margin-right: 7px; flex: 1; background: var(--border); content: ""; }
.template-editor-steps b { width: 22px; height: 22px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--surface-subtle); font-size: 8px; }
.template-editor-steps b .icon { width: 12px; }
.template-editor-steps li.is-active { color: var(--primary); font-weight: 700; }
.template-editor-steps li.is-active b { color: white; background: var(--primary); }
.template-editor-body { min-height: 0; padding: 14px; overflow-y: auto; }
.template-editor-basic { max-width: 760px; margin: auto; display: grid; gap: 11px; }
.template-editor-basic .field { margin: 0; }
.template-editor-basic .field textarea, .template-block-fields textarea { width: 100%; padding: 9px 11px; resize: vertical; border: 1px solid var(--border); border-radius: 8px; color: var(--ink); background: var(--surface); font-size: 10px; }
.template-choice-field { margin: 0; padding: 0; border: 0; }
.template-choice-field legend { margin-bottom: 7px; font-size: 10px; font-weight: 700; }
.template-choice-field > div { display: flex; gap: 6px; flex-wrap: wrap; }
.template-choice-field button { min-height: 30px; padding: 0 9px; display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 7px; color: var(--text); font-size: 8px; }
.template-choice-field button.is-selected { color: var(--primary); border-color: #93c5fd; background: var(--primary-soft); }
.template-choice-field .icon { width: 11px; }
.template-structure-editor { max-width: 820px; margin: auto; display: grid; gap: 10px; }
.template-chapter-editor { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.template-chapter-editor > header { min-height: 46px; padding: 7px 9px; display: flex; align-items: center; gap: 7px; background: var(--surface-subtle); }
.template-chapter-editor > header > b { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; color: var(--primary); background: var(--primary-soft); font-size: 8px; }
.template-chapter-editor > header > input { min-width: 0; flex: 1; padding: 5px 7px; border: 1px solid transparent; border-radius: 6px; background: transparent; font-size: 10px; font-weight: 700; }
.template-chapter-editor > header > input:focus { border-color: var(--border-strong); background: var(--surface); outline: 0; }
.template-chapter-editor > header > span { color: var(--muted); font-size: 7px; }
.template-chapter-editor header > div { display: flex; gap: 3px; }
.template-chapter-editor header > div button, .template-block-editor header button { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 6px; color: var(--muted); background: var(--surface); }
.template-chapter-editor header button:disabled, .template-block-editor header button:disabled { opacity: .3; }
.template-chapter-editor header .icon, .template-block-editor header .icon { width: 12px; }
.template-block-list { padding: 9px; display: grid; gap: 8px; }
.template-block-editor { border: 1px solid var(--border); border-radius: 8px; }
.template-block-editor > header { min-height: 38px; padding: 6px 8px; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--border); }
.template-block-editor > header strong { min-width: 0; flex: 1; overflow: hidden; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.template-block-type { padding: 3px 5px; border-radius: 5px; color: var(--primary); background: var(--primary-soft); font-size: 7px; }
.template-block-editor > header > div { display: flex; gap: 3px; }
.template-block-fields { padding: 9px; display: grid; gap: 8px; }
.template-block-fields .field { margin: 0; }
.template-add-block, .template-add-chapter { min-height: 34px; display: flex; align-items: center; justify-content: center; gap: 5px; color: var(--primary); font-size: 8px; font-weight: 700; }
.template-add-block { width: calc(100% - 18px); margin: 0 9px 9px; border: 1px dashed #93c5fd; border-radius: 7px; background: var(--primary-soft); }
.template-add-chapter { border: 1px dashed var(--border-strong); border-radius: 9px; }
.template-add-block .icon, .template-add-chapter .icon { width: 13px; }
.template-editor > footer { padding: 9px 12px; display: flex; justify-content: flex-end; gap: 7px; border-top: 1px solid var(--border); }
.template-editor > footer button { min-width: 76px; min-height: 34px; font-size: 9px; }

@media (min-width: 768px) {
  .device-pad .template-toolbar { flex-wrap: nowrap; align-items: center; }
  .device-pad .template-toolbar > .search-field { width: min(360px, 42%); }
  .device-pad .template-toolbar-actions { width: auto; margin-left: auto; }
  .device-pad .template-master-detail { grid-template-columns: minmax(430px, 1.15fr) minmax(320px, .85fr); gap: 12px; }
  .device-pad .template-detail-panel { display: block; }
  .device-pad .template-table-head { min-height: 32px; padding: 0 45px 0 38px; display: grid; grid-template-columns: minmax(150px, 1fr) 125px 110px 30px; align-items: center; gap: 8px; color: var(--muted); background: var(--surface-subtle); font-size: 7px; }
  .device-pad .template-row { min-height: 64px; contain-intrinsic-size: 0 64px; }
  .device-pad .template-row-main { grid-template-columns: minmax(150px, 1fr) 125px 110px; align-items: center; gap: 8px; }
  .device-pad .template-row-title strong { font-size: 9px; }
  .device-pad .template-list-footer { justify-content: flex-end; }
  .device-pad .template-phone-more { display: none; }
  .device-pad .template-pagination { display: flex; }
  .device-pad .template-editor-basic { grid-template-columns: 1fr 1fr; }
  .device-pad .template-editor-wide { grid-column: 1 / -1; }
  .device-pad .template-block-fields { grid-template-columns: repeat(3, 1fr); }
  .device-pad .template-block-wide { grid-column: 1 / -1; }
}

@media (max-width: 767px) {
  .device-phone .template-master-detail.is-phone-detail .template-list-panel { display: none; }
  .device-phone .template-master-detail.is-phone-detail .template-detail-panel { display: block; }
  .device-phone .template-detail-card > header { grid-template-columns: minmax(0, 1fr) 30px; }
  .device-phone .template-detail-back { display: inline-flex; }
  .device-phone .template-editor-steps li span { max-width: 80px; }
}
