/* PDF Template Editor — styles.
 * Scoped with .tpl- prefix so it cannot leak into other sections.
 * Palette variables come from the main styles.css (var(--bg), etc.)
 */

/* Секция заполняет доступную высоту в #content (см. styles.css :has), без лишней прокрутки страницы */
#content:has(#sec-templates.section.active) #sec-templates.section.active {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  display: flex;
  flex-direction: column;
}

#sec-templates.section.active {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Fallback, если :has недоступен */
#sec-templates {
  min-height: min(70vh, calc(100vh - 140px));
}

.tpl-root {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  gap: 12px;
}

/* Полноэкранный режим: z-index < .modal-overlay (100), чтобы модалки оставались поверх */
body.tpl-editor-fullscreen {
  overflow: hidden !important;
}

body.tpl-editor-fullscreen #sec-templates {
  position: fixed;
  inset: 0;
  z-index: 90;
  width: 100vw;
  height: 100vh !important;
  max-height: 100vh;
  margin: 0;
  padding: 10px 14px 14px;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

body.tpl-editor-fullscreen #sec-templates .tpl-root {
  flex: 1;
  min-height: 0;
}

body.tpl-editor-fullscreen #sec-templates .tpl-split {
  flex: 1;
  min-height: 0;
}

body.tpl-editor-fullscreen #sec-templates .tpl-list-pane {
  min-height: 0;
}

body.tpl-editor-fullscreen #sec-templates .tpl-editor-pane {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.tpl-editor-fullscreen #sec-templates .tpl-editor-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

body.tpl-editor-fullscreen #sec-templates .tpl-editor-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

body.tpl-editor-fullscreen #sec-templates .tpl-editor-canvas-col {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.tpl-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.tpl-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.tpl-toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tpl-filter,
.tpl-search {
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  min-width: 180px;
}

.tpl-search:focus,
.tpl-filter:focus {
  border-color: var(--accent);
}

.tpl-split {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
}

body.tpl-list-collapsed .tpl-split {
  grid-template-columns: minmax(0, 1fr);
}

body.tpl-list-collapsed .tpl-list-pane {
  display: none;
}

.tpl-list-pane {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tpl-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tpl-list .empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text2);
  font-size: 13px;
}

.tpl-list-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  font: inherit;
}

.tpl-list-item:hover {
  border-color: var(--accent);
}

.tpl-list-item.is-selected {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.15);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.tpl-list-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tpl-list-name {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.2;
  word-break: break-word;
}

.tpl-list-item-mid {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--text2);
  font-size: 12px;
  flex-wrap: wrap;
}

.tpl-list-item-bot {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--text2);
  font-size: 11px;
  flex-wrap: wrap;
}

.tpl-assigned-chip {
  background: rgba(52, 211, 153, 0.15);
  border-color: rgba(52, 211, 153, 0.5);
  color: #34d399;
}

.tpl-inactive-chip {
  background: rgba(156, 163, 180, 0.15);
  border-color: rgba(156, 163, 180, 0.4);
  color: var(--text2);
}

.tpl-editor-pane {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

/* "Назначен" toggle turns greenish when the current template is the
 * live assignment for its document type. Stays neutral otherwise. */
#tpl-assign-btn.is-active {
  background: rgba(52, 211, 153, 0.18);
  border-color: rgba(52, 211, 153, 0.55);
  color: #6ee7b7;
}

/* ─── Preview slide-over (STEP 13) ─── */
.tpl-preview-slideover {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 85%);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.28);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 220ms ease, visibility 0s linear 220ms;
}

.tpl-preview-slideover.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 220ms ease, visibility 0s linear 0s;
}

.tpl-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.tpl-preview-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  min-width: 0;
}

.tpl-preview-status {
  font-size: 11.5px;
  color: var(--text2);
}
.tpl-preview-status[data-kind="ok"] { color: #6ee7b7; }
.tpl-preview-status[data-kind="error"] { color: #fca5a5; }

.tpl-preview-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
}

.tpl-preview-body {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  background: var(--bg);
}

.tpl-preview-iframe {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

.tpl-preview-shimmer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(96, 165, 250, 0.15);
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}

.tpl-preview-shimmer-bar {
  width: 40%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(96, 165, 250, 0.7) 50%,
    transparent 100%
  );
  animation: tpl-shimmer 1100ms linear infinite;
}

@keyframes tpl-shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.tpl-preview-error {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  padding: 8px 10px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  color: #fca5a5;
  font-size: 12px;
  line-height: 1.4;
  z-index: 3;
}

/* ─── QZ debug expander (STEP 13) ─── */
.tpl-qz-debug {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}

.tpl-qz-debug-summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text2);
  letter-spacing: 0.2px;
  user-select: none;
}

.tpl-qz-debug[open] .tpl-qz-debug-summary {
  color: var(--text);
}

.tpl-qz-debug .tpl-qz-preview {
  margin-top: 8px;
}

.tpl-editor-empty[hidden] {
  display: none !important;
}

.tpl-editor-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  color: var(--text2);
  text-align: center;
  padding: 32px 20px;
}

.tpl-editor-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.75;
}

