/* Safe mobile rebuild: only styles the existing layout and injected bottom nav.
   Intentionally does not target .post-lightbox or #shared-media-lightbox. */

:root {
  --safe-mobile-nav-h: 68px;
}

.safe-mobile-bottom-nav {
  display: none;
}

@media (max-width: 980px) {
  html, body {
    overflow-x: hidden;
  }

  .app-shell {
    min-height: 100dvh;
    background: var(--bg, #f5f5f5);
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    padding-top: max(8px, env(safe-area-inset-top));
    backdrop-filter: blur(12px);
  }

  .topbar .topbar-left {
    min-width: 0;
    flex: 1 1 auto;
    gap: 10px;
  }

  .brand {
    font-weight: 800;
    font-size: 24px;
    white-space: nowrap;
  }

  .search-form {
    min-width: 0;
    flex: 1 1 auto;
  }

  .search-form input {
    min-height: 40px;
    border-radius: 999px;
    padding-inline: 14px;
  }

  .topbar .topbar-right {
    gap: 8px;
    flex-wrap: nowrap;
  }

  .topbar .top-link {
    font-size: 12px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  .layout-grid {
    display: block !important;
    padding: 10px 8px calc(var(--safe-mobile-nav-h) + env(safe-area-inset-bottom) + 16px) !important;
    max-width: 100%;
  }

  .left-sidebar,
  .right-sidebar,
  .footer-bar {
    display: none !important;
  }

  .main-content {
    width: 100%;
    min-width: 0;
  }

  .main-content .card,
  .main-content .panel,
  .main-content .post-card {
    border-radius: 16px !important;
    overflow: hidden;
  }

  #feed,
  .feed-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .post-card,
  .card.post-card {
    margin: 0 !important;
  }

  .feed-post-avatar,
  .profile-post-avatar {
    width: 42px !important;
    height: 42px !important;
  }

  .post-content {
    font-size: 14px;
    line-height: 1.45;
  }

  .media-grid {
    gap: 4px !important;
  }

  .media-grid-image {
    min-height: 120px;
    object-fit: cover;
  }

  .reaction-bar {
    gap: 6px !important;
    flex-wrap: wrap;
  }

  .reaction-btn,
  .comment-toggle-btn,
  .comment-load-more-btn,
  .follow-btn,
  button,
  .top-link {
    min-height: 40px;
  }

  .comment-form input,
  .profile-comment-form input {
    min-height: 42px;
  }

  .comment-form button,
  .profile-comment-form button {
    min-height: 42px;
  }

  .safe-mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 950;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: rgba(255,255,255,.96);
    border-top: 1px solid var(--line, #ddd);
    backdrop-filter: blur(14px);
    min-height: calc(var(--safe-mobile-nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }

  .safe-mobile-bottom-nav-link {
    display: flex;
    min-height: var(--safe-mobile-nav-h);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: var(--muted, #666);
    font-size: 11px;
    font-weight: 700;
  }

  .safe-mobile-bottom-nav-link.is-active {
    color: var(--accent, #1877f2);
  }

  .safe-mobile-bottom-nav-icon {
    font-size: 20px;
    line-height: 1;
  }

  .safe-mobile-bottom-nav-label {
    line-height: 1;
  }
}

@media (max-width: 560px) {
  .brand {
    font-size: 20px;
  }

  .topbar {
    padding-inline: 10px;
  }

  .layout-grid {
    padding-top: 8px !important;
    padding-inline: 8px !important;
  }

  .topbar .topbar-right {
    gap: 6px;
  }
}


/* Footer/sidebar desktop patch compatibility */
@media (max-width: 980px) {
  body {
    padding-bottom: 0 !important;
  }

  .footer-bar {
    display: none !important;
  }
}
