/* PathKEY — the library pages (question sets, scorings, report sections).
 * This sheet holds what the three pages share, then the Question sets page.
 * Role tokens only (docs/foundation-api.md §3). */

/* ================================================== shared by the libraries === */
.lib-filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.lib-filterbar > .input-wrap { flex: 0 1 300px; min-width: min(100%, 220px); }
.lib-filterbar > .select { width: auto; max-width: 100%; min-height: var(--h-sm); padding-top: 4px; padding-bottom: 4px; font-size: var(--fs-12); }
.lib-count { margin: 0; font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-muted); }
.lib-count .btn-link { font-size: inherit; }
.lib-filter-tools { margin-left: auto; display: flex; gap: var(--sp-1); }

.lib-link { color: var(--text-link); font-weight: var(--fw-medium); text-decoration: none; border-radius: var(--r-4); }
.lib-link:hover { text-decoration: underline; color: var(--accent-pressed); }
.lib-used { font-size: var(--fs-12); color: var(--text-2); }
.lib-used .lib-link { font-weight: var(--fw-medium); }

/* how strongly a statement counts (scorecard.strengthMark): the strength
 * control's three bars in teal, the word, and the arrow only for "lowers it" */
.smark { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-12); line-height: var(--lh-12); font-weight: var(--fw-medium); color: var(--text-2); white-space: nowrap; }
.smark .bars[data-level="1"] i:nth-child(-n + 1), .smark .bars[data-level="2"] i:nth-child(-n + 2), .smark .bars[data-level="3"] i { background: var(--accent); }
.smark-dir { display: inline-flex; color: var(--accent-text); }

/* what a search found, in every library list */
.sets-page mark, .sc-page mark, .sections-page mark { background: var(--highlight-soft); color: inherit; border-radius: 2px; box-shadow: 0 0 0 1px var(--highlight-soft); }

/* bare status marks with a legend (the scorings master list) */
.lib-mark { gap: 0; }
.lib-legend { display: flex; flex-wrap: wrap; gap: var(--sp-1) 10px; margin: 0; }
.lib-legend .status { font-size: var(--fs-11); color: var(--text-muted); font-weight: var(--fw-regular); gap: 6px; }

/* lists inside dialogs: what a delete changes, what blocks it */
.dlg-list { margin: var(--sp-2) 0 var(--sp-3); padding-left: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-1); font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); }
.dlg-list li::marker { color: var(--highlight); }

/* the arrival of something just created or asked for: a gold halo that fades */
@keyframes lib-arrive {
  0%   { box-shadow: 0 0 0 0 var(--highlight), var(--shadow-card); }
  30%  { box-shadow: 0 0 0 3px var(--highlight-soft), var(--shadow-card); }
  100% { box-shadow: 0 0 0 0 transparent, var(--shadow-card); }
}
.set-item.is-flash > .accordion, .sec-item.is-flash > .accordion, .sc-score.is-flash > .object-header .icon-tile {
  animation: lib-arrive calc(var(--dur-4) * 4) var(--ease) both;
}

/* library accordions: the title keeps at least 220px; chips and actions wrap under it */
.set-item > .accordion > .accordion-head, .sec-item > .accordion > .accordion-head { flex-wrap: wrap; row-gap: 0; padding-top: var(--sp-1); padding-bottom: var(--sp-1); }
.set-item .accordion-title, .sec-item .accordion-title { flex: 1 1 220px; }
.set-item .accordion-chips, .sec-item .accordion-chips { flex: 0 1 auto; }
.set-item .accordion-actions, .sec-item .accordion-actions { flex: none; margin-left: auto; }

/* a name in every language (dialogs) */
.lib-names { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--sp-3); }

/* the tags of a scoring (dialog) */
.lib-tags { display: flex; flex-direction: column; gap: var(--sp-3); }
.lib-tag-row { display: flex; flex-direction: column; gap: var(--sp-3); margin: 0; padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-card); background: var(--bg-surface); box-shadow: var(--shadow-card); min-width: 0; }
.lib-tag-top { display: flex; align-items: flex-end; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); }
.lib-tag-name { flex: 1 1 240px; max-width: 360px; }
.lib-tag-remove { margin-left: auto; }
.lib-tag-used { margin: 0; }

