/* CFO (#/cfo, cfo.js + cfo-view.js): the building switch, one row per
   building, then one line per question that opens to its detail (chart,
   numbers, levers). Prefix cfo-. Colors and sizes from tokens only. */

.cfo { max-width: 1040px; margin: 0 auto; padding: 4px 0 40px; display: grid; gap: 16px; min-width: 0; }
.cfo-top { display: grid; gap: 2px; }
.cfo-top .ivy-lede { margin-top: 4px; font-size: var(--fs-lead); line-height: 1.45; color: var(--fg); max-width: 70ch; }
.cfo-asof { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.cfo-state { padding: 18px; border-radius: var(--r-card); background: var(--card); border: 1px solid var(--line); color: var(--fg-soft); }
.cfo-state.is-error { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger-ink); }
.cfo-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cfo-num, .cfo .num { font-variant-numeric: tabular-nums; }
.cfo .is-up { color: var(--danger-ink); }
.cfo .is-down { color: var(--ok-ink); }

/* status dot: square-ish, no glow */
.cfo-dot { width: 9px; height: 9px; border-radius: 2px; flex: none; display: inline-block; background: var(--faint); }
.cfo-dot[data-tone="bad"] { background: var(--danger); }
.cfo-dot[data-tone="warn"] { background: var(--warn); }
.cfo-dot[data-tone="ok"] { background: var(--ok); }

/* building switch */
.cfo-switch { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--card); overflow: hidden; box-shadow: var(--shadow-sm); }
.cfo-sw { display: grid; gap: 2px; padding: 10px 14px; border: 0; border-left: 1px solid var(--line); border-bottom: 3px solid transparent; background: var(--card);
  color: var(--fg); font: inherit; text-align: left; cursor: pointer; min-height: var(--ctl-h-lg); min-width: 0; }
.cfo-sw:first-child { border-left: 0; }
.cfo-sw:hover { background: var(--surface-hover); }
.cfo-sw.is-on { border-bottom-color: var(--teal); background: var(--surface-sunk); }
.cfo-sw-name { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: var(--fs-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cfo-sw small { font-size: var(--fs-xs); color: var(--fg-soft); padding-left: 17px; }
.cfo-sw:first-child small { padding-left: 0; }

/* all buildings: one row each */
.cfo-board { border: 1px solid var(--line); border-radius: var(--r-card); background: var(--card); box-shadow: var(--shadow-sm); overflow: hidden; }
.cfo-board-table { width: 100%; margin: 0; }
.cfo-board-table th, .cfo-board-table td { padding: 10px 14px; vertical-align: middle; }
.cfo-board-table thead th { font-size: var(--fs-xs); color: var(--muted); font-weight: 650; }
.cfo-board-table td { font-size: var(--fs-base); }
.cfo-board-table small { font-size: var(--fs-xs); color: var(--muted); margin-left: 1px; }
.cfo-board-table th[scope="row"] { background: none; text-transform: none; letter-spacing: 0; }
.cfo-board-table td { white-space: nowrap; }
.cfo-bname { display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: none; font: inherit; color: var(--fg); cursor: pointer; text-align: left; }
.cfo-bname span { display: grid; font-weight: 700; }
.cfo-bname small { margin: 0; font-weight: 600; font-size: var(--fs-xs); color: var(--fg-soft); }
.cfo-bname:hover span { color: var(--teal); }
.cfo-open { text-align: right; width: 1%; }

/* the questions */
.cfo-answers { display: grid; grid-template-columns: minmax(0, 1fr); border: 1px solid var(--line); border-radius: var(--r-card); background: var(--card); box-shadow: var(--shadow-sm); overflow: hidden; }
.cfo-q { min-width: 0; }
.cfo-q + .cfo-q { border-top: 1px solid var(--line); }
.cfo-q > summary, .cfo-goals > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: auto 190px minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 13px 16px; }
.cfo-q > summary::-webkit-details-marker, .cfo-goals > summary::-webkit-details-marker { display: none; }
.cfo-q > summary:hover, .cfo-goals > summary:hover { background: var(--surface-hover); }
.cfo-q[open] > summary { background: var(--surface-sunk); border-bottom: 1px solid var(--line-soft); }
.cfo-q-q { font-weight: 700; color: var(--fg); font-size: var(--fs-base); }
.cfo-q-a { color: var(--fg); font-size: var(--fs-md); line-height: 1.45; min-width: 0; }
.cfo-q-btn { justify-self: end; }
.cfo-q-chev { width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: 0 4px 4px 6px; transition: transform 0.15s; }
.cfo-q[open] > summary .cfo-q-chev, .cfo-goals[open] > summary .cfo-q-chev { transform: rotate(-135deg); margin-bottom: -2px; }
.cfo-q-body { padding: 14px 16px 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }
.cfo-q-body > *, .cfo-q-body > div > * { min-width: 0; }
.cfo-q-body p { margin: 0; font-size: var(--fs-md); line-height: 1.5; color: var(--fg); }
.cfo-sub { font-size: var(--fs-sm) !important; font-weight: 700; color: var(--fg-soft) !important; display: flex; align-items: center; gap: 8px; }
.cfo-muted { margin: 0; font-size: var(--fs-md); color: var(--fg-soft) !important; }
.cfo-note { font-size: var(--fs-sm) !important; color: var(--muted) !important; }
.cfo-missing { margin: 0; font-size: var(--fs-sm); color: var(--warn-ink); }

/* one building: the verdict */
.cfo-verdict { display: grid; gap: 8px; padding: 14px 16px; border-radius: var(--r-card); border: 1px solid var(--line); border-left: 4px solid var(--faint); background: var(--card); box-shadow: var(--shadow-sm); }
.cfo-verdict[data-tone="bad"] { border-left-color: var(--danger); }
.cfo-verdict[data-tone="warn"] { border-left-color: var(--warn); }
.cfo-verdict[data-tone="ok"] { border-left-color: var(--ok); }
.cfo-verdict-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.cfo-verdict h2 { margin: 0; display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: var(--fs-xl); color: var(--fg); }
.cfo-take { margin: 0; font-size: var(--fs-md); line-height: 1.5; color: var(--fg); }
.cfo-take small { font-size: var(--fs-xs); }

/* numbers strip inside an answer */
.cfo-kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); box-shadow: none; }
.cfo-kpis .ivy-kpi { padding: 10px 14px; }
.cfo-kpis .ivy-kpi-value { font-size: var(--fs-xl); }

