/* ==========================================================================
   Statistics page — one design, two sizes (phone base · desktop >= 721px). Pairs with js/stats-ui.js.
   Tokens come from --m-* (mobile-redesign.css), so light/dark and the app theme are automatic.
   Scale: 11 label · 12 meta · 14 body · 16 title · 30–44 hero number · radii 14/18/22 · touch >= 44px
   ========================================================================== */
.stx { display: none; }
@media screen {
    html.stx-on .stx { display: grid; gap: 14px; min-width: 0; color: var(--m-ink); font-size: 14px; line-height: 1.6; }
    html.stx-on body #view-stats > :not(#stx):not(.manual-report-card) { display: none !important; }   /* old web/mobile stats markup stays in the DOM for printing */
    .stx :is(h2, h3, p, small, b, strong, dl, dd, dt, ul, ol, li) { margin: 0; padding: 0; min-width: 0; }
    .stx :is(ul, ol) { list-style: none; }
    .stx button { font-family: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
    .stx :focus-visible { outline: 2px solid var(--m-accent); outline-offset: 2px; }
    html.stx-on body #view-stats .manual-report-card { margin-top: 6px; }

    /* header */
    .stx-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
    .stx-title h2 { font-size: 20px; font-weight: 800; letter-spacing: -.2px; }
    .stx-title p { font-size: 12px; color: var(--m-muted); margin-top: 2px; }
    .stx-tools { display: flex; gap: 8px; flex: none; }
    .stx-icon { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--m-line); background: var(--m-surface); color: var(--m-ink); display: grid; place-items: center; transition: transform .2s var(--m-ease), background .2s; }
    .stx-icon .material-symbols-outlined { font-size: 22px; }
    .stx-icon.is-primary { background: var(--m-accent); color: var(--m-on-accent); border-color: transparent; box-shadow: 0 6px 16px color-mix(in srgb, var(--m-accent) 35%, transparent); }
    .stx-icon:active { transform: scale(.9); }

    /* range switch */
    .stx-seg { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; height: 48px; border-radius: 16px; background: var(--m-raised); border: 1px solid var(--m-line); }
    .stx-seg button { position: relative; z-index: 1; border: 0; background: transparent; color: var(--m-muted); font-size: 14px; font-weight: 700; transition: color .25s; }
    .stx-seg button[aria-pressed="true"] { color: var(--m-ink); }
    .stx-thumb { position: absolute; inset-block: 4px; inset-inline-start: 4px; width: calc((100% - 8px) / 3); border-radius: 12px; background: var(--m-surface); box-shadow: 0 2px 10px rgba(0, 0, 0, .09); transition: transform .45s var(--m-ease); }
    .stx-seg[data-i="1"] .stx-thumb { transform: translateX(-100%); }
    .stx-seg[data-i="2"] .stx-thumb { transform: translateX(-200%); }
    html[dir="ltr"] .stx-seg[data-i="1"] .stx-thumb { transform: translateX(100%); }
    html[dir="ltr"] .stx-seg[data-i="2"] .stx-thumb { transform: translateX(200%); }

    .stx-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
    .stx-card { padding: 16px; border-radius: 22px; border: 1px solid var(--m-line); background: var(--m-surface); min-width: 0; animation: stx-rise .55s var(--m-ease) both; }
    .stx-card > header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
    .stx-card h3 { font-size: 15px; font-weight: 800; }
    .stx-note { font-size: 12px; color: var(--m-muted); }
    .stx-mute { display: grid; justify-items: center; gap: 6px; padding: 18px 8px; text-align: center; color: var(--m-muted); font-size: 13px; }
    .stx-mute .material-symbols-outlined { font-size: 34px; color: var(--m-accent); opacity: .8; }
    .stx-link { border: 0; background: color-mix(in srgb, var(--m-accent) 14%, transparent); color: var(--m-accent); height: 40px; padding: 0 16px; border-radius: 12px; font-weight: 700; }

    /* hero */
    .stx-hero { position: relative; overflow: hidden; display: grid; gap: 14px; padding: 18px;
        background: linear-gradient(135deg, color-mix(in srgb, var(--m-accent) 15%, var(--m-surface)), var(--m-surface) 72%); }
    .stx-hero-main small { font-size: 12px; color: var(--m-muted); }
    .stx-big { display: flex; align-items: baseline; gap: 8px; margin-top: 2px; }
    .stx-big b { font-size: 44px; font-weight: 800; letter-spacing: -1px; line-height: 1.15; font-variant-numeric: tabular-nums; }
    .stx-big span { font-size: 15px; font-weight: 700; color: var(--m-muted); }
    .stx-delta { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; height: 28px; padding: 0 10px; border-radius: 14px; font-size: 12px; font-weight: 700; }
    .stx-delta .material-symbols-outlined { font-size: 17px; }
    .stx-delta.up { background: color-mix(in srgb, var(--m-good) 16%, transparent); color: var(--m-good); }
    .stx-delta.down { background: color-mix(in srgb, var(--m-bad) 14%, transparent); color: var(--m-bad); }
    .stx-spark { position: absolute; inset-inline-end: 0; top: 14px; width: 46%; height: 64px; opacity: .95; pointer-events: none; }
    .stx-spark .a { fill: color-mix(in srgb, var(--m-accent) 16%, transparent); stroke: none; }
    .stx-spark .l { fill: none; stroke: var(--m-accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; stroke-dasharray: 100; stroke-dashoffset: 100; animation: stx-draw 1.1s var(--m-ease) .15s forwards; }
    .stx-mini { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .stx-mini > div { padding: 10px 12px; border-radius: 14px; background: color-mix(in srgb, var(--m-ink) 5%, transparent); }
    .stx-mini dt { font-size: 11px; color: var(--m-muted); }
    .stx-mini dd { font-size: 13px; font-weight: 700; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .stx-mini dd small { display: block; font-size: 11px; font-weight: 500; color: var(--m-muted); }

    .stx-goal { margin-top: 12px; max-width: 280px; }
    .stx-goal i { display: block; height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--m-ink) 10%, transparent); overflow: hidden; position: relative; }
    .stx-goal i::after { content: ''; position: absolute; inset-block: 0; inset-inline-start: 0; width: var(--g); border-radius: 4px; background: var(--m-good); animation: stx-fill .9s var(--m-ease) .2s both; }
    .stx-goal small { display: block; margin-top: 5px; font-size: 11.5px; color: var(--m-muted); }

    /* KPIs */
    .stx-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .stx-kpi { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "ic l" "ic v"; align-items: center; column-gap: 12px; padding: 14px; border-radius: 18px; border: 1px solid var(--m-line); background: var(--m-surface); animation: stx-rise .5s var(--m-ease) both; animation-delay: calc(var(--i) * 60ms + 80ms); }
    .stx-kpi-ic { grid-area: ic; width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; background: color-mix(in srgb, var(--m-accent) 15%, transparent); color: var(--m-accent); }
    .stx-kpi.warm .stx-kpi-ic { background: color-mix(in srgb, var(--m-warn) 18%, transparent); color: var(--m-warn); }
    .stx-kpi small { grid-area: l; font-size: 11.5px; color: var(--m-muted); }
    .stx-kpi strong { grid-area: v; font-size: 16px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* trend bars */
    .stx-chart { position: relative; padding-top: 30px; }
    .stx-bars { position: relative; display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-bottom: 24px; border-bottom: 1px solid var(--m-line); z-index: 1;
        background: repeating-linear-gradient(to top, transparent 0, transparent calc(25% - 1px), color-mix(in srgb, var(--m-ink) 7%, transparent) calc(25% - 1px), color-mix(in srgb, var(--m-ink) 7%, transparent) 25%); background-size: 100% calc(100% - 24px); background-repeat: no-repeat; }
    .stx-chart.is-dense .stx-bars { gap: 3px; }
    .stx-bar { position: relative; flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; padding: 0; border: 0; background: transparent; color: var(--m-muted); }
    .stx-bar i { display: block; width: 100%; max-width: 34px; height: var(--h); min-height: 0; border-radius: 9px 9px 4px 4px; background: color-mix(in srgb, var(--m-accent) 42%, transparent); transform-origin: bottom; animation: stx-grow .7s var(--m-ease) both; animation-delay: calc(var(--i) * 35ms); transition: background .2s, filter .2s; }
    .stx-chart.is-dense .stx-bar i { border-radius: 4px 4px 2px 2px; }
    .stx-bar.is-zero i { height: 3px; background: color-mix(in srgb, var(--m-ink) 12%, transparent); }
    .stx-bar.is-best i, .stx-bar.is-today i { background: var(--m-accent); }
    .stx-bar span { position: absolute; bottom: -24px; inset-inline: -4px; text-align: center; font-size: 11px; line-height: 24px; white-space: nowrap; }
    .stx-bar.is-today span { color: var(--m-accent); font-weight: 800; }
    .stx-bar::after { content: attr(data-v); position: absolute; bottom: calc(var(--h) + 8px); left: 50%; transform: translate(-50%, 6px) scale(.9); padding: 4px 9px; border-radius: 10px; background: var(--m-ink); color: var(--m-bg); font-size: 11.5px; font-weight: 700; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .18s, transform .25s var(--m-ease); z-index: 3; }
    .stx-bar.is-on::after, .stx-bar:focus-visible::after { opacity: 1; transform: translate(-50%, 0) scale(1); }
    .stx-bar.is-on i { filter: brightness(1.12); background: var(--m-accent); }
    .stx-avg { position: absolute; inset-inline: 0; bottom: calc(24px + (100% - 24px) * var(--a)); height: 0; border-top: 1.5px dashed color-mix(in srgb, var(--m-ink) 30%, transparent); z-index: 2; pointer-events: none; }
    .stx-avg em { position: absolute; inset-inline-start: 0; top: -19px; font-style: normal; font-size: 10.5px; color: var(--m-muted); background: var(--m-surface); padding: 0 4px; }

    /* subjects */
    .stx-subj { display: grid; gap: 16px; justify-items: stretch; }
    .stx-donut { position: relative; width: 148px; height: 148px; margin-inline: auto; }
    .stx-donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
    html[dir="rtl"] .stx-donut svg { transform: rotate(-90deg) scaleY(-1); }
    .stx-donut circle { fill: none; stroke-width: 9; }
    .stx-donut .trk { stroke: color-mix(in srgb, var(--m-ink) 8%, transparent); }
    .stx-donut .seg { stroke-linecap: round; animation: stx-seg .9s var(--m-ease) both; animation-delay: calc(var(--i) * 90ms); }
    .stx-donut > div { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
    .stx-donut b { font-size: 24px; font-weight: 800; line-height: 1.1; }
    .stx-donut small { font-size: 11px; color: var(--m-muted); }
    .stx-legend { display: grid; gap: 4px; }
    .stx-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 42px; align-items: center; gap: 10px; min-height: 40px; padding: 0 4px; border-radius: 12px; animation: stx-rise .5s var(--m-ease) both; animation-delay: calc(var(--i) * 60ms + 200ms); }
    .stx-legend i { width: 12px; height: 12px; border-radius: 4px; background: var(--c); }
    .stx-legend span { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .stx-legend em { font-style: normal; font-size: 12px; color: var(--m-muted); }
    .stx-legend b { font-size: 12.5px; font-weight: 800; text-align: end; }

    /* plan adherence */
    .stx-planbox { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
    .stx-ring { position: relative; width: 104px; height: 104px; }
    .stx-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
    .stx-ring circle { fill: none; stroke-width: 7; }
    .stx-ring .t { stroke: color-mix(in srgb, var(--m-ink) 9%, transparent); }
    .stx-ring .v { stroke: var(--m-good); stroke-linecap: round; stroke-dasharray: 100; animation: stx-ring 1s var(--m-ease) .1s both; }
    .stx-ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 20px; font-weight: 800; }
    .stx-counts { display: grid; gap: 6px; }
    .stx-counts li { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--m-muted); }
    .stx-counts i { width: 9px; height: 9px; border-radius: 50%; background: color-mix(in srgb, var(--m-ink) 25%, transparent); }
    .stx-counts .ok i { background: var(--m-good); } .stx-counts .warn i { background: var(--m-warn); } .stx-counts .bad i { background: var(--m-bad); }
    .stx-counts b { margin-inline-start: auto; color: var(--m-ink); font-size: 14px; }

    /* heatmap */
    .stx-heatwrap { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: stretch; }
    .stx-wdl { display: grid; grid-template-rows: repeat(7, 1fr); gap: 4px; font-size: 10.5px; color: var(--m-muted); text-align: center; align-items: center; }
    .stx-heatgrid { display: grid; grid-template-columns: repeat(var(--w), minmax(0, 1fr)); grid-template-rows: repeat(7, auto); gap: 4px; direction: rtl; }
    .stx-heatgrid i { aspect-ratio: 1; border-radius: 6px; background: color-mix(in srgb, var(--m-ink) 7%, transparent); animation: stx-pop .5s var(--m-ease) both; animation-delay: calc(var(--i) * 14ms); }
    .stx-heatgrid .lv1, .stx-scale .lv1 { background: color-mix(in srgb, var(--m-accent) 28%, transparent); }
    .stx-heatgrid .lv2, .stx-scale .lv2 { background: color-mix(in srgb, var(--m-accent) 52%, transparent); }
    .stx-heatgrid .lv3, .stx-scale .lv3 { background: color-mix(in srgb, var(--m-accent) 76%, transparent); }
    .stx-heatgrid .lv4, .stx-scale .lv4 { background: var(--m-accent); }
    .stx-heatgrid .fut { background: transparent; border: 1px dashed color-mix(in srgb, var(--m-ink) 12%, transparent); }
    .stx-heatgrid .now { outline: 2px solid var(--m-accent); outline-offset: 1px; }
    .stx-scale { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 10px; font-size: 11px; color: var(--m-muted); }
    .stx-scale i { width: 14px; height: 14px; border-radius: 4px; }

    /* insights */
    .stx-insights ul { display: grid; gap: 8px; }
    .stx-insights li { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 10px 12px; border-radius: 14px; background: color-mix(in srgb, var(--m-ink) 4.5%, transparent); font-size: 13px; animation: stx-rise .5s var(--m-ease) both; animation-delay: calc(var(--i) * 70ms + 250ms); }
    .stx-insights li .material-symbols-outlined { font-size: 20px; color: var(--m-accent); }

    /* empty state: soften numbers, keep layout */
    .stx.is-empty .stx-hero::after { content: 'با تایمر تمرکز یا ثبت گزارش، نمودارها زنده می‌شوند.'; font-size: 12.5px; color: var(--m-muted); }

    @keyframes stx-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
    @keyframes stx-fill { from { width: 0; } }
    @keyframes stx-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
    @keyframes stx-draw { to { stroke-dashoffset: 0; } }
    @keyframes stx-seg { from { stroke-dasharray: 0 100; } }
    @keyframes stx-ring { from { stroke-dashoffset: 100; } }
    @keyframes stx-pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }
}
@media print { .stx { display: none !important; } }
@media screen and (max-width: 340px) { .stx-big b { font-size: 36px; } .stx-mini { grid-template-columns: 1fr; } }

/* ---------- Desktop / tablet ---------- */
@media screen and (min-width: 721px) {
    html.stx-on .stx { max-width: 1180px; margin-inline: auto; gap: 20px; font-size: 15px; }
    .stx-title h2 { font-size: 28px; } .stx-title p { font-size: 14px; }
    .stx-icon { width: 48px; height: 48px; }
    .stx-seg { width: 360px; height: 52px; border-radius: 18px; }
    .stx-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; align-items: stretch; }
    .stx-hero { grid-column: span 8; padding: 26px; align-content: space-between; min-height: 250px; }
    .stx-big b { font-size: 64px; } .stx-big span { font-size: 18px; }
    .stx-spark { width: 40%; height: 96px; top: 22px; }
    .stx-kpis { grid-column: span 4; grid-template-columns: 1fr 1fr; gap: 14px; align-content: stretch; }
    .stx-kpi { grid-template-columns: 1fr; grid-template-areas: "ic" "l" "v"; row-gap: 2px; padding: 16px; align-content: center; }
    .stx-kpi-ic { margin-bottom: 6px; } .stx-kpi strong { font-size: 18px; }
    .stx-trend { grid-column: span 12; padding: 22px; }
    .stx-bars { height: 220px; gap: 12px; } .stx-bar i { max-width: 46px; }
    .stx-chart.is-dense .stx-bars { gap: 5px; }
    .stx-subjects { grid-column: span 7; } .stx-plan { grid-column: span 5; }
    .stx-subj { grid-template-columns: 170px 1fr; align-items: center; gap: 26px; } .stx-donut { width: 170px; height: 170px; }
    .stx-planbox { grid-template-columns: 1fr; justify-items: center; gap: 18px; } .stx-ring { width: 128px; height: 128px; }
    .stx-counts { width: 100%; }
    .stx-heat { grid-column: span 8; } .stx-insights { grid-column: span 4; }
    .stx-card { padding: 22px; }
    .stx-card h3 { font-size: 17px; }
}
@media screen and (min-width: 721px) and (max-width: 1000px) {
    .stx-hero, .stx-kpis, .stx-subjects, .stx-plan, .stx-heat, .stx-insights { grid-column: span 12; }
    .stx-kpis { grid-template-columns: repeat(4, 1fr); } .stx-kpi { grid-template-columns: auto 1fr; grid-template-areas: "ic l" "ic v"; }
    .stx-subj { grid-template-columns: 1fr; } .stx-planbox { grid-template-columns: auto 1fr; }
}
@media screen and (hover: hover) {
    .stx-bar:hover::after { opacity: 1; transform: translate(-50%, 0) scale(1); }
    .stx-bar:hover i { background: var(--m-accent); }
    .stx-kpi, .stx-card { transition: transform .25s var(--m-ease), border-color .25s, box-shadow .25s; }
    .stx-kpi:hover, .stx-card:hover { border-color: color-mix(in srgb, var(--m-accent) 40%, var(--m-line)); }
    .stx-kpi:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(20, 12, 50, .08); }
    .stx-legend li:hover { background: color-mix(in srgb, var(--m-ink) 5%, transparent); }
    .stx-icon:hover { transform: scale(1.06); }
}
@media (prefers-reduced-motion: reduce) { .stx *, .stx *::before, .stx *::after { animation: none !important; transition-duration: .01ms !important; } }