/* the condition builder (report-section versions and tags) */
.cond { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--line-soft); border-radius: var(--r-12); background: var(--bg-subtle); min-width: 0; }
.cond-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); min-height: var(--h-sm); }
.cond-lead { font-size: var(--fs-13); font-weight: var(--fw-semibold); color: var(--text); }
.cond-always { font-size: var(--fs-13); color: var(--text-2); }
.cond .select, .cond .input { width: auto; min-height: var(--h-sm); padding-top: 3px; padding-bottom: 3px; font-size: var(--fs-13); }
.cond-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.cond-row .cond-field { gap: 4px; }
.cond-line { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: start; gap: var(--sp-2); }
.cond-join { padding-top: 7px; text-align: right; font-size: var(--fs-11); font-weight: var(--fw-bold); letter-spacing: var(--track-eyebrow); text-transform: uppercase; color: var(--text-eyebrow); }
.cond-ctrls { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); min-width: 0; }
.cond-values { display: contents; }
.cond .cond-fact { flex: 0 0 auto; max-width: 100%; }
.cond .cond-pick { flex: 1 1 150px; min-width: 140px; max-width: min(100%, 300px); }
.cond .cond-op { flex: 0 0 auto; }
.cond-num-wrap { display: inline-flex; align-items: center; gap: 6px; }
.cond .cond-num { width: 64px; text-align: right; }
.cond-unit { font-size: var(--fs-12); color: var(--text-muted); }
.cond .cond-text { flex: 1 1 160px; }
.cond-row .field-error { padding-left: 38px; }
.cond-foot { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); }
.cond-say { flex: 1 1 280px; margin: 0; font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-2); }
.cond-say-label { margin-right: 6px; font-size: var(--fs-11); font-weight: var(--fw-bold); letter-spacing: var(--track-eyebrow); text-transform: uppercase; color: var(--text-eyebrow); }
.cond.is-fixed { align-items: flex-start; }
.cond-fixed-text { margin: 0; font-size: var(--fs-13); color: var(--text); }
.cond-fixed-text .cond-lead { margin-right: 4px; }
.cond.is-fixed .hint { margin: 0; }

/* try it with a sample respondent */
.try { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-4); border: 1px solid var(--accent-soft-2); border-radius: var(--r-12); background: var(--bg-selected-row); }
.try-title { display: flex; align-items: center; gap: 6px; margin: 0; font-size: var(--fs-11); font-weight: var(--fw-bold); letter-spacing: var(--track-eyebrow); text-transform: uppercase; color: var(--text-eyebrow); }
.try-hint { margin: 0; font-size: var(--fs-12); color: var(--text-muted); }
.try-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--sp-2) var(--sp-3); }
.try.is-empty .try-grid { display: none; }
.try-f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.try-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-12); font-weight: var(--fw-medium); color: var(--text-2); }
.try-f .input, .try-f .select { width: 100%; min-height: var(--h-sm); padding-top: 3px; padding-bottom: 3px; font-size: var(--fs-13); }
.try-result { display: flex; align-items: center; gap: var(--sp-2); margin: 0; padding-top: var(--sp-2); border-top: 1px solid var(--accent-soft-2); font-size: var(--fs-13); color: var(--text); }
.try-result .icon { flex: none; color: var(--accent); }
.ver-try, .lib-tag-try { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: var(--r-full); background: var(--bg-sunken); font-size: var(--fs-11); font-weight: var(--fw-medium); color: var(--text-muted); white-space: nowrap; }
.ver-try:empty, .lib-tag-try:empty { display: none; }
.ver-try.is-on, .lib-tag-try.is-on { background: var(--ok-soft); color: var(--ok-text); }

/* language tabs inside a dialog */
.lang-tabs { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; }
.lang-pan { display: flex; flex-direction: column; gap: var(--sp-3); }
.lang-pan .hint { margin: 0; }

/* a long list opens short: "Show 50 more" */
tr.dt-more > td { padding: var(--sp-2) var(--sp-4); background: var(--bg-subtle); text-align: left; }
.dt-more-note { margin-left: var(--sp-3); font-size: var(--fs-12); color: var(--text-muted); }

