/* ============================================================
   Mobile hardening (accessibility + reachability)
   Goal: keep every feature reachable on small screens, avoid
   scroll traps, and make overlays/modals reliably scrollable.
   ============================================================ */

@media (max-width: 900px) {

  /* Prevent iOS Safari from zooming inputs on focus (requires >=16px). */
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px !important;
  }

  /* Use dynamic viewport units where available to avoid bottom cut-offs. */
  @supports (height: 100dvh) {
    .app-layout {
      min-height: calc(100dvh - var(--header-stack-height));
    }
  }

  /* Reset layout margins for all variants on mobile */
  .main-content,
  .main-content--full,
  .main-content--wide {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: 16px;
    /* standard mobile safe padding */
  }

  /* Sidebars are handled as drawers in style.css for max-width: 900px */

  /* Modals: align to top with safe-area padding; always scroll inside. */
  .modal-overlay {
    align-items: flex-start;
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  }

  .modal {
    width: min(520px, 100%);
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: auto;
  }

  /* Toasts: keep them below the fixed navbar on phones. */
  .toast-container {
    top: calc(var(--header-stack-height) + 10px);
    left: 12px;
    right: 12px;
  }

  .toast {
    min-width: 0;
    width: 100%;
  }

  /* Dropdowns: cap height so actions don't go off-screen. */
  .dropdown__menu {
    max-height: calc(100dvh - var(--header-stack-height) - 24px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Sidebar drawer: respect notches and allow full scroll. */
  .sidebar-left {
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-overlay {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Floating chat button: keep it above the home indicator area. */
  .fab-chat {
    right: 14px !important;
    left: auto !important;
    bottom: calc(14px + env(safe-area-inset-bottom)) !important;
    top: auto !important;
  }

  .fab-chat-overlay {
    padding: 12px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  /* Navbar: keep "links oficiais" row compact (avoid huge gap between icons). */
  .navbar__nav {
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .navbar__nav::-webkit-scrollbar {
    display: none;
  }

  .navbar__nav-spacer {
    display: none;
  }

  .navbar__nav-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .navbar__nav-tools {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 0 0 auto;
  }

  /* Feed: keep post actions usable on narrow screens (avoid overlap + FAB occlusion). */
  .ig-post__actions {
    gap: 6px;
  }

  .ig-action {
    min-width: 0;
    overflow: hidden;
  }

  .ig-action__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Feed: ensure content can scroll past the floating chat button. */
  .feed-page {
    padding-bottom: calc(110px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 520px) {
  :root {
    --navbar-height: 118px;
  }

  .navbar__brand-logo {
    height: 32px;
  }

  .navbar__search {
    display: none;
    /* Hide global search on small mobile to prevent horizontal overflow */
  }

  .navbar__nav a,
  .navbar__nav-tool,
  .navbar__notif {
    width: 36px;
    height: 36px;
  }

  /* Slightly smaller FAB reduces obstruction on phones. */
  .fab-chat {
    width: 56px;
    height: 56px;
    border-radius: 16px;
  }

  .fab-chat__icon {
    width: 24px;
    height: 24px;
  }

  .fab-chat__pulse {
    inset: -6px;
    border-radius: 20px;
  }
}

@media (max-width: 640px) {

  /* Feed counts: align cleanly on phones (2x2 grid). */
  .ig-post__counts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    justify-items: start;
  }

  .ig-count,
  .ig-count--ghost {
    width: 100%;
    justify-content: flex-start;
  }

  /* Hide action labels on phones to prevent cramped/overlapping text. */
  .ig-post__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .ig-action {
    flex: 0 0 54px;
    width: 54px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    gap: 0;
  }

  .ig-action__label {
    display: none;
  }
}