/* ==============================================================================
   SMA MEDANGGILI CIRUAS - COMPREHENSIVE RESPONSIVE STYLES
   Mobile, Tablet, Laptop & Desktop Cross-Device Optimization
   ============================================================================== */

/* -----------------------------------------------------------------------------
   0. UNIVERSAL RESPONSIVE SAFETY RESETS
----------------------------------------------------------------------------- */
html, body {
  max-width: 100vw !important;
  overflow-x: hidden !important;
  position: relative;
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after {
  box-sizing: border-box;
}

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

/* Container safety */
.container {
  width: 100%;
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
}

/* -----------------------------------------------------------------------------
   1. LAPTOP & DESKTOP (max-width: 1200px)
----------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .hero-title {
    font-size: 2.35rem;
  }
  
  .nav-menu {
    gap: 3px;
    padding: 4px 6px;
  }
  
  .nav-link {
    padding: 7px 11px;
    font-size: 0.82rem;
  }

  .news-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  .ekskul-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  .prestasi-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
  
  .teachers-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
}

/* -----------------------------------------------------------------------------
   2. TABLET LANDSCAPE & MOBILE DRAWER (max-width: 1140px)
----------------------------------------------------------------------------- */
@media (max-width: 1140px) {
  .mobile-toggle {
    display: inline-flex !important;
  }
  
  .nav-menu {
    position: fixed;
    top: 0;
    right: -360px;
    left: auto;
    width: 320px;
    max-width: 86vw;
    height: 100vh;
    background: #FFFFFF !important;
    flex-direction: column;
    align-items: stretch;
    padding: 85px 18px 30px;
    box-shadow: -15px 0 50px rgba(25, 45, 35, 0.25);
    border-radius: 28px 0 0 28px;
    border: 1.5px solid rgba(74, 107, 91, 0.16);
    border-right: none;
    transition: right 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1050;
    overflow-y: auto;
    gap: 8px;
    white-space: normal;
  }
  
  .nav-menu.active {
    right: 0;
  }

  /* Dark Dimmed Backdrop Overlay (No Blur Over Menu) */
  .nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 30, 22, 0.55);
    z-index: 1040;
    cursor: pointer;
  }

  .nav-backdrop.active {
    display: block;
    animation: drawerBackdropFade 0.25s ease;
  }

  @keyframes drawerBackdropFade {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  body.nav-drawer-open {
    overflow: hidden !important;
  }
  
  .nav-item {
    width: 100%;
    list-style: none !important;
  }
  
  .nav-link {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    font-size: 0.94rem;
    font-weight: 700;
    background: #FFFFFF;
    border: 1.5px solid rgba(74, 107, 91, 0.12);
    border-radius: 14px;
    box-shadow: 2px 4px 10px rgba(50, 75, 63, 0.05), -2px -2px 6px #FFFFFF;
    white-space: normal;
  }

  .nav-link:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
  }

  .nav-link.active {
    background: var(--primary-gradient);
    color: #FFFFFF !important;
    border-color: rgba(255, 255, 255, 0.3);
  }

  /* Mobile Dropdown Accordion */
  .has-dropdown .nav-dropdown {
    position: static !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    box-shadow: none !important;
    border: 1.5px solid rgba(74, 107, 91, 0.12) !important;
    background: #F3F7F4 !important;
    border-radius: 14px !important;
    margin-top: 6px !important;
    padding: 8px !important;
    display: none !important;
    pointer-events: auto !important;
    width: 100% !important;
    min-width: 100% !important;
  }
  
  .has-dropdown.mobile-open > .nav-dropdown {
    display: block !important;
    animation: navDropdownFade 0.22s ease forwards !important;
  }

  .has-dropdown.mobile-open > .nav-link .nav-chevron {
    transform: rotate(180deg) !important;
  }
  
  .nav-dropdown-link {
    padding: 10px 14px !important;
    font-size: 0.88rem !important;
    white-space: normal !important;
    word-break: break-word !important;
  }

  .mobile-cta-item,
  #mobile-cta-item {
    display: block !important;
  }
}

