/* ===================================================================
   COST HISTORY — Unit Cost Library results + drill-down (cost-library.css)
   Styles for cost-library.js: the compact results head (count, "Group
   similar names", sort), division headers + paging in the results list,
   and the #costDetailModal drill-down (stat tiles, range strip, name-variant
   chips, data-point table). Design-system pass 2026-10-18: K tokens only
   (DESIGN-SYSTEM.md). Shared pieces used here (styles.css "SHARED LIST +
   CONTROL COMPONENTS"): .k-switch, .k-sort, .k-grp-row + .k-csi +
   .k-grp-count, .k-more, .k-num.
   Color jobs: ink / gray for structure and every figure; brand red for the
   one data series (your projects' dots on the range strip), selection (the
   picked name variant) and the Kinnect History source icon; the benchmark
   series is gray (§2.5), the median an ink rule.
   Scoped to #panel-cost and #costDetailModal.
   =================================================================== */

/* ----- results head: one compact row (tally · switch · quiet sort) ----- */
#panel-cost .cl-results-tools{display:flex;align-items:center;gap:16px;flex-wrap:wrap;justify-content:flex-end;min-width:0}
#panel-cost .cl-toggle,#costDetailModal .cl-toggle{display:inline-flex;align-items:center;gap:8px;font-size:12px;font-weight:500;color:var(--k-text);cursor:pointer;white-space:nowrap;user-select:none}

/* ----- results list ----- */
/* Division header = the shared group row (.k-grp-row): CSI token, name, count. */
#panel-cost .cl-div-head{display:flex;align-items:center;gap:8px;margin-top:8px;padding:7px 12px;border-radius:var(--k-r-md)}
#panel-cost .cl-div-head:first-child{margin-top:0}
#panel-cost .cl-div-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#panel-cost .cl-div-head .k-grp-count{margin-left:0}
/* One item = two short lines: name + source tags, then the facts. Both stay
   on one line (ellipsis; the full text is the tooltip) so every row is the
   same slim height. */
#panel-cost .cost-result-card{padding:9px 14px;gap:14px}
#panel-cost .cl-card-l1{display:flex;align-items:center;gap:6px;min-width:0}
#panel-cost .cl-card-l1 .cost-result-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#panel-cost .cl-card-l1 .cost-source-badge-library,#panel-cost .cl-card-l1 .cost-region-badge{flex-shrink:0;height:18px}
#panel-cost .cost-result-meta{margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#panel-cost .cost-result-meta .cl-fig{font-family:var(--k-mono);font-weight:600;color:var(--k-text);font-variant-numeric:tabular-nums}
#panel-cost .cost-result-avg{font-size:var(--k-fs-lg)}
/* Range line: the figures in mono. */
#panel-cost .cl-card-range{margin-top:2px;font-size:var(--k-fs-xs);color:var(--k-text-3);white-space:nowrap}
#panel-cost .cl-card-range .cl-fig{font-family:var(--k-mono);font-weight:500;color:var(--k-text-2);font-variant-numeric:tabular-nums}
/* "Custom group" = the outline pill. */
#panel-cost .cl-badge-custom{border-radius:var(--k-r-pill);background:var(--k-surface);box-shadow:inset 0 0 0 1px var(--k-line-strong);color:var(--k-text-2);font-family:var(--k-font);font-size:11px;font-weight:600;letter-spacing:0;padding:0 8px}
/* "Showing 60 of 120 · Show 60 more" = the shared .k-more row. */
#panel-cost .cl-more b{font-family:var(--k-mono);font-weight:700;color:var(--k-text-2);font-variant-numeric:tabular-nums}

/* ----- drill-down modal shell (.modal-xl) ----- */
/* Its own fixed layout (header / scrolling body / footer), so it opts out of
   the shared sticky header + footer; the footer still runs edge to edge. */