/* charts */
.cfo-fig { margin: 0; display: grid; gap: 6px; min-width: 0; }
.cfo-chart { width: 100%; min-width: 0; overflow: hidden; }
.cfo-svg { display: block; }
.cfo-svg .cfo-grid { stroke: var(--line-soft); stroke-width: 1; }
.cfo-svg .cfo-grid.is-zero { stroke: var(--line); }
.cfo-svg .cfo-ax, .cfo-svg .cfo-end, .cfo-svg .cfo-target-lbl { font-family: var(--font-sans); font-size: var(--fs-2xs); fill: var(--muted); font-variant-numeric: tabular-nums; }
.cfo-svg .cfo-end { fill: var(--fg); font-weight: 700; }
.cfo-svg .cfo-target-lbl { fill: var(--danger-ink); font-weight: 700; }
.cfo-svg .cfo-ln { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.cfo-svg .cfo-ln.is-now { stroke: var(--teal); }
.cfo-svg .cfo-ln.is-ly { stroke: var(--muted); stroke-width: 1.6; stroke-dasharray: 5 4; }
.cfo-svg .cfo-pt.is-now { fill: var(--teal); }
.cfo-svg .cfo-target { stroke: var(--danger); stroke-width: 1.6; stroke-dasharray: 6 4; }
.cfo-svg .cfo-bar { fill: var(--teal); }
.cfo-svg .cfo-bar.is-ok { fill: var(--ok); }
.cfo-svg .cfo-bar.is-bad { fill: var(--warn); }
.cfo-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: var(--fs-xs); color: var(--fg-soft); }
.cfo-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cfo-legend i { display: inline-block; width: 14px; height: 3px; background: var(--teal); }
.cfo-legend i.is-ly { background: none; border-top: 2px dashed var(--muted); height: 0; }
.cfo-legend i.is-goal { background: none; border-top: 2px dashed var(--danger); height: 0; }
.cfo-legend i.is-ok { background: var(--ok); height: 10px; width: 10px; }
.cfo-legend i.is-bad { background: var(--warn); height: 10px; width: 10px; }
.cfo-legend i.is-plain { background: var(--teal); height: 10px; width: 10px; }