/* the import wizard (question sets) */
.imp-steps { padding-bottom: var(--sp-3); border-bottom: 1px solid var(--line-soft); }
.imp-panel { display: flex; flex-direction: column; gap: var(--sp-4); }
.imp-file { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); }
.imp-file-btn { cursor: pointer; }
.imp-file-btn:focus-within { box-shadow: var(--focus-ring); }
.imp-paste { min-height: 180px; }
.imp-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--sp-2); }
.imp-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-12); background: var(--bg-surface); }
.imp-col-name { font-size: var(--fs-12); font-weight: var(--fw-semibold); color: var(--text); overflow-wrap: anywhere; }
.imp-col .select { width: 100%; min-height: var(--h-sm); padding-top: 3px; padding-bottom: 3px; font-size: var(--fs-13); }
.imp-col-sample { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-12); color: var(--text-muted); }
.imp-counts { margin: 0; font-size: var(--fs-13); color: var(--text-2); }
.imp-missing { color: var(--warn-text); }
.imp-issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-12); color: var(--text-2); }
.imp-issues li { display: flex; align-items: flex-start; gap: 6px; }
.imp-issues .icon { flex: none; margin-top: 2px; color: var(--warn); }
.imp-preview { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-12); }
.imp-preview table { min-width: 560px; }
.imp-flag { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-size: var(--fs-12); color: var(--ok-text); }
.imp-flag.is-warn { color: var(--warn-text); }
.imp-flag.is-crit { color: var(--crit-text); }
.imp-dest { display: flex; flex-direction: column; gap: var(--sp-2); margin: 0; padding: 0; border: 0; min-width: 0; }
.imp-dest-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: var(--sp-3); align-items: start; }
.imp-clash { display: flex; flex-direction: column; gap: var(--sp-2); margin: 0; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-12); min-width: 0; }
.imp-summary { display: flex; flex-direction: column; gap: 4px; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--accent-soft-2); border-radius: var(--r-12); background: var(--bg-selected-row); }
.imp-summary:empty { display: none; }
.imp-sum-lead { display: flex; align-items: center; gap: var(--sp-2); margin: 0; font-size: var(--fs-14); font-weight: var(--fw-medium); color: var(--text); }
.imp-sum-lead .icon { flex: none; color: var(--accent); }
.imp-summary .hint { margin: 0; }

/* ======================================================== question sets === */
.set-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.set-item { min-width: 0; }
.set-about { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3) var(--sp-4) var(--sp-2) calc(var(--sp-4) + var(--grip-w)); font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-muted); }
.set-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1) var(--sp-2); margin: 0; }
.set-about-sep { color: var(--text-disabled); }
.set-desc { margin: 0; max-width: 84ch; color: var(--text-muted); }
.set-item .accordion-inner > .empty-state { margin: var(--sp-2) var(--sp-4) var(--sp-4); border-radius: var(--r-12); }

/* the statements of a set */
.q-wrap { border-top: 1px solid var(--line-soft); }
table.q-table { min-width: 720px; }
table.q-table .col-grip { width: 34px; padding-left: var(--sp-3); padding-right: 0; }
table.q-table .col-num { width: 44px; color: var(--text-muted); }
table.q-table .col-measures { width: 40%; }
table.q-table .col-acts { width: 1%; white-space: nowrap; }
table.q-table td { vertical-align: top; }
table.q-table td.col-grip, table.q-table td.col-acts { padding-top: 7px; }

/* the statement is the row's own control: a button that reads as text */
.stmt { display: block; width: 100%; text-align: left; font: inherit; color: var(--text); background: none; border: 0; padding: 0; cursor: pointer; border-radius: var(--r-4); text-wrap: pretty; }
.stmt:hover { color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; }
/* only what needs doing: an AI draft, the languages it is missing */
.q-notes { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); margin-top: 4px; }
/* what it counts towards: the score, then how strongly, in two aligned columns */
.measure-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 220px) max-content; gap: 4px var(--sp-4); align-items: center; }
.measure { display: contents; }
.measure-name { min-width: 0; font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text); }

