/* ============================================================
   Clinical — the new look for Hall audits (#/hall-audits), the Tag
   heat map (#/survey-heatmap) and the Daily Standup landing's saved
   list and summary (#/admin-meeting). All three render in rebuild.js.
   Loads after ivy-refresh.css and uses its tokens (--card, --line,
   --teal, --danger, --warn, --ok, --fg, --muted ...). Every selector
   is scoped under .cln (or .cln-ha for the hall audit sheet, which
   opens in the shared modal), so other screens are untouched. The
   few values the refresh does not name are tokens below; the screen
   code carries no colors.
   ============================================================ */

:root {
  --cln-heat-2: color-mix(in srgb, var(--danger) 9%, var(--card));
  --cln-heat-3: color-mix(in srgb, var(--danger) 17%, var(--card));
  --cln-heat-4: color-mix(in srgb, var(--danger) 27%, var(--card));
}

/* ---------- page frame ---------- */
.cln { display: flex; flex-direction: column; gap: 16px; min-width: 0; color: var(--fg); }
.cln :is(h1, h2, h3) { font-family: var(--font-display); letter-spacing: -0.01em; margin: 0; }
.cln-i { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: inline-block; vertical-align: -2px; }
.cln .cln-muted { color: var(--muted); }

.cln-head { display: flex; align-items: flex-end; gap: 12px 16px; flex-wrap: wrap; }
.cln-head-text { flex: 1 1 420px; min-width: 0; }
.cln-eyebrow { margin: 0 0 4px; }
.cln-sub { margin: 6px 0 0; max-width: 78ch; }
.cln-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- buttons ---------- */
.cln .cln-btn { gap: 7px; box-shadow: var(--shadow-sm); }
.cln .cln-btn:hover { background: var(--surface-hover); }
.cln .cln-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.cln .cln-btn-primary { background: var(--teal); border-color: var(--teal); color: var(--on-solid); }
.cln .cln-btn-primary:hover { background: var(--teal-deep); border-color: var(--teal-deep); }

/* ---------- status: icon + word + color ---------- */
.cln-status { align-items: center; white-space: nowrap; color: var(--muted); }
.cln-status .cln-i { width: 13px; height: 13px; }
.cln-status.is-critical { color: var(--danger-ink); }
.cln-status.is-warning { color: var(--warn-ink); }
.cln-status.is-success { color: var(--ok-ink); }
.cln-status.is-info { color: var(--teal-deep); }