#costDetailModal .cl-modal{display:flex;flex-direction:column;max-height:calc(100vh - 48px);overflow:hidden}
#costDetailModal .cl-modal:focus{outline:none}
#costDetailModal .modal-header{flex:0 0 auto;gap:16px;margin-bottom:14px}
#costDetailModal .cl-modal-head{min-width:0}
#costDetailModal .cl-modal-head .modal-title{overflow-wrap:anywhere}
#costDetailModal .cl-modal-actions{display:flex;align-items:center;gap:8px;flex-shrink:0}
#costDetailModal .cl-head-actions{display:flex;gap:6px}
#costDetailModal .cl-modal-body{flex:1 1 auto;min-height:0;overflow:auto;padding:2px 2px 2px 0;margin:-2px 0 0}
#costDetailModal .modal-footer{flex:0 0 auto;margin:16px calc(-1 * var(--k-mp-x)) 0;padding:14px var(--k-mp-x) 0}

/* filter / variant notes = the neutral callout */
#costDetailModal .cl-note{display:flex;align-items:center;flex-wrap:wrap;gap:6px 8px;margin-bottom:12px;padding:8px 12px;border:1px solid var(--k-line);border-radius:var(--k-r-md);background:var(--k-fill);font-size:12px;line-height:1.5;color:var(--k-text)}
#costDetailModal .cl-note i{font-size:11px;color:var(--k-text-3)}
#costDetailModal .cl-note-plain{background:var(--k-surface);border-style:dashed;border-color:var(--k-line-strong)}
#costDetailModal .cl-linkbtn{background:none;border:none;padding:0;font:600 12px var(--k-font);color:var(--k-accent-ink);cursor:pointer}
#costDetailModal .cl-linkbtn:hover{text-decoration:underline;text-underline-offset:2px}

/* name-variant chips: the shared filter-chip geometry (.k-chip — 28px,
   radius 8) split into a filter half and a Move… half; the picked one is
   "on" (red wash, red-700 text). */
#costDetailModal .cl-variants{display:flex;align-items:center;flex-wrap:wrap;gap:6px;margin-bottom:12px}
#costDetailModal .cl-variants-label{margin-right:2px;font-size:var(--k-fs-micro);font-weight:700;letter-spacing:var(--k-ls-micro);text-transform:uppercase;color:var(--k-text-2)}
#costDetailModal .cl-chip{display:inline-flex;align-items:stretch;max-width:100%;min-height:var(--k-control-h-sm);border:1px solid var(--k-line-strong);border-radius:var(--k-r-md);background:var(--k-surface);overflow:hidden;transition:border-color .15s,background .15s}
#costDetailModal .cl-chip.on{border-color:var(--k-accent-line);background:var(--k-accent-wash)}
#costDetailModal .cl-chip-main{padding:4px 10px;border:none;background:none;font:500 12px var(--k-font);color:var(--k-text);text-align:left;cursor:pointer;overflow-wrap:anywhere;transition:background .15s,color .15s}
#costDetailModal .cl-chip-main:hover{background:var(--k-fill);color:var(--k-ink)}
#costDetailModal .cl-chip.on .cl-chip-main{color:var(--k-red-500);font-weight:600}
#costDetailModal .cl-chip.on .cl-chip-main:hover{background:transparent}
#costDetailModal .cl-chip-n{margin-left:3px;font-family:var(--k-mono);font-size:10.5px;font-weight:500;color:var(--k-text-3)}
#costDetailModal .cl-chip-pin{margin-left:3px;font-size:9px;color:var(--k-text-3)}
#costDetailModal .cl-chip-act{padding:4px 10px;border:none;border-left:1px solid var(--k-line);background:none;font:600 11.5px var(--k-font);color:var(--k-text-2);cursor:pointer;white-space:nowrap;transition:background .15s,color .15s}
#costDetailModal .cl-chip.on .cl-chip-act{border-left-color:var(--k-accent-line)}
#costDetailModal .cl-chip-act:hover{background:var(--k-fill-2);color:var(--k-ink)}
#costDetailModal .cl-chip-main:focus-visible,#costDetailModal .cl-chip-act:focus-visible{outline:none;box-shadow:inset 0 0 0 2px var(--k-accent)}
#costDetailModal .cl-linkbtn:focus-visible{outline:none;box-shadow:var(--k-focus-ring);border-radius:var(--k-r-xs)}

