/* ============================================================================
   Library — modal + modern UI primitives.
   Centered modal shell rendered into #lib-modal via htmx, plus polish for
   the existing card / table / hero primitives on the Library surface.
   ============================================================================ */

.lib-modal-mount:empty { display: none; }

body.lib-modal-open { overflow: hidden; }

.lib-modal {
  position: fixed; inset: 0;
  z-index: 1080;
  display: flex; align-items: flex-start; justify-content: center;
  padding: max(48px, 6vh) 16px 16px;
  animation: lib-modal-in .18s ease-out;
}
.lib-modal[hidden] { display: none; }
.lib-modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(11,14,23,.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.lib-modal__card {
  position: relative;
  width: min(900px, 100%);
  max-height: calc(100vh - 96px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex; flex-direction: column;
  animation: lib-modal-card-in .22s cubic-bezier(.2,.8,.2,1);
}
.lib-modal--sm .lib-modal__card { width: min(480px, 100%); }
.lib-modal--md .lib-modal__card { width: min(680px, 100%); }
.lib-modal--lg .lib-modal__card { width: min(900px, 100%); }
.lib-modal--xl .lib-modal__card { width: min(1040px, 100%); }
.lib-modal__head {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elev-2) 0%, var(--surface) 100%);
}
.lib-modal__title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin: 4px 0 2px;
  letter-spacing: -0.01em;
}
.lib-modal__subtitle { font-size: .9rem; color: var(--text-subtle); }
.lib-modal__close {
  appearance: none;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 32px; height: 32px;
  line-height: 1;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.lib-modal__close:hover {
  background: var(--err-50);
  border-color: var(--err);
  color: var(--err);
}
.lib-modal__body { padding: 20px 24px 22px; overflow-y: auto; }
.lib-modal__foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev-2);
}

