/* =========================================================
   Gaudau.lt – mobile responsive hardening
   Production-readiness pass for the mobile breakpoints.

   Goals:
   - No horizontal overflow at any width (320px → 1280px+).
   - Mobile nav panel never overflows the viewport and
     scrolls internally when the list is taller than the
     screen.
   - Map layout stacks cleanly and the Leaflet canvas keeps
     a usable height on small screens.
   - Catch / article / video / competition grids collapse to
     a single column without clipping their controls.
   - Competition table scrolls horizontally inside its own
     wrapper instead of pushing the page wider.
   - Toolbars wrap instead of overflowing.
   ========================================================= */

/* ---------- Global overflow guard ---------- */
html,
body {
  max-width: 100%;
  /* clip (not hidden): hidden turns html/body into scroll containers and
     breaks position: sticky for the header and section navigation. */
  overflow-x: clip;
}

/* Long unbroken strings (locations, notes, video titles) must never
   widen the layout. */
.catch-card,
.article-card,
.video-card,
.map-list-item,
.competition-table td,
.hero-recent-body,
.hero-recent-species,
.hero-recent-location {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---------- Header / mobile nav ---------- */
@media (max-width: 720px) {
  .header-inner {
    padding: 0 14px;
    gap: 10px;
  }

  /* The nav panel is absolutely positioned under the header. Cap its
     height to the remaining viewport and let it scroll internally so a
     long list of links never pushes content off-screen. */
  .site-nav {
    max-height: calc(100vh - var(--header-h) - 8px);
    max-height: calc(100dvh - var(--header-h) - 8px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Keep the toggle and theme button comfortably tappable. */
  .nav-toggle,
  .theme-toggle {
    width: 44px;
    height: 44px;
  }
}

/* Very narrow phones: hide the brand subtitle and shrink the mark so
   the header row never overflows. */
@media (max-width: 380px) {
  .brand-text small {
    display: none;
  }

  .brand-text strong {
    font-size: 0.9rem;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-mark svg {
    width: 18px;
    height: 18px;
  }
}

/* ---------- Sections ---------- */
@media (max-width: 640px) {
  .section {
    padding-left: 14px;
    padding-right: 14px;
  }

  .section-lede {
    font-size: 0.92rem;
  }
}

/* ---------- Hero ---------- */
@media (max-width: 480px) {
  .hero-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-actions .btn {
    width: 100%;
  }

  .hero-stats {
    gap: 14px 20px;
  }

  .hero-card {
    max-width: 100%;
  }

  .hero-recent-item {
    padding: 0.45rem 0.55rem;
  }
}

/* ---------- Catches: form + list ---------- */
@media (max-width: 900px) {
  .catches-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  /* Row direction + wrap: search on its own line, sort + reset share
     the next one. (A column direction here wraps into a second,
     off-screen column.) */
  .catches-toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .catches-search {
    flex: 1 1 100%;
    min-width: 0;
  }

  .catches-sort {
    flex: 1 1 auto;
    min-width: 0;
  }

  .catches-filter-reset {
    flex: 0 0 auto;
  }

  .catches-row {
    grid-template-columns: 1fr;
  }

  .catches-form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .catches-form-actions .catches-submit,
  .catches-form-actions .catches-cancel {
    width: 100%;
  }

  .catches-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Map ---------- */
@media (max-width: 900px) {
  .map-layout {
    grid-template-columns: 1fr;
  }

  .map-side {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .map-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .map-field {
    flex: 1 1 100%;
    min-width: 0;
  }

  .map-field-search {
    flex: 1 1 100%;
  }

  .map-today,
  .map-reset {
    flex: 1 1 auto;
  }

  /* Leaflet needs an explicit height on small screens; keep it usable
     but not taller than the viewport. */
  .map-canvas {
    min-height: 260px;
    height: 60vh;
    max-height: 420px;
  }

  .map-seasonal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .map-list-item {
    padding: 0.55rem 0.65rem;
  }
}

@media (max-width: 380px) {
  .map-seasonal-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Competition ---------- */
@media (max-width: 900px) {
  .competition-layout {
    grid-template-columns: 1fr;
  }

  .competition-stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .competition-board-head {
    flex-wrap: wrap;
    gap: 8px;
  }

  .competition-board-tools {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* The leaderboard table scrolls horizontally inside its wrapper so it
     never widens the page. */
  .competition-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .competition-table {
    min-width: 480px;
  }

  .competition-form {
    flex-direction: column;
    align-items: stretch;
  }

  .competition-form .competition-submit,
  .competition-form .competition-cancel {
    width: 100%;
  }

  .competition-stats-grid {
    grid-template-columns: 1fr;
  }

  .competition-species-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .competition-species-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Weather ---------- */
@media (max-width: 640px) {
  .weather-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .weather-city-label {
    flex: 1 1 100%;
  }

  .weather-city-select {
    flex: 1 1 auto;
    min-width: 0;
  }

  .weather-refresh {
    flex: 0 0 auto;
  }

  .weather-current {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .weather-forecast {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .weather-spots-row {
    flex-wrap: wrap;
  }
}

@media (max-width: 380px) {
  .weather-forecast {
    grid-template-columns: 1fr;
  }
}

/* ---------- Articles ---------- */
@media (max-width: 640px) {
  .articles-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .articles-search {
    flex: 1 1 100%;
    min-width: 0;
  }

  .articles-cats {
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  .article-fav-filter,
  .articles-clear {
    flex: 0 0 auto;
  }

  .article-grid {
    grid-template-columns: 1fr;
  }

  .articles-empty-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ---------- Video ---------- */
@media (max-width: 640px) {
  .video-form {
    flex-direction: column;
    align-items: stretch;
  }

  .video-form-fields {
    grid-template-columns: 1fr;
  }

  .video-submit {
    width: 100%;
  }

  .video-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .video-grid {
    grid-template-columns: 1fr;
  }

  .video-empty-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ---------- Article modal ---------- */
@media (max-width: 640px) {
  .article-modal-dialog {
    width: calc(100% - 24px);
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ---------- Footer ---------- */
@media (max-width: 480px) {
  .footer-nav {
    gap: 8px 14px;
  }

  .footer-nav a {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }
}

/* ---------- Touch targets ---------- */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .nav-link,
  .theme-toggle,
  .nav-toggle,
  .catches-submit,
  .catches-cancel,
  .competition-submit,
  .competition-cancel,
  .video-submit,
  .weather-refresh,
  .map-today,
  .map-reset,
  .map-list-toggle,
  .map-seasonal-more-btn,
  .hero-recent-more,
  .articles-more-btn,
  .video-more-btn,
  .competition-table-more-btn {
    min-height: 44px;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .site-nav {
    transition: none;
  }
}
