/* ============================================================
   TABLET (<=1024px)
   ============================================================ */
@media (max-width: 1024px) {
  :root {
    --hdr-h: 72px;
  } /* висота хедера для обчислень */

  body {
    padding: 16px;
    font-size: 15px;
  }

  /* Лого трохи компактніше, без «100%» щоб не ламати верстку */
  .logo img {
    max-width: 240px;
    width: 68%;
    height: auto;
  }

  /* Гамбургер */
  .filter-toggle {
    width: 44px;
    height: 44px;
  }

  /* Поповер-меню під гамбургером */
  #filter-container,
  .filter-container {
    right: 16px;
    top: calc(100% + 8px);
    max-width: 240px;
  }

  /* Уніфікована позиція всіх «панелей» (права колонка) */
  .ingredients-container-flower,
  .categories-container-flower,
  .sorting-container-flower,
  .settings-container-flower {
    position: fixed;
    top: calc(var(--hdr-h) + 8px);
    right: 200px;
    left: auto;
    width: min(92vw, 360px);
    max-height: calc(100vh - var(--hdr-h) - 24px);
    overflow: hidden; /* скрол всередині секції */
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.12);
    padding: 0; /* внутрішні секції мають свій паддінг */
    z-index: 1100;
    display: none; /* стартом закриті */
  }
  .ingredients-container-flower.active,
  .categories-container-flower.active,
  .sorting-container-flower.active,
  .settings-container-flower.active {
    display: block;
  }

  /* Внутрішні секції панелей — скроляться */
  #ingredients-section,
  #categories-section {
    max-height: calc(100vh - var(--hdr-h) - 24px);
    overflow: hidden;
  }
  #available-ingredients,
  #available-categories {
    overflow-y: auto;
  }

  /* Хрестик у куті показуємо на моб/планшетах */
  .panel-close {
    display: block !important;
    position: absolute;
    top: 8px;
    right: 10px;
    background: transparent;
    border: 0;
    font-size: 24px;
    line-height: 1;
    color: #333;
    cursor: pointer;
    z-index: 5;
  }

  /* Сітка рецептів — 2 колонки */
  #recipes-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
    padding: 16px;
  }

  .recipe {
    text-align: center;
    padding: 8px;
    transition: transform 0.2s ease;
  }
  .recipe-image-container {
    display: flex;
    justify-content: center;
  }
  .recipe-image {
    width: 100%;
    max-width: 360px;
    height: auto;
    object-fit: contain;
    aspect-ratio: 4 / 3;
  }
  .recipe-name {
    margin-top: 8px;
    font-size: 18px;
    font-weight: 700;
  }
  .recipe ul {
    font-size: 14px;
  }

  /* Пошук: кнопка стабільно всередині поля */
  .search-container {
    max-width: 720px;
    padding: 0 8px;
  }
  #search-input {
    width: 100%;
    padding: 12px 44px 12px 16px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 10px;
  }
  #search-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    cursor: pointer;
  }

  /* Кнопки */
  .button-style,
  .apply-categories,
  .clear-categories,
  .apply-ingredients,
  .clear-ingredients {
    padding: 10px 14px;
    font-size: 16px;
  }

  /* Туторіал */
  .tutorial-popup {
    top: calc(var(--hdr-h) + 8px);
    right: 16px;
    left: 16px;
    width: auto;
    padding: 16px 16px 56px;
  }
  .tutorial-popup .tp-title {
    font-size: 17px;
  }

  /* Load more */
  #load-more {
    padding: 12px 28px;
    font-size: 16px;
  }

  /* Страховка */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }
}

/* ============================================================
   PHONE (<=600px)
   ============================================================ */
@media (max-width: 600px) {
  :root {
    --hdr-h: 64px;
  }

  body {
    padding: 10px;
    font-size: 16px;
  }

  .logo img {
    width: 84%;
    max-width: 220px;
    height: auto;
  }

  .filter-toggle {
    width: 36px;
    height: 36px;
  }

  /* Поповер-меню — компактніше */
  #filter-container,
  .filter-container {
    right: 12px;
    top: calc(100% + 6px);
    max-width: 210px;
    padding: 12px;
  }

  /* Панелі — центровані по екрану, ширина ~90vw */
  .ingredients-container-flower,
  .categories-container-flower,
  .sorting-container-flower,
  .settings-container-flower {
    position: fixed;
    top: calc(var(--hdr-h) + 6px);
    left: auto;
    right: auto;
    transform: translateX(-50%);
    width: min(94vw, 420px);
    max-height: calc(100vh - var(--hdr-h) - 18px);
    overflow: hidden;
    padding: 0;
    z-index: 1100;
    display: none;
  }
  .ingredients-container-flower.active,
  .categories-container-flower.active,
  .sorting-container-flower.active,
  .settings-container-flower.active {
    display: block;
  }

  #ingredients-section,
  #categories-section {
    max-height: calc(100vh - var(--hdr-h) - 18px);
    overflow: hidden;
  }
  #available-ingredients,
  #available-categories {
    overflow-y: auto;
  }

  .panel-close {
    display: block !important;
    position: absolute;
    top: 8px;
    right: 10px;
    background: transparent;
    border: 0;
    font-size: 24px;
    line-height: 1;
    color: #333;
    cursor: pointer;
    z-index: 5;
  }

  /* Сітка рецептів — одна колонка */
  #recipes-container {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }
  .recipe-image {
    max-width: 420px;
  }

  .recipe-name {
    font-size: 18px;
  }
  .recipe ul {
    font-size: 13px;
  }

  /* Пошук */
  .search-container {
    padding: 0 6px;
  }
  #search-input {
    padding: 12px 44px 12px 14px;
    font-size: 16px;
    border-radius: 10px;
  }
  #search-btn {
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
  }

  /* Кнопки */
  .button-style,
  .apply-categories,
  .clear-categories,
  .apply-ingredients,
  .clear-ingredients {
    padding: 10px 12px;
    font-size: 16px;
  }

  /* Всередині списків обмежимо висоту на дуже малих екранах */
  .category-list {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 24px;
  }

  /* Туторіал — між краями з урахуванням safe-area */
  .tutorial-popup {
    left: 16px;
    right: 16px;
    width: auto;
    max-width: none;
    padding: 14px 14px 54px;
  }
  @supports (padding: max(0px)) {
    .tutorial-popup {
      margin-left: max(0px, env(safe-area-inset-left));
      margin-right: max(0px, env(safe-area-inset-right));
    }
  }

  #load-more {
    padding: 10px 22px;
    font-size: 16px;
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }
}
