/* ============================================================
   Stats pages — teacher/student. Используется глобально,
   т.к. в проекте CSS isolation (.razor.css) не подключён.
   ============================================================ */

/* ---- StatKpiCard ---- */

.stat-kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 120px;
}

.stat-kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-kpi-card__head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.stat-kpi-card__title {
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-light);
    letter-spacing: 0.01em;
}

.stat-kpi-card__icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-kpi-card__value {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.1;
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}

.stat-kpi-card__suffix {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-light);
    letter-spacing: normal;
}

.stat-kpi-card__hint {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

@media (max-width: 768px) {
    .stat-kpi-card {
        padding: 1rem 1.15rem;
        min-height: 100px;
    }

    .stat-kpi-card__value {
        font-size: 1.6rem;
    }
}

/* ---- PeriodSwitcher ---- */

.period-switcher {
    display: inline-flex;
    background: var(--bg-alt);
    border: 1px solid var(--border-light);
    border-radius: 100px;
    padding: 4px;
    gap: 2px;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.period-switcher::-webkit-scrollbar {
    display: none;
}

.period-switcher__btn {
    border: 0;
    background: transparent;
    color: var(--text-light);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.55rem 1.1rem;
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    min-height: 36px;
}

.period-switcher__btn:hover {
    color: var(--text);
}

.period-switcher__btn--active {
    background: var(--text);
    color: var(--bg-card);
    box-shadow: var(--shadow-sm);
}

@media (max-width: 768px) {
    .period-switcher__btn {
        min-height: 44px;
        padding: 0.6rem 1rem;
    }
}

/* ---- Stats page layout ---- */

.stats-toolbar {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 1.5rem;
}

.stats-section {
    margin-bottom: 2rem;
}

.stats-section__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.stats-section__title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
    margin: 0 0 1rem 0;
}

.stats-section__head .stats-section__title {
    margin: 0;
}

.stats-section__meta {
    color: var(--text-light);
    font-size: 0.875rem;
}

.stats-grid--kpi {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

@media (max-width: 1024px) {
    .stats-grid--kpi {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .stats-grid--kpi {
        grid-template-columns: 1fr;
    }
}

.stats-loader {
    display: flex;
    justify-content: center;
    padding: 3rem 0;
}

.stats-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    padding: 3rem 1rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-light);
    text-align: center;
    background: var(--bg-card);
}

.stats-table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.stats-table-wrap .mud-table-root {
    background: transparent;
}

.stats-table-wrap .mud-table-head th {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.stats-table-wrap .mud-table-body td {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text);
}

.stats-student-cell {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.stats-section--referral {
    margin-top: 2.5rem;
}

.stats-referral {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem 1.75rem;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(255, 107, 53, 0.08) 0%, rgba(124, 58, 237, 0.06) 100%);
    border: 1px solid var(--border-light);
    flex-wrap: wrap;
}

.stats-referral__title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1rem;
    margin: 0 0 0.25rem 0;
    color: var(--text);
}

.stats-referral__hint {
    margin: 0;
    color: var(--text-light);
    font-size: 0.85rem;
}

.stats-referral__value {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: -0.02em;
}

/* ---- Trends grid: chart + heatmap ---- */

.stats-grid--trends {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.stats-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
}

.stats-panel__title {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 0.25rem 0;
    letter-spacing: -0.01em;
}

.stats-panel__hint {
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--text-muted);
    margin: 0 0 1rem 0;
}

@media (max-width: 768px) {
    .stats-panel {
        padding: 1rem 1.1rem;
    }
}

/* ---- LessonsTrendChart ---- */

.trend-chart {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.trend-chart__bars {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 0.45rem;
    align-items: end;
    height: 180px;
    padding-bottom: 0.25rem;
    border-bottom: 1px dashed var(--border-light);
}

/* Защита от обёрток MudTooltip: они не должны ломать grid */
.trend-chart__bars > .mud-tooltip-root,
.heatmap__grid > .mud-tooltip-root {
    display: contents;
}

.trend-chart__col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    height: 100%;
    width: 100%;
    cursor: default;
}

.trend-chart__bar-wrap {
    flex: 1 1 auto;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    min-height: 0;
}

.trend-chart__bar {
    width: 100%;
    max-width: 36px;
    border-radius: 8px 8px 4px 4px;
    background: linear-gradient(180deg, var(--accent) 0%, rgba(255, 107, 53, 0.55) 100%);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                filter 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 2px;
}

.trend-chart__col:hover .trend-chart__bar {
    filter: brightness(1.08);
    transform: scaleY(1.03);
    transform-origin: bottom;
}

