/**
 * Divyansh Educational Foundation - Responsive Overrides
 * Enhanced breakpoints: 320px, 360px, 480px, 768px
 * Mobile-first hardening with root cause fixes
 */

/* ============================================
   TABLET (≤ 768px)
   ============================================ */
@media (max-width: 768px) {

    /* Container Fix */
    .container {
        padding-left: var(--container-padding, 1rem);
        padding-right: var(--container-padding, 1rem);
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Typography Scaling */
    h1 {
        font-size: 2rem;
        line-height: 1.2;
    }

    h2 {
        font-size: 1.75rem;
        line-height: 1.3;
    }

    h3 {
        font-size: 1.5rem;
    }

    h4 {
        font-size: 1.25rem;
    }

    .hero-title {
        font-size: 2.25rem !important;
    }

    .section-title {
        font-size: 1.875rem !important;
    }

    /* Word Break for long text */
    .hero-title,
    .section-title,
    .hero-subtitle,
    .section-subtitle,
    h1,
    h2,
    h3 {
        overflow-wrap: break-word;
        word-break: break-word;
    }

    /* Grid Stacking */
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    /* Card Scaling */
    .card {
        padding: 1.5rem !important;
    }

    /* Top Bar Stacking */
    .top-bar-content {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }

    .top-bar-left {
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .top-bar-right {
        text-align: center;
        width: 100%;
        font-size: 0.75rem;
    }

    /* Navbar Height & Logo */
    .main-header {
        height: auto !important;
        padding: 0.5rem 0;
    }

    .nav-container {
        height: auto !important;
        padding: 0.5rem 1rem !important;
    }

    .logo-img {
        height: 40px !important;
        width: auto !important;
    }

    .logo-title {
        font-size: 1.25rem !important;
        letter-spacing: 0.05em;
    }

    .logo-subtitle {
        font-size: 0.625rem !important;
    }

    /* Hamburger Menu Button */
    .mobile-menu-btn {
        margin-left: auto;
    }

    /* Hero Section */
    .section-hero {
        padding: 3rem 1rem !important;
        text-align: center;
    }

    .hero-subtitle {
        font-size: 1.125rem !important;
        margin-bottom: 2rem !important;
    }

    /* Background Blobs - Clamp size to prevent overflow */
    .blur-blob {
        opacity: 0.15 !important;
    }

    .blur-blob-primary {
        width: 12rem !important;
        height: 12rem !important;
    }

    .blur-blob-secondary {
        width: 16rem !important;
        height: 16rem !important;
    }

    /* Contact card - prevent overflow on hover */
    .contact-card:hover {
        transform: translateX(3px);
    }

    /* Timeline - prevent overflow and stack on mobile */
    .timeline-step:hover {
        transform: translateX(5px);
    }

    .timeline-step,
    .library-timeline-item {
        flex-direction: column;
        gap: 1rem !important;
        align-items: flex-start;
    }

    .timeline-step:not(:last-child)::after,
    .library-timeline-connector {
        left: 1.75rem !important;
        top: 3.5rem !important;
    }

    /* Stats Grid responsive fix */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ============================================
   MOBILE (≤ 480px)
   ============================================ */
@media (max-width: 480px) {

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1.25rem !important;
    }

    .stat-item {
        padding: 1.25rem !important;
    }

    /* Course Cards */
    .course-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .course-card-footer {
        margin: 0 -1.5rem -1.5rem !important;
        padding: 1rem 1.5rem !important;
        flex-direction: column;
        gap: 0.75rem;
    }

    /* Badges & Flags */
    .badge {
        font-size: 0.7rem !important;
        padding: 0.25rem 0.5rem !important;
    }

    /* Timeline / Step Position Adjustment */
    .step-number {
        left: -0.5rem !important;
        top: -0.75rem !important;
        width: 2.25rem !important;
        height: 2.25rem !important;
        font-size: 0.875rem !important;
    }

    /* Timing Cards */
    .timing-card-grid {
        grid-template-columns: 1fr !important;
        gap: 1.25rem !important;
    }

    .timing-card-day-icon {
        width: 3.5rem !important;
        height: 3.5rem !important;
    }

    /* Certificate Fixes */
    .certificate-inner {
        padding: 1.5rem !important;
        border-width: 4px !important;
    }

    .certificate-footer {
        flex-direction: column !important;
        gap: 1.5rem !important;
        text-align: center !important;
    }

    /* Buttons full-width at mobile */
    .btn {
        padding: 0.75rem 1.5rem;
    }

    /* Contact card hover disabled at small sizes */
    .contact-card:hover {
        transform: none;
    }

    /* Sections reduced padding */
    .section {
        padding: 2.5rem 1rem !important;
    }

    /* #statsGrid responsive override */
    #statsGrid {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================
   SMALL MOBILE (≤ 360px)
   ============================================ */
@media (max-width: 360px) {

    h1,
    .hero-title {
        font-size: 1.75rem !important;
    }

    h2,
    .section-title {
        font-size: 1.5rem !important;
    }

    h3 {
        font-size: 1.25rem !important;
    }

    .logo-title {
        font-size: 1.125rem !important;
    }

    .section {
        padding: 2.5rem 0.75rem !important;
    }

    .btn {
        width: 100%;
        text-align: center;
        padding: 0.75rem 1rem !important;
    }

    /* Course Card Specifics */
    .course-card-footer {
        margin: 0 -1rem -1rem !important;
        padding: 0.75rem 1rem !important;
    }

    .card {
        padding: 1rem !important;
    }
}

/* ============================================
   MINIMUM MOBILE (≤ 320px)
   ============================================ */
@media (max-width: 320px) {

    h1,
    .hero-title {
        font-size: 1.5rem !important;
    }

    h2,
    .section-title {
        font-size: 1.25rem !important;
    }

    .hero-subtitle {
        font-size: 0.95rem !important;
    }

    .section {
        padding: 2rem 0.5rem !important;
    }

    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .top-bar {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
    }

    .footer-content {
        padding: 2rem 0.5rem;
    }

    .certificate-inner {
        padding: 1rem !important;
        border-width: 3px !important;
    }
}

/* ============================================
   OVERFLOW ROOT CAUSE FIXES (Global)
   ============================================ */

/* Fix: Stats grid repeated column override */
#statsGrid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
}

/* Fix: Ensure all images respect container bounds */
img,
video,
svg {
    max-width: 100%;
}

/* Fix: Tables should scroll horizontally, not page */
table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%; 
}