/* ==========================================================================
   Мобильная версия (телефоны до 760 px). Подключается последней — после app.css и strict.css.
   Принципы: до действия меньше листать, таблицы — строками, касания от 44 px, без горизонтальной прокрутки страницы.
   ========================================================================== */

/* Элементы, которые есть только на телефоне */
.hw-cart, .hw-cart-pad, .ln-sticky { display: none; }

@media (max-width: 760px) {
    /* ---------- Каркас ---------- */
    .tab { font-size: 11px; font-weight: 600; letter-spacing: -0.01em; padding: 4px 0; }
    .tab span { overflow: visible; text-overflow: clip; }
    .tab.active { color: var(--blue-dark); background: var(--tint-blue); }
    .cabinet-top { padding: 6px 0; }
    .cabinet-bar .logo-text { font-size: 17px !important; }

    /* Ссылки-«хвосты» у заголовков, «Разбор», «Все домашки»: зона нажатия не меньше 44 px */
    .h-row a, .page-body > a.link, details.solution > summary, .link-button { display: inline-flex; align-items: center; min-height: 44px; }
    details.solution > summary { width: 100%; }
    .icon-button.small { width: 40px; height: 40px; }

    /* Вкладки-фильтры (экзамен, порядок, разделы оплаты) не переносятся, а листаются вбок до края экрана */
    .role-filter {
        flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
        margin-right: -16px; padding-right: 16px; scroll-snap-type: x proximity;
    }
    .role-filter::-webkit-scrollbar { display: none; }
    .role-filter > * { flex: none; scroll-snap-align: start; }

    /* Таблицы, которые листаются вбок: первый столбец (имя) остаётся на месте */
    .table-wrap { margin-right: -16px; padding-right: 16px; }
    .table-wrap .table th:first-child, .table-wrap .table td:first-child {
        position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--line);
    }

    /* Цифры-карточки — три в ряд, а не по экрану на каждую */
    .grid-3.stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .stat-grid > .card { padding: 12px 10px; border-radius: 14px; min-width: 0; }
    .stat-grid > .card:first-child { grid-column: auto; }
    .stat-grid .stat-xl, .stat-grid .stat-lg { font-size: 30px; line-height: 1.05; letter-spacing: -0.03em; }
    .stat-grid .label { font-size: 12px; }
    .stat-grid .muted { font-size: 12px; line-height: 1.3; }
    .stat-grid > .card > * { overflow-wrap: anywhere; }

    /* Условия заданий: без «рек» из пробелов, таблицы и картинки не вылезают за экран */
    .html-content, .statement { text-align: left !important; hyphens: auto; }
    .html-content p, .html-content div { text-align: left !important; }
    .html-content img { max-width: 100%; height: auto; }
    .html-content table { font-size: 14px; }
    .html-content td, .html-content th { padding: 4px 6px; }
    .task-card { padding-left: 14px; padding-right: 14px; }

    /* ---------- Главная ученика: сначала действие ---------- */
    .dash { display: flex; flex-direction: column; gap: 20px; border-top: 0; }
    .dash-main, .dash-aside { display: contents; }
    .dash-who { order: 1; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; }
    .dash-who .stat-xl { font-size: 64px; }
    .dash .dash-delta { font-size: 13px; margin: 6px 0 0 8px; }
    .dash-level { gap: 8px; }
    .dash-level > b { width: 44px; height: 44px; font-size: 20px; border-radius: 13px; }
    .dash-level span { font-size: 12px; }
    .dash-level strong { font-size: 14px; }
    .ladder { order: 2; margin-top: -8px; }
    .dash > div > .notice-card { order: 3; }
    .dash-aside > .next-card { order: 3; }
    .dash-aside > section:first-of-type { order: 4; }          /* цель на сегодня */
    .dash-aside > .plan-rows, .dash-aside > p { order: 5; }
    .dash-main > section:not(.dash-lessons) { order: 6; }      /* график и последние задачи */
    .dash-lessons { order: 7; }
    .facts { order: 8; }
    .elo-chart { height: 120px; }

    /* «Последние задачи»: строки вместо таблицы */
    .rows-table thead { display: none; }
    .rows-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 8px 0; }
    .rows-table td { padding: 0; border: 0; }
    .rows-table td.r { font-size: 13px; color: var(--muted); }
    .rows-table td.r:last-child { color: inherit; }
    .rows-table td small { font-size: 12px; }
    .att { gap: 10px; }
    .kim-chip { width: 32px; height: 32px; }

    /* ---------- Тренировка: компактные строки номеров ---------- */
    .kim-rows { gap: 6px; }
    .kim-row {
        grid-template-columns: 38px minmax(0, 1fr) auto; grid-template-rows: auto auto; gap: 4px 10px;
        padding: 9px 12px; border-radius: 14px; min-height: 60px;
    }
    .kim-row > .kim-sq { grid-row: 1 / 3; grid-column: 1; width: 38px; height: 38px; }
    .kim-row > span:nth-child(2) { grid-row: 1; grid-column: 2; min-width: 0; }
    .kim-row .kim-title { display: block; font-size: 15px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .kim-row > span:nth-child(2) small { display: none; }
    .kim-segs { grid-row: 2; grid-column: 2; display: flex; align-items: center; gap: 8px; }
    .kim-segs .s { flex: 1; gap: 1px; }
    .kim-segs .s i { height: 5px; }
    .kim-segs small { flex: none; font-size: 12px; }
    .kim-elo { grid-row: 1 / 3; grid-column: 3; display: block; text-align: right; }
    .kim-elo b { display: block; font-size: 15px; }
    .kim-elo small { font-size: 11px; max-width: 72px; line-height: 1.2; }
    .kim-elo small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .kim-act { display: none; }
    .kim-toolbar { gap: 10px; }
    .kim-legend { gap: 6px 12px; font-size: 12px; }
    .lv-key { font-size: 12px; }
    .lv-key i { width: 20px; height: 20px; font-size: 10px; }

    /* Пробник и домашка: номера заданий — полоса, которая листается вбок */
    .mock-nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 10px; gap: 6px; top: 0; }
    .mock-nav::-webkit-scrollbar { display: none; }
    .mock-nav > * { flex: none; }

    /* ---------- Расписание преподавателя: шторка занятия ---------- */
    .schedule-layout { align-items: stretch; }
    .day-empty { padding: 6px 2px; }
    .hero-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; }
    .hero-actions .btn { padding-left: 6px; padding-right: 6px; font-size: 14px; }
    .hero-actions .btn-light { grid-column: 1 / -1; }

    /* Карточка занятия — шторка снизу, а не в конце страницы */
    .schedule-panel {
        position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 70; width: auto;
        max-height: 86vh; overflow-y: auto; margin: 0; border-radius: 22px 22px 0 0; border: 0;
        padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
        box-shadow: 0 0 0 100vmax rgba(15, 16, 33, 0.45), 0 -8px 30px rgba(15, 16, 33, 0.2);
        animation: sheet-up 0.22s ease-out;
    }
    .schedule-panel::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 6px; flex: none; }
    .schedule-panel .panel-head { position: sticky; top: -10px; background: var(--surface); z-index: 1; padding-top: 4px; }
    @media (prefers-reduced-motion: reduce) { .schedule-panel { animation: none; } }

    /* ---------- Выдача ДЗ: счётчик и кнопка всегда на виду ---------- */
    .task-pick { max-height: 62vh; }
    .hw-cart {
        position: fixed; left: 10px; right: 10px; z-index: 45;
        bottom: calc(72px + env(safe-area-inset-bottom));
        display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 16px;
        background: var(--ink); color: var(--surface); box-shadow: 0 12px 30px -10px rgba(15, 16, 33, 0.5);
    }
    .hw-cart b { flex: 1; font-size: 15px; }
    .hw-cart .btn { min-height: 44px; }
    .hw-cart-pad { display: block; height: 72px; }

    /* ---------- Родитель ---------- */
    .child-head { display: grid; gap: 12px; }
    .child-head .btn { width: 100%; justify-content: center; }
    .child-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .child-stats > div { background: var(--light); border-radius: 12px; padding: 10px 12px; min-width: 0; }

    /* ---------- Лендинг ---------- */
    .ln-list li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    .ln-list li span { text-align: left; }
    .ln-sticky {
        display: flex; justify-content: center; position: fixed; left: 12px; right: 12px; z-index: 40;
        bottom: calc(12px + env(safe-area-inset-bottom)); min-height: 52px; border-radius: 16px;
        box-shadow: 0 14px 30px -12px rgba(79, 70, 229, 0.7);
    }
    .ln-footer { padding-bottom: 96px; }
}

