/* ============================================
   RESPONSIVE v4 — Mobile / Tablet / Touch
   ============================================ */
html, body { overflow-x: hidden; }

/* ============================================
   ГАМБУРГЕР-МЕНЮ
   ============================================ */
.menu-toggle { display: none; }

@media (max-width: 820px) {
  .header { position: sticky; top: 0; z-index: 100; }

  .nav {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap !important;
    padding: 8px 0;
    position: relative;
  }
  .brand { width: auto !important; flex-shrink: 0; }
  .brand img { height: 34px; }

  .menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 42px; height: 42px;
    background: transparent;
    border: 1px solid rgba(139,128,95,0.35);
    border-radius: 10px;
    cursor: pointer; padding: 0;
    z-index: 1001; flex-shrink: 0;
  }
  .menu-toggle span {
    display: block; width: 20px; height: 2px;
    background: #8B805F; border-radius: 2px;
    margin: 0 auto;
    transition: transform 0.25s, opacity 0.2s;
  }
  .menu-toggle.is-active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .menu-toggle.is-active span:nth-child(2) { opacity: 0; }
  .menu-toggle.is-active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .menu {
    display: none !important;
    position: absolute;
    top: 100%; left: -16px; right: -16px;
    z-index: 1000;
    flex-direction: column;
    gap: 0; padding: 6px;
    background: #141414;
    border: 1px solid rgba(139,128,95,0.30);
    border-top: none;
    border-radius: 0 0 14px 14px;
    box-shadow: 0 18px 40px rgba(0,0,0,0.5);
    font-size: 15px;
  }
  .menu.menu-open { display: flex !important; }

  .menu a {
    display: block;
    padding: 13px 16px;
    font-size: 15px; font-weight: 550;
    color: #8B805F;
    border-radius: 10px;
    text-align: left;
    white-space: normal;
  }
  .menu a:hover { background: rgba(139,128,95,0.10); }
  .menu a.active {
    background: rgba(139,128,95,0.72);
    color: #141414;
  }
}

/* ============================================
   ФУТЕР
   ============================================ */
@media (max-width: 700px) {
  .footer { padding: 16px 0; border-top: 1px solid rgba(139,128,95,0.30); }
  .footer-flex { flex-direction: column; gap: 6px; text-align: center; }
  .footer-left { font-size: 12px; line-height: 1.4; opacity: 0.75; }
  .footer-right { padding-right: 0; }
  .footer-right a { font-size: 12px; opacity: 0.75; }
}

/* ============================================
   ГЛАВНАЯ
   ============================================ */
@media (max-width: 820px) {
  .hero { padding: 32px 0 24px; }
  .hero h1 { font-size: 26px; }
  .events-sub { font-size: 15px; }
  .events-page .btn-row { flex-direction: column; gap: 10px; }
  .events-page .btn-row .btn { width: 100%; text-align: center; padding: 14px 18px; }
  .grid { grid-template-columns: 1fr; }
  .grid > [style*="grid-column"] { grid-column: span 1 !important; }
  .card { min-height: auto; padding: 22px 18px; }
}

/* ============================================
   БИБЛИОТЕКА — карточки книг
   ============================================ */