/* -----------------------------------------------------------------------------
   3. TABLET PORTRAIT (max-width: 992px)
----------------------------------------------------------------------------- */
@media (max-width: 992px) {
  .hero-banner-card {
    min-height: 440px;
    padding: 48px 0;
    border-radius: 22px;
    background-position: center;
  }
  
  .hero-banner-title {
    font-size: 2.2rem;
  }

  .hero-grid {
    grid-template-columns: 1fr !important;
    gap: 32px !important;
  }

  /* Sambutan Kepala Sekolah 2-column to 1-column */
  .kepsek-grid {
    grid-template-columns: 1fr !important;
    gap: 28px !important;
  }

  .kepsek-photo-box {
    max-width: 280px;
    margin: 0 auto;
  }

  .kepsek-photo {
    height: 280px;
  }

  /* News & Blog Layout Sidebar Stacking */
  .news-layout-grid {
    grid-template-columns: 1fr !important;
    gap: 35px !important;
  }

  /* Contact Page Grid Stacking */
  .contact-grid-layout {
    grid-template-columns: 1fr !important;
    gap: 32px !important;
  }

  /* SPMB Info Grid Stacking */
  .spmb-info-grid {
    grid-template-columns: 1fr !important;
    gap: 28px !important;
  }
  
  .teachers-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }
  
  .news-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

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

