/* Charts for reports (bars, lines, donut, ranked bars) and the per-client report page.
   Colors come from the app tokens so light and dark both work; a report can set --report-brand to its own accent.
   Every rule starts with #app so it wins over the older shared sheets; class names avoid the suffixes those sheets grab. */

#app { --rcx-accent: var(--report-brand, var(--km2-accent, #147d64)); --rcx-purple: #8b6bd0; }

/* ---- tones ---- */
#app .rcx-t-accent { fill: var(--rcx-accent); background: var(--rcx-accent); }
#app .rcx-t-blue   { fill: var(--km2-blue, #2679ed); background: var(--km2-blue, #2679ed); }
#app .rcx-t-amber  { fill: var(--km2-warning, #d99118); background: var(--km2-warning, #d99118); }
#app .rcx-t-red    { fill: var(--km2-danger, #c34d48); background: var(--km2-danger, #c34d48); }
#app .rcx-t-green  { fill: var(--km2-success, #147d64); background: var(--km2-success, #147d64); }
#app .rcx-t-gray   { fill: var(--km2-border-strong, #c9d6d1); background: var(--km2-border-strong, #c9d6d1); }
#app .rcx-t-purple { fill: var(--rcx-purple); background: var(--rcx-purple); }
#app .rcx-s-accent { stroke: var(--rcx-accent); }
#app .rcx-s-blue   { stroke: var(--km2-blue, #2679ed); }
#app .rcx-s-amber  { stroke: var(--km2-warning, #d99118); }
#app .rcx-s-red    { stroke: var(--km2-danger, #c34d48); }
#app .rcx-s-green  { stroke: var(--km2-success, #147d64); }
#app .rcx-s-gray   { stroke: var(--km2-border-strong, #c9d6d1); }
#app .rcx-s-purple { stroke: var(--rcx-purple); }

/* ---- a chart ---- */
#app .rcx-fig { margin: 0; padding: 10px 12px 8px; border: 1px solid var(--km2-border, #dce5e1); border-radius: 10px; background: var(--km2-surface, #fff); min-width: 0; break-inside: avoid; }
#app .rcx-cap { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; justify-content: space-between; font-size: .86rem; color: var(--km2-text, #16231e); margin-bottom: 4px; }
#app .rcx-legend { display: inline-flex; gap: 10px; font-size: .74rem; color: var(--km2-muted, #687871); }
#app .rcx-key { display: inline-flex; align-items: center; gap: 4px; }
#app .rcx-sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; flex: none; }
#app .rcx-svg { display: block; width: 100%; height: auto; }
#app .rcx-grid { stroke: var(--km2-border, #e3ebe7); stroke-width: 1; }
#app .rcx-axis { stroke: var(--km2-border-strong, #c9d6d1); stroke-width: 1; }
#app .rcx-tick, #app .rcx-cat { fill: var(--km2-muted, #687871); font-size: 10px; }
#app .rcx-val { fill: var(--km2-text, #16231e); font-size: 9.5px; }
#app .rcx-line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
#app .rcx-none { margin: 8px 0 4px; color: var(--km2-muted, #687871); font-size: .85rem; }

/* donut */
#app .rcx-donut { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
#app .rcx-ring { width: 128px; height: 128px; flex: none; }
#app .rcx-track { fill: none; stroke: var(--km2-border, #e3ebe7); stroke-width: 20; }
#app .rcx-slice { fill: none; stroke-width: 20; }
#app .rcx-center { fill: var(--km2-text, #16231e); font-size: 11px; font-weight: 700; }
#app .rcx-sub { fill: var(--km2-muted, #687871); font-size: 7.5px; letter-spacing: .06em; text-transform: uppercase; }
#app .rcx-rows { list-style: none; margin: 0; padding: 0; flex: 1 1 170px; min-width: 0; display: grid; gap: 4px; font-size: .8rem; }
#app .rcx-rows li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 36px; align-items: center; gap: 6px; }
#app .rcx-rows .rcx-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--km2-text, #16231e); }
#app .rcx-rows b { font-variant-numeric: tabular-nums; }
#app .rcx-rows em { font-style: normal; color: var(--km2-muted, #687871); text-align: right; font-size: .74rem; }

/* ranked bars */
#app .rcx-hbars { list-style: none; margin: 4px 0 2px; padding: 0; display: grid; gap: 7px; font-size: .8rem; }
#app .rcx-hbars li { display: grid; grid-template-columns: minmax(70px, 34%) minmax(0, 1fr) auto; align-items: center; gap: 8px; }
#app .rcx-hbars .rcx-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#app .rcx-track-h { height: 8px; border-radius: 4px; background: var(--km2-border, #e3ebe7); overflow: hidden; }
#app .rcx-track-h i { display: block; height: 100%; border-radius: 4px; }
#app .rcx-hbars b { font-variant-numeric: tabular-nums; }