@media (max-width: 400px) {
    .dash-who .stat-xl { font-size: 56px; }
    .stat-grid .stat-xl, .stat-grid .stat-lg { font-size: 26px; }
}

@keyframes sheet-up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }

/* Телефон и планшет: шторка меню выезжает справа — там же, где кнопка «Меню». */
@media (max-width: 1099px) {
    .cabinet-side {
        left: auto; right: 0; transform-origin: right center;
        box-shadow: -12px 0 40px rgba(0, 0, 0, 0.35);
        border-radius: 16px 0 0 16px;
        padding-top: max(20px, env(safe-area-inset-top, 0px));
        padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
    }
}

/* Подсказка «Установить на телефон» (js/install.js): карточка над нижней панелью. */
.install-hint {
    position: fixed; z-index: 45; left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 12px;
    background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.install-hint[hidden] { display: none; }
.install-hint img { flex: none; width: 40px; height: 40px; border-radius: 10px; }
.ih-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; line-height: 1.35; }
.ih-text b { font-weight: 600; }
.ih-text span { color: var(--muted); font-size: 13px; }
.ih-install { flex: none; min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--btn); color: var(--on-btn); font: inherit; font-weight: 600; cursor: pointer; }
.ih-close { flex: none; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.ih-close:hover { background: var(--light); color: var(--ink); }
@media (max-width: 760px) { .install-hint { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); } }
@media (min-width: 1100px) { .install-hint { display: none !important; } }
