/* ============================================================
   QUINNOVEC — Responsive Breakpoints
   Empresa Química Venezolana | quinnovec.com.ve
   
   Breakpoints:
   - Mobile:    < 640px
   - Tablet:    640px - 1023px
   - Desktop:   1024px - 1279px
   - Wide:      ≥ 1280px
   ============================================================ */

/* ============================================================
   TABLETS & SMALL DESKTOPS (max-width: 1200px)
   ============================================================ */
@media (max-width: 1200px) {
    .footer-grid {
        grid-template-columns: 1.5fr 1fr 1fr;
    }

    .footer-grid > *:last-child {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-4);
    }

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

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

    .hero-stats {
        gap: var(--space-6);
    }
}

/* ============================================================
   TABLETS (max-width: 1024px)
   ============================================================ */
@media (max-width: 1024px) {
    :root {
        --header-height: 70px;
    }

    .main-nav {
        position: fixed;
        top: 0;
        right: -100%;
        width: 320px;
        height: 100vh;
        background: var(--color-primary-900);
        flex-direction: column;
        align-items: flex-start;
        padding: calc(var(--header-height) + var(--space-8)) var(--space-8) var(--space-8);
        transition: right var(--transition-slow);
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.3);
        overflow-y: auto;
    }

    .main-nav.open {
        right: 0;
    }

    .main-nav a {
        width: 100%;
        font-size: var(--font-size-base);
        padding: var(--space-3) var(--space-4);
    }

    .menu-toggle {
        display: flex;
    }

    .header-cta {
        display: none;
    }

    /* Show CTA in mobile menu */
    .main-nav .mobile-cta {
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
        width: 100%;
        margin-top: var(--space-6);
        padding-top: var(--space-6);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

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

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

    .hero h1 {
        font-size: var(--font-size-4xl);
    }

    .hero-visual {
        display: none;
    }

    .cta-inner {
        flex-direction: column;
        text-align: center;
    }

    .cta-content {
        max-width: none;
    }

    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-8);
    }
}

/* ============================================================
   MOBILE LANDSCAPE & SMALL TABLETS (max-width: 768px)
   ============================================================ */
@media (max-width: 768px) {
    h1 { font-size: var(--font-size-3xl); }
    h2 { font-size: var(--font-size-2xl); }
    h3 { font-size: var(--font-size-xl); }

    .section {
        padding-block: var(--space-12);
    }

    .section-lg {
        padding-block: var(--space-16);
    }

    .hero {
        min-height: auto;
        padding-top: calc(var(--header-height) + var(--space-12));
        padding-bottom: var(--space-12);
    }

    .hero h1 {
        font-size: var(--font-size-3xl);
    }

    .hero-description {
        font-size: var(--font-size-base);
    }

    .hero-stats {
        flex-wrap: wrap;
        gap: var(--space-6);
    }

    .hero-stat {
        min-width: 100px;
    }

    .hero-buttons {
        flex-direction: column;
    }

    .hero-buttons .btn {
        width: 100%;
        justify-content: center;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-4);
    }

    .stat-card {
        padding: var(--space-5) var(--space-4);
    }

    .stat-number {
        font-size: var(--font-size-3xl);
    }

    .features-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .feature-item {
        padding: var(--space-6);
        text-align: left;
        display: flex;
        gap: var(--space-5);
    }

    .feature-icon {
        margin: 0;
        flex-shrink: 0;
    }

    .contact-map {
        height: 300px;
    }

    .page-header {
        padding-top: calc(var(--header-height) + var(--space-8));
        padding-bottom: var(--space-8);
    }

    .page-header h1 {
        font-size: var(--font-size-3xl);
    }

    .footer-grid {
        grid-template-columns: 1fr;
        gap: var(--space-8);
    }

    .footer-bottom {
        flex-direction: column;
        gap: var(--space-4);
        text-align: center;
    }

    .whatsapp-float {
        bottom: var(--space-4);
        right: var(--space-4);
    }

    .whatsapp-tooltip {
        display: none;
    }

    .whatsapp-btn {
        width: 54px;
        height: 54px;
        font-size: 24px;
    }

    .whatsapp-btn svg {
        width: 26px;
        height: 26px;
    }
}

/* ============================================================
   MOBILE PHONES (max-width: 480px)
   ============================================================ */
@media (max-width: 480px) {
    :root {
        --container-padding: var(--space-4);
    }

    h1 { font-size: var(--font-size-2xl); }
    h2 { font-size: var(--font-size-xl); }

    .hero h1 {
        font-size: var(--font-size-2xl);
    }

    .hero-label {
        font-size: 10px;
    }

    .hero-stats {
        gap: var(--space-4);
    }

    .hero-stat-value {
        font-size: var(--font-size-2xl);
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-3);
    }

    .stat-card {
        padding: var(--space-4) var(--space-3);
    }

    .stat-number {
        font-size: var(--font-size-2xl);
    }

    .stat-label {
        font-size: var(--font-size-xs);
    }

    .card {
        padding: var(--space-5);
    }

    .product-card-image {
        height: 160px;
    }

    .btn-lg {
        padding: var(--space-3) var(--space-6);
        font-size: var(--font-size-sm);
    }

    .section-heading h2 {
        font-size: var(--font-size-2xl);
    }

    .trust-strip {
        gap: var(--space-6);
    }

    .modal {
        margin: var(--space-4);
        border-radius: var(--radius-xl);
    }

    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-left: var(--space-4);
        padding-right: var(--space-4);
        scroll-padding-left: var(--space-4);
        margin-left: calc(-1 * var(--space-4));
        margin-right: calc(-1 * var(--space-4));
    }

    .tab {
        white-space: nowrap;
        flex-shrink: 0;
    }
}

