/* PhysioSapiens | Уроки — JS, часть 3 из 4. Отдельный блок GetCourse. */
(function () {
  'use strict';
  if (!/^\/(?:pl\/)?teach\/control\/lesson\/webview\/?$/i.test(location.pathname) &&
      !/^\/(?:pl\/)?teach\/control\/lesson\/webview\/id\/\d+\/?$/i.test(location.pathname)) return;
  if (new URLSearchParams(location.search).get('kinesio_lesson_off') === '1') return;
  const EXTRA_CSS = "\n/* ============================================================\n   kinesio | Уроки WebView v2.2\n   Вкладка \"Ответы\" + компактная мобильная навигация.\n   Область применения: /pl/teach/control/lesson/webview\n   Сохранена работа оригинальных форм GetCourse.\n   ============================================================ */\nhtml.kinesio-lesson-webview {\n  --kinesio-answers-accent:#f58220;\n  --kinesio-answers-link:#af5513;\n  --kinesio-answers-bg:#faf6f1;\n  --kinesio-answers-border:#e7e1da;\n  --kinesio-answers-muted:#77716b;\n  --kinesio-answers-text:#33312f;\n}\n\n/* Общая карточка формы и комментариев: вместо серого прямоугольника. */\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block,\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .lt-block-wrapper {\n  box-sizing:border-box!important;\n  width:100%!important;\n  max-width:100%!important;\n  min-width:0!important;\n  background:transparent!important;\n  box-shadow:none!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .lt-block-wrapper {\n  margin:0!important;\n  padding:clamp(16px,2.4vw,30px)!important;\n  border:1px solid var(--kinesio-answers-border)!important;\n  border-radius:20px!important;\n  background:var(--kinesio-answers-bg)!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .lt-block-wrapper > .container,\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .row,\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .row > [class*=\"col-\"] {\n  box-sizing:border-box!important;\n  width:100%!important;\n  max-width:100%!important;\n  min-width:0!important;\n  margin-left:0!important;\n  margin-right:0!important;\n  padding-left:0!important;\n  padding-right:0!important;\n  float:none!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .simple-answer.user-answer.gc-comment-form {\n  box-sizing:border-box!important;\n  width:100%!important;\n  max-width:100%!important;\n  min-width:0!important;\n  margin:0 0 18px!important;\n  padding:0!important;\n  border:0!important;\n  background:transparent!important;\n  box-shadow:none!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .simple-answer > .new-comment.new-answer {\n  box-sizing:border-box!important;\n  display:grid!important;\n  grid-template-columns:46px minmax(0,1fr)!important;\n  gap:12px!important;\n  align-items:start!important;\n  width:100%!important;\n  max-width:100%!important;\n  min-width:0!important;\n  padding:0!important;\n  margin:0!important;\n  background:transparent!important;\n  float:none!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .new-comment.new-answer > .user-image {\n  display:block!important;\n  position:static!important;\n  width:46px!important;\n  height:46px!important;\n  max-width:46px!important;\n  margin:0!important;\n  padding:0!important;\n  float:none!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .new-comment.new-answer > .user-image img {\n  width:46px!important;\n  height:46px!important;\n  max-width:46px!important;\n  border-radius:50%!important;\n  object-fit:cover!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .new-comment.new-answer > .answer-comment.textarea-block {\n  box-sizing:border-box!important;\n  display:block!important;\n  position:relative!important;\n  grid-column:2!important;\n  width:100%!important;\n  max-width:100%!important;\n  min-width:0!important;\n  margin:0!important;\n  padding:0!important;\n  float:none!important;\n  background:transparent!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer-comment .emoji-container {\n  box-sizing:border-box!important;\n  position:relative!important;\n  width:100%!important;\n  min-width:0!important;\n  max-width:100%!important;\n  margin:0!important;\n  background:#fff!important;\n  border-radius:14px!important;\n  overflow:visible!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block textarea.new-comment-textarea {\n  box-sizing:border-box!important;\n  display:block!important;\n  width:100%!important;\n  max-width:100%!important;\n  min-width:0!important;\n  min-height:108px!important;\n  margin:0!important;\n  padding:15px 64px 15px 16px!important;\n  border:1px solid #e9d8c8!important;\n  border-radius:14px!important;\n  background:#fff!important;\n  color:var(--kinesio-answers-text)!important;\n  font:400 15px/1.55 Manrope,Arial,sans-serif!important;\n  resize:vertical!important;\n  overflow-wrap:anywhere!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block textarea.new-comment-textarea:focus {\n  outline:0!important;\n  border-color:var(--kinesio-answers-accent)!important;\n  box-shadow:0 0 0 3px rgba(71,112,213,.1)!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer-comment .emoji-button,\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer-comment .lesson-comment-attach {\n  color:var(--kinesio-answers-accent)!important;\n  z-index:2;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer-comment .lesson-comment-files,\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer-comment .uploadifive-queue {\n  box-sizing:border-box!important;\n  max-width:100%!important;\n  min-width:0!important;\n  overflow-wrap:anywhere!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer-comment > .btn-send {\n  display:inline-flex;\n  align-items:center;\n  justify-content:center;\n  min-height:44px!important;\n  margin:12px 0 0!important;\n  padding:11px 24px!important;\n  border:1px solid var(--kinesio-answers-accent)!important;\n  border-radius:11px!important;\n  background:var(--kinesio-answers-accent)!important;\n  color:#fff!important;\n  font:700 14px/1.3 Manrope,Arial,sans-serif!important;\n  box-shadow:none!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer-comment > .btn-send:hover {\n  background:#d96c16!important;border-color:#d96c16!important;\n}\n\n/* Уже опубликованные комментарии — аккуратные карточки, без подпрыгиваний. */\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .other-answers {\n  box-sizing:border-box!important;width:100%!important;min-width:0!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .other-answers > .answer_wrapper {\n  box-sizing:border-box!important;\n  margin:0 0 14px!important;\n  padding:18px!important;\n  border:1px solid var(--kinesio-answers-border)!important;\n  border-radius:16px!important;\n  background:#fff!important;\n  box-shadow:none!important;\n  transform:none!important;\n  transition:border-color .15s ease!important;\n  min-width:0!important;\n  overflow-wrap:anywhere!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .other-answers > .answer_wrapper:hover {\n  transform:none!important;\n  border-color:#e9c8aa!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer_wrapper .answer-content,\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer_wrapper .answer-text {\n  min-width:0!important;max-width:100%!important;\n  overflow-wrap:anywhere!important;word-break:break-word!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer_wrapper img.user-profile-image {\n  border-radius:50%!important;object-fit:cover!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer_wrapper a {\n  color:var(--kinesio-answers-link)!important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .answer_wrapper :is(.btn,.button) {\n  border-radius:9px!important;box-shadow:none!important;\n}\n\n/* Кнопки навигации в WebView: родные href остаются неизменными. */\n@media(max-width:760px) {\n  html.kinesio-lesson-webview .kinesio-wv-quick-navigation {\n    box-sizing:border-box!important;\n    display:grid!important;\n    grid-template-columns:repeat(2,minmax(0,1fr))!important;\n    gap:9px!important;\n    align-items:stretch!important;\n    width:100%!important;\n    max-width:100%!important;\n    padding:8px 16px 12px!important;\n    margin:0 auto!important;\n  }\n  html.kinesio-lesson-webview .kinesio-wv-quick-navigation > div {\n    box-sizing:border-box!important;\n    float:none!important;\n    flex:auto!important;\n    min-width:0!important;\n    width:100%!important;\n    padding:0!important;\n    margin:0!important;\n    text-align:center!important;\n  }\n  html.kinesio-lesson-webview .kinesio-wv-quick-navigation > div:only-child:has(a[href*=\"lesson/webview\"]) {\n    grid-column:2!important;\n  }\n  html.kinesio-lesson-webview .kinesio-wv-quick-navigation > div > a,\n  html.kinesio-lesson-webview .kinesio-wv-lesson-bottom-nav > a {\n    box-sizing:border-box!important;\n    display:flex!important;\n    align-items:center!important;\n    justify-content:center!important;\n    width:100%!important;\n    min-width:0!important;\n    max-width:100%!important;\n    min-height:46px!important;\n    margin:0!important;\n    padding:10px 8px!important;\n    border:1px solid #efcba6!important;\n    border-radius:11px!important;\n    background:#fff!important;\n    color:var(--kinesio-answers-link)!important;\n    text-align:center!important;\n    text-decoration:none!important;\n    font:700 13px/1.25 Manrope,Arial,sans-serif!important;\n    white-space:nowrap!important;\n  }\n  html.kinesio-lesson-webview .kinesio-wv-lesson-bottom-nav {\n    box-sizing:border-box!important;\n    display:grid!important;\n    grid-template-columns:repeat(2,minmax(0,1fr))!important;\n    gap:9px!important;\n    width:100%!important;\n    padding:0 16px!important;\n  }\n  html.kinesio-lesson-webview .kinesio-wv-lesson-bottom-nav > a {\n    flex:none!important;\n  }\n  html.kinesio-lesson-webview .kinesio-wv-lesson-bottom-nav > a:only-child {\n    grid-column:1/-1;\n  }\n  html.kinesio-lesson-webview body.gc-chtm-webview > .lesson-content {\n    box-sizing:border-box!important;width:100%!important;\n    max-width:100%!important;min-width:0!important;\n    padding:14px 16px 36px!important;\n  }\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n    .lt-lesson-comment-block .lt-block-wrapper {\n    padding:16px!important;border-radius:16px!important;\n  }\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n    .lt-lesson-comment-block .simple-answer > .new-comment.new-answer {\n    grid-template-columns:34px minmax(0,1fr)!important;\n    gap:9px!important;\n  }\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n    .lt-lesson-comment-block .new-comment.new-answer > .user-image,\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n    .lt-lesson-comment-block .new-comment.new-answer > .user-image img {\n    width:34px!important;height:34px!important;max-width:34px!important;\n  }\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n    .lt-lesson-comment-block textarea.new-comment-textarea {\n    min-height:108px!important;padding:13px 55px 13px 12px!important;\n    font-size:14px!important;\n  }\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n    .lt-lesson-comment-block .other-answers > .answer_wrapper {\n    padding:14px!important;border-radius:13px!important;\n  }\n}\n@media(max-width:360px) {\n  html.kinesio-lesson-webview .kinesio-wv-quick-navigation {gap:6px!important;padding-left:10px!important;padding-right:10px!important;}\n  html.kinesio-lesson-webview .kinesio-wv-quick-navigation > div > a,\n  html.kinesio-lesson-webview .kinesio-wv-lesson-bottom-nav > a {font-size:12px!important;padding:10px 5px!important;}\n}\n";
  const AVATAR_FALLBACK_CSS = "\n/* ============================================================\n   PhysioSapiens | Иконка пользователя в поле ответа/комментария v1.9\n   Только заглушка, когда у пользователя нет настоящего фото.\n   Основная страница урока + WebView GetCourse.\n   ============================================================ */\n\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image:has(> img.user-default-profile-image),\nhtml.kinesio-lesson-view .kinesio-lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image:has(> img.user-default-profile-image) {\n  display: block !important;\n  position: relative !important;\n  float: none !important;\n  flex-shrink: 0 !important;\n  padding: 0 !important;\n  background: #ffefe1 !important;\n  border-radius: 50% !important;\n  overflow: hidden !important;\n  isolation: isolate;\n}\n\n/* Убираем серую штатную заглушку, но не реальные фотографии. */\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image > img.user-default-profile-image,\nhtml.kinesio-lesson-view .kinesio-lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image > img.user-default-profile-image {\n  display: none !important;\n}\n\n/* Голова заполненного синего человечка. */\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image:has(> img.user-default-profile-image)::before,\nhtml.kinesio-lesson-view .kinesio-lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image:has(> img.user-default-profile-image)::before {\n  content: \"\" !important;\n  display: block !important;\n  position: absolute !important;\n  z-index: 1;\n  top: 18% !important;\n  left: 35% !important;\n  width: 30% !important;\n  height: 30% !important;\n  border-radius: 50% !important;\n  background: #f58220 !important;\n  pointer-events: none;\n}\n\n/* Плечи заполненного синего человечка. */\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image:has(> img.user-default-profile-image)::after,\nhtml.kinesio-lesson-view .kinesio-lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image:has(> img.user-default-profile-image)::after {\n  content: \"\" !important;\n  display: block !important;\n  position: absolute !important;\n  z-index: 1;\n  bottom: 16% !important;\n  left: 19% !important;\n  width: 62% !important;\n  height: 33% !important;\n  border-radius: 65% 65% 24% 24% !important;\n  background: #f58220 !important;\n  pointer-events: none;\n}\n";
  const AVATAR_VISIBLE_CSS = "\n/* kinesio | WebView v2.5 — показывать настоящее фото даже на телефоне */\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image {\n  display: block !important;\n  visibility: visible !important;\n  opacity: 1 !important;\n  flex-shrink: 0 !important;\n  overflow: hidden !important;\n  border-radius: 50% !important;\n}\nhtml.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n.lt-lesson-comment-block .new-comment.new-answer > .user-image > img.user-profile-image:not(.user-default-profile-image)[src]:not([src=\"\"]) {\n  display: block !important;\n  visibility: visible !important;\n  opacity: 1 !important;\n  width: 100% !important;\n  height: 100% !important;\n  max-width: 100% !important;\n  object-fit: cover !important;\n  border-radius: 50% !important;\n}\n@media (max-width: 767px) {\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .simple-answer > .new-comment.new-answer {\n    display: grid !important;\n    grid-template-columns: 34px minmax(0, 1fr) !important;\n    column-gap: 9px !important;\n    align-items: start !important;\n  }\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .new-comment.new-answer > .user-image {\n    width: 34px !important;\n    height: 34px !important;\n    min-width: 34px !important;\n    max-width: 34px !important;\n  }\n  html.kinesio-lesson-webview body.gc-chtm-webview .lesson-content\n  .lt-lesson-comment-block .new-comment.new-answer > .answer-comment.textarea-block {\n    grid-column: 2 !important;\n    min-width: 0 !important;\n    width: 100% !important;\n  }\n}\n";
  function restoreRealAvatars() {
    document.querySelectorAll('.lesson-content .lt-lesson-comment-block .new-comment.new-answer > .user-image').forEach(avatar => {
      avatar.style.setProperty('display', 'block', 'important');
      avatar.style.setProperty('visibility', 'visible', 'important');
      const photo = avatar.querySelector('img.user-profile-image:not(.user-default-profile-image)[src]:not([src=""])');
      if (photo) {
        photo.style.setProperty('display', 'block', 'important');
        photo.style.setProperty('visibility', 'visible', 'important');
        photo.style.setProperty('opacity', '1', 'important');
      }
    });
  }
  function apply() {
    if (!document.body || !document.body.classList.contains('gc-chtm-webview')) return false;
    if (!document.getElementById('kinesio-wv-css-v22')) {
      const st = document.createElement('style');
      st.id = 'kinesio-wv-css-v22';
      st.textContent = EXTRA_CSS + AVATAR_FALLBACK_CSS + AVATAR_VISIBLE_CSS;
      (document.head || document.documentElement).appendChild(st);
    }
    restoreRealAvatars();
    // Тексты сокращаются только на узких экранах. Ссылки GetCourse не меняем.
    const w = document.documentElement.clientWidth;
    document.querySelectorAll('.kinesio-wv-quick-navigation a, .kinesio-wv-lesson-bottom-nav a').forEach(a => {
      if (!a.dataset.kinesioFullNav) a.dataset.kinesioFullNav = a.textContent.trim().replace(/\s+/g, ' ');
      const full = a.dataset.kinesioFullNav;
      if (/Предыдущий урок/i.test(full)) {
        const label = w <= 360 ? '← Назад' : w <= 760 ? '← Предыдущий' : full;
        if (a.textContent !== label) a.textContent = label;
        a.setAttribute('aria-label', full);
      } else if (/Следующий урок/i.test(full)) {
        const label = w <= 360 ? 'Далее →' : w <= 760 ? 'Следующий →' : full;
        if (a.textContent !== label) a.textContent = label;
        a.setAttribute('aria-label', full);
      }
    });
    return true;
  }
  const boot = () => {
    apply();
    // После переключения вкладки GetCourse может заменить блок комментариев.
    // CSS уже действует на новые элементы без изменения их содержимого.
    let pending = false;
    const obs = new MutationObserver(() => {
      if (pending) return;
      pending = true;
      requestAnimationFrame(() => { pending = false; apply(); });
    });
    if (document.body) obs.observe(document.body, {childList:true,subtree:true});
    window.addEventListener('resize',apply,{passive:true});
  };
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
  else boot();
})();

/* PhysioSapiens | Финальная тема CSS для обычных уроков и WebView. */
