/* ==========================================================================
   Responsive Overrides & Mobile Experience (Android & iOS Optimized)
   ========================================================================== */

/* Global safety against horizontal scroll on mobile */
html, body {
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

/* Ensure mobile close button hidden on desktop */
.mobile-close-btn {
  display: none !important;
}

/* iOS Safari form zoom prevention: input font-size must be at least 16px */
input, select, textarea {
  font-size: 16px !important;
}

/* Desktops/Laptops (max-width: 1024px) */
@media (max-width: 1024px) {
  .hero-container {
    grid-template-columns: 1fr;
    gap: 3.5rem;
  }

  .hero-content {
    max-width: 100%;
    text-align: center;
  }

  .hero-badges {
    justify-content: center;
  }

  .hero-subtitle {
    margin-left: auto;
    margin-right: auto;
  }

  .hero-buttons {
    justify-content: center;
  }

  .hero-stats-grid {
    justify-content: center;
  }

  .hero-showcase {
    margin: 0 auto;
  }

  .hero-title {
    font-size: 2.85rem;
  }
  
  .section {
    padding: 3.5rem 0;
  }

  .profil-wrapper {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }

  .kontak-wrapper {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }
}

/* Tablets & Mobile Navigation (max-width: 768px) */
@media (max-width: 768px) {
  /* Compact and Slim Mobile Header */
  .header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    padding: max(0.4rem, env(safe-area-inset-top)) 0.75rem 0.4rem !important;
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    box-shadow: 0 2px 12px rgba(14, 27, 77, 0.08) !important;
    z-index: 1000 !important;
  }
  
  .header.scrolled {
    padding: max(0.35rem, env(safe-area-inset-top)) 0.75rem 0.35rem !important;
    box-shadow: 0 3px 15px rgba(14, 27, 77, 0.1) !important;
  }

  .navbar {
    padding: 0.25rem 0.5rem !important;
    background: transparent !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    border: none !important;
  }

  .logo-link {
    gap: 0.5rem !important;
  }

  .logo-icon {
    width: 36px !important;
    height: 36px !important;
    font-size: 1rem !important;
  }

  .logo-text {
    font-size: 0.95rem !important;
  }

  .logo-subtext {
    font-size: 0.6rem !important;
    letter-spacing: 0.8px !important;
  }

  /* Sembunyikan tombol Search dan Tombol PPDB panjang di navbar mobile agar tidak memakan tempat */
  .nav-search-btn,
  .btn-nav-ppdb,
  .nav-cta-desktop {
    display: none !important;
  }

  .mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 38px !important;
    height: 38px !important;
    border-radius: 8px !important;
    background: rgba(7, 44, 119, 0.08) !important;
    color: var(--primary, #072C77) !important;
    font-size: 1.15rem !important;
    border: none;
    cursor: pointer;
    transition: background 0.2s ease;
  }

  .mobile-menu-btn:active {
    background: rgba(7, 44, 119, 0.18) !important;
  }

  /* Safe spacing under header so content is NEVER covered */
  .hero {
    padding-top: calc(5.2rem + env(safe-area-inset-top)) !important;
    padding-bottom: 3rem !important;
  }
  
  .hero-banner {
    padding-top: calc(5.5rem + env(safe-area-inset-top)) !important;
    padding-bottom: 2.5rem !important;
  }

  .hero-title {
    font-size: 2.15rem;
  }

  /* Off-canvas Drawer Navigation */
  .nav-links {
    position: fixed;
    top: 0;
    right: -100%;
    width: 82%;
    max-width: 320px;
    height: 100vh;
    height: 100dvh;
    background-color: #FFFFFF;
    flex-direction: column;
    align-items: flex-start;
    padding: calc(4.5rem + env(safe-area-inset-top)) 1.75rem calc(2rem + env(safe-area-inset-bottom));
    box-shadow: -8px 0 25px rgba(14, 27, 77, 0.15);
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-links.active {
    right: 0;
  }

  .nav-item {
    width: 100%;
    margin-bottom: 0.5rem;
  }

  .nav-link {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--primary-dark, #0E1B4D);
    padding: 0.75rem 0;
    width: 100%;
    display: block;
    border-bottom: 1px solid rgba(14, 27, 77, 0.06);
  }

  .dropdown-menu {
    position: static;
    box-shadow: none;
    padding-left: 1rem;
    border-left: 2px solid var(--accent, #F47B20);
    margin: 0.5rem 0;
    display: block;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    background: #F8FAFC;
    border-radius: 8px;
  }

  .dropdown-menu li a {
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    color: var(--text-body);
  }

  /* Overlay for mobile menu */
  .mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(14, 27, 77, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .mobile-overlay.active {
    display: block;
    opacity: 1;
  }
  
  /* Close button inside mobile menu */
  .mobile-close-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: calc(1.25rem + env(safe-area-inset-top));
    right: 1.25rem;
    width: 40px;
    height: 40px;
    background: #F1F5F9;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--primary-dark, #0E1B4D);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  }

  /* Program Unggulan Mobile Layout */
  .program-row, .program-row.reverse {
    flex-direction: column !important;
    gap: 1.5rem;
    padding: 1.5rem;
    margin-bottom: 2.25rem;
    border-radius: 16px;
  }

  .program-text h2 {
    font-size: 1.45rem;
  }

  .program-img {
    width: 100%;
    min-height: auto;
  }

  .program-img img {
    height: 220px;
  }

  /* Sambutan section mobile */
  .flex-row {
    flex-direction: column !important;
    gap: 2rem;
  }

  .sambutan-img {
    max-width: 280px;
    margin: 0 auto;
  }

  /* Guru Grid */
  .guru-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }

  .guru-card {
    padding: 1.25rem 0.75rem;
  }

  .guru-card img {
    width: 100px;
    height: 100px;
  }

  /* Galeri Grid Mobile (Both .gallery-grid and .galeri-grid) */
  .galeri-grid, .gallery-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.85rem !important;
  }

  .galeri-item, .gallery-item {
    min-height: 160px !important;
    height: 180px !important;
    border-radius: 12px !important;
    background: #E2E8F0 !important;
    display: block !important;
    overflow: hidden !important;
  }

  .galeri-item img, .gallery-item img, .gallery-photo {
    width: 100% !important;
    height: 100% !important;
    min-height: 160px !important;
    object-fit: cover !important;
    display: block !important;
  }

  .galeri-overlay, .gallery-overlay {
    opacity: 1 !important;
    background: linear-gradient(180deg, transparent 40%, rgba(14,27,77,0.85) 100%) !important;
    padding: 0.75rem !important;
  }

  .galeri-overlay p, .gallery-overlay p, .gallery-overlay h4 {
    font-size: 0.85rem !important;
    color: #fff !important;
    margin: 0 !important;
  }

  .galeri-filter, .gallery-filters {
    overflow-x: auto !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    padding-bottom: 10px !important;
    margin-bottom: 1.75rem !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }

  .galeri-filter::-webkit-scrollbar, .gallery-filters::-webkit-scrollbar {
    display: none !important;
  }

  .filter-btn {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 0.45rem 1rem !important;
    font-size: 0.85rem !important;
  }

  /* Floating WhatsApp Button - Mobile Safe Area */
  .floating-buttons {
    bottom: calc(1.25rem + env(safe-area-inset-bottom));
    right: calc(1rem + env(safe-area-inset-right));
    gap: 0.65rem;
  }

  .btn-float {
    width: 48px;
    height: 48px;
    font-size: 1.15rem;
  }

  .footer-top {
    flex-direction: column;
    gap: 2rem;
  }
}

/* Small devices / Smartphones (max-width: 640px) */
@media (max-width: 640px) {
  .hero-title {
    font-size: 1.85rem;
    line-height: 1.25;
  }

  .hero-subtitle {
    font-size: 0.95rem;
    line-height: 1.5;
  }

  .hero-buttons {
    flex-direction: column;
    width: 100%;
    gap: 0.75rem;
  }

  .hero-buttons .btn {
    width: 100%;
    justify-content: center;
    padding: 0.85rem 1.25rem;
  }

  .hero-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    width: 100%;
    margin-top: 1.5rem;
  }

  .stat-card {
    padding: 0.65rem 0.5rem;
  }

  .stat-num {
    font-size: 1.35rem;
  }

  .stat-lbl {
    font-size: 0.68rem;
  }

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

  .hero-main-slide {
    height: 260px;
  }

  .hero-thumbs-row {
    bottom: -10px;
    right: 5px;
  }

  .hero-thumb {
    width: 52px;
    height: 36px;
  }
  
  .section-title {
    font-size: 1.65rem;
  }

  /* Identitas table scrollable on small screens */
  .table-identitas {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-identitas th, .table-identitas td {
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
  }

  /* PPDB Timeline / Alur Grid */
  .alur-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1rem !important;
  }

  .alur-item {
    background: #F8FAFC;
    padding: 1.25rem 0.75rem;
    border-radius: 12px;
  }

  .alur-item i {
    font-size: 2rem !important;
    color: var(--primary);
  }

  /* Guru card text on small screen */
  .guru-card h3 {
    font-size: 0.95rem;
  }

  .guru-card p {
    font-size: 0.78rem;
  }
}

/* Extra small devices (< 380px) */
@media (max-width: 380px) {
  .guru-grid {
    grid-template-columns: 1fr;
  }

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

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