/* the move arrows appear on hover or focus; a phone uses the row's ⋯ menu */
.q-acts { display: inline-flex; gap: 2px; justify-content: flex-end; opacity: 0; transition: opacity var(--dur-1) var(--ease); }
/* an arrow that cannot move the row: a faint glyph, not a filled disc in every row */
.q-acts .btn:disabled, .q-acts .btn[aria-disabled="true"] { background: transparent; }
tr:hover .q-acts, .q-acts:focus-within { opacity: 1; }
.q-menu { display: none; }
@media (hover: none) { .q-acts { opacity: 1; } }
.sets-filters > .select[data-sets-show] { display: none; }

/* a row that has just moved holds a tint for a moment */
@keyframes pk-row-flash { from { background: var(--accent-soft); } to { background: transparent; } }
tr[data-sort-item].is-moved { animation: pk-row-flash calc(var(--dur-4) * 3) var(--ease) both; }
tr[data-sort-item].is-moved > td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.accordion[data-sort-item].is-moved { animation: lib-arrive calc(var(--dur-4) * 3) var(--ease) both; }

/* the birth-data system field */
.sys-field .card-head { align-items: center; }
.sys-field .card-action { gap: var(--sp-2); }
.sys-field .card-body:empty { display: none; }
.sys-field .card-head { border-bottom: 0; }

/* phone: a statement is a card — statement first, then what it counts towards */
@media screen and (max-width: 767px) {
  .lib-filter-tools { margin-left: 0; }
  .lib-filterbar > .input-wrap { flex: 1 1 100%; }
  .lib-filterbar > .select { flex: 1 1 150px; }
  /* a view filter too wide for a phone scrolls sideways; the question sets' four choices become a select */
  .lib-filterbar > .segmented { flex: 0 1 auto; }
  .sets-filters > .segmented { display: none; }
  .sets-filters > .select[data-sets-show] { display: block; flex: 1 1 100%; }
  .health-sum .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .health-row { grid-template-columns: auto minmax(0, 1fr); }
  .health-row > .btn { grid-column: 2; justify-self: start; }
  .cond-line { grid-template-columns: 26px minmax(0, 1fr) auto; }
  .cond .cond-pick { flex-basis: 100%; max-width: 100%; }
  .cond-row .field-error { padding-left: 0; }
  /* a report section keeps its ⋯ beside its name; the status goes under */
  .sec-item .accordion-title { flex: 1 1 0; }
  .sec-item .accordion-actions { order: 2; }
  .sec-item .accordion-chips { order: 3; flex: 1 0 100%; padding: 0 0 var(--sp-2) calc(var(--grip-w) + var(--sp-2)); }
  /* the birth-data card: its tag and About go under the text */
  .sys-field .card-head { display: grid; grid-template-columns: 32px minmax(0, 1fr); align-items: start; }
  .sys-field .card-action { grid-column: 2; }
  .set-about { padding-left: var(--sp-4); }
  .set-about-sep { display: none; }
  .set-meta .lib-used { flex-basis: 100%; }
  table.q-table { min-width: 0; }
  table.q-table thead { display: none; }
  table.q-table, table.q-table tbody { display: block; }
  table.q-table tr { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "grip stmt acts" ". measures measures"; gap: var(--sp-2); padding: var(--sp-3) var(--sp-2); border-bottom: 1px solid var(--line-soft); }
  table.q-table td { display: block; padding: 0; border: 0; width: auto; }
  table.q-table td.col-grip { grid-area: grip; }
  table.q-table td.col-num { display: none; }
  table.q-table td.col-stmt { grid-area: stmt; }
  table.q-table td.col-measures { grid-area: measures; width: auto; }
  table.q-table td.col-acts { grid-area: acts; padding-top: 0; }
  table.q-table tr.dt-more { display: block; padding: 0; }
  table.q-table tr.dt-more > td { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); padding: var(--sp-3) var(--sp-4); }
  table.q-table tr.dt-more .dt-more-note { flex-basis: 100%; margin-left: 0; }
  .q-acts { display: none; }
  .q-menu { display: inline-flex; margin-top: -4px; }
  .measure-list { grid-template-columns: minmax(0, 1fr) max-content; }
}
@media (prefers-reduced-motion: reduce) {
  tr[data-sort-item].is-moved, .accordion[data-sort-item].is-moved,
  .set-item.is-flash > .accordion, .sec-item.is-flash > .accordion, .sc-score.is-flash > .object-header .icon-tile { animation: none; }
}