/* ---------- KPI strip ---------- */
.cln-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; box-shadow: var(--shadow-sm); }
.cln-kpi { display: flex; flex-direction: column; gap: 3px; background: var(--card); min-width: 0; }
.cln-kpi-label { display: flex; align-items: center; gap: 7px; }
.cln-kpi-label::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--line); flex: none; }
.cln-kpi.is-critical .cln-kpi-label::before { background: var(--danger); }
.cln-kpi.is-warning .cln-kpi-label::before { background: var(--warn); }
.cln-kpi.is-success .cln-kpi-label::before { background: var(--ok); }
.cln-kpi-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cln-kpi-value small { font-size: var(--fs-md); font-weight: 600; color: var(--muted); letter-spacing: 0; }
.cln-kpi.is-critical .cln-kpi-value { color: var(--danger-ink); }
.cln-kpi-foot { font-size: var(--fs-sm); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- cards, main + rail ---------- */
.cln-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.cln-rail { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cln-card { padding: 16px 18px 18px; min-width: 0; }
.cln-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 14px; }
.cln-card-head h2 { font-size: var(--fs-lg); font-weight: 700; }
.cln-card-sub { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.cln-note h3 { font-size: var(--fs-lead); font-weight: 700; margin-bottom: 6px; }
.cln-note p { margin: 0; font-size: var(--fs-base); color: var(--fg-soft); line-height: 1.5; }
.cln-empty span { max-width: 46ch; }

/* ---------- Tag heat map ---------- */
.cln .cln-heat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.cln .cln-heat-cell { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 11px 12px 10px; min-height: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); text-align: left; font: inherit; cursor: pointer; box-shadow: none; transform: none; transition: border-color 120ms, box-shadow 120ms; }
.cln .cln-heat-cell:hover { border-color: var(--danger); box-shadow: var(--shadow-sm); transform: none; }
.cln .cln-heat-cell:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.cln .cln-heat-cell.is-l2 { background: var(--cln-heat-2); border-color: var(--danger-line); }
.cln .cln-heat-cell.is-l3 { background: var(--cln-heat-3); border-color: var(--danger-line); }
.cln .cln-heat-cell.is-l4 { background: var(--cln-heat-4); border-color: var(--danger); }
.cln-heat-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.cln .cln-heat-tag { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 750; color: var(--fg); letter-spacing: -0.01em; }
.cln .cln-heat-name { font-size: var(--fs-sm); color: var(--fg-soft); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cln-heat-bar { display: block; height: 4px; border-radius: 999px; background: var(--surface-sunk); overflow: hidden; margin-top: auto; }
.cln-heat-bar i { display: block; height: 100%; border-radius: inherit; background: var(--danger); }
.cln-legend { display: flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--muted); }
.cln-legend span { display: inline-flex; align-items: center; gap: 4px; }
.cln-legend i { width: 14px; height: 10px; border-radius: 3px; border: 1px solid var(--line); background: var(--card); }
.cln-legend i.is-l2 { background: var(--cln-heat-2); border-color: var(--danger-line); }
.cln-legend i.is-l3 { background: var(--cln-heat-3); border-color: var(--danger-line); }
.cln-legend i.is-l4 { background: var(--cln-heat-4); border-color: var(--danger); }

/* survey history timeline */
.cln-tl { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cln-tl-item { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.cln-tl-item:first-child { border-top: 0; padding-top: 0; }
.cln-tl-dot { width: 26px; height: 26px; border-radius: 999px; background: var(--teal-soft); color: var(--teal); display: grid; place-items: center; }
.cln-tl-dot .cln-i { width: 13px; height: 13px; }
.cln-tl-top { display: flex; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; font-size: var(--fs-base); }
.cln-tl-fine { margin-left: auto; font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.cln-tl-fine.has-fine { color: var(--fg); font-weight: 650; }
.cln-tagrow { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.cln .cln-tagchip { border: 1px solid var(--line); background: var(--card); color: var(--fg); font: inherit; cursor: pointer; }
.cln .cln-tagchip:hover { border-color: var(--teal); color: var(--teal-deep); }
.cln .cln-tagchip.is-repeat { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger-ink); }
.cln-tagmore { font-size: var(--fs-xs); color: var(--muted); align-self: center; padding: 0 3px; }

/* live history: source line, filters, worst-letter chip, harm edges, drill-down */
.cln-heat .cln-source .cln-i { color: var(--teal); }
.cln-heat .cln-source[data-heat-source="offline"] .cln-i { color: var(--warn); }
.cln-heat-filters { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.cln-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; background: var(--card); padding: 2px; max-width: 100%; overflow-x: auto; }
.cln .cln-seg-btn { border: 0; background: transparent; color: var(--fg-soft); font: inherit; font-size: var(--fs-sm); font-weight: 600; padding: 6px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap; box-shadow: none; min-height: 32px; }
.cln .cln-seg-btn:hover { color: var(--fg); background: var(--surface-hover); }
.cln .cln-seg-btn[aria-pressed="true"] { background: var(--teal-soft); color: var(--teal-deep); }
.cln .cln-seg-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
.cln-sev { display: inline-grid; place-items: center; min-width: 24px; height: 22px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--fg-soft); font-size: var(--fs-sm); font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1; flex: none; }
.cln-sev.is-sm { min-width: 20px; height: 19px; font-size: var(--fs-xs); padding: 0 5px; }
.cln-sev.is-none { color: var(--muted); font-weight: 600; }
.cln-sev.is-harm { border-color: var(--danger); color: var(--danger-ink); background: var(--danger-soft); }
.cln-sev.is-ij { border-color: var(--danger); background: var(--danger); color: var(--on-solid); }
.cln .cln-heat-cell.is-harm { box-shadow: inset 3px 0 0 var(--danger); }
.cln .cln-heat-cell.is-ij { box-shadow: inset 6px 0 0 var(--danger); border-color: var(--danger); }
.cln .cln-heat-cell.is-open { outline: 2px solid var(--teal); outline-offset: 1px; }
.cln-heat-foot { display: flex; align-items: center; justify-content: space-between; gap: 4px 8px; flex-wrap: wrap; min-width: 0; }
.cln-heat-where { font-size: var(--fs-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.cln-legend i.is-harm { box-shadow: inset 3px 0 0 var(--danger); }
.cln-legend i.is-ij { box-shadow: inset 6px 0 0 var(--danger); border-color: var(--danger); }
.cln-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cln-heat-drill { border-color: var(--teal); scroll-margin-top: 80px; }
.cln-drill { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cln-drill-row { padding: 10px 0; border-top: 1px solid var(--line-soft); min-width: 0; }
.cln-drill-row:first-child { border-top: 0; padding-top: 0; }
.cln-drill-top { display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; font-size: var(--fs-base); }
.cln-drill-text { margin: 5px 0 0; font-size: var(--fs-sm); color: var(--fg-soft); line-height: 1.5; overflow-wrap: anywhere; }
.cln-drill-chains { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line-soft); min-width: 0; }
.cln-drill-chain { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cln-drill-chain > .cln-muted { font-size: var(--fs-xs); }
.cln-drill-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.cln-tl-top .cln-sev { align-self: center; }
.cln-tl-meta { font-size: var(--fs-sm); margin-top: 2px; }

/* ---------- Hall audits ---------- */
.cln .cln-hall-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.cln .cln-hall { display: flex; flex-direction: column; gap: 10px; padding: 14px 14px 12px; border: 1px solid var(--line); border-left: 3px solid var(--ok); border-radius: 10px; background: var(--card); box-shadow: none; min-width: 0; }
.cln .cln-hall.is-warning { border-left-color: var(--warn); }
.cln .cln-hall.is-critical { border-left-color: var(--danger); }
.cln-hall-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.cln-hall-head h3 { font-size: var(--fs-lg); font-weight: 700; }
.cln-hall-head .cln-muted { font-size: var(--fs-sm); }
.cln-hall-last { display: flex; flex-direction: column; gap: 6px; margin: 0; font-size: var(--fs-sm); color: var(--fg-soft); }
.cln-progress { display: block; height: 5px; border-radius: 999px; background: var(--surface-sunk); overflow: hidden; }
.cln-progress i { display: block; height: 100%; background: var(--teal); border-radius: inherit; }
.cln-hall-facts { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.cln .cln-hall-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.cln-checks { margin: 0; padding: 0 0 0 20px; display: grid; gap: 6px; font-size: var(--fs-base); color: var(--fg-soft); }
.cln-checks li::marker { color: var(--muted); font-size: var(--fs-sm); }
/* where the halls came from ("From the PCC 72-hour report, Oct 16") */
.cln-source { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--fg-soft); font-size: var(--fs-sm); max-width: 100%; align-self: flex-start; }
.cln-source .cln-i { width: 14px; height: 14px; color: var(--teal); flex: none; }
.cln-source[data-hall-source="roster"] .cln-i { color: var(--warn); }
.cln-note-line { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line-soft); font-size: var(--fs-sm); color: var(--muted); }

/* the hall audit sheet (opens in the shared modal) */
.cln-ha .ha-detail-head h2 { font-family: var(--font-display); font-weight: 700; }
.cln-ha-legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.cln-ha-legend .ha-tri { width: 22px; height: 22px; display: inline-grid; place-items: center; cursor: default; }
.cln-ha .ha-table-wrap { border-color: var(--line); border-radius: 10px; -webkit-overflow-scrolling: touch; }
.cln-ha .ha-table th { background: var(--surface-sunk); color: var(--fg-soft); border-bottom-color: var(--line); }
.cln-ha .ha-table td { border-bottom-color: var(--line-soft); }
.cln-ha .ha-table .cln-ha-res { position: sticky; left: 0; z-index: 1; background: var(--card); box-shadow: 1px 0 0 var(--line); min-width: 130px; }
.cln-ha .ha-table th.cln-ha-res { background: var(--surface-sunk); z-index: 2; }
.cln-ha .ha-tri { border-radius: 6px; }
.cln-ha .ha-table .ha-cell { white-space: nowrap; min-width: 66px; }
.cln-ha .ha-tri.is-pass { background: var(--ok-soft); color: var(--ok-ink); border-color: var(--ok); }
.cln-ha .ha-tri.is-fail { background: var(--danger-soft); color: var(--danger-ink); border-color: var(--danger); }
.cln-ha .ha-detail-foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 12px; }

/* ---------- Daily Standup landing: saved stand-ups ---------- */
.cln-saved { list-style: none; margin: 0; padding: 0; }
.cln-saved-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(130px, 0.9fr) minmax(0, 1fr) auto; align-items: center; gap: 8px 14px; padding: 10px 0; border-top: 1px solid var(--line-soft); font-size: var(--fs-base); }
.cln-saved-row:first-child { border-top: 0; padding-top: 2px; }
.cln-saved-main { display: flex; flex-direction: column; min-width: 0; }
.cln-saved-main .cln-muted { font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cln-saved-facts { display: flex; gap: 4px 12px; flex-wrap: wrap; color: var(--fg-soft); font-variant-numeric: tabular-nums; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .cln-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .cln-head-actions, .cln-head-actions .cln-btn { width: 100%; }
  .cln-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cln-kpi { padding: 11px 12px 12px; }
  .cln-kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .cln-kpi-value { font-size: var(--fs-3xl); }
  .cln-kpi-foot { white-space: normal; }
  .cln-card { padding: 14px; }
  .cln .cln-heat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cln .cln-heat-cell { padding: 10px; }
  .cln-heat-top { gap: 4px; }
  .cln-heat-filters, .cln-seg { width: 100%; }
  .cln .cln-seg-btn { flex: 1 1 auto; }
  .cln-drill-actions .cln-btn { flex: 1 1 auto; justify-content: center; }
  .cln .cln-hall-grid { grid-template-columns: minmax(0, 1fr); }
  .cln .cln-hall-actions .cln-btn { flex: 1 1 auto; }
  .cln-saved-row { grid-template-columns: minmax(0, 1fr) auto; }
  .cln-saved-state { grid-column: 1; grid-row: 2; }
  .cln-saved-facts { grid-column: 1 / -1; grid-row: 3; font-size: var(--fs-sm); }
  .cln-saved-row .cln-btn { grid-column: 2; grid-row: 1 / span 2; }
  .cln-ha .ha-detail-foot .button { flex: 1 1 auto; }
}
