/* Finding library, library picker sheet, template builder. Mobile first (390 px).
   The .cl-* editor checklist rules are v2; the v3 walkthrough styles live in walkthrough.css. */

.lib-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.lib-icon { width: 44px; min-height: 44px; padding: 0; font-size: 1.1rem; }

/* ------------------------------------------------------------------ editor: jump link */
/* A fourth jump link: tighten the row so all four fit at 390 px; icon instead of the word on narrow phones. */
.jump-nav:has(.jump-checklist) { gap: 5px; }
.jump-nav:has(.jump-checklist) a { flex: 1 1 auto; padding: 0 4px; font-size: 0.8rem; gap: 3px; }
.jump-nav:has(.jump-checklist) .count { min-width: 18px; padding: 0 4px; }
.jl-icon { display: none; width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 379px) {
  .jl-icon { display: block; }
  .jl-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ------------------------------------------------------------------ editor: checklist */
.cl-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.cl-head .section-title { margin: 0; }
.cl-progress { display: grid; gap: 6px; font-size: 0.875rem; color: var(--muted); }
.cl-left { color: var(--danger); }
.cl-bar { display: block; height: 6px; border-radius: 3px; background: #e3e7ec; overflow: hidden; }
.cl-bar i { display: block; height: 100%; background: var(--brand); border-radius: 3px; transition: width 0.25s; }
.cl-progress.is-done .cl-bar i { background: var(--ok); }

.cl-card { overflow: hidden; }
.cl-section {
  margin: 0; padding: 10px 16px; background: #f3f5f8; border-bottom: 1px solid var(--border);
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted);
}
.cl-section:not(:first-child) { border-top: 1px solid var(--border); }
.cl-list { list-style: none; margin: 0; padding: 0; }
.cl-item { padding: 12px 16px 14px; border-bottom: 1px solid var(--border); box-shadow: inset 4px 0 transparent; }
.cl-item:last-child { border-bottom: 0; }
.cl-item.cl-ok { box-shadow: inset 4px 0 var(--ok); }
.cl-item.cl-issue { box-shadow: inset 4px 0 var(--danger); background: #fffafa; }
.cl-item.cl-na { box-shadow: inset 4px 0 #9aa6b2; }
.cl-text { margin: 0 0 10px; font-weight: 600; overflow-wrap: anywhere; }
.cl-req {
  display: inline-block; margin-left: 4px; padding: 0 8px; border-radius: 999px; vertical-align: 1px;
  font-size: 0.72rem; font-weight: 700; line-height: 1.7; background: #fbe4e1; color: var(--danger);
}
.cl-item:not(.cl-unchecked) .cl-req { background: #eef1f5; color: var(--muted); }
.cl-answer { margin: 0; }
.cl-pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cl-pill {
  min-height: 44px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 700; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cl-pill:active { transform: translateY(1px); }
.cl-pill:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.cl-pill-ok[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.cl-pill-issue[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: #fff; }
.cl-pill-na[aria-pressed="true"] { background: #5d6b7a; border-color: #5d6b7a; color: #fff; }
.htmx-request .cl-pill { opacity: 0.7; }
.cl-note { margin: 10px 0 0; }
.cl-note input { width: 100%; }
.cl-add-finding { width: 100%; margin-top: 10px; min-height: 44px; color: var(--danger); border-color: #f0c4be; }
.cl-finding-link {
  display: inline-flex; align-items: center; min-height: 44px; margin-top: 4px;
  font-weight: 600; font-size: 0.95rem; text-decoration: none;
}
.cl-empty p { margin-bottom: 10px; }

/* ------------------------------------------------------------------ editor: add from library */
.lib-open { margin-bottom: 12px; min-height: 52px; color: var(--brand); border-style: dashed; border-width: 2px; }
.lib-open svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

html.lib-sheet-open { overflow: hidden; }
dialog.lib-sheet {
  position: fixed; inset: auto 0 0 0; width: 100%; max-width: 640px; max-height: 88vh; max-height: 88dvh;
  margin: 0 auto; padding: 0; border: 0; border-radius: 18px 18px 0 0;
  background: var(--surface); color: var(--text); box-shadow: 0 -8px 32px rgba(16, 24, 40, 0.25);
}
dialog.lib-sheet::backdrop { background: rgba(16, 24, 40, 0.5); }
dialog.lib-sheet[open] { animation: lib-sheet-up 0.22s ease-out; }
@keyframes lib-sheet-up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
/* Fixed height so the sheet doesn't jump while search results change. */
.lib-sheet-inner { display: flex; flex-direction: column; height: 82vh; height: 82dvh; }
.lib-sheet-head { position: relative; display: flex; align-items: center; gap: 8px; padding: 18px 8px 6px 16px; }
.lib-sheet-head h2 { flex: 1; margin: 0; font-size: 1.15rem; }
.lib-grab { position: absolute; top: 7px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: #d5dbe2; }
.lib-close {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: #eef1f5; color: var(--text);
  font-size: 26px; line-height: 1; cursor: pointer;
}
.lib-search { padding: 4px 16px 10px; border-bottom: 1px solid var(--border); }
.lib-search input { width: 100%; }
.lib-results {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(20px + env(safe-area-inset-bottom));
}
.lib-loading, .lib-hint { margin: 10px 0; color: var(--muted); font-size: 0.85rem; text-align: center; }
.lib-group {
  margin: 14px 0 8px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted);
}
.lib-options { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lib-option {
  display: grid; gap: 4px; width: 100%; min-height: 64px; padding: 12px 14px; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.lib-option:active { background: #eef3f9; border-color: var(--brand); }
.lib-option:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.lib-option[disabled] { opacity: 0.6; }
.lib-option-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.lib-option-title { font-weight: 700; line-height: 1.3; }
.lib-option-caption {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  color: var(--muted); font-size: 0.875rem; line-height: 1.35;
}
.lib-option-service { font-size: 0.8rem; font-weight: 600; color: var(--brand); }

.finding-card.lib-flash { animation: lib-flash 1.8s ease-out; }
@keyframes lib-flash { 0%, 30% { box-shadow: 0 0 0 3px var(--brand); } 100% { box-shadow: var(--shadow); } }

@media (prefers-reduced-motion: reduce) {
  dialog.lib-sheet[open], .finding-card.lib-flash { animation: none; }
  .cl-bar i { transition: none; }
}

/* ------------------------------------------------------------------ settings: finding library */
.lib-filter { display: flex; align-items: center; gap: 12px; margin: 0 0 8px; }
.lib-filter select { flex: 1; min-width: 0; }
.lib-show { flex: none; margin: 0; font-size: 0.9rem; }
.lib-count { margin: 0 0 12px; }
.lib-kind { font-weight: 600; letter-spacing: 0; text-transform: none; }
.lib-row { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--border); }
.lib-row:last-child { border-bottom: 0; }
.lib-row:target { background: #f2f7fc; }
.lib-row-main {
  flex: 1; min-width: 0; display: grid; gap: 4px; padding: 10px 8px 10px 16px; min-height: 60px;
  color: var(--text); text-decoration: none;
}
.lib-row-main:active { background: #eef1f5; }
.lib-row-title { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.lib-row-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.lib-row-service { color: var(--muted); font-size: 0.8rem; }
.lib-row.is-inactive .lib-row-title { color: var(--muted); }
.lib-move { display: flex; gap: 4px; padding-right: 8px; }
.lib-move form { margin: 0; }
.lib-form .sev-pills { margin-top: 2px; }
.lib-form textarea { min-height: 120px; }
.lib-active-help { margin: -8px 0 16px; }

/* ------------------------------------------------------------------ settings: template builder (v3) */
.lib-group-here { font-weight: 700; letter-spacing: 0; text-transform: none; color: var(--brand); }

.tb-list-row .row-title, .tb-list-row .row-sub { white-space: normal; overflow-wrap: anywhere; }
.tb-list-row.is-off .row-title { color: var(--muted); }
.tb-chip-default { background: #dcf1e5; color: var(--ok); }
.tb-chip-off { background: #eef1f5; color: var(--muted); }

.tb-head { margin-bottom: 12px; }
.tb-title { margin: 0 0 6px; overflow-wrap: anywhere; }
.tb-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
.tb-counts { margin: 0; }
.tb-desc { margin: 8px 0 0; color: var(--muted); font-size: 0.95rem; overflow-wrap: anywhere; }
.tb-note {
  margin: 0 0 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: #eef3f9;
  color: var(--text); font-size: 0.875rem; line-height: 1.4;
}
.tb-optional { margin-left: 4px; font-weight: 500; font-size: 0.8rem; color: var(--muted); }
.tb-optional::before { content: "("; }
.tb-optional::after { content: ")"; }
.tb-js .tb-nojs { display: none; }
.tb-narrow { max-width: 120px; }

/* Collapsible panels: settings, edit forms, add forms. */
.tb-settings { padding: 0; }
.tb-settings > summary, .tb-edit > summary, .tb-add > summary, .tb-add-sec > summary {
  list-style: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.tb-settings > summary::-webkit-details-marker, .tb-edit > summary::-webkit-details-marker,
.tb-add > summary::-webkit-details-marker, .tb-add-sec > summary::-webkit-details-marker { display: none; }
.tb-settings-toggle {
  position: relative; display: flex; flex-direction: column; justify-content: center; gap: 2px;
  min-height: 60px; padding: 10px 44px 10px 16px;
}
.tb-settings-toggle::after, .tb-edit-toggle::after {
  content: ""; position: absolute; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg);
  transition: transform 0.15s;
}
.tb-settings-toggle::after { right: 18px; }
.tb-settings[open] > .tb-settings-toggle::after, .tb-edit[open] > .tb-edit-toggle::after {
  transform: rotate(-135deg); margin-top: -2px;
}
.tb-settings-title { font-weight: 700; }
.tb-settings-form { padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.tb-default-note {
  margin: 0 0 8px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: #dcf1e5; color: #1f5c39; font-size: 0.9rem; font-weight: 600;
}

/* Jump list: one pill per section, scrolls sideways on a phone. */
.tb-jump { margin: 0 -16px 14px; }
.tb-jump ol {
  display: flex; gap: 8px; margin: 0; padding: 2px 16px 6px; list-style: none; overflow-x: auto;
  counter-reset: tbjump; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tb-jump ol::-webkit-scrollbar { display: none; }
.tb-jump li { flex: none; counter-increment: tbjump; }
.tb-jump a {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; max-width: 220px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text);
  font-size: 0.85rem; font-weight: 600; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-jump a::before { content: counter(tbjump); color: var(--muted); font-weight: 700; }

/* Sections */
.tb-sections, .tb-items { list-style: none; margin: 0; padding: 0; }
.tb-sec { margin-bottom: 14px; scroll-margin-top: 72px; }
.tb-sec:target, .tb-item:target { animation: tb-flash 1.6s ease-out; }
.tb-sec-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 8px 8px 12px; }
.tb-num {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; margin-top: 2px;
  border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: 0.9rem;
}
.tb-main { flex: 1; min-width: 0; }
.tb-sec-title { margin: 3px 0 2px; font-size: 1.05rem; overflow-wrap: anywhere; }
.tb-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; margin: 0;
  color: var(--muted); font-size: 0.82rem;
}
.tb-req {
  display: inline-block; padding: 0 8px; border-radius: 999px; background: #fbe4e1; color: var(--danger);
  font-size: 0.75rem; font-weight: 700; line-height: 1.7;
}
.tb-cat { font-weight: 600; }
.tb-instr {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  margin: 0 12px 4px 52px; color: #3d4a57; font-size: 0.875rem; line-height: 1.45;
  cursor: pointer; overflow-wrap: anywhere;
}
.tb-instr.is-open { display: block; -webkit-line-clamp: unset; }
.tb-instr.is-empty { color: var(--muted); font-style: italic; cursor: default; }

/* Move buttons */
.tb-move { flex: none; display: flex; gap: 4px; margin: 0; }
.tb-mv {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.tb-mv svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tb-mv:active { background: #eef3f9; border-color: var(--brand); }
.tb-mv:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.tb-mv[disabled] { opacity: 0.35; cursor: default; }
.tb-move.is-busy .tb-mv { opacity: 0.6; }

/* Edit toggles ("Edit section", "Edit") */
.tb-edit { margin: 0; }
.tb-edit-toggle {
  position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 0 26px 0 0;
  color: var(--brand); font-weight: 600; font-size: 0.9rem;
}
.tb-edit-toggle::after { right: 6px; width: 7px; height: 7px; border-color: var(--brand); }
.tb-sec-edit { padding: 0 12px 2px 52px; }
.tb-sec-edit[open] { padding-left: 12px; }
.tb-form {
  margin: 4px 0 12px; padding: 14px 12px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fafbfc;
}
.tb-form .btn-row { margin-top: 6px; }
.tb-form .checkbox { margin-bottom: 8px; }
.tb-types { margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.tb-type-pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tb-type-pills label { justify-content: center; padding: 8px 6px; font-size: 0.9rem; line-height: 1.2; text-align: center; }
.tb-form textarea[name=help] { min-height: 64px; }
.tb-type-hint { margin: 6px 0 0; color: var(--muted); font-size: 0.85rem; }

/* Items */
.tb-items { border-top: 1px solid var(--border); }
.tb-item { padding: 10px 8px 0 12px; border-bottom: 1px solid var(--border); scroll-margin-top: 72px; }
.tb-item:last-child { border-bottom: 0; }
.tb-row { display: flex; align-items: flex-start; gap: 10px; }
.tb-icon {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; margin-top: 2px;
  border-radius: 8px; background: #e3edf8; color: var(--info);
}
.tb-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tb-type-question .tb-icon { background: #f1e8fb; color: #6b3fa0; }
.tb-type-check .tb-icon { background: #dcf1e5; color: var(--ok); }
.tb-label { margin: 3px 0 2px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.tb-choices {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin: 3px 0 0; color: #3d4a57; font-size: 0.82rem;
}
.tb-help { margin: 3px 0 0; color: var(--muted); font-size: 0.82rem; font-style: italic; overflow-wrap: anywhere; }
.tb-item > .tb-edit { padding-left: 40px; }
.tb-item > .tb-edit[open] { padding-left: 0; }
.tb-empty { padding: 14px 16px; color: var(--muted); font-size: 0.9rem; }
.tb-no-sections { margin: 0 0 10px; }

/* Add item / add section */
.tb-add { padding: 10px 12px 0; border-top: 1px solid var(--border); background: #fbfcfd; }
.tb-add-toggle, .tb-add-sec-toggle {
  display: flex; align-items: center; justify-content: center; min-height: 48px; margin-bottom: 10px; padding: 8px 12px;
  border: 2px dashed #b9c6d4; border-radius: var(--radius-sm); color: var(--brand); font-weight: 700; text-align: center;
}
.tb-add-toggle span, .tb-add-sec-toggle span { overflow-wrap: anywhere; }
.tb-add[open] > .tb-add-toggle, .tb-add-sec[open] > .tb-add-sec-toggle { border-style: solid; border-color: var(--border); color: var(--muted); }
.tb-add-sec { padding: 12px; }
.tb-add-sec > .tb-add-sec-toggle { margin: 0; }
.tb-add-sec[open] > .tb-add-sec-toggle { margin-bottom: 10px; }
.tb-add-sec[open] > .tb-form { margin-bottom: 0; }
.tb-more { margin-top: 24px; }
.tb-more form { margin: 0; }
.tb-more .help { margin: 6px 0 14px; }
.tb-more .help:last-child { margin-bottom: 0; }

@keyframes tb-flash { 0%, 35% { box-shadow: 0 0 0 3px var(--brand); background-color: #f2f7fc; } 100% { box-shadow: none; } }
.tb-sec.tb-flash, .tb-item.tb-flash { animation: tb-flash 1.2s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .tb-sec:target, .tb-item:target, .tb-sec.tb-flash, .tb-item.tb-flash { animation: none; }
  .tb-settings-toggle::after, .tb-edit-toggle::after { transition: none; }
}
@media (min-width: 700px) {
  .tb-jump { margin-left: 0; margin-right: 0; }
  .tb-jump ol { flex-wrap: wrap; overflow: visible; padding-left: 0; padding-right: 0; }
  .tb-jump a { max-width: none; }
}