@media (max-width: 820px) {
  .book-grid { gap: 14px; }
  .book-grid.four { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 520px) {
  .book-grid, .book-grid.four { grid-template-columns: 1fr; gap: 12px; }
  .book {
    display: grid; grid-template-columns: 90px 1fr;
    border-radius: 14px; min-height: 0;
  }
  .book-ph { height: auto; min-height: 120px; border-radius: 14px 0 0 14px; }
  .book-ph img { padding: 6px; }
  .book-body, .book-meta {
    padding: 10px 12px; display: flex; flex-direction: column; justify-content: center;
  }
  .book-title { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .book-author { font-size: 12px; }
}

/* ============================================
   БИЗНЕС-ЛИТЕРАТУРА — навигация
   ============================================ */
@media (max-width: 820px) {
  .library-business-page .section-nav {
    display: flex; flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px; padding-bottom: 8px;
    margin: 8px -12px 18px; padding-left: 12px; padding-right: 12px;
    scrollbar-width: none;
  }
  .library-business-page .section-nav::-webkit-scrollbar { display: none; }
  .library-business-page .section-nav a {
    flex-shrink: 0; padding: 8px 14px; font-size: 13px; white-space: nowrap;
  }
  .library-business-page .page-sticky { padding: 12px 0 8px; }
  .library-business-page .page-sticky h1 { font-size: 22px; margin-bottom: 6px; }
  .library-business-page .page-sticky.is-stuck h1 { font-size: 17px; }
}

/* ============================================
   ЧИТАЛКА — ДВЕ СТРОКИ контролов на мобильных
   ============================================ */
@media (max-width: 820px) {
  .reader-wrap { padding: 10px 0 30px; }
  .viewer { max-width: 100%; }

  .viewer-bar {
    display: flex; flex-direction: column; align-items: stretch;
    gap: 8px; padding: 10px 12px;
    border-radius: 12px; margin-bottom: 8px;
  }

  /* Название: по центру, компактно */
  .viewer-meta { text-align: center; }
  .viewer-title {
    font-size: 15px; -webkit-line-clamp: 1;
    display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden;
  }
  .viewer-author { font-size: 12px; }

  /* Контролы: РАЗБИВАЕМ на две строки */
  .viewer-controls {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  /* Строка 1: навигация (← 1 из 307 →) */
  .ctrl-nav {
    display: flex; align-items: center; justify-content: center; gap: 6px;
  }

  /* Строка 2: зум (− 100% + ⛶) */
  .ctrl-zoom {
    display: flex; align-items: center; justify-content: center; gap: 6px;
  }

  .sep { display: none; } /* убираем разделитель на мобильных */

  .vbtn { height: 36px; min-width: 36px; font-size: 15px; border-radius: 9px; }
  .vbtn.ib { width: 36px; }
  .pg { font-size: 13px; gap: 4px; }
  .pg input { width: 38px; height: 28px; font-size: 13px; border-radius: 6px; }
  .zm { font-size: 12px; min-width: 32px; }

  .viewer-canvas { border-radius: 12px; min-height: 350px; }
  .canvas-scroll { padding: 10px 6px; }
  .back-link { font-size: 13px; margin-bottom: 8px; }
}

@media (max-width: 380px) {
  .vbtn { height: 34px; min-width: 34px; font-size: 14px; }
  .vbtn.ib { width: 34px; }
  .pg input { width: 34px; height: 26px; }
  .zm { font-size: 11px; min-width: 28px; }
}

/* ============================================
   МЕРОПРИЯТИЯ / СЕМИНАРЫ
   ============================================ */
@media (max-width: 820px) {
  .events-grid { grid-template-columns: 1fr; gap: 14px; }

  .event-card {
    display: grid; grid-template-columns: 110px 1fr;
    border-radius: 14px; overflow: hidden;
  }
  .event-thumb { aspect-ratio: auto; height: 100%; min-height: 90px; }
  .event-thumb img { width: 100%; height: 100%; object-fit: cover; }
  .event-info { padding: 10px 12px; }
  .event-title { font-size: 14px; margin-bottom: 4px; }
  .event-date { font-size: 12px; }

  /* Модалка мероприятия */
  .event-detail:target { padding: 8px; align-items: flex-start; }
  .event-detail:target > .event-detail-inner {
    width: 100%; max-height: calc(100vh - 16px);
    padding: 14px; border-radius: 14px; margin-top: 8px;
  }
  .event-detail h2 { font-size: 18px; margin-bottom: 10px; padding-right: 40px; }
  .event-close { width: 34px; height: 34px; font-size: 20px; top: 10px; right: 10px; }
  .event-detail-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Видеоплеер */
  .event-media-frame { border-radius: 12px !important; }
  .event-media-frame video { border-radius: 12px; }

  /* Плеер: тулбар */
  .ep-toolbar { flex-wrap: wrap; gap: 6px; margin-bottom: 8px; font-size: 13px; }
  .ep-select { padding: 6px 10px; font-size: 13px; }

  /* Кастомные контролы плеера */
  .ep-controls {
    padding: 6px 8px; gap: 6px; border-radius: 10px;
    flex-wrap: nowrap;
  }
  .ep-btn { width: 32px; height: 30px; border-radius: 8px; font-size: 14px; }
  .ep-time { font-size: 11px; min-width: 70px; }
  .ep-seek { min-width: 60px; }
  .ep-vol { width: 60px; }
  .ep-bigbtn { width: 56px; height: 56px; font-size: 24px; }

  /* Даты */
  .event-dates { grid-template-columns: 1fr; gap: 4px; }
  .event-dates-time { border-left: 0; padding-left: 0; }
  .event-dates-time::before { display: none; }
  .event-block-title { font-size: 14px; }
  .event-block-text { font-size: 14px; }
}

/* ============================================
   КОНТАКТЫ
   ============================================ */
@media (max-width: 820px) {
  .contacts-page .grid { grid-template-columns: 1fr; }
  .contacts-page .grid > [style*="grid-column"] { grid-column: span 1 !important; }
  .contacts-page .card { min-height: auto; padding: 20px 18px; }
  .contacts-textarea { min-height: 120px; }
}

/* ============================================
   БИБЛИОТЕКА ХАБ
   ============================================ */
@media (max-width: 820px) {
  .library-page h1 { font-size: 26px; }
  .library-page .library-subtitle { font-size: 14px; }
  .library-page .library-grid { grid-template-columns: 1fr; gap: 14px; }
  .library-page .card.lib-card { padding: 20px 18px; min-height: auto; }
}

/* ============================================
   МОДАЛКИ / CONSENT / LOGIN
   ============================================ */
@media (max-width: 820px) {
  .consent-modal { width: calc(100vw - 20px); max-height: calc(100vh - 20px); }
}
@media (max-width: 520px) {
  .container { padding: 0 12px; }
  .section { padding: 22px 0; }
  .login-page .card { padding: 22px 16px 18px; }
}

/* ============================================
   КЕЙСЫ / АВТОРСКИЕ МАТЕРИАЛЫ
   ============================================ */
@media (max-width: 820px) {
  .cases-page h1 { font-size: 24px; }
  .library-authors-page h1 { font-size: 24px; }
}

/* ============================================
   TOUCH
   ============================================ */
@media (hover: none) and (pointer: coarse) {
  .menu a { padding: 12px 14px; }
  .vbtn { min-height: 44px; min-width: 44px; }
  .card:hover, .book:hover { transform: none; box-shadow: 0 4px 16px rgba(15,23,42,0.06); }
  .edge-zone:hover { background: transparent; }
  .library-business-page .section-nav { scroll-snap-type: x mandatory; }
  .library-business-page .section-nav a { scroll-snap-align: start; }
}

/* ============================================
   ПЛАНШЕТ (600-820px)
   ============================================ */
@media (min-width: 521px) and (max-width: 820px) {
  .book-grid, .book-grid.four { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .book { display: flex; flex-direction: column; }
  .events-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .event-card { display: block; }
  .event-thumb { aspect-ratio: 4/3; }
}

/* ============================================
   SAFE AREA
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
  .header { padding-top: env(safe-area-inset-top); }
  .footer { padding-bottom: env(safe-area-inset-bottom); }
}
