/* =============================================================================
   Cloodle – Raportit (tiedolla johtaminen): stat tiles, server-rendered HTML charts,
   progress meters, status badges. CSP forbids style="" attributes, so proportions come
   from the generated percentage classes at the end (.h-N height, .w-N width, .at-N left).
   Chart specs (dataviz method): bars <= 24px with 4px rounded data end and square
   baseline, hairline recessive grid, single series = no legend, selective value labels,
   hover/focus tooltip, every chart has a table view.
   ============================================================================= */

:root {
    --viz-series: #0b57a4;
    --viz-series-soft: #c9dcf1;
    --viz-grid: #e3e8ef;
    --viz-axis: #4b5563;
    --st-stop: #b42318;
    --st-warn: #e0a100;
    --st-ok: #0b57a4;
    --st-done: #136f3a;
    --st-none: #8a96a6;
}
[data-bs-theme="dark"] {
    --viz-series: #3d8bdc;
    --viz-series-soft: #1d3554;
    --viz-grid: #2a3440;
    --viz-axis: #aab4c0;
    --st-stop: #e5534b;
    --st-warn: #c99419;
    --st-ok: #3d8bdc;
    --st-done: #2e9e5e;
    --st-none: #66768a;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.report-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); margin-bottom: 1rem; }
.report-card { background: var(--cl-surface); border: 1px solid var(--cl-border); border-radius: var(--cl-radius); padding: 1rem 1.1rem; min-width: 0; }
.report-card > h2, .report-card > h3 { font-size: 1.08rem; margin: 0 0 .15rem; }
.report-card .sub { color: var(--cl-muted); font-size: .86rem; margin: 0 0 .75rem; }
.report-filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
.report-filters .form-label { font-size: .85rem; margin-bottom: .2rem; }
.report-filters .form-select, .report-filters .form-control { min-width: 11rem; }
.report-note { font-size: .88rem; color: var(--cl-muted); }

/* KPI tiles */
.kpi-tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); margin-bottom: 1rem; }
.kpi { background: var(--cl-surface); border: 1px solid var(--cl-border); border-radius: var(--cl-radius); padding: .8rem 1rem; }
.kpi .kpi-label { font-size: .85rem; color: var(--cl-muted); margin: 0; }
.kpi .kpi-value { font-size: 1.75rem; font-weight: 650; line-height: 1.15; margin: .1rem 0 0; }
.kpi .kpi-unit { font-size: .95rem; font-weight: 500; color: var(--cl-muted); margin-left: .2rem; }
.kpi .kpi-foot { font-size: .8rem; color: var(--cl-muted); margin: .2rem 0 0; }
.kpi a { text-decoration: none; }
.kpi a:hover { text-decoration: underline; }
.kpi.kpi-alert { border-left: 4px solid var(--st-stop); }
.kpi.kpi-warn { border-left: 4px solid var(--st-warn); }