/* nursing hours per resident day */
.cfo-hprd { display: grid; gap: 6px; }
.cfo-hprd ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.cfo-hprd li { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "d l" ". v" ". t"; column-gap: 8px; align-items: center; padding: 10px 12px; border-left: 1px solid var(--line); font-size: var(--fs-sm); color: var(--fg-soft); }
.cfo-hprd li:first-child { border-left: 0; }
.cfo-hprd li .cfo-dot { grid-area: d; }
.cfo-hprd-l { grid-area: l; }
.cfo-hprd b { grid-area: v; font-size: var(--fs-lg); color: var(--fg); }
.cfo-hprd small { grid-area: t; font-size: var(--fs-xs); color: var(--muted); }

/* lists */
.cfo-drivers, .cfo-needs, .cfo-bylist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cfo-drivers li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: baseline; font-size: var(--fs-md); color: var(--fg); line-height: 1.45; }
.cfo-drivers li .cfo-dot, .cfo-needs li .cfo-dot { align-self: start; margin-top: 7px; }
.cfo-drivers b { font-size: var(--fs-md); text-align: right; white-space: nowrap; }
.cfo-needs li { display: flex; gap: 10px; font-size: var(--fs-md); color: var(--fg); line-height: 1.45; }
.cfo-bylist > li { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.cfo-bylist > li:first-child { padding-top: 0; border-top: 0; }

/* where to cut */
.cfo-levers { list-style: none; margin: 0; padding: 0; display: grid; }
.cfo-lever { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 6px 16px; align-items: start; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.cfo-lever:first-child { border-top: 0; padding-top: 0; }
.cfo-lever-amt { text-align: right; padding-top: 1px; }
.cfo-amt { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 750; color: var(--fg); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cfo-amt small { font-family: var(--font-sans); font-size: var(--fs-xs); font-weight: 600; color: var(--muted); margin-left: 1px; }
.cfo-amt.is-none { font-family: var(--font-sans); font-size: var(--fs-sm); font-weight: 600; color: var(--muted); }
.cfo-lever-main { display: grid; gap: 2px; min-width: 0; }
.cfo-lever-main p { margin: 0; }
.cfo-lever-title { font-weight: 700; font-size: var(--fs-md) !important; }
.cfo-lever-who { font-size: var(--fs-sm) !important; }
.cfo-owner { display: inline-block; padding: 1px 6px; border: 1px solid var(--line); border-radius: var(--r-xs); background: var(--surface-sunk); color: var(--fg-soft); font-weight: 600; font-size: var(--fs-xs); }
.cfo-lever-text { font-size: var(--fs-sm) !important; color: var(--fg-soft) !important; line-height: 1.45; }
.cfo-lever-acts { display: grid; gap: 6px; justify-items: stretch; }

/* tables */
.cfo-scroll { overflow-x: auto; }
.cfo-table { width: 100%; font-size: var(--fs-sm); }
.cfo-table th[scope="row"] { text-align: left; font-weight: 600; color: var(--fg); text-transform: none; letter-spacing: 0; font-size: var(--fs-sm); }
.cfo-table .num { text-align: right; white-space: nowrap; }
.cfo-table small { color: var(--muted); }
.cfo-more > summary { cursor: pointer; font-weight: 650; font-size: var(--fs-sm); color: var(--teal); padding: 2px 0; }
.cfo-more[open] > summary { margin-bottom: 8px; }
.cfo-more > :not(summary) + :not(summary) { margin-top: 8px; }

/* goals */
.cfo-goals { border: 1px solid var(--line); border-radius: var(--r-card); background: var(--card); box-shadow: var(--shadow-sm); overflow: hidden; }
.cfo-goals > summary { grid-template-columns: 190px minmax(0, 1fr) auto; }
.cfo-goal { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 10px; align-items: end; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.cfo-goal.is-compact { padding-top: 0; border-top: 0; }
.cfo-goal[data-cfo-dscr] { grid-template-columns: minmax(0, 220px) auto; justify-content: start; }
.cfo-goal-name { grid-column: 1 / -1; font-weight: 700; }
.cfo-goal label { display: grid; gap: 4px; font-size: var(--fs-sm); color: var(--fg-soft); min-width: 0; }
.cfo-goal input { height: var(--ctl-h); border: 1px solid var(--input-line); border-radius: var(--r-sm); padding: 0 10px; font: inherit; color: var(--fg); background: var(--card); min-width: 0; font-variant-numeric: tabular-nums; }
.cfo-goal input:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

@media (max-width: 1100px) {
  .cfo-q > summary { grid-template-columns: auto 150px minmax(0, 1fr) auto auto; }
}

@media (max-width: 720px) {
  .cfo { gap: 12px; }
  .cfo-switch { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cfo-sw { border-left: 1px solid var(--line); border-top: 1px solid var(--line); padding: 8px 12px; }
  .cfo-sw:nth-child(odd) { border-left: 0; }
  .cfo-sw:nth-child(-n+2) { border-top: 0; }

  /* the board turns into one card per building */
  .cfo-board-table thead { display: none; }
  .cfo-board-table, .cfo-board-table tbody { display: block; }
  .cfo-board-table tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
  .cfo-board-table tr:first-child { border-top: 0; }
  .cfo-board-table th, .cfo-board-table td { padding: 0; border: 0; }
  .cfo-board-table th[scope="row"] { grid-column: 1 / 3; }
  .cfo-board-table td.cfo-open { grid-column: 3; grid-row: 1; text-align: right; width: auto; }
  .cfo-board-table td[data-label] { display: grid; gap: 1px; text-align: left; font-size: var(--fs-md); }
  .cfo-board-table td[data-label]::before { content: attr(data-label); font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }

  .cfo-q > summary, .cfo-goals > summary { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "d q c" ". a a" ". b b"; gap: 4px 10px; padding: 12px 14px; }
  .cfo-q > summary > .cfo-dot { grid-area: d; }
  .cfo-q > summary .cfo-q-q { grid-area: q; }
  .cfo-q > summary .cfo-q-a { grid-area: a; }
  .cfo-q > summary .cfo-q-btn { grid-area: b; justify-self: start; margin-top: 4px; }
  .cfo-q > summary .cfo-q-chev { grid-area: c; }
  .cfo-goals > summary { grid-template-areas: "q c" "a a"; grid-template-columns: minmax(0, 1fr) auto; }
  .cfo-goals > summary .cfo-q-q { grid-area: q; }
  .cfo-goals > summary .cfo-q-a { grid-area: a; }
  .cfo-goals > summary .cfo-q-chev { grid-area: c; }
  .cfo-q-body { padding: 12px 14px 16px; }

  .cfo-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cfo-kpis .ivy-kpi { padding: 8px 10px; }
  .cfo-kpis .ivy-kpi-value { font-size: var(--fs-lg); }
  .cfo-hprd li { padding: 8px; }

  .cfo-lever { grid-template-columns: 76px minmax(0, 1fr); }
  .cfo-lever-acts { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; }
  .cfo-goal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cfo-goal button[type="submit"] { grid-column: 1 / -1; }
  .cfo-goal[data-cfo-dscr] { grid-template-columns: minmax(0, 1fr) auto; }
  .cfo-goal[data-cfo-dscr] button[type="submit"] { grid-column: auto; }
  .cfo-verdict h2 { font-size: var(--fs-lg); }
}

/* Phone: Ivy turns every .ivy-table into cards; the CFO's small number
   tables stay tables (denser), scrolling inside their box if needed. */
@media (max-width: 720px) {
  .cfo .cfo-table { display: table; width: 100%; }
  .cfo .cfo-table thead { display: table-header-group; }
  .cfo .cfo-table tbody { display: table-row-group; }
  .cfo .cfo-table tr { display: table-row; margin: 0; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
  .cfo .cfo-table th, .cfo .cfo-table td { display: table-cell; width: auto; padding: 7px 8px; border-bottom: 1px solid var(--line-soft); }
  .cfo .cfo-table td::before { content: none; }
  .cfo .cfo-table th:first-child, .cfo .cfo-table td:first-child { padding-left: 0; }
  .cfo .cfo-board-table tr { margin: 0; border-radius: 0; background: var(--card); box-shadow: none; border-left: 0; border-right: 0; border-bottom: 0; }
}
