/* ============================================================
   Bengal Landmark Realty Portal V5 - Responsive Stability Patch
   Additive only: does not remove or hide homepage sections/images.
   ============================================================ */

html, body { max-width: 100%; overflow-x: clip; }
@supports not (overflow: clip) { html, body { overflow-x: hidden; } }

img, video, iframe, svg { max-width: 100%; }
img { height: auto; }

/* Preserve existing site sections while preventing layout overflow. */
main > section,
.portal-section,
.search-shell,
.partner-strip,
.page-hero,
.results-page,
.site-footer,
footer { width: 100%; max-width: 100%; }

.container { max-width: 100%; }

/* Header / menu stability */
.site-header { width: 100%; }
.nav-wrap { min-width: 0; }
.brand, .brand a { min-width: 0; }
.brand img { max-width: min(230px, 48vw); object-fit: contain; }
.main-nav { min-width: 0; }

/* Hero remains image-first and keeps all current images. */
.portal-hero,
.portal-hero-image-only,
.portal-hero-image-only .portal-slide { width: 100%; max-width: 100%; }
.portal-hero-image-only .portal-slide img {
  display: block;
  width: 100%;
  max-width: none;
  height: clamp(300px, 38vw, 560px);
  object-fit: cover;
  object-position: center;
}

/* Cards/grids: prevent long content from pushing the viewport. */
.portal-card,
.result-card,
.project-feature,
.quick-category,
.location-card,
.blog-card,
.tool-card,
.amenity-icon-card { min-width: 0; }
.portal-card-title,
.result-main h3,
.project-feature-copy h3,
.location-card strong,
.blog-card h3,
.tool-card h3 { overflow-wrap: anywhere; }

/* Safe responsive tables for public/admin screens. */
.table-responsive,
.admin-table-wrap,
.report-table-wrap,
.data-table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { max-width: 100%; }

/* Forms */
input, select, textarea, button { max-width: 100%; }
textarea { resize: vertical; }
.form-grid, .admin-form-grid { min-width: 0; }

/* Prevent floating actions from covering content on compact screens. */
.floating-actions, .floating-contact { max-width: calc(100vw - 20px); }

