/* ==========================================================
   RUSTIC Website - Comprehensive Mobile Responsive Overhaul
   Bootstrap 5.3 + Custom Override System
   ========================================================== */

/* =====================================================
   BOOTSTRAP CONFLICT FIXES
   Our design uses .container with max-width in style.css.
   Ensure Bootstrap doesn't override our container sizing.
   ===================================================== */
.container {
  max-width: 1260px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
}

/* =====================================================
   BASE: DESKTOP DEFAULTS (>1024px)
   ===================================================== */
.mobile-toggle,
.mobile-menu-btn {
  display: none !important;
}

.mobile-nav-drawer {
  position: fixed;
  top: 0;
  right: -360px;
  width: 340px;
  max-width: 88vw;
  height: 100vh;
  background: #07172b;
  z-index: 2000;
  box-shadow: -10px 0 35px rgba(0, 0, 0, 0.45);
  transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.mobile-nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 23, 43, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.desktop-nav {
  display: block !important;
}


/* =====================================================
   BREAKPOINT: COMPACT DESKTOP (1025px – 1280px)
   ===================================================== */
@media (max-width: 1280px) {
  .nav-menu {
    gap: 4px;
  }

  .nav-link {
    font-size: 0.82rem;
    padding: 8px 5px;
  }

  .brand-tagline {
    display: none;
  }

  .cta-btn {
    padding: 7px 10px;
    font-size: 0.78rem;
  }

  .mega-dropdown {
    width: 92vw;
  }
}


/* =====================================================
   BREAKPOINT: TABLET / MOBILE NAV (≤1024px)
   ===================================================== */
@media (max-width: 1024px) {
  /* Hide Desktop Nav */
  .desktop-nav {
    display: none !important;
  }

  .brand-tagline {
    display: none !important;
  }

  .search-kbd,
  .search-btn-label {
    display: none !important;
  }

  .cta-btn {
    display: none !important;
  }

  /* Show Hamburger */
  .mobile-toggle,
  .mobile-menu-btn {
    display: flex !important;
  }

  /* Enable Off-Canvas Drawer */
  .mobile-nav-drawer {
    display: flex !important;
  }

  .mobile-nav-drawer.active {
    right: 0 !important;
  }

  .mobile-nav-backdrop {
    display: block !important;
  }

  .mobile-nav-backdrop.active {
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* Prevent body scroll when drawer is open */
  body.no-scroll {
    overflow: hidden !important;
  }

  /* --- Layout Grids: Force 2-Column --- */
  .hero-grid {
    grid-template-columns: 1fr !important;
    gap: 30px !important;
    text-align: center;
  }

  .hero-badge,
  .hero-cta,
  .hero-trust-badges {
    justify-content: center !important;
  }

  .hero-stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .programs-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .footer-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 30px !important;
  }

  /* eBook reader sidebars */
  .monograph-drawer,
  .profile-drawer,
  .form-sidebar {
    display: none !important;
  }

  .monograph-viewer-layout,
  .profile-viewer-layout,
  .form-layout {
    flex-direction: column;
  }

  /* =====================================================
     HAMBURGER BUTTON — visible bars
     ===================================================== */
  .mobile-toggle,
  .mobile-menu-btn {
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 42px;
    height: 42px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    padding: 8px;
    transition: all 0.2s ease;
    z-index: 100;
  }

  .mobile-toggle:hover,
  .mobile-menu-btn:hover {
    background: rgba(15, 48, 87, 0.08);
  }

  .mobile-toggle .bar,
  .mobile-menu-btn .bar {
    display: block;
    width: 22px;
    height: 2.5px;
    background-color: var(--text-main, #1e293b);
    border-radius: 2px;
    transition: all 0.3s ease;
  }

  /* Dark mode hamburger bars */
  [data-theme="dark"] .mobile-toggle .bar,
  [data-theme="dark"] .mobile-menu-btn .bar {
    background-color: #e2e8f0;
  }

  [data-theme="dark"] .mobile-toggle,
  [data-theme="dark"] .mobile-menu-btn {
    border-color: rgba(255,255,255,0.15);
  }

  /* =====================================================
     MOBILE DRAWER — Link & Dropdown Styles
     Must be at 1024px since drawer is enabled here
     ===================================================== */
  .drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
  }

  .drawer-body {
    padding: 16px 20px;
    flex: 1;
    overflow-y: auto;
  }

  .mobile-menu {
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .mobile-menu > li {
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }

  .mobile-link {
    display: block;
    padding: 14px 0;
    color: #ffffff !important;
    text-decoration: none !important;
    font-size: 1rem;
    font-weight: 600;
    transition: color 0.2s ease;
  }

  .mobile-link:hover,
  .mobile-link:focus {
    color: var(--accent-400, #fbbf24) !important;
    text-decoration: none !important;
  }

  .mobile-dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 0;
    background: none;
    border: none;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
  }

  .mobile-dropdown-toggle i {
    transition: transform 0.3s ease;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
  }

  .mobile-dropdown.active .mobile-dropdown-toggle i {
    transform: rotate(180deg);
  }

  .mobile-submenu {
    display: none;
    padding: 0 0 10px 14px;
    flex-direction: column;
    gap: 2px;
  }

  .mobile-dropdown.active .mobile-submenu {
    display: flex;
  }

  .mobile-submenu a {
    display: block;
    padding: 10px 12px;
    color: #cbd5e1 !important;
    text-decoration: none !important;
    font-size: 0.9rem;
    border-radius: 6px;
    transition: all 0.2s ease;
  }

  .mobile-submenu a:hover {
    background: rgba(255,255,255,0.06);
    color: #fff !important;
  }

  .drawer-close {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .drawer-close:hover {
    background: rgba(255,255,255,0.15);
  }

  /* =====================================================
     TEXT OVERFLOW PROTECTION — prevent horizontal cut-off
     ===================================================== */
  * {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .container {
    max-width: 100%;
    overflow-x: hidden;
  }

  section, div, p, h1, h2, h3, h4, h5, h6, span, li, a {
    max-width: 100%;
  }

  html, body {
    overflow-x: hidden;
  }
}


/* =====================================================
   BREAKPOINT: SMARTPHONE (≤768px)
   THE BIG ONE — fixes all inline style grids
   ===================================================== */
@media (max-width: 768px) {

  /* --- Top Bar: Hide completely --- */
  .top-bar {
    display: none !important;
  }

  /* --- Header Adjustments --- */
  .main-header {
    padding: 8px 0;
  }

  .header-container {
    padding: 0 12px !important;
  }

  .brand-logo img,
  .logo-img {
    height: 36px !important;
  }

  .brand-name {
    font-size: 1.15rem;
  }

  /* --- Container Padding --- */
  .container {
    padding: 0 16px;
  }

  /* --- Section Spacing --- */
  .section-padding {
    padding: 40px 0 !important;
  }

  /* --- Hero Section --- */
  .hero {
    padding: 60px 0 45px !important;
  }

  .hero-title {
    font-size: 1.8rem !important;
    line-height: 1.2 !important;
  }

  .hero-subtitle {
    font-size: 0.92rem !important;
  }

  /* --- Page Banners --- */
  section[style*="padding: 75px 0"],
  section[style*="padding: 80px 0"],
  section[style*="padding: 70px 0"] {
    padding: 50px 0 40px !important;
  }

  .page-banner {
    padding: 50px 0 40px !important;
  }

  .page-title {
    font-size: 1.7rem !important;
  }

  /* --- Section Titles --- */
  .section-title {
    font-size: 1.6rem !important;
  }

  h1 {
    font-size: 1.7rem !important;
    word-wrap: break-word;
  }

  h2 {
    font-size: 1.35rem !important;
    word-wrap: break-word;
  }

  h3 {
    font-size: 1.15rem !important;
  }

  /* =====================================================
     MASTER FIX: Force ALL inline grid layouts to 1-col
     This targets every inline style= grid on all pages
     ===================================================== */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }

  /* Fix specific multi-column flex layouts */
  [style*="display: flex"][style*="gap: 28px"],
  [style*="display: flex"][style*="gap: 40px"],
  [style*="display: flex"][style*="gap: 50px"],
  [style*="display: flex"][style*="gap: 30px"] {
    flex-direction: column !important;
    gap: 20px !important;
  }

  /* Fix display:grid containers with inline columns */
  div[style*="grid-template-columns: 1.1fr"],
  div[style*="grid-template-columns: 1.15fr"],
  div[style*="grid-template-columns: 0.8fr"],
  div[style*="grid-template-columns: 1fr 1.1fr"],
  div[style*="grid-template-columns: 1.2fr"],
  div[style*="grid-template-columns: 0.35fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns: repeat(2"],
  div[style*="grid-template-columns: repeat(3"],
  div[style*="grid-template-columns: repeat(4"],
  div[style*="grid-template-columns: repeat(5"],
  div[style*="grid-template-columns: 0.4fr"],
  div[style*="grid-template-columns: 0.45fr"],
  div[style*="grid-template-columns: 0.5fr"] {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }

  /* =====================================================
     STATS / IMPACT COUNTER STRIP — 2-col on mobile
     ===================================================== */
  .stats-strip .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }

  .stat-box {
    border-right: none !important;
    border-bottom: 1px solid rgba(255,255,255,0.1) !important;
    padding-bottom: 12px !important;
  }

  .stat-number {
    font-size: 1.9rem !important;
  }

  /* Also catch inline stats grids */
  div[style*="repeat(5, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }

  /* =====================================================
     PROGRAMS & GALLERY GRIDS
     ===================================================== */
  .programs-grid {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }

  .gallery-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* =====================================================
     FOOTER — single column on mobile
     ===================================================== */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 28px !important;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: 10px;
  }

  .footer-bottom-links {
    justify-content: center;
    flex-wrap: wrap;
  }

  /* =====================================================
     FORM GRIDS
     ===================================================== */
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  .form-group.full-width {
    grid-column: span 1 !important;
  }

  /* =====================================================
     REPORT CARDS & CERT CARDS — stack vertically
     ===================================================== */
  .report-card {
    flex-direction: column !important;
    align-items: center !important;
    text-align: center;
    padding: 24px !important;
  }

  .report-cover {
    width: 120px !important;
    height: 160px !important;
  }

  .report-meta {
    justify-content: center;
    flex-wrap: wrap;
  }

  .cert-card {
    flex-direction: column !important;
    text-align: center;
    gap: 14px !important;
  }

  /* =====================================================
     GOVERNANCE: ED photo + bio grid
     ===================================================== */
  div[style*="grid-template-columns: 0.35fr 0.65fr"] {
    grid-template-columns: 1fr !important;
    text-align: center;
  }

  /* =====================================================
     PARTNER CARDS GRID
     ===================================================== */
  div[style*="grid-template-columns: repeat(2, 1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* =====================================================
     INLINE PADDING OVERRIDES
     Some PHP pages have style="padding: 45px;" etc.
     ===================================================== */
  div[style*="padding: 45px"],
  div[style*="padding: 40px"],
  div[style*="padding: 50px"] {
    padding: 20px !important;
  }

  div[style*="padding: 36px"],
  div[style*="padding: 35px"] {
    padding: 18px !important;
  }

  /* =====================================================
     INLINE FONT SIZE OVERRIDES
     ===================================================== */
  [style*="font-size: 2.9rem"],
  [style*="font-size: 2.8rem"],
  [style*="font-size: 2.7rem"],
  [style*="font-size: 2.6rem"],
  [style*="font-size: 2.5rem"] {
    font-size: 1.65rem !important;
  }

  [style*="font-size: 2.4rem"],
  [style*="font-size: 2.3rem"],
  [style*="font-size: 2.2rem"],
  [style*="font-size: 2.1rem"],
  [style*="font-size: 2rem"] {
    font-size: 1.4rem !important;
  }

  [style*="font-size: 1.85rem"],
  [style*="font-size: 1.75rem"] {
    font-size: 1.3rem !important;
  }

  [style*="font-size: 3.5rem"],
  [style*="font-size: 3.2rem"],
  [style*="font-size: 3rem"] {
    font-size: 1.8rem !important;
  }

  /* =====================================================
     IMAGE SIZE OVERRIDES for mobile
     ===================================================== */
  img[style*="width: 220px"],
  img[style*="width: 200px"] {
    width: 140px !important;
    height: auto !important;
  }

  div[style*="width: 220px"][style*="height: 260px"] {
    width: 160px !important;
    height: 200px !important;
    margin: 0 auto 14px !important;
  }

  img[style*="height: 440px"],
  img[style*="height: 400px"],
  img[style*="height: 380px"] {
    height: 220px !important;
  }

  /* =====================================================
     EBOOK READER PAGES (WaterAid, Profile 2022, etc.)
     ===================================================== */
  .monograph-toolbar,
  .profile-viewer-toolbar,
  .form-toolbar {
    padding: 8px 12px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .monograph-stage,
  .profile-stage,
  .form-stage {
    padding: 16px 8px 60px !important;
  }

  .monograph-page-sheet,
  .profile-page-sheet,
  .form-page-sheet {
    max-width: 100% !important;
    min-height: auto !important;
    padding: 20px 16px !important;
  }

  .form-page-sheet {
    padding: 24px 18px !important;
  }

  /* Viewer controls */
  .viewer-tool-btn {
    padding: 5px 8px !important;
    font-size: 0.75rem !important;
  }

  .profile-brand-title {
    font-size: 0.78rem !important;
  }

  .page-jump-box {
    width: 38px !important;
  }

  /* Dossier page headers/footers */
  .dossier-page-header,
  .dossier-page-footer,
  .form-page-header,
  .form-page-footer {
    font-size: 0.68rem !important;
    padding-bottom: 8px !important;
    padding-top: 8px !important;
  }

  /* =====================================================
     TABLE RESPONSIVENESS
     ===================================================== */
  table {
    width: 100% !important;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table thead,
  table tbody,
  table tr,
  table th,
  table td {
    min-width: auto;
  }

  .form-grid-table {
    font-size: 0.78rem !important;
  }

  .form-grid-table th,
  .form-grid-table td {
    padding: 6px 8px !important;
  }

  .form-field-label {
    width: auto !important;
  }

  /* =====================================================
     GALLERY FILTER BAR — horizontal scroll
     ===================================================== */
  .filter-bar {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 10px;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    gap: 6px !important;
  }

  .filter-btn {
    white-space: nowrap;
    font-size: 0.78rem;
    padding: 6px 12px;
    flex-shrink: 0;
  }

  /* =====================================================
     SEARCH MODAL — mobile fit
     ===================================================== */
  .search-modal-container {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 10vh auto 0 !important;
  }

  .search-modal-quicktags {
    flex-wrap: wrap;
    gap: 6px !important;
  }

  .quicktag-btn {
    font-size: 0.72rem !important;
    padding: 4px 8px !important;
  }

  /* =====================================================
     ABOUT PAGE — banner buttons
     ===================================================== */
  div[style*="display: flex"][style*="justify-content: center"][style*="gap: 14px"] {
    flex-direction: column !important;
    align-items: center !important;
    gap: 10px !important;
  }

  /* =====================================================
     MISC UTILITY OVERRIDES
     ===================================================== */

  /* Prevent horizontal overflow anywhere */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* Fix images from overflowing */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Fix video/iframe overflow */
  iframe, video, embed, object {
    max-width: 100%;
  }
}


/* =====================================================
   BREAKPOINT: SMALL PHONE (≤480px)
   ===================================================== */
@media (max-width: 480px) {
  .container {
    padding: 0 12px;
  }

  h1 {
    font-size: 1.45rem !important;
  }

  h2 {
    font-size: 1.2rem !important;
  }

  .hero-title {
    font-size: 1.5rem !important;
  }

  .stat-number {
    font-size: 1.6rem !important;
  }

  .report-cover {
    width: 100px !important;
    height: 140px !important;
  }

  /* Even smaller padding */
  div[style*="padding: 45px"],
  div[style*="padding: 40px"],
  div[style*="padding: 50px"] {
    padding: 14px !important;
  }

  /* Stack trust badges vertically */
  .hero-trust-badges {
    flex-direction: column !important;
    gap: 10px !important;
  }

  /* Smaller buttons */
  .btn {
    padding: 10px 18px !important;
    font-size: 0.85rem !important;
  }

  .btn-sm {
    padding: 8px 14px !important;
    font-size: 0.8rem !important;
  }
}