/* ============================================================
   ANTI-OVERFLOW GLOBAL — Ningún elemento debe salirse del viewport
   ============================================================ */

/* Base: todo el sitio sin overflow horizontal */
html {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Imágenes y medios: nunca se salen de su contenedor */
img, video, iframe, embed, object,
svg, canvas, audio {
    max-width: 100%;
    height: auto;
}

/* Tablas siempre con scroll si son muy anchas */
table {
    max-width: 100%;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Salvo tablas del admin que tienen su propio wrapper */
.admin-table,
.portal-table {
    display: table;
}

/* ============================================================
   MÓVIL < 768px — Correcciones de overflow específicas
   ============================================================ */
@media (max-width: 768px) {

    /* Contenedores generales: nunca más anchos que el viewport */
    .container,
    .section,
    .card,
    [class*="grid"],
    [class*="flex"] {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* ---- Formulario de contacto ----
       Los rows con flex + min-width:200px se convierten en columna */
    #contact-form .flex,
    form .flex[style*="flex-wrap"] {
        flex-direction: column !important;
        gap: var(--space-4) !important;
    }
    #contact-form .form-group[style*="flex:1"],
    form .form-group[style*="flex:1"] {
        min-width: 0 !important;
        width: 100% !important;
    }

    /* ---- Inputs ---- anti-zoom iOS */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px !important;
    }

    /* ---- Layout del sitio público (contacto, productos, etc.) ----
       Flex row con min-width que puede hacer overflow */
    [style*="min-width:280px"],
    [style*="min-width: 280px"],
    [style*="min-width:300px"],
    [style*="min-width: 300px"],
    [style*="min-width:320px"],
    [style*="min-width: 320px"] {
        min-width: 0 !important;
        width: 100% !important;
    }

    /* ---- Contenedor lateral sidebar de contacto ---- */
    [style*="flex:1"][style*="min-width"] {
        min-width: 0 !important;
        flex-basis: 100% !important;
    }

    /* ---- Secciones con flex horizontal que deben apilar ---- */
    .contact-layout,
    .page-two-col {
        flex-direction: column !important;
    }

    /* ---- Pre / code: scroll horizontal en lugar de desbordar ---- */
    pre, code {
        overflow-x: auto;
        white-space: pre-wrap;
        word-break: break-word;
    }

    /* ---- Textos largos sin espacios ---- */
    p, h1, h2, h3, h4, li, td, th {
        overflow-wrap: break-word;
        word-break: break-word;
    }

    /* ---- Cards del sector / producto ---- */
    .card {
        max-width: 100%;
        overflow: hidden;
    }

    /* ---- Hero buttons: columna en móvil ---- */
    .hero-buttons {
        width: 100%;
    }
    .hero-buttons .btn {
        width: 100%;
        justify-content: center;
        max-width: 100%;
    }

    /* ---- Footer contact items ---- */
    .footer-contact-item {
        word-break: break-all;
    }

    /* ---- Modales: no salen del viewport ---- */
    .modal {
        max-width: calc(100vw - 2rem);
        margin: 1rem;
        box-sizing: border-box;
    }

    /* ---- Stat cards en 2x2 ---- */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-3);
    }
}

/* ============================================================
   MÓVIL < 480px — Correcciones adicionales para pantallas muy pequeñas
   ============================================================ */
@media (max-width: 480px) {

    /* Padding mínimo en contenedores */
    .section,
    .container {
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }

    /* Textos del hero más pequeños para no desbordar */
    .hero h1 {
        font-size: clamp(1.5rem, 7vw, 2rem);
        line-height: 1.2;
    }

    /* Estadísticas del hero en wrap */
    .hero-stats {
        flex-wrap: wrap;
        gap: var(--space-4);
    }
    .hero-stat {
        min-width: 0;
        flex: 1 1 40%;
    }

    /* Trust strip: wrap */
    .trust-strip {
        flex-wrap: wrap;
        gap: var(--space-4);
    }

    /* Botón de WhatsApp flotante: no tapa contenido */
    .whatsapp-float {
        bottom: var(--space-3);
        right: var(--space-3);
    }

    /* Sección page-header padding reducido */
    .page-header {
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }

    /* Ocultar decoraciones SVG que pueden causar overflow */
    .hero-decoration,
    .section-decoration,
    .bg-decoration {
        display: none;
    }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */

@media print {
    .site-header,
    .site-footer,
    .whatsapp-float,
    .menu-toggle,
    .btn,
    .emergency-banner {
        display: none !important;
    }

    body {
        color: #000;
        background: #fff;
    }

    .hero {
        min-height: auto;
        padding: 20px 0;
        background: none !important;
        color: #000;
    }

    .hero h1,
    .hero p {
        color: #000 !important;
    }

    a {
        color: #000;
        text-decoration: underline;
    }

    .card {
        border: 1px solid #ddd;
        box-shadow: none;
        page-break-inside: avoid;
    }

    .section {
        padding-block: 20px;
    }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .animate-fade-up,
    .animate-fade-in,
    .animate-scale-in {
        opacity: 1;
        transform: none;
    }
}
