.tpl-dialog {
  width: min(980px, calc(100vw - 48px));
  max-height: min(880px, calc(100dvh - 48px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line, #dfe5dc);
  border-radius: 18px;
  background: var(--paper, #fffefb);
  color: var(--ink, #263b31);
  box-shadow: 0 24px 90px #263b3129;
  font-size: 14px;
}

.tpl-dialog::backdrop {
  background: #263b3166;
  backdrop-filter: blur(4px);
}

.tpl-shell {
  display: flex;
  flex-direction: column;
  max-height: min(878px, calc(100dvh - 50px));
  min-height: 0;
}

.tpl-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px 22px;
  flex: 0 0 auto;
}

.tpl-heading-copy { min-width: 0; }
.tpl-dialog h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.4px; }
.tpl-dialog h3 { margin: 0 0 16px; font-size: 15px; font-weight: 600; }
.tpl-dialog p, .tpl-dialog small { line-height: 1.75; }
.tpl-introduction { margin: 9px 0 0; color: var(--muted, #68766e); font-size: 13px; }
.tpl-muted, .tpl-dialog small { color: var(--muted, #68766e); }
.tpl-dialog small { display: block; font-size: 12px; font-weight: 400; }
.tpl-dialog a { color: var(--green, #285a45); text-underline-offset: 3px; }

.tpl-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 24px 32px 28px;
  background: var(--warm, #f7f7f2);
}

.tpl-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tpl-tabs { flex: 0 0 auto; padding: 0 32px 18px; border-bottom: 1px solid var(--line, #dfe5dc); }
.tpl-tab-list { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 10px; background: var(--warm, #f7f7f2); }
.tpl-tabs > button { margin-left: auto; }
.tpl-dialog .tpl-tab-list button { border-color: transparent; background: transparent; color: var(--muted, #68766e); padding: 9px 16px; }
.tpl-dialog .tpl-tab-list button[aria-selected="true"] { background: var(--green, #285a45); color: var(--paper, #fffefb); font-weight: 600; }

.tpl-dialog button, .tpl-dialog .tpl-link {
  min-height: 40px;
  padding: 10px 15px;
  border: 1px solid var(--line, #dfe5dc);
  border-radius: 8px;
  background: var(--paper, #fffefb);
  color: var(--green, #285a45);
  font: inherit;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.tpl-dialog button:hover:not(:disabled), .tpl-dialog .tpl-link:hover { background: var(--pale, #eaf1e9); border-color: #bfd0c0; }
.tpl-dialog .tpl-tab-list button[aria-selected="true"]:hover { background: var(--green, #285a45); border-color: transparent; }
.tpl-dialog button:disabled { opacity: .45; cursor: default; }
.tpl-dialog .tpl-primary { border-color: var(--green, #285a45); background: var(--green, #285a45); color: var(--paper, #fffefb); font-weight: 600; }
.tpl-dialog .tpl-primary:hover:not(:disabled) { background: #204a38; border-color: #204a38; }
.tpl-dialog .tpl-close { flex: 0 0 auto; min-width: 60px; background: transparent; }
.tpl-dialog :is(button, a, input, textarea, select, summary):focus-visible { outline: 3px solid #a3bda5; outline-offset: 3px; }

.tpl-card { margin-bottom: 18px; padding: 22px 24px; border: 1px solid var(--line, #dfe5dc); border-radius: 12px; background: var(--paper, #fffefb); }
.tpl-card:last-child { margin-bottom: 0; }
.tpl-field { display: flex; flex-direction: column; min-width: 0; gap: 9px; margin: 18px 0; font-size: 13px; font-weight: 600; }
.tpl-field:first-child { margin-top: 0; }
.tpl-field:last-child { margin-bottom: 0; }
.tpl-field > small { overflow-wrap: anywhere; }
.tpl-row > .tpl-field { flex: 1; margin: 0; }
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.tpl-grid > .tpl-field { margin: 0; }
.tpl-card > .tpl-grid { margin-top: 20px; }
.tpl-dialog input, .tpl-dialog textarea, .tpl-dialog select { box-sizing: border-box; width: 100%; min-width: 0; padding: 12px 13px; border: 1px solid #cfd8ce; border-radius: 8px; background: var(--paper, #fffefb); color: var(--ink, #263b31); font: inherit; font-size: 14px; font-weight: 400; }
.tpl-dialog :is(input, textarea)::placeholder { color: #8b968d; }
.tpl-dialog textarea { resize: vertical; line-height: 1.8; }
.tpl-dialog textarea[readonly] { background: var(--warm, #f7f7f2); color: #43574a; }
.tpl-version { margin: 14px 0 0; padding-top: 13px; border-top: 1px solid var(--line, #dfe5dc); overflow-wrap: anywhere; font-size: 11px; }
.tpl-version:empty { display: none; }
.tpl-version a { display: inline-block; margin-top: 5px; font-size: 12px; }
.tpl-writing > .tpl-muted { margin: -3px 0 22px; font-size: 12px; }
.tpl-writing .tpl-field + .tpl-field { margin-top: 26px; }
.tpl-source { min-height: 240px; tab-size: 2; font: 13px/1.85 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace !important; }

.tpl-slot { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-top: 12px; padding: 16px; border: 1px solid var(--line, #dfe5dc); border-radius: 8px; background: var(--warm, #f7f7f2); }
.tpl-slot > div { min-width: 0; }
.tpl-slot strong { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.tpl-slot pre { margin: 8px 0 0; color: var(--muted, #68766e); font: 12px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.tpl-slot > button { flex: 0 0 auto; min-height: 34px; padding: 7px 10px; font-size: 12px; }
.tpl-slot-empty { margin: 16px 0 0; padding: 14px 16px; border: 1px dashed var(--line, #dfe5dc); border-radius: 8px; color: var(--muted, #68766e); font-size: 12px; }
.tpl-actions { justify-content: flex-end; gap: 10px; margin-top: 22px; }
.tpl-action-note { flex: 1; min-width: 180px; }

.tpl-alert { margin: 0 0 20px; padding: 14px 16px; border: 1px solid #e0d9bf; border-radius: 9px; background: #f8f4e9; color: #746139; white-space: pre-wrap; font-size: 13px; }
.tpl-alert.tpl-success { border-color: #c9d8c8; background: var(--pale, #eaf1e9); color: var(--green, #285a45); }
.tpl-preview { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line, #dfe5dc); }
.tpl-check-badge { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 20px; background: var(--pale, #eaf1e9); color: var(--green, #285a45); font-size: 12px; font-weight: 600; }
.tpl-check-badge::before { content: "✓"; }
.tpl-preview-report { margin: 12px 0 18px; white-space: pre-wrap; color: var(--muted, #68766e); font-size: 12px; }
.tpl-dialog summary { color: var(--green, #285a45); font-size: 13px; font-weight: 600; cursor: pointer; line-height: 1.7; }
.tpl-preview details > textarea { margin-top: 12px; }

.tpl-empty { padding: 44px 28px 46px; border: 1px dashed #ccd7c9; border-radius: 12px; background: var(--paper, #fffefb); text-align: center; }
.tpl-kicker { display: block; margin-bottom: 13px; color: var(--green, #285a45); font-size: 11px; letter-spacing: 1.5px; }
.tpl-empty h3 { margin-bottom: 12px; font-size: 21px; font-weight: 500; }
.tpl-empty p { max-width: 440px; margin: 0 auto 24px; color: var(--muted, #68766e); font-size: 13px; }
.tpl-search { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line, #dfe5dc); }
.tpl-search > summary { color: var(--muted, #68766e); font-weight: 400; }
.tpl-search-content { padding-top: 18px; }
.tpl-search-content > small { margin-top: 12px; }
.tpl-search .tpl-row { align-items: flex-end; }
.tpl-search .tpl-link { white-space: nowrap; }
.tpl-dialog [hidden] { display: none !important; }

@media (max-width: 640px) {
  .tpl-dialog input, .tpl-dialog select, .tpl-dialog textarea { font-size: 16px; }
  .tpl-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); border-radius: 14px; }
  .tpl-shell { max-height: calc(100dvh - 22px); }
  .tpl-heading { padding: 22px 18px 18px; gap: 14px; }
  .tpl-dialog h2 { font-size: 19px; }
  .tpl-introduction { font-size: 12px; }
  .tpl-tabs { padding: 0 18px 14px; gap: 8px; }
  .tpl-tab-list { width: 100%; }
  .tpl-dialog .tpl-tab-list button { flex: 1; padding: 9px 7px; font-size: 12px; }
  .tpl-tabs > button { min-height: 32px; padding: 6px 9px; font-size: 12px; }
  .tpl-body { padding: 18px 16px 22px; }
  .tpl-card { padding: 18px 16px; }
  .tpl-grid { grid-template-columns: 1fr; gap: 18px; }
  .tpl-row > .tpl-field { min-width: 160px; }
  .tpl-action-note { flex-basis: 100%; }
  .tpl-actions > button { flex: 1; }
  .tpl-source { min-height: 220px; }
  .tpl-empty { padding: 34px 20px; }
  .tpl-slot { padding: 12px; gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .tpl-dialog button, .tpl-dialog .tpl-link { transition: none; }
}