/* ── Column chart (single series) ─────────────────────────────────────────── */
.vchart { margin: 0; }
.vchart-plot { position: relative; display: grid; grid-template-columns: 2.25rem minmax(0, 1fr); gap: .35rem; }
.vchart-y { position: relative; height: 10rem; font-size: .72rem; color: var(--viz-axis); font-variant-numeric: tabular-nums; }
.vchart-y span { position: absolute; right: 0; transform: translateY(50%); line-height: 1; }
.vchart-y .y-top { bottom: 100%; }
.vchart-y .y-mid { bottom: 50%; }
.vchart-y .y-zero { bottom: 0; }
.vchart-area { position: relative; height: 10rem; border-bottom: 1px solid var(--viz-axis); }
.vchart-area::before, .vchart-area::after { content: ""; position: absolute; left: 0; right: 0; border-top: 1px solid var(--viz-grid); }
.vchart-area::before { top: 0; }
.vchart-area::after { top: 50%; }
.vchart-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.vchart-col { position: relative; flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; outline: none; z-index: 1; }
.vchart-bar { display: block; width: 100%; max-width: 24px; min-height: 0; background: var(--viz-series); border-radius: 4px 4px 0 0; transition: filter .12s; }
.vchart-bar.is-zero { min-height: 0; height: 0; }
.vchart-col:hover .vchart-bar, .vchart-col:focus-visible .vchart-bar { filter: brightness(1.18); }
.vchart-col:focus-visible { box-shadow: 0 0 0 3px var(--cl-focus); border-radius: 4px; }
.vchart-val { font-size: .72rem; font-weight: 650; color: var(--cl-ink); line-height: 1; margin-bottom: .2rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vchart-x { display: grid; grid-template-columns: 2.25rem minmax(0, 1fr); gap: .35rem; margin-top: .3rem; }
.vchart-x ol { list-style: none; margin: 0; padding: 0; display: flex; gap: 2px; min-width: 0; }
/* min-width 0: a nowrap label must not widen its slot (the slots must line up with the columns above);
   flex centring lets a label wider than its slot overflow evenly to both sides. */
.vchart-x li { flex: 1 1 0; min-width: 0; display: flex; justify-content: center; font-size: .7rem; color: var(--viz-axis); white-space: nowrap; overflow: visible; }
.vchart-x li.is-skip { visibility: hidden; }
@media (max-width: 575.98px) { .vchart-x li.is-odd { visibility: hidden; } }

/* ── Horizontal bar list (single series) ──────────────────────────────────── */
.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.hbars li { display: grid; grid-template-columns: minmax(6rem, 9rem) 1fr 3.5rem; gap: .6rem; align-items: center; font-size: .9rem; }
.hbars .hb-label { color: var(--cl-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars .hb-track { position: relative; height: 14px; }
.hbars .hb-bar { display: block; height: 100%; max-height: 24px; background: var(--viz-series); border-radius: 0 4px 4px 0; min-width: 0; }
.hbars .hb-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── Status: segmented bar + legend ───────────────────────────────────────── */
.segbar { display: flex; gap: 2px; height: 28px; border-radius: 4px; overflow: hidden; margin: .25rem 0 .6rem; }
.segbar .seg { display: flex; align-items: center; padding: 0 .4rem; font-size: .78rem; font-weight: 700; white-space: nowrap; min-width: 0; border-radius: 4px; }
.seg-Pysahtynyt, .dot-Pysahtynyt { background: var(--st-stop); color: #fff; }
.seg-Huomioitava, .dot-Huomioitava { background: var(--st-warn); color: #1b1b1b; }
.seg-Etenee, .dot-Etenee { background: var(--st-ok); color: #fff; }
.seg-Suoritettu, .dot-Suoritettu { background: var(--st-done); color: #fff; }
.seg-EiAlkanut, .dot-EiAlkanut { background: var(--st-none); color: #1b1b1b; }
[data-bs-theme="dark"] .seg-Etenee, [data-bs-theme="dark"] .seg-Suoritettu, [data-bs-theme="dark"] .seg-Pysahtynyt { color: #0b1420; }
.seg-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem 1rem; font-size: .88rem; }
.seg-legend li { display: inline-flex; align-items: center; gap: .35rem; }
.seg-legend .dot { width: .75rem; height: .75rem; border-radius: 3px; display: inline-block; }
.seg-legend a { text-decoration: none; color: inherit; }
.seg-legend a:hover { text-decoration: underline; }

/* Status badge in tables (icon + text, never colour alone) */
.st-badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; font-weight: 650; padding: .15rem .5rem; border-radius: 1rem; white-space: nowrap; }
.st-badge.st-Pysahtynyt { background: #fde7e5; color: #8f1d14; }
.st-badge.st-Huomioitava { background: #fff1d6; color: #6b4a00; }
.st-badge.st-Etenee { background: var(--cl-primary-soft); color: var(--cl-primary-dark); }
.st-badge.st-Suoritettu { background: #e3f5ea; color: #0f5a2f; }
.st-badge.st-EiAlkanut { background: #eef1f5; color: #4b5563; }
[data-bs-theme="dark"] .st-badge.st-Pysahtynyt { background: #3b1a17; color: #ffb4ab; }
[data-bs-theme="dark"] .st-badge.st-Huomioitava { background: #3a2e12; color: #f2c45a; }
[data-bs-theme="dark"] .st-badge.st-Suoritettu { background: #143223; color: #7fdca5; }
[data-bs-theme="dark"] .st-badge.st-EiAlkanut { background: #232c37; color: #c3ccd6; }
.reasons { margin: .15rem 0 0; padding-left: 1rem; font-size: .82rem; color: var(--cl-muted); }

/* Progress meter: fill + expected-pace tick, number always printed beside it */
.meter { display: flex; align-items: center; gap: .5rem; min-width: 8rem; }
.meter-track { position: relative; flex: 1; height: 8px; border-radius: 4px; background: var(--viz-series-soft); }
.meter-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--viz-series); }
.meter-tick { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--cl-ink); border-radius: 1px; }
.meter-num { font-variant-numeric: tabular-nums; font-size: .85rem; min-width: 2.6rem; text-align: right; }

/* Tables */
.report-table { font-size: .9rem; }
.report-table td, .report-table th { vertical-align: top; }
.report-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.report-table thead th a { color: inherit; text-decoration: none; white-space: nowrap; }
.report-table thead th a:hover { text-decoration: underline; }
.report-table thead th[aria-sort] a::after { content: " ▾"; }
.report-table thead th[aria-sort="ascending"] a::after { content: " ▴"; }
.chart-table { margin-top: .6rem; font-size: .85rem; }
.chart-table summary { color: var(--bs-link-color); cursor: pointer; }
.chart-table table { margin: .5rem 0 0; }

/* Tooltip (reports.js) */
.viz-tip { position: fixed; z-index: 1080; pointer-events: none; background: var(--cl-surface); color: var(--cl-ink); border: 1px solid var(--cl-border);
           border-radius: .4rem; box-shadow: 0 .3rem 1rem rgba(16, 32, 64, .18); padding: .4rem .6rem; font-size: .82rem; max-width: 16rem; }
.viz-tip strong { display: block; font-size: .95rem; font-variant-numeric: tabular-nums; }
.viz-tip[hidden] { display: none; }

/* AI summary */
.ai-summary .prose { max-width: none; }

@media print {
    .report-filters, .site-header, .site-footer, .demo-banner, .no-print { display: none !important; }
    .report-card, .kpi { break-inside: avoid; }
}

/* ── Opettajan raportit (Progress) ────────────────────────────────────────── */
.status-counts { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .25rem .6rem; }
.status-counts li { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.key-figures dd { font-variant-numeric: tabular-nums; }
.rules-note { margin: 1.5rem 0 1rem; font-size: .9rem; }
.rules-note summary { color: var(--bs-link-color); cursor: pointer; }
.rules-note .rules-body { margin-top: .6rem; padding: .8rem 1rem; background: var(--cl-surface-2); border: 1px solid var(--cl-border); border-radius: var(--cl-radius); max-width: 60rem; }
.table-group th { background: var(--cl-surface-2); font-weight: 650; font-size: .85rem; }

/* Student × item matrix: sticky name column, compact cells, state = icon + text (never colour alone) */
.mx-wrap.mx-tall { max-height: 75vh; }
.mx-wrap:focus-visible { box-shadow: 0 0 0 3px var(--cl-focus); }
.mx-table { border-collapse: separate; border-spacing: 0; }
.mx-table thead th { position: sticky; top: 0; z-index: 2; background: var(--cl-surface); vertical-align: bottom; }
/* Topic row scrolls away vertically; only the item row sticks to the top. */
.mx-table thead tr.mx-topics th, .mx-table thead tr.mx-topics td { position: static; background: var(--cl-surface-2); font-size: .75rem; font-weight: 650;
                                                                   color: var(--cl-muted); border-left: 1px solid var(--cl-border); max-width: 1px; }
.mx-table thead tr.mx-topics .mx-sticky { position: sticky; left: 0; }
.mx-topic { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-table .mx-sticky { position: sticky; left: 0; z-index: 1; background: var(--cl-surface); min-width: 11rem; box-shadow: 1px 0 0 var(--cl-border); }
.mx-table thead .mx-sticky { z-index: 3; }
.mx-table .mx-item { text-align: center; min-width: 4.6rem; font-variant-numeric: tabular-nums; cursor: help; }
.mx-table .mx-progress .meter { min-width: 6.5rem; }
.mx-cell { text-align: center; white-space: nowrap; font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.mx-cell .bi { margin-right: .2rem; }
.mx-cell .mx-latesub { margin: 0 0 0 .2rem; font-size: .75rem; }
.mx-done { color: var(--cl-success); }
.mx-fail { color: #8f1d14; background: #fde7e5; }
.mx-wait { color: var(--cl-primary-dark); background: var(--cl-primary-soft); }
.mx-redo { color: var(--cl-warning-ink); background: #fff1d6; }
.mx-late { color: #8f1d14; background: #fde7e5; }
.mx-open { color: var(--cl-primary-dark); }
.mx-none { color: var(--cl-muted); font-weight: 400; }
[data-bs-theme="dark"] .mx-fail, [data-bs-theme="dark"] .mx-late { color: #ffb4ab; background: #3b1a17; }
[data-bs-theme="dark"] .mx-redo { background: #3a2e12; }
.mx-legend { list-style: none; margin: 0 0 .75rem; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; font-size: .85rem; color: var(--cl-muted); }
.mx-legend li { display: inline-flex; align-items: center; gap: .4rem; }
.mx-key { display: inline-flex; align-items: center; gap: .2rem; padding: .05rem .4rem; border-radius: .3rem; font-size: .8rem; font-weight: 600; border: 1px solid var(--cl-border); }
.mx-key.mx-done, .mx-key.mx-none { background: var(--cl-surface); }
@media print {
    .mx-wrap { max-height: none; overflow: visible; }
    .mx-table thead th, .mx-table .mx-sticky { position: static; }
}

/* ── Generated proportion classes ─────────────────────────────────────────── */
.h-0{height:0%}
.h-1{height:1%}
.h-2{height:2%}
.h-3{height:3%}
.h-4{height:4%}
.h-5{height:5%}
.h-6{height:6%}
.h-7{height:7%}
.h-8{height:8%}
.h-9{height:9%}
.h-10{height:10%}
.h-11{height:11%}
.h-12{height:12%}
.h-13{height:13%}
.h-14{height:14%}
.h-15{height:15%}
.h-16{height:16%}
.h-17{height:17%}
.h-18{height:18%}
.h-19{height:19%}
.h-20{height:20%}
.h-21{height:21%}
.h-22{height:22%}
.h-23{height:23%}
.h-24{height:24%}
.h-25{height:25%}
.h-26{height:26%}
.h-27{height:27%}
.h-28{height:28%}
.h-29{height:29%}
.h-30{height:30%}
.h-31{height:31%}
.h-32{height:32%}
.h-33{height:33%}
.h-34{height:34%}
.h-35{height:35%}
.h-36{height:36%}
.h-37{height:37%}
.h-38{height:38%}
.h-39{height:39%}
.h-40{height:40%}
.h-41{height:41%}
.h-42{height:42%}
.h-43{height:43%}
.h-44{height:44%}
.h-45{height:45%}
.h-46{height:46%}
.h-47{height:47%}
.h-48{height:48%}
.h-49{height:49%}
.h-50{height:50%}
.h-51{height:51%}
.h-52{height:52%}
.h-53{height:53%}
.h-54{height:54%}
.h-55{height:55%}
.h-56{height:56%}
.h-57{height:57%}
.h-58{height:58%}
.h-59{height:59%}
.h-60{height:60%}
.h-61{height:61%}
.h-62{height:62%}
.h-63{height:63%}
.h-64{height:64%}
.h-65{height:65%}
.h-66{height:66%}
.h-67{height:67%}
.h-68{height:68%}
.h-69{height:69%}
.h-70{height:70%}
.h-71{height:71%}
.h-72{height:72%}
.h-73{height:73%}
.h-74{height:74%}
.h-75{height:75%}
.h-76{height:76%}
.h-77{height:77%}
.h-78{height:78%}
.h-79{height:79%}
.h-80{height:80%}
.h-81{height:81%}
.h-82{height:82%}
.h-83{height:83%}
.h-84{height:84%}
.h-85{height:85%}
.h-86{height:86%}
.h-87{height:87%}
.h-88{height:88%}
.h-89{height:89%}
.h-90{height:90%}
.h-91{height:91%}
.h-92{height:92%}
.h-93{height:93%}
.h-94{height:94%}
.h-95{height:95%}
.h-96{height:96%}
.h-97{height:97%}
.h-98{height:98%}
.h-99{height:99%}
.h-100{height:100%}
.w-0{width:0%}
.w-1{width:1%}
.w-2{width:2%}
.w-3{width:3%}
.w-4{width:4%}
.w-5{width:5%}
.w-6{width:6%}
.w-7{width:7%}
.w-8{width:8%}
.w-9{width:9%}
.w-10{width:10%}
.w-11{width:11%}
.w-12{width:12%}
.w-13{width:13%}
.w-14{width:14%}
.w-15{width:15%}
.w-16{width:16%}
.w-17{width:17%}
.w-18{width:18%}
.w-19{width:19%}
.w-20{width:20%}
.w-21{width:21%}
.w-22{width:22%}
.w-23{width:23%}
.w-24{width:24%}
.w-25{width:25%}
.w-26{width:26%}
.w-27{width:27%}
.w-28{width:28%}
.w-29{width:29%}
.w-30{width:30%}
.w-31{width:31%}
.w-32{width:32%}
.w-33{width:33%}
.w-34{width:34%}
.w-35{width:35%}
.w-36{width:36%}
.w-37{width:37%}
.w-38{width:38%}
.w-39{width:39%}
.w-40{width:40%}
.w-41{width:41%}
.w-42{width:42%}
.w-43{width:43%}
.w-44{width:44%}
.w-45{width:45%}
.w-46{width:46%}
.w-47{width:47%}
.w-48{width:48%}
.w-49{width:49%}
.w-50{width:50%}
.w-51{width:51%}
.w-52{width:52%}
.w-53{width:53%}
.w-54{width:54%}
.w-55{width:55%}
.w-56{width:56%}
.w-57{width:57%}
.w-58{width:58%}
.w-59{width:59%}
.w-60{width:60%}
.w-61{width:61%}
.w-62{width:62%}
.w-63{width:63%}
.w-64{width:64%}
.w-65{width:65%}
.w-66{width:66%}
.w-67{width:67%}
.w-68{width:68%}
.w-69{width:69%}
.w-70{width:70%}
.w-71{width:71%}
.w-72{width:72%}
.w-73{width:73%}
.w-74{width:74%}
.w-75{width:75%}
.w-76{width:76%}
.w-77{width:77%}
.w-78{width:78%}
.w-79{width:79%}
.w-80{width:80%}
.w-81{width:81%}
.w-82{width:82%}
.w-83{width:83%}
.w-84{width:84%}
.w-85{width:85%}
.w-86{width:86%}
.w-87{width:87%}
.w-88{width:88%}
.w-89{width:89%}
.w-90{width:90%}
.w-91{width:91%}
.w-92{width:92%}
.w-93{width:93%}
.w-94{width:94%}
.w-95{width:95%}
.w-96{width:96%}
.w-97{width:97%}
.w-98{width:98%}
.w-99{width:99%}
.w-100{width:100%}
.at-0{left:0%}
.at-1{left:1%}
.at-2{left:2%}
.at-3{left:3%}
.at-4{left:4%}
.at-5{left:5%}
.at-6{left:6%}
.at-7{left:7%}
.at-8{left:8%}
.at-9{left:9%}
.at-10{left:10%}
.at-11{left:11%}
.at-12{left:12%}
.at-13{left:13%}
.at-14{left:14%}
.at-15{left:15%}
.at-16{left:16%}
.at-17{left:17%}
.at-18{left:18%}
.at-19{left:19%}
.at-20{left:20%}
.at-21{left:21%}
.at-22{left:22%}
.at-23{left:23%}
.at-24{left:24%}
.at-25{left:25%}
.at-26{left:26%}
.at-27{left:27%}
.at-28{left:28%}
.at-29{left:29%}
.at-30{left:30%}
.at-31{left:31%}
.at-32{left:32%}
.at-33{left:33%}
.at-34{left:34%}
.at-35{left:35%}
.at-36{left:36%}
.at-37{left:37%}
.at-38{left:38%}
.at-39{left:39%}
.at-40{left:40%}
.at-41{left:41%}
.at-42{left:42%}
.at-43{left:43%}
.at-44{left:44%}
.at-45{left:45%}
.at-46{left:46%}
.at-47{left:47%}
.at-48{left:48%}
.at-49{left:49%}
.at-50{left:50%}
.at-51{left:51%}
.at-52{left:52%}
.at-53{left:53%}
.at-54{left:54%}
.at-55{left:55%}
.at-56{left:56%}
.at-57{left:57%}
.at-58{left:58%}
.at-59{left:59%}
.at-60{left:60%}
.at-61{left:61%}
.at-62{left:62%}
.at-63{left:63%}
.at-64{left:64%}
.at-65{left:65%}
.at-66{left:66%}
.at-67{left:67%}
.at-68{left:68%}
.at-69{left:69%}
.at-70{left:70%}
.at-71{left:71%}
.at-72{left:72%}
.at-73{left:73%}
.at-74{left:74%}
.at-75{left:75%}
.at-76{left:76%}
.at-77{left:77%}
.at-78{left:78%}
.at-79{left:79%}
.at-80{left:80%}
.at-81{left:81%}
.at-82{left:82%}
.at-83{left:83%}
.at-84{left:84%}
.at-85{left:85%}
.at-86{left:86%}
.at-87{left:87%}
.at-88{left:88%}
.at-89{left:89%}
.at-90{left:90%}
.at-91{left:91%}
.at-92{left:92%}
.at-93{left:93%}
.at-94{left:94%}
.at-95{left:95%}
.at-96{left:96%}
.at-97{left:97%}
.at-98{left:98%}
.at-99{left:99%}
.at-100{left:100%}
