/* Radilux design system: styles for the templates area (landing, workspace,
   template view, builder, import/export, user panel, admin management,
   pending approvals). Tokens and base components live in rl.css; everything
   here is scoped to .tpl, the wrapper every fragment of the area carries.
   No colour literals: tokens only. */

.tpl { min-width: 0; }

/* The fragments can be swapped into pages that still load the legacy
   frameworks. Neutralise the few global rules of those frameworks that reach
   inside (form controls and tables are styled by the rl-* classes). */
.tpl fieldset { min-width: 0; margin: 0; }
.tpl legend { float: none; width: auto; margin: 0; font-size: inherit; line-height: inherit; }
.tpl label { margin: 0; }
.tpl table { margin: 0; }
.tpl pre { margin: 0; }
.tpl dl, .tpl dd, .tpl dt { margin: 0; }
.tpl ul.rl-list { padding: 0; margin: 0; }
.tpl summary { display: flex; }

/* Busy state of a button: the wrapper is the request's indicator. */
.tpl-state { display: inline-flex; align-items: center; gap: 7px; }
.tpl-state .rl-busy { align-items: center; gap: 7px; }

/* ── Page head ────────────────────────────────────────────────────────── */
.tpl-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; }
.tpl-head > .rl-grow { flex-basis: 280px; }
.tpl-head h1 { overflow-wrap: anywhere; }
.tpl-head p.rl-muted { margin-top: 4px; max-width: 72ch; }

/* ── Landing cards ────────────────────────────────────────────────────── */
.tpl-landing-card { min-height: 120px; justify-content: center; }
.tpl-landing-card .rl-tcard-desc { -webkit-line-clamp: 3; }

/* ── Statistics row ───────────────────────────────────────────────────── */
.tpl-stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ── Template lists (workspace, pending approvals, import result) ─────── */
.tpl .rl-details > .rl-list { border-top: 1px solid var(--rl-line); }
.tpl-item { flex-wrap: wrap; align-items: center; row-gap: 8px; }
.tpl-item-main { min-width: min(100%, 220px); display: flex; flex-direction: column; gap: 4px; }
.tpl-item-name { font-weight: 600; color: var(--rl-ink) !important; overflow-wrap: anywhere; }
.tpl-item-name:hover { color: var(--rl-accent) !important; }
.tpl-badges { gap: 6px; }
.tpl-badges:empty { display: none; }
.tpl-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.tpl-danger { color: var(--rl-danger) !important; }
.tpl-danger:hover { background: var(--rl-danger-soft); }
.tpl-empty { padding: 14px 16px; }
td.tpl-empty { text-align: center; padding: 28px 16px; }

/* ── Workspace filters ────────────────────────────────────────────────── */
.tpl-chips { border: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.tpl-chips > legend { padding: 0; margin-bottom: 6px; }
.tpl-chip { padding: 4px 10px; border: 1px solid var(--rl-line-strong); border-radius: 999px; font-size: .86rem; }
.tpl-chip:has(input:checked) { background: var(--rl-accent-soft); border-color: var(--rl-accent-line); color: var(--rl-accent); }
.tpl-chip:has(input:focus-visible) { outline: 2px solid var(--rl-focus); outline-offset: 2px; }

/* ── Template view ────────────────────────────────────────────────────── */
.tpl-view-section { display: flex; flex-direction: column; gap: 6px; }
.tpl .tpl-view-section > h2 { font: 650 .72rem/1.4 var(--rl-font); letter-spacing: .08em; color: var(--rl-muted); }
.tpl-pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.tpl-findings { display: flex; flex-direction: column; gap: 6px; }
.tpl-finding { display: grid; grid-template-columns: minmax(110px, 190px) minmax(0, 1fr); gap: 4px 14px; padding: 8px 12px; background: var(--rl-sunken); border-left: 3px solid var(--rl-accent-line); border-radius: var(--rl-radius-sm); }
.tpl-finding dt { font-weight: 600; color: var(--rl-ink-2); overflow-wrap: anywhere; }
@media (max-width: 640px) { .tpl-finding { grid-template-columns: minmax(0, 1fr); } }

/* ── Builder ──────────────────────────────────────────────────────────── */
.tpl-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); align-items: start; }
.tpl-grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.tpl-field-end { justify-content: flex-end; align-self: center; }
.tpl-ta { min-height: 64px; }
.tpl-section { border: 1px solid var(--rl-line); border-radius: var(--rl-radius); padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 14px; background: var(--rl-surface); }
.tpl-section > legend { padding: 0 6px; font-weight: 650; color: var(--rl-ink); }
.tpl-form .rl-check { align-items: flex-start; }
.tpl-form .rl-check input { margin-top: 3px; flex: none; }
.tpl-form-end { justify-content: flex-end; position: sticky; bottom: 0; padding: 10px 0; background: var(--rl-bg); border-top: 1px solid var(--rl-line); }
#tplFormStatus:empty { display: none; }

/* Anatomical field rows: numbered by a CSS counter, so the numbers stay
   right when rows are added and removed. */
#findings-container { counter-reset: tplfield; }
#findings-container:empty { display: none; }
.finding-field-group { counter-increment: tplfield; background: var(--rl-sunken); }
.finding-field-group > legend::before { content: counter(tplfield) ". "; color: var(--rl-muted); font-variant-numeric: tabular-nums; }
.tpl-remove { margin-left: auto; }

/* Output-format block: the summary says whether the template has its own
   rules, from the state of the text field. */
.tpl-fmt-state { display: inline-flex; margin-left: auto; margin-right: 10px; }
#outputFormatCard:has(#outputFormatTextarea:placeholder-shown) .tpl-fmt-custom { display: none; }
#outputFormatCard:not(:has(#outputFormatTextarea:placeholder-shown)) .tpl-fmt-default { display: none; }

/* ── Admin management ─────────────────────────────────────────────────── */
.tpl-col-check { width: 1%; white-space: nowrap; }
.tpl-col-actions { min-width: 380px; }
.tpl-col-name { min-width: 220px; }
.tpl-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 2px; overflow-wrap: anywhere; }
.tpl-col-check .rl-btn { min-height: 24px; padding: 0 6px; }
.template-checkbox { width: 16px; height: 16px; accent-color: var(--rl-accent); cursor: pointer; }
.tpl .rl-table tr:has(.template-checkbox:checked) { background: var(--rl-accent-soft); }
.tpl-alert-action { align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* Batch bar: shown while at least one row is ticked; the number of ticked
   rows is a CSS counter (the bar comes after the table in the document). */
#batchForm { counter-reset: tplsel; }
.template-checkbox:checked { counter-increment: tplsel; }
.tpl-batchbar { display: none; position: sticky; bottom: 0; z-index: 5; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--rl-surface-2); border: 1px solid var(--rl-accent-line); border-radius: var(--rl-radius); }
#batchForm:has(.template-checkbox:checked) .tpl-batchbar { display: flex; }
#batchForm:has(.template-checkbox:checked) .tpl-batch-hint { display: none; }
.tpl-selcount { font-weight: 600; }
.tpl-selcount::before { content: counter(tplsel) " "; font-variant-numeric: tabular-nums; }

/* While a list is being fetched again, dim it. */
.tpl .htmx-request > .rl-table-wrap, .tpl .rl-table-wrap.htmx-request { opacity: .6; }

@media (max-width: 640px) {
  .tpl-head { align-items: flex-start; }
  .tpl-actions .rl-btn--sm { min-height: 34px; }
}
