/* Template gallery (คลังแม่แบบ) */
.tpl-workspace { display: none; overflow: auto; grid-column: 2/-1; min-width: 0; background: #f5f6f8; }
.shell.tpl-open > .settings, .shell.tpl-open > .workarea, .shell.tpl-open > .ai-workspace { display: none !important; }
.shell.tpl-open > .tpl-workspace.show { display: block; }
.tpl-inner { max-width: 1340px; margin: auto; padding: 30px 40px 70px; }

.tpl-hero { display: grid; grid-template-columns: minmax(0, 1.02fr) minmax(0, 1fr); gap: 40px; align-items: start; padding-bottom: 28px; border-bottom: 1px solid #e3e7ed; }
.tpl-eyebrow { display: inline-block; font: 600 11px system-ui; letter-spacing: 1.6px; color: #5d7a2a; background: #eef5dc; border: 1px solid #d9e8b5; padding: 5px 10px; border-radius: 20px; }
.tpl-hero h1 { font-size: 46px; line-height: 1.22; letter-spacing: -1px; margin: 16px 0 14px; color: #171e2b; }
.tpl-hero h1 span { color: #5d7a2a; }
.tpl-hero p { color: #66748a; font-size: 16px; line-height: 1.75; margin: 0 0 22px; max-width: 600px; }
.tpl-search { display: flex; align-items: center; gap: 8px; background: #fff; border: 2px solid #273449; border-radius: 16px; padding: 7px 7px 7px 10px; box-shadow: 0 8px 24px #1b2a4012; }
.tpl-search-ico { width: 38px; height: 38px; display: grid; place-items: center; background: #f0f3f7; border-radius: 10px; color: #273449; flex-shrink: 0; }
.tpl-search-ico svg { width: 19px; height: 19px; }
.tpl-search input { flex: 1; border: 0; outline: none; font: inherit; font-size: 16px; min-width: 0; color: #202939; background: transparent; }
.tpl-search kbd { font: 11px system-ui; color: #8c97a6; border: 1px solid #dfe4ea; border-radius: 5px; padding: 2px 6px; }
.tpl-search button { background: #d1f36b; border-color: #d1f36b; color: #19221a; font-weight: 700; min-height: 42px; padding: 0 22px; border-radius: 11px; font-size: 15px; }
.tpl-popular { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 14px 0; font-size: 13px; color: #7c899b; }
.tpl-popular button { min-height: 32px; border-radius: 20px; padding: 4px 13px; font-size: 13px; color: #3c4a5e; }
.tpl-ai-link { border-radius: 22px; border: 1px solid #c8de8a; background: #f8fbef; color: #3f5520; font-size: 14px; padding: 9px 16px; }
.tpl-ai-link svg { width: 16px; height: 16px; }
.tpl-ai-link b { margin-left: 4px; }
.tpl-stats { display: flex; gap: 46px; margin: 28px 0 0; padding-top: 22px; border-top: 1px solid #e6eaf0; }
.tpl-stats div { display: flex; flex-direction: column-reverse; }
.tpl-stats dd { margin: 0; font: 800 32px/1.1 system-ui; color: #171e2b; letter-spacing: -1px; }
.tpl-stats dt { font-size: 13px; color: #7c899b; }

.tpl-carousel { min-width: 0; }
.tpl-slide { position: relative; border-radius: 22px; overflow: hidden; background: #eef0f3; aspect-ratio: 90 / 62; box-shadow: 0 18px 50px #1b2a401a; border: 1px solid #e2e6ec; }
.tpl-slide-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tpl-slide-img:not([src]) { visibility: hidden; }
.tpl-slide-label { position: absolute; left: 18px; top: 18px; background: #ffffffee; border: 1px solid #e2e6ec; border-radius: 14px; padding: 10px 15px; display: flex; flex-direction: column; max-width: 70%; box-shadow: 0 4px 14px #1b2a400d; }
.tpl-slide-label small { color: #5d7a2a; font-size: 11px; font-weight: 600; }
.tpl-slide-label strong { font-size: 16px; color: #171e2b; line-height: 1.35; }
.tpl-slide-label span { font-size: 12px; color: #7c899b; }
.tpl-slide-count { position: absolute; right: 16px; top: 16px; background: #273449; color: #fff; font: 600 12px system-ui; padding: 5px 10px; border-radius: 14px; }
.tpl-slide-nav { position: absolute; left: 16px; bottom: 16px; display: flex; gap: 8px; }
.tpl-slide-nav button, .tpl-nav { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%; background: #fff; box-shadow: 0 4px 12px #1b2a4018; }
.tpl-slide-nav svg, .tpl-nav svg { width: 18px; height: 18px; }
.tpl-open-hero { position: absolute; right: 16px; bottom: 16px; background: #d1f36b; border-color: #d1f36b; color: #19221a; font-weight: 700; border-radius: 22px; padding: 10px 20px; box-shadow: 0 6px 16px #6c8f1640; }
.tpl-dots { display: flex; justify-content: center; gap: 6px; margin-top: 14px; }
.tpl-dots button { width: 8px; height: 8px; min-height: 8px; padding: 0; border-radius: 8px; border: 0; background: #cfd6df; transition: width 0.2s; }
.tpl-dots button.active { width: 26px; background: #5d7a2a; }

.tpl-cats { display: flex; gap: 10px; overflow-x: auto; padding: 22px 2px 14px; scrollbar-width: thin; }
.tpl-cat { flex: 0 0 auto; width: 104px; flex-direction: column; gap: 6px; padding: 8px 6px 10px; border-radius: 14px; background: #fff; border: 1px solid #e3e7ed; white-space: normal; min-height: 132px; justify-content: flex-start; }
.tpl-cat-img { width: 84px; height: 62px; border-radius: 10px; background: #eef1f5; display: grid; place-items: center; overflow: hidden; }
.tpl-cat-img img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.3s; }
.tpl-cat-img img.ready { opacity: 1; }
.tpl-cat-all { color: #5d7a2a; background: #eef5dc; }
.tpl-cat-all svg { width: 28px; height: 28px; }
.tpl-cat b { font-size: 13px; line-height: 1.3; text-align: center; color: #273449; }
.tpl-cat small { font: 600 11px system-ui; color: #6d7b8e; background: #f0f3f7; border-radius: 10px; padding: 1px 8px; }
.tpl-cat.active { border-color: #273449; box-shadow: 0 0 0 1px #273449; background: #fbfdf5; }
.tpl-cat.active small { background: #273449; color: #d1f36b; }

.tpl-filters { position: sticky; top: 0; z-index: 4; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 0; background: #f5f6f8; border-bottom: 1px solid #e3e7ed; }
.tpl-seg { display: flex; background: #e9edf2; padding: 3px; border-radius: 11px; gap: 2px; }
.tpl-seg button { border: 0; background: transparent; min-height: 32px; padding: 4px 13px; border-radius: 9px; font-size: 13px; color: #5a687c; }
.tpl-seg button.active { background: #fff; color: #171e2b; box-shadow: 0 1px 4px #1b2a4020; font-weight: 600; }
.tpl-check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: #445268; background: #fff; border: 1px solid #e0e5ed; border-radius: 10px; padding: 6px 12px; cursor: pointer; }
.tpl-check input { accent-color: #5d7a2a; width: 16px; height: 16px; }
.tpl-count { margin-left: auto; font-size: 13px; color: #7c899b; }
.tpl-count b { color: #171e2b; }
.tpl-filters select { width: auto; min-width: 170px; font-size: 13px; min-height: 38px; }

.tpl-group { padding: 30px 0 6px; }
.tpl-group-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; }
.tpl-group-head h2 { margin: 0 0 4px; font-size: 22px; color: #171e2b; }
.tpl-group-head h2 span { font: 600 13px system-ui; color: #5d7a2a; background: #eef5dc; padding: 2px 9px; border-radius: 10px; vertical-align: middle; }
.tpl-group-head p { margin: 0; color: #7c899b; font-size: 13.5px; max-width: 760px; line-height: 1.6; }
.tpl-group-head button { flex-shrink: 0; border: 0; background: transparent; color: #3f5520; font-weight: 600; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(214px, 1fr)); gap: 18px; padding-top: 6px; }
.tpl-card { cursor: pointer; outline: none; min-width: 0; }
.tpl-thumb { position: relative; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; background: linear-gradient(135deg, #eef1f5, #e6eaf0); border: 1px solid #e3e7ed; transition: box-shadow 0.2s, transform 0.2s; }
.tpl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity 0.35s; }
.tpl-thumb img.ready { opacity: 1; }
.tpl-card:hover .tpl-thumb, .tpl-card:focus-visible .tpl-thumb { box-shadow: 0 12px 28px #1b2a4021; transform: translateY(-2px); }
.tpl-card:focus-visible .tpl-thumb { outline: 3px solid #6093f9; outline-offset: 2px; }
.tpl-view { position: absolute; left: 50%; bottom: 12px; transform: translate(-50%, 6px); opacity: 0; transition: 0.2s; background: #273449; color: #fff; font-size: 12px; padding: 5px 12px; border-radius: 14px; white-space: nowrap; }
.tpl-card:hover .tpl-view, .tpl-card:focus-visible .tpl-view { opacity: 1; transform: translate(-50%, 0); }
.tpl-badge { position: absolute; left: 10px; top: 10px; background: #d1f36b; color: #26330f; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 10px; }
.tpl-badge-cur { left: auto; right: 10px; background: #273449; color: #fff; }
.tpl-card h3 { font-size: 15px; margin: 10px 2px 2px; line-height: 1.4; color: #1d2838; }
.tpl-card p { margin: 0 2px; font-size: 12.5px; color: #7c899b; }
.tpl-empty { text-align: center; padding: 70px 20px; color: #7c899b; }
.tpl-empty strong { display: block; font-size: 20px; color: #273449; margin-bottom: 8px; }

/* Preview window */
.tpl-modal { width: min(1200px, 96vw); max-width: 96vw; height: min(780px, 92dvh); max-height: 92dvh; padding: 0; border-radius: 22px; overflow: hidden; display: none; }
.tpl-modal[open] { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr); }
.tpl-modal-view { position: relative; background: #eef0f3; min-height: 0; }
.tpl-modal-canvas { position: absolute; inset: 0; }
.tpl-modal-canvas canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.tpl-no3d { display: grid; place-items: center; height: 100%; color: #7c899b; }
.tpl-modal-hint { position: absolute; left: 16px; top: 14px; font-size: 12px; color: #6d7b8e; background: #ffffffd9; padding: 4px 10px; border-radius: 12px; pointer-events: none; }
.tpl-viewbar { position: absolute; right: 14px; bottom: 70px; display: flex; flex-direction: column; gap: 4px; background: #fff; padding: 5px; border-radius: 14px; box-shadow: 0 6px 18px #1b2a4018; }
.tpl-viewbar button { border: 0; min-height: 34px; min-width: 50px; font-size: 12px; border-radius: 9px; }
.tpl-viewbar button.active { background: #273449; color: #d1f36b; }
.tpl-opendoor { position: absolute; left: 16px; bottom: 16px; background: #fff; border-radius: 18px; box-shadow: 0 4px 12px #1b2a4018; font-size: 13px; }
.tpl-nav { position: absolute; top: 50%; transform: translateY(-50%); }
.tpl-prev { left: 14px; }
.tpl-next { right: 14px; }
.tpl-modal-info { display: flex; flex-direction: column; padding: 22px 26px; overflow: auto; border-left: 1px solid #e3e7ed; background: #fff; }
.tpl-modal-top { display: flex; align-items: center; gap: 10px; }
.tpl-chip { font-size: 12px; font-weight: 600; color: #3f5520; background: #eef5dc; padding: 4px 11px; border-radius: 12px; }
.tpl-modal-count { margin-left: auto; font: 12px system-ui; color: #8c97a6; }
.tpl-close { width: 36px; min-height: 36px; padding: 0; border-radius: 50%; font-size: 22px; line-height: 1; }
.tpl-modal-info h2 { font-size: 25px; margin: 16px 0 6px; color: #171e2b; line-height: 1.3; }
.tpl-modal-desc { color: #6d7b8e; font-size: 14px; line-height: 1.7; margin: 0 0 16px; }
.tpl-dims { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tpl-dims div { background: #f5f7f2; border: 1px solid #e6ecda; border-radius: 12px; padding: 10px; text-align: center; }
.tpl-dims small { display: block; font-size: 12px; color: #7c899b; }
.tpl-dims b { font: 700 22px system-ui; color: #171e2b; }
.tpl-dims span { font-size: 12px; color: #7c899b; margin-left: 3px; }
.tpl-facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.tpl-facts span { font-size: 12px; border: 1px solid #e0e5ed; border-radius: 12px; padding: 3px 10px; color: #445268; }
.tpl-facts .tpl-chip-laser { background: #d1f36b; border-color: #d1f36b; color: #26330f; font-weight: 700; }
.tpl-points { padding-left: 0; list-style: none; margin: 6px 0 18px; }
.tpl-points li { position: relative; padding-left: 22px; font-size: 13.5px; color: #4f5d71; line-height: 1.65; margin: 6px 0; }
.tpl-points li::before { content: '✓'; position: absolute; left: 2px; color: #5d7a2a; font-weight: 700; }
.tpl-use { margin-top: auto; min-height: 50px; font-size: 16px; border-radius: 14px; }
dialog.tpl-modal::backdrop { background: #0c152280; backdrop-filter: blur(4px); }

/* Studio: current template card */
.tpl-current { display: flex; gap: 12px; align-items: center; border: 1px solid #e3e7ed; border-radius: 12px; padding: 8px; background: #fbfcfe; }
.tpl-current img { width: 76px; height: 57px; object-fit: cover; border-radius: 8px; background: #eef1f5; flex-shrink: 0; }
.tpl-current strong { display: block; font-size: 14px; line-height: 1.35; }
.tpl-current small { color: #7f8c9f; font-size: 12px; }
.bom-wrap { margin-top: 26px; }

@media (max-width: 1100px) {
  .tpl-inner { padding: 24px 24px 60px; }
  .tpl-hero { gap: 26px; }
  .tpl-hero h1 { font-size: 38px; }
}
@media (max-width: 900px) {
  .tpl-hero { grid-template-columns: 1fr; }
  .tpl-modal[open] { grid-template-columns: 1fr; grid-template-rows: 52dvh auto; overflow: auto; }
  .tpl-modal-info { border-left: 0; border-top: 1px solid #e3e7ed; overflow: visible; }
}
@media (max-width: 720px) {
  .tpl-workspace { grid-column: 1/-1; order: 1; overflow: visible; }
  .tpl-inner { padding: 18px 16px 40px; }
  .tpl-hero h1 { font-size: 30px; }
  .tpl-hero p { font-size: 14px; }
  .tpl-search kbd { display: none; }
  .tpl-search button { padding: 0 14px; }
  .tpl-stats { gap: 24px; }
  .tpl-stats dd { font-size: 26px; }
  .tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .tpl-card h3 { font-size: 13.5px; }
  .tpl-card p { font-size: 11.5px; }
  .tpl-group-head { flex-direction: column; align-items: flex-start; }
  .tpl-count { margin-left: 0; }
  .tpl-filters select { min-width: 0; flex: 1; }
  .tpl-modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .tpl-modal-info { padding: 18px; }
  .tpl-viewbar { flex-direction: row; bottom: 14px; right: 50%; transform: translateX(50%); }
  .tpl-opendoor { bottom: 66px; }
}

/* Flat laser pieces in the preview window. */
/* Sized from the window, not the drawing, so tall pieces still fit. */
.tpl-flat-pic { position: absolute; inset: 0; }
.tpl-flat-pic svg { position: absolute; inset: 50px 70px; width: calc(100% - 140px); height: calc(100% - 100px); filter: drop-shadow(0 10px 18px #2b1a0c2e); }
@media (max-width: 900px) { .tpl-flat-pic svg { inset: 40px 54px; width: calc(100% - 108px); height: calc(100% - 80px); } }
.tpl-thumb img.flat, .tpl-slide-img.flat { object-fit: contain; padding: 7%; }
.tpl-slide-img.flat { padding: 12% 16%; }