/* ---- the per-client report page ---- */
#app .crp-page { --rcx-accent: var(--report-brand, var(--km2-accent, #147d64)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
#app .crp-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#app .crp-bar .crp-grow { flex: 1 1 260px; display: flex; gap: 6px; align-items: center; font-size: .85rem; white-space: nowrap; min-width: 0; }
#app .crp-bar .crp-grow select { flex: 1 1 auto; min-width: 0; max-width: 340px; }
#app .app-layout:not(.mfg-shell) .page-content .crp-brand { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 10px; color: #fff !important; background: var(--rcx-accent) !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
#app .app-layout:not(.mfg-shell) .page-content .crp-brand strong, #app .app-layout:not(.mfg-shell) .page-content .crp-brand span { color: #fff !important; }
#app .crp-brand img { height: 34px; width: auto; border-radius: 4px; background: rgba(255,255,255,.9); padding: 2px; }
#app .crp-brand strong { font-size: 1.05rem; display: block; }
#app .crp-brand span { font-size: .8rem; opacity: .92; }
#app .crp-intro { margin: 0; color: var(--km2-text, #16231e); font-size: .92rem; line-height: 1.5; }
#app .crp-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; border: 1px solid var(--km2-border, #dce5e1); border-radius: 10px; overflow: hidden; background: var(--km2-surface, #fff); }
#app .crp-strip > div { padding: 9px 14px; border-right: 1px solid var(--km2-border, #dce5e1); min-width: 0; }
#app .crp-strip > div:last-child { border-right: 0; }
#app .crp-strip b { display: block; font-size: 1.12rem; font-variant-numeric: tabular-nums; color: var(--km2-text, #16231e); }
#app .crp-strip small { color: var(--km2-muted, #687871); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
#app .crp-good { margin: 0; padding: 10px 14px 10px 30px; border-left: 4px solid var(--rcx-accent); border-radius: 6px; background: color-mix(in srgb, var(--rcx-accent) 9%, transparent); font-size: .88rem; line-height: 1.5; }
#app .crp-sec { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
#app .crp-sec > h2 { margin: 6px 0 0; font-size: 1rem; padding-bottom: 5px; border-bottom: 2px solid var(--rcx-accent); color: var(--km2-text, #16231e); }
#app .crp-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
#app .crp-tbl { width: 100%; min-width: 0; border-collapse: collapse; font-size: .84rem; }
#app .crp-tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: #fff; background: var(--rcx-accent); padding: 6px 8px; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
#app .crp-tbl td { padding: 6px 8px; border-bottom: 1px solid var(--km2-border, #e3ebe7); }
#app .crp-tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
#app .crp-tbl tr.crp-total td { font-weight: 700; background: color-mix(in srgb, var(--rcx-accent) 11%, transparent); border-top: 2px solid var(--rcx-accent); }
#app .crp-late { color: var(--km2-danger, #c34d48); font-weight: 600; }
#app .crp-foot { margin: 0; color: var(--km2-muted, #687871); font-size: .76rem; }
#app .crp-custom { border: 1px solid var(--km2-border, #dce5e1); border-radius: 10px; padding: 8px 12px; background: var(--km2-surface, #fff); }
#app .crp-custom summary { cursor: pointer; font-weight: 600; font-size: .88rem; }
#app .crp-form { display: grid; gap: 8px; margin-top: 10px; }
#app .crp-form label { display: grid; gap: 3px; font-size: .8rem; }
#app .crp-form .crp-checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 4px 14px; }
#app .crp-form .crp-checks label { display: flex; align-items: center; gap: 6px; }

@media (max-width: 760px) {
  #app .crp-2 { grid-template-columns: minmax(0, 1fr); }
  #app .crp-tbl { font-size: .72rem; table-layout: fixed; width: 100%; max-width: 100%; }
  #app .crp-tbl th { font-size: .6rem; letter-spacing: 0; }
  #app .crp-tbl th, #app .crp-tbl td { padding: 5px 3px; overflow-wrap: anywhere; }
  #app .crp-tbl td.num, #app .crp-tbl th.num { white-space: nowrap; }
  #app .crp-tbl .crp-sm-hide { display: none; }
  #app .crp-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media print {
  #app .crp-noprint { display: none !important; }
  #app .crp-page { gap: 10px; }
  #app .rcx-fig, #app .crp-sec, #app .crp-strip { break-inside: avoid; }
  #app .rcx-fig *, #app .crp-brand, #app .crp-tbl th, #app .crp-tbl tr.crp-total td, #app .crp-good { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  #app .crp-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