.tpl-editor-empty h4 {
  margin: 0 0 8px;
  color: var(--text);
}

.tpl-editor-empty p {
  font-size: 13px;
  max-width: 380px;
  line-height: 1.5;
}

.tpl-editor-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* Без !important `display: flex` выше перекрывает HTML-атрибут hidden,
 * и после удаления/закрытия шаблона тело редактора остаётся видимым
 * со старыми данными поверх плейсхолдера `.tpl-editor-empty`. */
.tpl-editor-body[hidden] {
  display: none !important;
}

.tpl-editor-main {
  display: flex;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.tpl-editor-canvas-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.tpl-inspector {
  width: 320px;
  flex: 0 0 320px;
  min-height: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12.5px;
}

.tpl-inspector h4 {
  margin: 4px 0 6px;
  font-size: 13px;
  color: var(--text);
  letter-spacing: 0.2px;
}

.tpl-inspector .tpl-inspector-hint {
  color: var(--text2);
  font-size: 11.5px;
  line-height: 1.4;
}

.tpl-inspector-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.tpl-inspector-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 2px;
}

.tpl-inspector-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  align-items: center;
}

.tpl-inspector-row.tpl-row-col { grid-template-columns: 1fr; gap: 4px; }
.tpl-inspector-row.tpl-row-pair { grid-template-columns: 1fr 1fr; gap: 8px; }
.tpl-inspector-row label { color: var(--text2); font-size: 12px; line-height: 1.2; }

.tpl-inspector input[type="text"],
.tpl-inspector input[type="number"],
.tpl-inspector select,
.tpl-inspector textarea {
  width: 100%;
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12.5px;
  outline: none;
  font-family: inherit;
}

.tpl-inspector textarea {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  resize: vertical;
  min-height: 56px;
}

.tpl-inspector input[type="color"] {
  width: 100%;
  height: 28px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.tpl-inspector input:focus,
.tpl-inspector select:focus,
.tpl-inspector textarea:focus {
  border-color: var(--accent);
}

.tpl-inspector .tpl-form-hint {
  font-size: 11px;
  color: var(--text2);
  line-height: 1.4;
}

.tpl-inspector .tpl-form-warn {
  color: #fbbf24;
}

.tpl-inspector .tpl-form-error {
  color: #fca5a5;
  font-size: 11px;
  line-height: 1.4;
}

.tpl-segmented {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}

.tpl-segmented button {
  flex: 1 1 auto;
  background: transparent;
  color: var(--text2);
  border: 0;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background .1s, color .1s;
}

.tpl-segmented button.is-active {
  background: var(--accent);
  color: #fff;
}

.tpl-inline-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.tpl-margins-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto auto;
  gap: 6px;
  align-items: center;
  justify-items: stretch;
}

.tpl-margins-grid .tpl-margin-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tpl-margins-grid .tpl-margin-cell label {
  font-size: 10px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tpl-margin-lock-cell {
  display: flex;
  justify-content: center;
  align-items: center;
}

.tpl-margin-lock {
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  cursor: pointer;
  color: var(--text2);
}

.tpl-margin-lock.is-active {
  color: var(--accent);
  border-color: var(--accent);
}

.tpl-qz-preview {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text2);
  white-space: pre-wrap;
  word-break: break-all;
}

.tpl-zbtns {
  display: flex;
  gap: 4px;
}

.tpl-zbtns button {
  flex: 1 1 auto;
  padding: 4px 6px;
  font-size: 11.5px;
}

/* Column editor (tables) */
.tpl-cols {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  padding: 4px;
}

.tpl-col-row {
  display: grid;
  grid-template-columns: 18px 1fr 1fr 54px 42px 78px 20px;
  gap: 3px;
  align-items: center;
  padding: 3px 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.tpl-col-row.is-dragging {
  opacity: 0.6;
  border-style: dashed;
}

.tpl-col-row.is-over {
  border-color: var(--accent);
}

.tpl-col-handle {
  cursor: grab;
  color: var(--text2);
  text-align: center;
  user-select: none;
  font-size: 12px;
}

.tpl-col-row input,
.tpl-col-row select {
  padding: 3px 5px !important;
  font-size: 11.5px !important;
}

.tpl-col-remove {
  background: transparent;
  color: #fca5a5;
  border: 0;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.tpl-col-sum {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text2);
  padding: 2px 4px;
}

.tpl-col-sum.is-over {
  color: #fca5a5;
}

.tpl-dirty-dot {
  color: #fbbf24;
  font-size: 14px;
  margin-left: 6px;
  vertical-align: middle;
}

.tpl-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.tpl-editor-title {
  min-width: 0;
  flex: 1 1 auto;
}

.tpl-editor-title h3 {
  margin: 0 0 8px;
}

.tpl-editor-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tpl-editor-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.tpl-editor-placeholder {
  background: var(--bg3);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text2);
  font-size: 13px;
  line-height: 1.5;
  flex: 0 0 auto;
}

.tpl-editor-placeholder summary {
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: var(--text);
}

.tpl-editor-placeholder-sub {
  font-size: 12px;
  margin-top: 4px;
}