@keyframes lib-modal-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes lib-modal-card-in {
  from { opacity: 0; transform: translateY(6px) scale(.985); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* ── Sticky in-form save bar ─────────────────────────────────────────── */
.lib-savebar {
  position: sticky; bottom: 0;
  margin: 16px -1px -1px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end; align-items: center;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.lib-savebar__hint { flex: 1; font-size: .85rem; color: var(--text-subtle); }

/* ── Grouped-type inline editor (library/_editor.html + row partials) ─── */
.lib-editor-form { padding-bottom: 12px; }

/* Group-details block above the items. */
.lib-editor-section { margin-bottom: 8px; }
.lib-editor-section__head { margin-bottom: 14px; }
.lib-editor-section__title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  letter-spacing: -.01em;
  margin: 0 0 2px;
}
.lib-editor-section__hint { font-size: .85rem; color: var(--text-subtle); margin: 0; }

.lib-editor {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.lib-editor__bar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.lib-editor__title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  margin: 0;
  letter-spacing: -.01em;
}
.lib-editor__rows {
  display: flex; flex-direction: column; gap: 12px;
  counter-reset: librow;
}
.lib-editor__row {
  position: relative;
  display: flex; align-items: flex-start; gap: 14px;
  padding: 16px 16px 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition: border-color .12s, box-shadow .12s;
}
.lib-editor__row:not(.d-none) { counter-increment: librow; }
.lib-editor__row:hover { border-color: var(--border-strong); }
.lib-editor__row:focus-within {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}
/* Auto-numbered badge (re-flows when a row is hidden/removed). */
.lib-editor__num {
  flex: 0 0 auto;
  width: 26px; height: 26px; margin-top: 2px;
  border-radius: 999px;
  background: var(--brand-50);
  color: var(--brand);
  font-size: .8rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; justify-content: center;
}
.lib-editor__num::before { content: counter(librow); }
.lib-editor__row-body { flex: 1 1 auto; min-width: 0; }
.lib-editor__grid { display: grid; gap: 0 14px; }
.lib-editor__grid--2 { grid-template-columns: 1fr 1fr; }
.lib-editor__grid--3 { grid-template-columns: repeat(3, 1fr); }
.lib-editor__grid--name-status { grid-template-columns: 1fr 170px; }
@media (max-width: 720px) {
  .lib-editor__grid--2,
  .lib-editor__grid--3,
  .lib-editor__grid--name-status { grid-template-columns: 1fr; }
}
.lib-editor__remove {
  appearance: none; flex: 0 0 auto;
  width: 30px; height: 30px; line-height: 1;
  font-size: 20px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.lib-editor__remove:hover {
  background: var(--err-50); border-color: var(--err); color: var(--err);
}

/* Empty-state doubles as an "add first row" drop-zone button. */
.lib-editor__empty {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 26px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text-subtle);
  font-size: .92rem;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.lib-editor__empty:hover {
  border-color: var(--brand);
  background: var(--brand-50);
  color: var(--brand);
}
.lib-editor__empty-plus {
  width: 24px; height: 24px; flex: 0 0 auto;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid currentColor;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; line-height: 1;
}

/* Compact field label inside a row. */
.form-label--sm {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-subtle);
  margin-bottom: .25rem;
}
.lib-field--ok    .form-label--sm { color: var(--ok); }
.lib-field--warn  .form-label--sm { color: var(--gold-600, var(--gold)); }
.lib-field--bad   .form-label--sm { color: var(--err); }
.lib-field--muted .form-label--sm { color: var(--text-muted); }

/* Stance picker — segmented, colour-coded chips (RadioSelect).
   The widget renders an outer <div> (which also picks up .form-check-input
   from the bootstrap mixin) wrapping one <div> per option; reset that box and
   lay the options out as a chip row. */
.lib-stance > div,
.lib-stance > ul {
  display: flex; flex-wrap: wrap; gap: 8px;
  list-style: none; margin: 0; padding: 0;
  width: auto; height: auto; min-height: 0;
  border: 0; background: none; box-shadow: none; appearance: none;
}
.lib-stance > div > div,
.lib-stance > ul > li { margin: 0; }
.lib-stance label {
  display: inline-flex; align-items: center; gap: 7px;
  margin: 0; padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: .85rem; font-weight: 500;
  cursor: pointer;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.lib-stance label:hover { border-color: var(--border-strong); }
.lib-stance input { accent-color: var(--brand); cursor: pointer; margin: 0; }
.lib-stance label:has(input[value="acceptable"]:checked) {
  border-color: var(--ok); background: var(--ok-50);
  box-shadow: inset 0 0 0 1px var(--ok);
}
.lib-stance label:has(input[value="negotiable"]:checked) {
  border-color: var(--gold, #b8860b); background: var(--gold-50);
  box-shadow: inset 0 0 0 1px var(--gold, #b8860b);
}
.lib-stance label:has(input[value="unacceptable"]:checked) {
  border-color: var(--err); background: var(--err-50);
  box-shadow: inset 0 0 0 1px var(--err);
}

/* ── Per-item permissions modal (library/_permission_modal.html) ───── */
.perm-section + .perm-section { margin-top: 22px; }
.perm-section__title {
  font-size: .72rem; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-subtle);
  margin: 0 0 10px;
}
.perm-grants {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.perm-grant {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .12s, background .12s;
}
.perm-grant:hover { border-color: var(--border-strong); background: var(--bg-elev); }
.perm-grant__who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.perm-grant__id { display: flex; flex-direction: column; min-width: 0; }
.perm-grant__name {
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.perm-grant__meta {
  font-size: .76rem; color: var(--text-subtle);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.perm-grant .pill { flex: 0 0 auto; }
.perm-grant__revoke { margin: 0; flex: 0 0 auto; }
.perm-grant__revoke-btn {
  appearance: none; cursor: pointer;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 4px 11px; font-size: .8rem; font-weight: 500;
  color: var(--text-muted);
  transition: background .12s, border-color .12s, color .12s;
}
.perm-grant__revoke-btn:hover,
.perm-grant__revoke-btn:focus-visible {
  background: var(--err-50); border-color: var(--err); color: var(--err);
  outline: none;
}

.perm-empty {
  padding: 18px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text-subtle);
  font-size: .88rem;
  text-align: center;
}

.perm-add {
  display: grid;
  grid-template-columns: minmax(7rem, .8fr) minmax(0, 2fr) minmax(6rem, .7fr) auto;
  gap: 10px; align-items: end;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
.perm-add__field { display: flex; flex-direction: column; gap: 4px; margin: 0; min-width: 0; }
.perm-add__label {
  font-size: .72rem; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; color: var(--text-subtle);
}
.perm-add__submit { white-space: nowrap; }
.perm-hint { font-size: .8rem; color: var(--text-subtle); margin: 10px 2px 0; }

@media (max-width: 560px) {
  .perm-add { grid-template-columns: 1fr 1fr; }
  .perm-add__field--grow, .perm-add__submit { grid-column: 1 / -1; }
}

/* ── Scope chooser: 3-way access picker + scalable team picker ──────── */
.lib-scope__opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.lib-scope__opt {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  flex: 1 1 0;
  min-width: 9rem;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.lib-scope__opt:hover {
  border-color: var(--brand-100);
  background: var(--bg-elev);
}
.lib-scope__opt:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand);
}
.lib-scope__opt:focus-within {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.lib-scope__opt input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: none;
  accent-color: var(--brand);
  cursor: pointer;
}
.lib-scope__opt-text { font-size: .92rem; font-weight: 500; color: var(--text); }

.lib-scope__target { margin-top: 10px; }
.lib-scope__target[hidden] { display: none; }
.lib-scope__target .form-label {
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Team multi-select (checkbox chips) under "My team". */
.lib-scope__teams {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.lib-scope__team {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.lib-scope__team:hover {
  border-color: var(--brand-100);
  background: var(--bg-elev);
}
.lib-scope__team:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand);
}
.lib-scope__team:focus-within {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.lib-scope__team input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: none;
  accent-color: var(--brand);
  cursor: pointer;
}
.lib-scope__team-text { font-size: .9rem; font-weight: 500; color: var(--text); }

/* ── Two-pane prompt editor: write + live preview ────────────────────── */
.lib-prompt-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}
.lib-prompt-editor__pane {
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.lib-prompt-editor__pane-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.lib-prompt-editor__pane-head .grow { flex: 1; }
.lib-prompt-editor__textarea {
  flex: 1; border: 0; resize: vertical;
  min-height: 360px;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: .92rem; line-height: 1.55;
  background: transparent; outline: none; color: var(--text);
}
.lib-prompt-editor__textarea:focus { background: var(--bg-elev-2); }
.lib-prompt-editor__preview {
  flex: 1;
  padding: 16px 18px;
  overflow-y: auto;
  max-height: 60vh;
  background: var(--bg-elev);
}
.lib-prompt-editor__preview h1,
.lib-prompt-editor__preview h2,
.lib-prompt-editor__preview h3 { font-family: var(--font-serif); }
.lib-prompt-editor__preview code {
  background: var(--bg-elev-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .88em;
}
.lib-prompt-editor__preview pre {
  background: var(--surface-ink);
  color: #d3d7e7;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.lib-prompt-editor__preview pre code { background: transparent; padding: 0; color: inherit; }
.lib-prompt-editor__preview blockquote {
  border-left: 3px solid var(--brand);
  margin: 0; padding: 6px 14px;
  color: var(--text-muted);
  background: var(--brand-50);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.lib-prompt-editor__empty {
  color: var(--text-faint);
  font-style: italic;
  padding: 24px 0;
  text-align: center;
}

@media (max-width: 920px) {
  .lib-prompt-editor { grid-template-columns: 1fr; }
  .lib-prompt-editor__preview { max-height: 40vh; }
}

/* ── Sticky detail-page header ───────────────────────────────────────── */
.lib-detail-head {
  position: sticky; top: 0;
  z-index: 5;
  background: linear-gradient(180deg, var(--bg) 70%, transparent 100%);
  padding: 14px 0 12px;
  margin-bottom: 16px;
}
.lib-detail-head__row {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.lib-detail-head__title {
  font-family: var(--font-serif);
  font-size: 1.85rem;
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 4px 0 4px;
}
.lib-detail-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Right-aligned surface switcher ──────────────────────────────────── */
/* Stack the switcher over the "+ New" button so the create action sits on
   its own line beneath the dropdown (Knowledge Files / Templates show only
   the switcher, so they are unaffected). */
.lib-detail-head__actions--stack {
  flex-direction: column; align-items: flex-end;
}
.lib-surface-switch__toggle {
  display: inline-flex; align-items: center; gap: 6px;
}
.lib-surface-switch__caret {
  flex: none; transition: transform .15s;
}
.lib-surface-switch__toggle[aria-expanded="true"] .lib-surface-switch__caret { transform: rotate(180deg); }
.lib-surface-switch__menu { min-width: 230px; }
.lib-surface-switch__menu .dropdown-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.lib-surface-switch__menu .dropdown-item.active {
  background: var(--brand-50, #eef2ff);
  color: var(--brand-700, #4338ca);
  font-weight: 600;
}

/* ── Table polish ────────────────────────────────────────────────────── */
.data-table__table tbody tr { transition: background .12s; }
.data-table__table tbody tr:hover { background: var(--brand-50); }
.data-table__th {
  position: sticky; top: 0;
  background: var(--bg-elev-2);
  z-index: 1;
}
.data-table__empty .empty-state__inner { padding: 36px 16px; }

/* ── Quick-action tiles on home ──────────────────────────────────────── */
.lib-quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.lib-quick-tile {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: all .18s;
}
.lib-quick-tile:hover {
  border-color: var(--brand-100);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  background: var(--bg-elev);
}
.lib-quick-tile__icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  background: var(--brand-50);
  color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
}
.lib-quick-tile__title { font-weight: 600; }
.lib-quick-tile__meta { font-size: .82rem; color: var(--text-subtle); }

/* ── Stats strip ─────────────────────────────────────────────────────── */
/* Tight, polished strip — borrows the .spec-grid rhythm from app.css
   (caps label, modest value). Reads as a quiet meta row, not eight hero
   stats. Hover is restrained: tinted icon + brand border, no lift. */
.lib-stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  margin-bottom: 24px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.lib-stat-card {
  background: var(--bg-elev);
  padding: 12px 14px;
  display: flex; gap: 10px; align-items: center;
  text-decoration: none;
  color: inherit;
  transition: background .15s;
  min-width: 0;
}
.lib-stat-card:hover {
  background: var(--bg-elev-2);
  color: inherit;
}
.lib-stat-card:hover .lib-stat-card__icon {
  background: var(--brand);
  color: #fff;
}
.lib-stat-card__icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-50);
  color: var(--brand);
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.lib-stat-card__icon svg { width: 14px; height: 14px; }
.lib-stat-card__body { min-width: 0; line-height: 1.15; }
.lib-stat-card__value {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.005em;
  color: var(--text);
}
.lib-stat-card__label {
  margin-top: 1px;
  font-size: .68rem;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Recently-added rows: tighten meta, match site doc-row sizing ───── */
.lib-recent-row.doc-row {
  text-decoration: none;
  color: inherit;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.lib-recent-row.doc-row:hover { background: var(--bg-elev-2); }
.lib-recent-row .doc-row__title {
  font-size: .95rem;
  font-weight: 500;
}
.lib-recent-row .doc-row__meta {
  font-size: .82rem;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}
.lib-recent-row .doc-row__meta .pill { font-size: .7rem; }
.lib-recent-row .doc-row__right { font-size: .8rem; }

/* Per-type icon tint so the feed is scannable by colour, not just label. */
.lib-recent-row--files       .doc-row__icon { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand); }
.lib-recent-row--clauses     .doc-row__icon { background: var(--info-50);  border-color: transparent; color: var(--info); }
.lib-recent-row--websites    .doc-row__icon { background: var(--ok-50);    border-color: transparent; color: var(--ok); }
.lib-recent-row--prompts     .doc-row__icon { background: var(--gold-50);  border-color: transparent; color: var(--gold-600); }
.lib-recent-row--question_sets .doc-row__icon { background: var(--info-50); border-color: transparent; color: var(--info); }

/* ── Tag chip helper ─────────────────────────────────────────────────── */
.lib-tag-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.lib-tag-chips .pill { font-size: .72rem; }

/* ── Improve-prompt tool cluster ─────────────────────────────────────── */
.lib-tool-cluster { display: inline-flex; gap: 6px; align-items: center; }
.lib-tool-cluster .text-subtle.small { margin-right: 4px; }

/* ── Overview: headline KPI cards (live inside the hero) ─────────────── */
/* Rendered as the hero's `hero__stats` row, so they sit on the fuchsia
   gradient. Give them a solid surface fill so they read as cards, plus a
   per-card accent rail to turn four grey boxes into a scannable dashboard. */
.lib-kpi-grid.hero__stats {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 0;
}
.lib-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.lib-kpi {
  position: relative;
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
/* Accent rail + tinted icon — cycles brand / info / ok / gold across the row. */
.lib-kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--brand);
}
.lib-kpi--1::before { background: var(--brand); }
.lib-kpi--2::before { background: var(--info); }
.lib-kpi--3::before { background: var(--ok); }
.lib-kpi--4::before { background: var(--gold); }
.lib-kpi--2 .lib-kpi__icon { background: var(--info-50);  color: var(--info); }
.lib-kpi--3 .lib-kpi__icon { background: var(--ok-50);    color: var(--ok); }
.lib-kpi--4 .lib-kpi__icon { background: var(--gold-50);  color: var(--gold-600); }
.lib-kpi__icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--brand-50);
  color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.lib-kpi__icon svg { width: 18px; height: 18px; }
.lib-kpi__body { min-width: 0; line-height: 1.2; }
.lib-kpi__value {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.75rem;
  letter-spacing: -.018em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.lib-kpi__label {
  margin-top: 2px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
  color: var(--text-subtle);
}
.lib-kpi__hint { margin-top: 3px; font-size: .8rem; color: var(--text-muted); }

/* ── Overview: two-column board (recent items + activity feed) ───────── */
.lib-board {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px 24px;
  align-items: start;
}
@media (min-width: 992px) {
  .lib-board { grid-template-columns: 1fr 1fr; }
}
.lib-board__col { min-width: 0; }

/* ── Overview: activity feed rows ────────────────────────────────────── */
.lib-activity-row {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.lib-activity-row:last-child { border-bottom: 0; }
.lib-activity-row__dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 6px; flex-shrink: 0;
  background: var(--text-subtle);
}
.lib-activity-row__dot--create,
.lib-activity-row__dot--upload   { background: var(--ok); }
.lib-activity-row__dot--update,
.lib-activity-row__dot--move,
.lib-activity-row__dot--status_change { background: var(--info); }
.lib-activity-row__dot--delete,
.lib-activity-row__dot--permission_revoke { background: var(--err); }
.lib-activity-row__dot--permission_grant  { background: var(--brand); }
.lib-activity-row__body { min-width: 0; flex: 1 1 auto; }
.lib-activity-row__line {
  font-size: .9rem;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.lib-activity-row__line .pill { font-size: .68rem; }
.lib-activity-row__summary {
  margin-top: 2px;
  font-size: .82rem;
  color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lib-activity-row__when {
  font-size: .78rem;
  color: var(--text-subtle);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Folder browser (Knowledge Files + Templates) ─────────────────────── */
.lib-folders { margin: 0 0 18px; }
.lib-folders__crumbs {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  padding: 4px 0 12px; font-size: .9rem;
}
.lib-folders__crumb { color: var(--brand); text-decoration: none; font-weight: 500; }
.lib-folders__crumb:hover { text-decoration: underline; }
.lib-folders__crumb.is-current { color: var(--text); font-weight: 600; }
.lib-folders__sep { color: var(--text-muted); }
.lib-folders__actions {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: auto; flex-wrap: wrap;
}
.lib-folders__iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text-muted);
  cursor: pointer; transition: all .15s;
}
.lib-folders__iconbtn:hover {
  border-color: var(--brand-100); background: var(--bg-elev); color: var(--brand);
}
/* Labeled toolbar buttons (Upload file / New folder) */
.lib-folders__btn {
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.lib-folders__btn svg { flex: none; }

/* Leading file-type icon on Knowledge Files / Templates name cells, so file
   rows read like the folder rows above them. */
.cell-file { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.cell-fileicon {
  color: var(--text-muted); display: inline-flex; flex: 0 0 auto;
}
.cell-fileicon svg { width: 18px; height: 18px; }

/* Folder rows rendered inside the file table (one unified explorer list) */
.lib-folders__row { cursor: pointer; }
.lib-folders__row td { vertical-align: middle; }
.lib-folders__col-name { white-space: nowrap; }
.lib-folders__link {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text); max-width: 100%;
}
.lib-folders__icon { color: var(--brand); display: inline-flex; flex: none; }
.lib-folders__icon svg { width: 20px; height: 20px; }
.lib-folders__name {
  font-weight: 600; font-size: .92rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lib-folders__rest-inner {
  display: flex; align-items: center; gap: 16px; width: 100%;
}
.lib-folders__meta { font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
/* Settled indexing state — a files-style coloured dot + label. */
.lib-folders__index { display: inline-flex; align-items: center; }
.lib-folders__settled { display: inline-flex; align-items: center; gap: 6px; }
.lib-folders__dot {
  width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto;
  background: var(--text-disabled, #cbd5e1);
}
.lib-folders__dot[data-state="indexed"] { background: #16a34a; }
.lib-folders__dot[data-state="staging"] { background: #2563eb; }
.lib-folders__dot[data-state="queued"]  { background: #d97706; }
.lib-folders__dot[data-state="failed"]  { background: #dc2626; }
.lib-folders__dot[data-state="excluded"]{ background: #9ca3af; }
/* In-flight bar — indicative only, kept narrow (≤ a column's worth). */
.lib-folders__progress {
  display: inline-flex; align-items: center; gap: 8px;
  width: 120px; flex: 0 0 auto;
}
.lib-folders__progress .progress { flex: 1; background: var(--bg-elev-2); }
.lib-folders__pct { font-size: .72rem; color: var(--text-muted); flex: none; }

@media (max-width: 640px) {
  .lib-folders__actions { width: 100%; margin-left: 0; }
}