.trend-chart__label {
    font-family: var(--font-body);
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.trend-chart__footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-light);
    flex-wrap: wrap;
}

.trend-chart__footer strong {
    color: var(--text);
    font-weight: 600;
}

@media (max-width: 600px) {
    .trend-chart__bars {
        height: 150px;
        gap: 0.3rem;
    }

    .trend-chart__label {
        font-size: 0.65rem;
    }
}

/* ---- HourlyHeatmap ---- */

.heatmap {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.heatmap__scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.heatmap__grid {
    display: grid;
    grid-template-columns: 36px repeat(24, minmax(18px, 1fr));
    gap: 3px;
    min-width: 560px;
}

.heatmap__corner {
    width: 36px;
    height: 22px;
}

.heatmap__hour {
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--text-muted);
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 1px;
    opacity: 0;
}

.heatmap__hour.is-visible {
    opacity: 1;
}

.heatmap__day {
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    width: 36px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.heatmap__cell {
    height: 22px;
    border-radius: 4px;
    background: var(--bg-alt);
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
}

.heatmap__cell.has-value {
    background: rgba(255, 107, 53, calc(0.15 + var(--cell-ratio, 0) * 0.75));
    box-shadow: inset 0 0 0 1px rgba(255, 107, 53, calc(0.2 + var(--cell-ratio, 0) * 0.3));
}

.heatmap__cell.has-value:hover {
    transform: scale(1.18);
}

.heatmap__legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-body);
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.heatmap__legend-scale {
    display: inline-flex;
    gap: 3px;
}

.heatmap__legend-cell {
    width: 18px;
    height: 14px;
    border-radius: 3px;
    background: rgba(255, 107, 53, calc(0.15 + var(--cell-ratio, 0) * 0.75));
    box-shadow: inset 0 0 0 1px rgba(255, 107, 53, calc(0.2 + var(--cell-ratio, 0) * 0.3));
}

.heatmap__legend-meta {
    margin-left: auto;
    color: var(--text-light);
}

@media (max-width: 600px) {
    .heatmap__grid {
        grid-template-columns: 32px repeat(24, minmax(16px, 1fr));
        min-width: 520px;
    }

    .heatmap__cell,
    .heatmap__day {
        height: 20px;
    }
}

/* ---- Student stats: Homework progress ---- */

.stats-hw {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.stats-hw__head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
}

.stats-hw__value {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.stats-hw__value span {
    font-size: 1rem;
    color: var(--text-light);
    font-weight: 500;
    margin-left: 0.15rem;
}

.stats-hw__sub {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.stats-hw__percent {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.stats-hw__foot {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text-light);
    flex-wrap: wrap;
}

.stats-hw__foot strong {
    color: var(--text);
    font-weight: 600;
}

.stats-hw__overdue {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: #EF4444;
}

.stats-hw__overdue strong {
    color: #EF4444;
}

/* ---- Student stats: Teacher summary ---- */

.stats-teacher {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.stats-teacher__info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    flex: 1 1 auto;
}

.stats-teacher__name {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.stats-teacher__meta {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text-light);
}

.stats-teacher__meta strong {
    color: var(--text);
    font-weight: 600;
}

/* ---- Student stats: Next key lesson ---- */

.stats-keylesson {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    background: linear-gradient(135deg, rgba(255, 107, 53, 0.08) 0%, rgba(255, 107, 53, 0.02) 100%);
}

.stats-keylesson__badge {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: rgba(255, 107, 53, 0.15);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stats-keylesson__info {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.stats-keylesson__topic {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.stats-keylesson__when {
    font-family: var(--font-body);
    font-size: 0.88rem;
    color: var(--text-light);
}

.stats-keylesson__left {
    text-align: right;
    padding-left: 0.75rem;
    border-left: 1px solid var(--border-light);
}

.stats-keylesson__left-value {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--accent);
    line-height: 1;
    letter-spacing: -0.02em;
}

.stats-keylesson__left-label {
    font-family: var(--font-body);
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    line-height: 1.2;
}

.stats-empty--keylesson {
    flex-direction: row;
    text-align: left;
    align-items: center;
    gap: 1rem;
}

.stats-empty--keylesson .stats-empty__title {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.stats-empty--keylesson .stats-empty__text {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.45;
}

@media (max-width: 600px) {
    .stats-keylesson__left {
        border-left: 0;
        padding-left: 0;
        border-top: 1px dashed var(--border-light);
        padding-top: 0.75rem;
        width: 100%;
        text-align: left;
    }

    .stats-empty--keylesson {
        flex-direction: column;
        text-align: center;
    }
}