.tpl-canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex: 0 0 auto;
}

.tpl-canvas-tools,
.tpl-canvas-historyzoom {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.tpl-canvas-spacer { flex: 1 1 auto; min-width: 8px; }

.tpl-canvas-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  display: inline-block;
}

.tpl-btn-label { display: none; }
@media (min-width: 1200px) { .tpl-btn-label { display: inline; margin-left: 3px; } }

.tpl-palette {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  font-size: 12px;
  color: var(--text);
  flex: 0 0 auto;
  min-height: 0;
}

.tpl-palette[hidden] { display: none !important; }

.tpl-palette-details {
  padding: 0;
}

.tpl-palette-details > .tpl-palette-summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
}

.tpl-palette-details[open] > .tpl-palette-summary {
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
}

.tpl-palette-details > .tpl-palette-summary::marker,
.tpl-palette-details > .tpl-palette-summary::-webkit-details-marker {
  display: none;
}

.tpl-palette-title {
  font-weight: 600;
  color: var(--text);
  font-size: 12.5px;
}

.tpl-palette-sp-toggle {
  font-size: 11px !important;
  padding: 3px 8px !important;
}

.tpl-palette-sp-toggle.is-active {
  background: rgba(79, 140, 255, 0.2);
  border-color: var(--accent);
  color: var(--accent);
}

.tpl-palette-groups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px 12px;
  max-height: 180px;
  overflow-y: auto;
}

@media (max-width: 1100px) {
  .tpl-palette-groups { grid-template-columns: 1fr; max-height: 220px; }
}

.tpl-palette-group-title {
  font-size: 10.5px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text2);
  margin-bottom: 4px;
}

.tpl-palette-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tpl-palette-item {
  display: grid;
  grid-template-columns: minmax(120px, 34%) minmax(80px, 1fr) minmax(60px, auto);
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: grab;
  transition: border-color .15s, background .15s;
}

.tpl-palette-item:hover {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.08);
}

.tpl-palette-item:active {
  cursor: grabbing;
}

.tpl-palette-item.is-dragging {
  opacity: 0.6;
  border-style: dashed;
}

.tpl-palette-item.is-optional .tpl-palette-code {
  opacity: 0.75;
}

.tpl-palette-item-array .tpl-palette-code {
  color: #fbbf24;
}

.tpl-palette-code {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  color: #93c5fd;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-palette-label {
  font-size: 11.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-palette-sample {
  font-size: 10.5px;
  color: var(--text2);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-palette-hint {
  padding: 6px 12px 10px;
  font-size: 11px;
  color: var(--text2);
  line-height: 1.4;
}

.tpl-canvas-surface {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #0f172a;
}

.tpl-canvas-stage.tpl-drop-target,
.tpl-canvas-surface:has(.tpl-canvas-stage.tpl-drop-target) {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

.tpl-canvas-stage {
  width: 100%;
  height: 100%;
  min-height: 0;
  outline: none;
}

.tpl-canvas-stage:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.tpl-canvas-rotation-hint {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 2;
  background: rgba(79, 140, 255, 0.2);
  color: #cbd5e1;
  border: 1px solid rgba(79, 140, 255, 0.4);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  pointer-events: none;
}

.tpl-canvas-statusbar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text2);
  font-size: 12px;
  font-family: 'Consolas', 'Monaco', monospace;
  flex: 0 0 auto;
}


.tpl-schema-preview {
  margin-top: 12px;
  max-height: 260px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  color: var(--text);
  white-space: pre;
}

.tpl-modal-error {
  margin-top: 10px;
  padding: 8px 10px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  color: #fca5a5;
  font-size: 12px;
  line-height: 1.4;
}

.tpl-inspector-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.tpl-inspector-tab {
  flex: 1 1 0;
  padding: 5px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 0.2px;
}

.tpl-inspector-tab.is-active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
}

.tpl-inspector-tab:hover:not(.is-active) {
  color: var(--text);
}

.tpl-inspector-tab-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.tpl-history-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tpl-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 4px;
}

.tpl-history-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
}

.tpl-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 520px;
  overflow-y: auto;
}

.tpl-history-row {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tpl-history-row.is-current {
  border-color: rgba(52, 211, 153, 0.6);
  background: rgba(52, 211, 153, 0.08);
}

.tpl-history-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tpl-history-version {
  font-family: 'Consolas', 'Monaco', monospace;
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
}

.tpl-history-when {
  color: var(--text2);
  font-size: 11.5px;
}

.tpl-history-current {
  background: rgba(52, 211, 153, 0.2);
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.4);
}

.tpl-history-row-mid {
  font-size: 11.5px;
  color: var(--text2);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.tpl-history-notes {
  color: var(--text);
}

.tpl-history-author {
  margin-left: 6px;
  opacity: 0.8;
}

.tpl-history-row-bot {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 1200px) {
  .tpl-editor-main { flex-direction: column; }
  .tpl-inspector { width: 100%; flex: 0 0 auto; max-height: 420px; }
}

@media (max-width: 960px) {
  .tpl-split { grid-template-columns: 1fr; }
  .tpl-list-pane { max-height: 260px; }
}
