.template-library { min-width: 0; }
.template-library-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; padding: 1.5rem 0 1.75rem; }
.template-library-heading h2 { margin: 0; font-size: clamp(1.45rem, 2.4vw, 2rem); }
.template-library-heading p { max-width: 65ch; margin: .5rem 0 0; color: var(--muted); font-size: 1rem; }
.template-library-heading > .button { flex-shrink: 0; }
.template-library-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1.75rem; border-top: 1px solid var(--line-strong); }
.template-sidebar { padding: 1.25rem 1rem 1rem 0; border-right: 1px solid var(--line); }
.template-search input { width: 100%; min-width: 0; font-size: .84rem; padding-left: 2.15rem; }
.template-search > .ui-icon { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); width: 1rem; height: 1rem; color: var(--muted); pointer-events: none; }
.template-library-group { margin-top: .75rem; border-bottom: 1px solid var(--line); }
.template-library-group > summary { display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: .75rem .25rem; list-style: none; cursor: pointer; color: var(--navy); font-size: 1rem; font-weight: 600; }
.template-library-group > summary::-webkit-details-marker { display: none; }
.template-group-chevron { width: 1rem; height: 1rem; flex-shrink: 0; }
.template-library-group[open] > summary .template-group-chevron { transform: rotate(90deg); }
.template-group-count { margin-left: auto; color: var(--muted); font-size: .84rem; font-weight: 400; font-variant-numeric: tabular-nums; }
.template-group-items { margin: 0 0 .9rem .75rem; padding-left: .5rem; border-left: 1px solid var(--line-strong); }
.template-library-item { display: grid; gap: .25rem; min-height: 44px; padding: .6rem .55rem; margin-block: .2rem; border: 1px solid transparent; border-radius: 8px; color: var(--navy); text-decoration: none; overflow-wrap: anywhere; }
.template-library-item strong { font-size: .84rem; line-height: 1.4; font-weight: 600; }
.template-library-item small { color: var(--muted); font-size: .84rem; font-variant-numeric: tabular-nums; }
.template-library-item.selected { background: var(--lilac-soft); border-color: var(--line-strong); }
.template-library-item.selected small { color: var(--navy); }
.template-library [hidden] { display: none !important; }
.template-no-results { margin: 1rem .5rem; color: var(--muted); font-size: .84rem; }
.template-detail { min-width: 0; padding-top: 1.25rem; }
.template-detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.template-detail-heading h3 { margin: 0; font-family: var(--font-sans); font-size: 1rem; line-height: 1.4; }
.template-detail-heading p { margin: .5rem 0 0; color: var(--muted); font-size: .84rem; line-height: 1.5; max-width: 65ch; }
.template-detail-heading > .button { flex-shrink: 0; }
.template-save-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 0; border-top: 1px solid var(--line); margin-top: 1.25rem; }
.template-save-bar [role=status], .template-saved { font-size: .84rem; color: var(--muted); }
.template-save-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.template-definition { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.template-definition label { font-size: .84rem; }
.template-definition input, .template-definition select { width: 100%; }
.template-library-item:focus-visible, .template-library-group > summary:focus-visible { outline: 3px solid var(--periwinkle); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) {
  .template-library-item:hover { background: var(--lilac-soft); }
}
@media (max-width: 1000px) {
  .template-library-layout { grid-template-columns: 190px minmax(0, 1fr); gap: 1rem; }
  .template-library-heading { flex-wrap: wrap; }
  .template-detail-heading { flex-wrap: wrap; }
  .template-save-bar { flex-wrap: wrap; }
}
@media (max-width: 700px) {
  .template-library-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .template-sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 1rem 0; }
  .template-sidebar nav { overflow-y: auto; padding: .25rem; max-height: 12rem; }
  .template-library-item { padding: .5rem; }
  .template-library-heading { padding-block: 1rem; gap: 1rem; }
  .template-definition { grid-template-columns: minmax(0, 1fr); }
  .template-save-actions { width: 100%; justify-content: flex-end; }
}

.template-library-heading > div { min-width: 0; max-width: 100%; }
.template-library-heading p { overflow-wrap: anywhere; }
.template-search { display: block; position: relative; min-width: 0; max-width: 100%; margin-bottom: .5rem; }
