/* Mobile overrides: keep categories in one place on small screens
   - Fixed sidebar under topbar
   - make menu scrollable
   Adjust `top` if your topbar height differs. */

/* Hide the sidebar toggle by default (desktop) - shown only on small screens */
#toggleSidebarBtn { display: none; }

@media (max-width: 900px) {
  /* Make the sidebar fixed and centered like the container */
  .sidebar {
    position: fixed;
    top: 20px; /* adjust if your topbar height is different */
    left: 50%;
    transform: translateX(-50%);
    width: min(420px, 92%);
    z-index: 50;
    margin: 0 auto;
    border-radius: 14px;
    background: rgba(255,255,255,0.96);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  /* Ensure the menu inside the fixed sidebar scrolls if it's tall */
  .sidebar .menu {
    max-height: calc(100vh - 120px); /* viewport minus topbar & some padding */
    overflow: auto;
    padding-right: 6px; /* keep scrollbar away from items */
  }

  /* Layout padding is set dynamically via JS to match sidebar height on small screens */
  .layout { padding-top: 0; }

  /* Keep floating gallery FAB above the sidebar */
  .fab-gallery { z-index: 60; }
  .noticebar, .topbar { z-index: 70; }
}

/* Compact header on small screens */
@media (max-width: 520px) {
  /* Top row: logo left, language right */
  .topbar__row {
    gap: 8px;
    padding: 8px 0;
    align-items: center;
    flex-wrap: wrap;
    flex-direction: column;
  }

  /* Layout ordering: brand left, lang right; others stacked below */
  .brand { order: 1; }
  .lang { order: 2; margin-left: auto; }

  /* Hide the mobile toggle, we show full search in stack */
  #mobileSearchToggle { display: none !important; }

  /* Show full search directly under top row */
  .search { display: flex; order: 3; width: 100%; gap: 8px; padding-top: 8px; align-items: center; }

  /* Search input grows, OK button stays to the right */
  .search-field { flex: 1; max-width: none; }
  .search .btn { flex: 0 0 auto; padding: 8px 10px; }

  /* Filter (select) should be full-width under search */
  .search .select { display: block; width: 100%; margin-top: 8px; }

  /* Gallery buttons: show both in the flow, under the filter */
  .gallery-btn, .fab-gallery { display: inline-flex; order: 4; width: 100%; justify-content: center; gap: 8px; margin-top: 8px; }

  /* Override floating FAB to behave like a normal button in mobile stack */
  .fab-gallery {
    position: static !important;
    right: auto; bottom: auto;
    z-index: auto;
    padding: 10px 14px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--green), #37b24d);
    color: #fff;
    border: none;
    box-shadow: none;
  }

  /* Slightly smaller language links */
  .lang a { padding: 6px 8px; font-size: 12px; }
}

/* Toggle button visual style and positioning (we'll position it in JS) */
@media (max-width: 520px) {
  #toggleSidebarBtn {
    display: inline-flex;
    position: fixed;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 90;
    padding: 0;
    font-weight: 800;
  }
}

/* Sidebar toggle: show button on mobile and support hidden state */
@media (max-width: 520px) {
  #toggleSidebarBtn { display: inline-flex; }
  .sidebar.is-hidden {
    display: none !important;
    visibility: hidden;
    pointer-events: none;
  }
}


/* iOS Safari: не давать кнопке "OK" схлопываться */
.search .btn {
  flex: 0 0 auto;     /* не растягивать и не схлопывать */
  flex-shrink: 0;     /* критично для iOS */
  min-width: 56px;    /* чтобы текст влезал */
  justify-content: center;
}

/* чтобы инпут занимал место, а не "съедал" кнопку */
.search-field {
  flex: 1 1 220px;
  min-width: 180px;
}

/* селект тоже не должен ломать кнопку */
.search .select {
  flex: 0 0 auto;
  min-width: 160px;
}

button.btn {
  -webkit-appearance: none;
  appearance: none;
}