/* stat tiles — .cost-detail-summary / .cost-detail-stat (styles.css) */
#costDetailModal .cl-stats{margin-top:0}
#costDetailModal .cl-stats .cost-detail-stat-value.cl-low,
#costDetailModal .cl-stats .cost-detail-stat-value.cl-high{color:var(--k-text)}
#costDetailModal .cl-split{margin-top:8px;font-size:var(--k-fs-xs);line-height:1.5;color:var(--k-text-2)}
#costDetailModal .cl-split strong{font-family:var(--k-mono);font-weight:600;color:var(--k-ink)}

/* range strip: min → max track, one dot per data point.
   Your projects = red (the series), Kinnect History = hollow gray, median = ink. */
#costDetailModal .cl-range{margin:16px 0 4px;padding:0 8px}
#costDetailModal .cl-range-track{position:relative;height:22px;margin:0 2px}
#costDetailModal .cl-range-track::before{content:'';position:absolute;left:0;right:0;top:50%;height:4px;margin-top:-2px;border-radius:2px;background:var(--k-fill-2)}
#costDetailModal .cl-range-median{position:absolute;top:1px;bottom:1px;width:2px;margin-left:-1px;border-radius:1px;background:var(--k-ink)}
#costDetailModal .cl-dot{position:absolute;top:50%;width:11px;height:11px;margin:-5.5px 0 0 -5.5px;padding:0;border:2px solid var(--k-surface);border-radius:50%;background:var(--k-accent);box-shadow:0 0 0 1px var(--k-accent);cursor:pointer;transition:transform .12s,box-shadow .12s}
#costDetailModal .cl-dot.lib{background:var(--k-surface);border-color:var(--k-gray-400);box-shadow:none}
#costDetailModal .cl-dot:hover,#costDetailModal .cl-dot.on{z-index:2;transform:scale(1.35);box-shadow:0 0 0 1px var(--k-accent),var(--k-focus-ring)}
#costDetailModal .cl-dot.lib:hover,#costDetailModal .cl-dot.lib.on{box-shadow:var(--k-focus-ring)}
#costDetailModal .cl-dot:focus-visible{z-index:2;outline:none;box-shadow:var(--k-focus-ring)}
#costDetailModal .cl-range-axis{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:4px;font-family:var(--k-mono);font-size:var(--k-fs-micro);color:var(--k-text-3)}
#costDetailModal .cl-range-legend{display:inline-flex;align-items:center;flex-wrap:wrap;justify-content:center;gap:5px;font-family:var(--k-font);font-size:var(--k-fs-xs);color:var(--k-text-2)}
#costDetailModal .cl-key{display:inline-block;width:9px;height:9px;margin-left:8px;border-radius:50%;background:var(--k-accent)}
#costDetailModal .cl-key.lib{background:var(--k-surface);box-shadow:inset 0 0 0 2px var(--k-gray-400)}
#costDetailModal .cl-key-med{display:inline-block;width:2px;height:10px;margin-left:8px;background:var(--k-ink)}

/* table toolbar: switch · quiet sort (.k-sort) · row tally */
#costDetailModal .cl-toolbar{display:flex;align-items:center;gap:16px;flex-wrap:wrap;margin:14px 0 8px}
#costDetailModal .cl-rowcount{margin-left:auto;font-size:12px;color:var(--k-text-2);white-space:nowrap}
#costDetailModal .cl-rowcount b{font-family:var(--k-mono);font-weight:700;color:var(--k-ink);font-variant-numeric:tabular-nums}