/* -----------------------------------------------------------------------------
   4. MOBILE SMARTPHONES & PHABLETS (max-width: 768px)
----------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .container {
    padding-left: 14px;
    padding-right: 14px;
  }

  /* Topbar Mobile Optimization */
  .topbar {
    padding: 6px 0;
    font-size: 0.76rem;
  }

  .topbar-content {
    justify-content: center;
    text-align: center;
    gap: 8px;
  }
  
  .topbar-info {
    justify-content: center;
    font-size: 0.76rem;
    gap: 10px;
    flex-wrap: wrap;
  }

  /* Hide long secondary items in topbar on phone */
  .topbar-info span:first-child,
  .topbar-info span:last-child {
    display: none !important;
  }

  .topbar-social {
    display: none;
  }

  /* Navbar Sticky Mobile Header */
  .navbar-sticky {
    padding: 0 !important;
  }

  .nav-container {
    padding: 8px 14px !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .brand-wrapper {
    min-width: 0 !important;
    flex: 1 1 auto !important;
    max-width: calc(100% - 94px) !important;
    gap: 8px !important;
  }

  .brand-logo {
    width: 38px !important;
    height: 38px !important;
    flex-shrink: 0 !important;
  }

  .brand-text {
    min-width: 0 !important;
    flex: 1 1 auto !important;
    overflow: hidden !important;
  }

  .brand-title,
  .brand-text h1 {
    font-size: clamp(0.9rem, 3.8vw, 1.05rem) !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .brand-subtitle,
  .brand-text span {
    font-size: clamp(0.62rem, 2.4vw, 0.72rem) !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .nav-actions {
    gap: 8px !important;
    flex-shrink: 0 !important;
  }

  .btn-header-spmb {
    padding: 8px 12px !important;
    border-radius: 50px !important;
    font-size: 0.82rem !important;
    width: auto !important;
  }

  .btn-header-spmb span {
    display: none !important;
  }

  .btn-login-header {
    display: none !important;
  }

  .mobile-toggle {
    width: 40px !important;
    height: 40px !important;
    flex-shrink: 0 !important;
  }

  /* Panoramic Hero Banner Mobile Card */
  .hero-panoramic-section {
    padding: 10px 0 24px !important;
  }

  .hero-banner-card {
    min-height: 390px !important;
    padding: 36px 0 !important;
    border-radius: 20px !important;
    background-position: center !important;
    box-shadow: 0 12px 30px rgba(35, 60, 48, 0.14) !important;
  }

  /* Full vertical gradient overlay so text contrast is sharp on mobile portrait */
  .hero-banner-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(16, 36, 26, 0.90) 0%, rgba(22, 46, 34, 0.88) 50%, rgba(14, 30, 22, 0.94) 100%) !important;
    z-index: 1;
    border-radius: inherit;
    pointer-events: none;
  }
  
  .hero-banner-content {
    padding: 0 16px !important;
    max-width: 100% !important;
  }

  .hero-banner-title {
    font-size: clamp(1.4rem, 5.5vw, 1.95rem) !important;
    line-height: 1.25 !important;
    word-break: break-word !important;
    margin-bottom: 14px !important;
  }
  
  .hero-banner-subtitle {
    font-size: 0.92rem !important;
    line-height: 1.6 !important;
    margin-bottom: 20px !important;
    max-width: 100% !important;
  }

  /* Hide slider arrows on small screens so they don't cover text; rely on dots */
  .hero-slider-arrow {
    display: none !important;
  }

  .hero-slider-dots {
    bottom: 12px !important;
  }

  .hero-cta {
    flex-direction: column !important;
    width: 100% !important;
    gap: 10px !important;
  }

  .hero-cta .btn-clay {
    width: 100% !important;
    justify-content: center !important;
  }

  /* 3D Counters Grid: Clean 2x2 grid on mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .stat-card {
    padding: 16px 10px !important;
    border-radius: 16px !important;
  }

  .stat-icon {
    width: 44px !important;
    height: 44px !important;
    font-size: 1.15rem !important;
    margin-bottom: 8px !important;
  }

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

  .stat-label {
    font-size: 0.78rem !important;
  }

  /* Sambutan Kepala Sekolah Content */
  .kepsek-content {
    padding: 24px 16px !important;
    border-radius: 18px !important;
  }

  .kepsek-content h2 {
    font-size: 1.45rem !important;
    line-height: 1.3 !important;
  }

  .kepsek-quote {
    font-size: 0.92rem !important;
    line-height: 1.65 !important;
  }

  /* Grids Collapse to 1 Column */
  .ekskul-grid,
  .prestasi-grid,
  .news-grid,
  .teachers-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Generic Inline Minmax Grids Collapse cleanly */
  div[style*="minmax(320px, 1fr)"],
  div[style*="minmax(280px, 1fr)"],
  div[style*="minmax(240px, 1fr)"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Form Clay Cards & 2-Col Form Grids on Mobile */
  .clay-card,
  form.clay-card {
    padding: 22px 16px !important;
    border-radius: 18px !important;
  }

  form div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1.2fr"] {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  /* Section Headings */
  .section-padding {
    padding: 38px 0 !important;
  }

  .section-title,
  .page-header h1 {
    font-size: 1.65rem !important;
    line-height: 1.3 !important;
  }

  .section-desc {
    font-size: 0.92rem !important;
  }

  /* Table Responsive Wrappers */
  .admin-table-wrapper,
  .table-responsive {
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin-bottom: 16px !important;
    border-radius: 14px !important;
  }

  .admin-table {
    min-width: 580px;
    font-size: 0.85rem;
  }

  /* Footer Mobile */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 26px !important;
  }

  .footer-col h3,
  .footer-col span {
    white-space: normal !important;
    word-break: break-word !important;
  }
}

/* -----------------------------------------------------------------------------
   5. COMPACT SMARTPHONES (max-width: 480px)
----------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .brand-logo {
    width: 36px !important;
    height: 36px !important;
  }

  .btn-clay {
    font-size: 0.88rem !important;
    padding: 10px 18px !important;
  }

  .badge-clay {
    font-size: 0.76rem !important;
    padding: 4px 10px !important;
  }
}

/* -----------------------------------------------------------------------------
   6. EXTRA SMALL SMARTPHONES (max-width: 390px)
----------------------------------------------------------------------------- */
@media (max-width: 390px) {
  /* Hide header SPMB button so brand name has 100% full width */
  .btn-header-spmb {
    display: none !important;
  }

  .brand-wrapper {
    max-width: calc(100% - 46px) !important;
  }

  .brand-title,
  .brand-text h1 {
    font-size: 0.88rem !important;
  }

  .brand-subtitle,
  .brand-text span {
    font-size: 0.64rem !important;
  }

  .stats-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .stat-card {
    display: flex !important;
    align-items: center !important;
    text-align: left !important;
    gap: 14px !important;
    padding: 14px 16px !important;
  }

  .stat-icon {
    margin-bottom: 0 !important;
    flex-shrink: 0 !important;
  }
}
