/* Templates tab: library, layers, canvas editor, inspector. */
.workspace.enter { animation: wsIn 0.35s var(--ease); }
@keyframes wsIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes sectionIn { from { opacity: 0; transform: translateY(-4px); } }
.hidden { display: none !important; }

body[data-tab="templates"] .bottom, body[data-tab="templates"] footer { display: none; }
body.admin[data-tab="templates"] { grid-template-rows: 86px minmax(0, 1fr); }

.tpl-workspace { display: grid; grid-template-columns: minmax(230px, 280px) minmax(0, 1fr) minmax(290px, 340px); gap: 14px; min-height: 0; height: 100%; padding: 14px; }
.tpl-workspace > * { min-height: 0; min-width: 0; }
.tpl-left, .tpl-right { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; scrollbar-width: thin; }
.tpl-center { display: flex; flex-direction: column; gap: 10px; }

/* library */
.tpl-list { display: grid; gap: 8px; }
.tpl-card { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 10px; padding: 7px; border: 1px solid var(--line); border-radius: 11px; background: #231810; cursor: pointer; transition: border-color 0.2s, background 0.2s, transform 0.2s var(--ease); }
.tpl-card:hover { background: #2c1f14; transform: translateX(2px); }
.tpl-card.on { border-color: var(--gold); background: #38271a; }
.tpl-card.dirty .tpl-name:after { content: " •"; color: var(--gold); }
.tpl-thumb { position: relative; aspect-ratio: 16/9; border-radius: 6px; overflow: hidden; background: #000; }
.tpl-card-body { min-width: 0; }
.tpl-name { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-meta { font-size: 11px; color: var(--muted); }
.tpl-more { min-height: 28px; width: 28px; padding: 0; background: transparent; border: 0; box-shadow: none; color: var(--muted); }
.tpl-more:hover { background: #644127; color: var(--cream); box-shadow: none; }
.tpl-none { padding: 18px; text-align: center; color: var(--muted); border: 1.5px dashed #6b4d33; border-radius: 11px; }
.tpl-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* layers */
.layers-wrap { display: grid; gap: 6px; align-content: start; flex: 1 0 auto; min-height: 150px; padding-bottom: 24px; }
.layers { display: grid; gap: 3px; }
.layer { display: flex; align-items: center; gap: 6px; min-height: 34px; padding: 3px 5px; border: 1px solid transparent; border-radius: 8px; background: #231810; cursor: pointer; transition: background 0.15s, border-color 0.15s, opacity 0.15s; }
.layer:hover { background: #2c1f14; }
.layer.on { border-color: var(--gold); background: #38271a; }
.layer.off { opacity: 0.45; }
.layer-grip { cursor: grab; touch-action: none; color: var(--muted); width: 16px; text-align: center; }
.layer-ico { width: 20px; text-align: center; }
.layer-name { flex: 1; min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-spin { font-size: 10px; color: var(--gold); }
.layer-btn { min-height: 24px; width: 24px; padding: 0; border: 0; background: transparent; box-shadow: none; color: var(--muted); border-radius: 6px; }
.layer-btn:hover { background: #644127; color: var(--cream); box-shadow: none; }
.layer.lock .layer-btn.lock { color: var(--gold); }
.layer.dragging { background: #3a2818; box-shadow: 0 10px 24px #000a; z-index: 5; }
.add-els { display: flex; gap: 3px; flex-wrap: nowrap; }
.add-els .icon-btn { width: 30px; min-width: 0; padding-inline: 0; }

/* toolbar */
.tpl-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 8px; border: 1px solid var(--line); border-radius: 11px; background: #231810; }
.tb-group { display: flex; align-items: center; gap: 3px; }
.tb-group + .tb-group { padding-left: 8px; border-left: 1px solid var(--line); }
.tb-btn { min-height: 30px; min-width: 30px; padding: 0 9px; border: 0; background: transparent; box-shadow: none; color: var(--cream); border-radius: 7px; transition: background 0.15s; }
.tb-btn:hover:not(:disabled) { background: #644127; box-shadow: none; }
.tb-btn.on { background: #efb64f33; color: var(--gold); }
.tb-btn:disabled { opacity: 0.35; }
.tb-g { font-size: 15px; }
.tb-l { font-size: 12px; }
.tb-zoom { min-width: 48px; text-align: center; font-size: 12px; color: var(--muted); }
.tb-status { margin-left: auto; font-size: 11px; color: var(--muted); }
.tb-status.dirty { color: var(--gold); }
.tb-status.clean { color: #7ccf8f; }
.tb-preview { font-size: 12px; max-width: 160px; }

/* stage */
.tpl-stage-wrap { position: relative; flex: 1; min-height: 240px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 13px; background: repeating-conic-gradient(#1c130c 0 25%, #20160e 0 50%) 0 0 / 22px 22px; overflow: hidden; transition: box-shadow 0.2s, border-color 0.2s; }
.tpl-stage-wrap.drop { border-color: var(--gold); box-shadow: inset 0 0 0 3px #efb64f55; }
.tpl-stage { position: relative; width: 100%; height: 100%; display: grid; place-items: center; overflow: auto; }
.tpl-sizer { position: relative; flex: none; box-shadow: 0 18px 50px #000b; }
.tpl-view { position: absolute; inset: 0; background: #000; }
.tw-layer { position: absolute; inset: 0; pointer-events: auto; touch-action: none; cursor: default; }
.tw-safe { position: absolute; inset: 5%; border: 1px dashed #ffffff66; pointer-events: none; }
.tpl-drophint { position: absolute; inset: 0; display: grid; place-items: center; background: #000a; color: var(--gold); font-weight: 700; font-size: 18px; pointer-events: none; opacity: 0; transition: opacity 0.2s; }
.drop .tpl-drophint { opacity: 1; }
.tpl-empty { display: grid; place-items: center; gap: 8px; color: var(--muted); text-align: center; padding: 30px; }
.tpl-help { font-size: 11px; color: var(--muted); line-height: 1.5; }

/* transform widget */
.tw { position: absolute; pointer-events: none; touch-action: none; }
.tw[hidden] { display: none; }
.tw-outline { position: absolute; inset: 0; box-sizing: border-box; border: 1.5px solid var(--gold); box-shadow: 0 0 0 1px #0008; pointer-events: none; }
.tw.locked .tw-outline { border-style: dashed; border-color: #ffffff88; }
.tw-badge { position: absolute; padding: 2px 7px; border-radius: 6px; background: #000c; color: var(--cream); font: 600 11px/1.4 system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
.tw-h { position: absolute; pointer-events: auto; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; background: #fff; border: 1.5px solid var(--gold); border-radius: 2px; box-shadow: 0 1px 4px #0008; transition: transform 0.12s var(--ease), background 0.12s; touch-action: none; }
.tw-h:hover, .tw-h.active { background: var(--gold); transform: scale(1.3); }
.tw.tiny .tw-edge { display: none; }
.tw-edge { width: 9px; height: 9px; border-radius: 50%; }
.tw-rot { position: absolute; pointer-events: none; }
.tw-rot-stem { position: absolute; width: 1.5px; background: var(--gold); transform: translateX(-50%); }
.tw-rot-dot { position: absolute; pointer-events: auto; width: 15px; height: 15px; margin: -7.5px 0 0 -7.5px; border-radius: 50%; background: #fff; border: 2px solid var(--gold); cursor: grab; box-shadow: 0 1px 5px #0009; transition: transform 0.12s var(--ease); touch-action: none; }
.tw-rot-dot:hover, .tw-rot-dot.active { transform: scale(1.25); background: var(--gold); cursor: grabbing; }
.tw-guide { position: absolute; background: #ff4fd8; pointer-events: none; }
.tw-guide-x { top: 0; bottom: 0; width: 1px; }
.tw-guide-y { left: 0; right: 0; height: 1px; }

/* inspector */
.insp-host { display: grid; gap: 8px; }
.insp.enter { animation: sectionIn 0.25s var(--ease); }
.tpl-panel { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: #231810; }
.field-list, .used-list { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.inline-pick { display: flex; gap: 6px; align-items: center; }
.inline-pick input { flex: 1; min-width: 0; }

@media (max-width: 1100px) {
  .tpl-workspace { grid-template-columns: 230px minmax(0, 1fr); }
  .tpl-right { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  body[data-tab="templates"] .admin { grid-template-rows: auto 1fr 0; }
  .tpl-workspace { grid-template-columns: 1fr; height: auto; }
  .tpl-stage-wrap { min-height: 220px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }

.layer-ico { display: grid; place-items: center; height: 22px; }
.layer-ico img { width: 22px; height: 22px; object-fit: contain; border-radius: 3px; background: #0006; }
body.admin[data-tab="templates"] { grid-template-rows: 86px minmax(0, 1fr); }
.tpl-toolbar .tb-save { margin-left: auto; }

.tw-h[data-h="nw"] { left: 0; top: 0; } .tw-h[data-h="n"] { left: 50%; top: 0; } .tw-h[data-h="ne"] { left: 100%; top: 0; }
.tw-h[data-h="e"] { left: 100%; top: 50%; } .tw-h[data-h="se"] { left: 100%; top: 100%; } .tw-h[data-h="s"] { left: 50%; top: 100%; }
.tw-h[data-h="sw"] { left: 0; top: 100%; } .tw-h[data-h="w"] { left: 0; top: 50%; }
.tw-rot { left: 50%; top: -34px; width: 0; height: 0; }
.tw-rot-stem { left: 0; top: 0; height: 34px; }
.tw-rot-dot { left: 0; top: 0; }
.tw-badge { left: 50%; top: 100%; transform: translate(-50%, 12px); }
.tw-guide[hidden] { display: none; }

/* text inspector extras */
.f-hint.warn { color: var(--gold); }
textarea.flash { animation: taFlash 0.7s var(--ease); }
@keyframes taFlash { 0% { box-shadow: 0 0 0 0 #efb64f99; } 60% { box-shadow: 0 0 0 6px #efb64f22; } 100% { box-shadow: 0 0 0 0 #efb64f00; } }
.an-panel { padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #1d140d; animation: sectionIn 0.25s var(--ease); }
.an-case { display: grid; gap: 5px; padding: 8px 0; border-top: 1px dashed #4d3825; }
.an-case:first-of-type { border-top: 0; }
.an-case-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 12px; }
.an-case-h small { color: var(--muted); }
.an-case-c { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; align-items: center; font-size: 11px; color: var(--muted); }
.an-case-c span:last-child { grid-column: 1 / -1; margin-top: -2px; }

/* Auto name alignment: collapsible header, toggle pinned to the right */
.an-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 2px; }
.an-toggle-btn { flex: 1; display: flex; align-items: center; gap: 8px; padding: 6px 2px; border: 0; background: none; color: var(--cream); font: inherit; font-size: 13px; font-weight: 700; letter-spacing: 0.3px; text-align: left; cursor: pointer; }
.an-toggle-btn:hover { color: var(--gold); }
.an-toggle-btn .f-caret { transition: transform 0.18s var(--ease); }
.an-toggle-btn[aria-expanded="true"] .f-caret { transform: rotate(90deg); }
.an-head .f-toggle { flex: none; margin-left: auto; }
.an-wrap.collapsed { display: none; }
.f-num.scrubbing, .f-num.scrubbing * { cursor: ew-resize !important; }
.f-unit .f-num { cursor: ew-resize; }
.f-unit .f-num:focus { cursor: text; }
body.scrubbing, body.scrubbing * { cursor: ew-resize !important; user-select: none !important; }

/* Copy Transform Properties eyedropper */
body.eyedrop, body.eyedrop * { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'><path d='M20.7 5.3a2.4 2.4 0 0 0-3.4 0l-2.4 2.4-1-1-1.4 1.4 .9.9-7.2 7.2a2 2 0 0 0-.6 1.4V19l-.8.8 1.4 1.4.8-.8h1.7c.5 0 1-.2 1.4-.6l7.2-7.2.9.9 1.4-1.4-1-1 2.4-2.4a2.4 2.4 0 0 0 0-3.4z' fill='%23efb64f' stroke='%232a1608' stroke-width='1.2'/></svg>") 3 25, crosshair !important; }

/* Emitter variable controls */
.f-var { display: grid; gap: 6px; padding: 8px 0; border-top: 1px dashed #4d3825; }
.f-section-body > .f-var:first-child { border-top: 0; }
.f-var-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.f-var-head .f-label { font-weight: 700; font-size: 12px; color: var(--cream); }
.f-var-head .f-toggle { margin-left: auto; font-size: 11px; color: var(--muted); }
.f-var .f-slider[hidden], .f-var .f-row[hidden] { display: none; }
