/* OWNER: template-engine agent. Agreement template list and editor. */

.badge.published { background: var(--ok-soft); color: var(--ok); }
.badge.archived { background: var(--surface-2); color: var(--muted); }

.tpl-family h2 a { color: inherit; text-decoration: none; }
.tpl-family h2 a:hover, .tpl-family h2 a:focus-visible { text-decoration: underline; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.tpl-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-top: 12px;
}
.tpl-grid > .card + .card { margin-top: 0; }
.tpl-meta { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 0 12px; }
.tpl-toolbar { flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; align-items: center; }

/* Code editor with a line-number gutter. Gutter and textarea share font metrics so lines align. */
.tpl-code {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  margin-top: 4px;
}
.tpl-code:focus-within { outline: 3px solid rgba(var(--primary-rgb), 0.35); outline-offset: 1px; }
.tpl-gutter, .tpl-textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 20px;
}
.tpl-gutter {
  flex: 0 0 auto;
  min-width: 3.2em;
  padding: 10px 8px 10px 6px;
  text-align: right;
  color: var(--muted);
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
  height: 62vh;
  box-sizing: border-box;
}
.tpl-gutter div { height: 20px; }
textarea.tpl-textarea {
  flex: 1 1 auto;
  height: 62vh;
  min-height: 320px;
  margin: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  resize: none;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  box-sizing: border-box;
  background: transparent;
  color: var(--text);
}
textarea.tpl-textarea:focus { outline: none; box-shadow: none; }
textarea.tpl-textarea[readonly] { background: var(--surface-2); }

.tpl-issues-h { font-size: 16px; margin: 16px 0 6px; }
.tpl-issues ul { margin: 0 0 10px; padding-left: 20px; }
.tpl-issues li { margin: 4px 0; }
.tpl-issues .link { font-weight: 600; }
.tpl-ok { color: var(--ok); font-weight: 600; margin: 0; }
.tpl-bad { color: var(--danger); font-weight: 600; margin: 0 0 6px; }

.tpl-tabs { margin-bottom: 12px; }
.tpl-panel:focus-visible { outline: 3px solid rgba(var(--primary-rgb), 0.35); outline-offset: 2px; }

.tpl-fields td { padding: 4px 4px; vertical-align: middle; }
.tpl-fields input[type=text], .tpl-fields select { width: 100%; min-width: 7em; padding: 6px 8px; font-size: 13px; }
.tpl-fields .tpl-center { text-align: center; }
.tpl-fields .tpl-actions { white-space: nowrap; }
.tpl-fields .tpl-actions button + button { margin-left: 4px; }

.tpl-sample { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 12px; }
.tpl-sample .field textarea { min-height: 0; }

.tpl-preview { margin-top: 10px; max-height: 75vh; overflow: auto; padding: 4px; align-items: stretch; }
.tpl-preview .page-wrap { margin: 0 auto; }
.tpl-fieldbox {
  position: absolute;
  border: 2px dashed var(--bch-blue);
  background: rgba(49, 120, 201, 0.08);
  border-radius: 2px;
  pointer-events: none;
}
.tpl-fieldbox span {
  position: absolute; top: 2px; left: 4px;
  font-size: 11px; font-weight: 600; color: #1d4f8f;
}

.tpl-help h3 { font-size: 15px; margin: 14px 0 6px; }
.tpl-help h3:first-child { margin-top: 0; }
.tpl-help-item { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.tpl-help-item code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 3px;
  justify-self: start;
  word-break: break-word;
}

@media (max-width: 960px) {
  .tpl-grid { grid-template-columns: minmax(0, 1fr); }
  .tpl-meta { grid-template-columns: minmax(0, 1fr); }
  .tpl-gutter, textarea.tpl-textarea { height: 50vh; }
}

/* Template kinds and fillable PDF templates */
.badge.tpl-kind { font-size: 12px; vertical-align: middle; font-weight: 600; }
.badge.tpl-kind.pdf_form { background: rgba(49, 120, 201, 0.12); color: #1d4f8f; }
.badge.tpl-kind.text { background: var(--surface-2); color: var(--muted); }
fieldset.tpl-kind-choice { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; }
fieldset.tpl-kind-choice legend { font-weight: 600; padding: 0 4px; }
fieldset.tpl-kind-choice label.check { display: block; margin: 6px 0; }
.tpl-upload { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; margin: 8px 0; }
.tpl-upload input[type=file] { max-width: 100%; }
.tpl-pdf-fields td { font-size: 13px; vertical-align: top; padding: 4px 6px; }
.tpl-fname { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 3px; white-space: nowrap; }
.tpl-pdf-fields td:nth-child(5) { min-width: 12em; }
.tpl-services tr.tpl-hold td { background: rgba(196, 120, 0, 0.08); }
.tpl-services td .tpl-bad { display: block; margin: 2px 0 0; }
.tpl-fieldbox.grp-representative { border-color: #7a4cc2; background: rgba(122, 76, 194, 0.08); }
.tpl-fieldbox.grp-representative span { color: #5b3596; }
.tpl-fieldbox.grp-supporter { border-color: #4f7a28; background: rgba(79, 122, 40, 0.07); }
.tpl-fieldbox.grp-supporter span { color: #3c5e1e; }
.tpl-fieldbox.grp-auto { border-style: dotted; border-color: var(--muted); background: rgba(120, 120, 120, 0.06); }
.tpl-fieldbox.grp-auto span { color: var(--muted); }
.tpl-fieldbox span { font-size: 10px; white-space: nowrap; overflow: hidden; max-width: calc(100% - 6px); text-overflow: ellipsis; }
.tpl-services input[type=text] { min-width: 8em; }
.tpl-services td:nth-child(2) input, .tpl-services td:nth-child(3) input { min-width: 13em; }
.tpl-services td:nth-child(6) input { min-width: 12em; }

/* The fillable PDF has ~100 fields: keep the list in its own scroll area so the page stays a sensible length. */
.tpl-pdf-fields-wrap { max-height: 70vh; overflow: auto; }
.tpl-pdf-fields-wrap thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