/* Laptop / small desktop */
@media (max-width: 1180px) {
  .container { width: min(100% - 36px, 1180px); }
  .main-nav { gap: 14px; }
  .main-nav > a, .nav-drop > button { font-size: 13px; }
  .search-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .search-grid .search-btn { width: 100%; }
  .portal-grid, .insight-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .project-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tablet and mobile navigation. Existing JS toggles .open. */
@media (max-width: 1050px) {
  .site-header {
    position: sticky;
    top: 0;
    z-index: 5000;
    background: #fff;
  }
  .nav-wrap {
    position: relative;
    min-height: 72px;
    height: auto;
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .brand { flex: 0 1 auto; }
  .brand img { height: 50px; width: auto; max-width: 210px; }
  .menu-toggle {
    display: inline-grid !important;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    margin-left: auto;
    position: relative;
    z-index: 5002;
  }
  .main-nav {
    display: none !important;
    position: absolute;
    top: 100%;
    left: 50%;
    right: auto;
    width: 100vw;
    transform: translateX(-50%);
    max-height: calc(100dvh - 72px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border-top: 1px solid #e4edf2;
    border-bottom: 1px solid #d9e6ed;
    border-radius: 0 0 18px 18px;
    box-shadow: 0 18px 38px rgba(12,76,137,.14);
    padding: 10px 18px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    z-index: 5001;
  }
  .main-nav.open, .main-nav.is-open { display: flex !important; }
  .main-nav > a, .nav-drop > button {
    width: 100%;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 8px !important;
    margin: 0;
    border: 0 !important;
    border-bottom: 1px solid #edf2f5 !important;
    background: transparent;
    font-size: 15px;
    line-height: 1.3;
    text-align: left;
  }
  .nav-drop { width: 100%; position: relative; }
  .nav-drop .drop-menu,
  .nav-drop:hover .drop-menu {
    display: none !important;
    position: static !important;
    min-width: 0;
    width: 100%;
    padding: 4px 8px 9px 18px;
    margin: 0;
    border: 0;
    border-bottom: 1px solid #edf2f5;
    border-radius: 0;
    background: #f8fbfd;
    box-shadow: none;
  }
  .nav-drop.open .drop-menu,
  .nav-drop:focus-within .drop-menu { display: block !important; }
  .drop-menu a {
    display: block;
    width: 100%;
    min-height: 42px;
    padding: 10px 11px;
  }
  body.mobile-menu-open { overflow: hidden; }
  .post-property-btn { display: none !important; }

  .quick-categories { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .location-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-card { grid-template-columns: 220px minmax(0, 1fr); }
  .result-side {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line, #dfe9ef);
    padding: 12px 0 0;
  }
  .footer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .container { width: min(100% - 28px, 100%); }
  .portal-topbar { display: none; }
  .nav-wrap { min-height: 66px; }
  .brand img { height: 46px; max-width: 185px; }
  .main-nav { max-height: calc(100dvh - 66px); }

  .portal-hero-image-only .portal-slide img { height: clamp(260px, 68vw, 340px); }
  .portal-hero-image-only + .search-shell { margin-top: -28px !important; }
  .portal-search-box { padding-left: 14px; padding-right: 14px; }

  .search-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
  .search-tabs button { flex: 0 0 auto; white-space: nowrap; }
  .search-grid { grid-template-columns: 1fr !important; }

  .portal-section { padding: 52px 0; }
  .portal-section-head { align-items: flex-start; flex-direction: column; gap: 10px; }
  .portal-section-head h2, .page-hero h1 { font-size: clamp(26px, 8vw, 34px); }

  .quick-categories,
  .portal-grid,
  .insight-grid,
  .location-grid,
  .project-strip,
  .tool-grid { grid-template-columns: 1fr !important; }

  .result-card { grid-template-columns: 1fr !important; }
  .result-image { height: min(64vw, 260px); }
  .result-side { display: block; }
  .result-side .btn { margin-top: 8px; }

  .detail-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .amenity-icons { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .youtube-grid { grid-template-columns: 1fr !important; }
  .login-options-grid { grid-template-columns: 1fr !important; }

  .portal-cta { flex-direction: column; align-items: flex-start; padding: 26px 22px; }
  .portal-cta .btn { width: 100%; }

  .footer-grid { grid-template-columns: 1fr !important; }
  .footer-bottom { flex-direction: column; gap: 8px; }

  /* Admin portal mobile safety */
  .admin-layout, .admin-content, .admin-main, .content-wrapper { min-width: 0; max-width: 100%; }
  .admin-grid, .dashboard-grid, .stat-grid, .kpi-grid { grid-template-columns: 1fr !important; }
  .admin-actions, .action-buttons, .table-actions { display: flex; flex-wrap: wrap; gap: 6px; }
  .admin-actions .btn, .action-buttons .btn, .table-actions .btn { min-height: 40px; }
}

@media (max-width: 390px) {
  .container { width: calc(100% - 22px); }
  .brand img { max-width: 158px; height: 42px; }
  .menu-toggle { width: 40px; height: 40px; flex-basis: 40px; }
  .detail-gallery { grid-template-columns: 1fr !important; }
  .portal-card-body, .blog-card-body { padding-left: 14px; padding-right: 14px; }
}

/* V5 admin project status helpers */
.v5-status-active { color: #187a2a; background: #eff9f1; border: 1px solid #cfe8d4; }
.v5-status-inactive { color: #a23a3a; background: #fff1f1; border: 1px solid #f0caca; }
.v5-status-badge { display:inline-flex; align-items:center; padding:5px 9px; border-radius:999px; font-size:11px; font-weight:700; }