/* data-point table: the product table in its wrapper (1px line, radius 12).
   A long list scrolls inside the wrapper with the header pinned, like the
   other window tables (AI Estimate, Cost Extraction review). */
#costDetailModal .cl-table-wrap{max-height:48vh;overflow:auto;border:1px solid var(--k-line);border-radius:var(--k-r-lg)}
#costDetailModal .cl-table{margin:0;min-width:920px;width:100%;display:table;white-space:normal} /* opt out of styles.css's mobile .tbl{display:block;nowrap} — cells must wrap, the wrapper scrolls */
#costDetailModal .cl-table th{position:sticky;top:0;z-index:1;white-space:nowrap}
#costDetailModal .cl-table td{vertical-align:top}
/* K CORE left-aligns every .tbl header (body .tbl thead th): figure columns keep theirs right, in the UI font. */
#costDetailModal .cl-table th.k-num{text-align:right;font-family:var(--k-font)}
#costDetailModal td.cl-rate{font-weight:700;color:var(--k-ink)}
#costDetailModal .cl-date{font-family:var(--k-mono);font-size:var(--k-fs-xs);color:var(--k-text-2);white-space:nowrap}
#costDetailModal .cl-proj{font-weight:700;color:var(--k-ink)}
#costDetailModal .cl-sub{margin-top:2px;font-size:var(--k-fs-xs);line-height:1.4;color:var(--k-text-3)}
#costDetailModal .cl-c-proj{min-width:160px;max-width:220px;overflow-wrap:anywhere}
#costDetailModal .cl-c-name{min-width:150px;max-width:220px;overflow-wrap:anywhere}
#costDetailModal .cl-c-src{min-width:110px;max-width:180px}
#costDetailModal .cl-file{overflow-wrap:anywhere}
#costDetailModal .cl-c-notes{min-width:180px;max-width:300px;white-space:pre-wrap;overflow-wrap:anywhere;font-size:var(--k-fs-xs);color:var(--k-text-2)}
/* the row picked on the range strip = the selected row (--k-sel). Selection
   is a wash, never a red edge — that mark means "needs attention". */
#costDetailModal .cl-table tbody tr.cl-hi td{background:var(--k-sel) !important}
#costDetailModal .cl-table tbody tr.cl-zero td{opacity:0.6}

/* phones */
@media (max-width:640px){
  #panel-cost .cl-results-tools{justify-content:flex-start}
  /* phones: the price drops under the item instead of squeezing it */
  #panel-cost .cost-result-card{flex-direction:column;align-items:stretch;gap:8px}
  #panel-cost .cost-result-price{display:flex;align-items:baseline;flex-wrap:wrap;gap:4px 12px;text-align:left}
  #panel-cost .cost-result-price .cl-card-range{margin-top:0}
  #costDetailModal .cl-modal-actions{flex-wrap:wrap;justify-content:flex-end}
  #costDetailModal .cl-range-legend{display:none}
}

/* SF items that read as per SF of floor (2026-10-24): the note above the
   results and the review dialog that marks them GSF. */
#panel-cost .cl-floor-note{margin:0 0 10px}
.cl-floor-modal{display:flex;flex-direction:column;max-height:86vh}
.cl-floor-body{flex:1 1 auto;min-height:0;overflow:auto}
.cl-floor-intro{margin:0 0 12px;font-size:var(--k-fs-sm);line-height:1.55;color:var(--k-text)}
.cl-floor-wrap{max-height:50vh;overflow:auto;border:1px solid var(--k-line);border-radius:var(--k-r-md)}
.cl-floor-tbl{width:100%}
.cl-floor-tbl .cl-floor-ck{width:36px;text-align:center}
.cl-floor-tbl .cl-mono{font-family:var(--k-mono);font-variant-numeric:tabular-nums;white-space:nowrap}
#addUnitCostModal .uc-unit-hint{margin:-6px 0 14px}
