/**
 * Mobile Responsiveness Fixes
 * Additional rules to ensure perfect mobile display
 */

/* Prevent horizontal scroll - CRITICAL */
html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    position: relative;
}

/* Hero Section Mobile Optimizations - Compact Intro */
#hero {
    min-height: auto !important;
    padding-top: 3rem;
    padding-bottom: 3rem;
}

@media (min-width: 640px) {
    #hero {
        padding-top: 4rem;
        padding-bottom: 4rem;
    }
}

@media (min-width: 768px) {
    #hero {
        padding-top: 5rem;
        padding-bottom: 5rem;
    }
}

/* Ensure asymmetric shapes don't cause overflow */
#hero .absolute {
    max-width: 100vw;
    overflow: hidden;
}

/* Clip-path fallback for older browsers */
@supports not (clip-path: polygon(0 0, 100% 0)) {
    #hero .absolute > div {
        display: none;
    }
}

/* Mobile: Simplify asymmetric shapes */
@media (max-width: 640px) {
    #hero .absolute > div:first-child {
        clip-path: polygon(0 0, 100% 0, 92% 100%, 0 100%) !important;
    }
    
    #hero .absolute > div:last-child {
        width: 60% !important;
        height: 50% !important;
    }
}

/* Hero text responsive adjustments */
#hero h1 {
    line-height: 1.2 !important;
    word-break: keep-all;
}

@media (max-width: 640px) {
    #hero h1 {
        font-size: 1.75rem !important;
        line-height: 1.3 !important;
    }
    
    #hero .space-y-4 {
        gap: 1rem !important;
    }
}

/* Hero buttons stack properly on mobile */
#hero .flex-col {
    width: 100%;
}

#hero a {
    width: 100%;
    max-width: 100%;
}

@media (min-width: 640px) {
    #hero a {
        width: auto;
    }
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* Fix for iOS Safari scrolling issues */
body {
    -webkit-overflow-scrolling: touch;
}

/* Prevent momentum scrolling issues */
.modal-content {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Ensure all containers respect viewport */
* {
    box-sizing: border-box;
    max-width: 100%;
}

/* Prevent touch scrolling issues */
html {
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
}

/* Fix particles.js or canvas overflow */
canvas {
    max-width: 100% !important;
    width: 100% !important;
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
}

#particles-js {
    position: absolute !important;
    width: 100% !important;
    height: 100% !important;
    left: 0 !important;
    top: 0 !important;
    overflow: hidden !important;
}

/* Container fixes */
.container {
    max-width: 100% !important;
    padding-left: 1rem;
    padding-right: 1rem;
    overflow-x: hidden;
}

/* Main content wrapper */
main {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
}

/* Sections */
section {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    overflow-y: visible !important; /* Prevent unnecessary scrollbars */
}

/* Fix for grid/flex overflows */
.grid, [class*="grid-cols"] {
    width: 100%;
    max-width: 100%;
}

.flex {
    max-width: 100%;
}

/* Navbar mobile fixes */
@media (max-width: 1024px) {
    nav {
        width: 100vw !important;
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    nav .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Mobile menu */
    nav [x-show="mobileMenuOpen"] {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
}

/* Modal mobile fixes */
@media (max-width: 640px) {
    .modal-container {
        width: 100vw !important;
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
        padding: 0 !important;
    }
    
    .modal-wrapper {
        width: 100%;
        max-width: 100%;
        padding: 0.5rem;
    }
    
    .modal-content {
        width: 100% !important;
        max-width: calc(100vw - 1rem) !important;
        margin: 0 auto;
    }
    
    /* Form inputs in modals */
    .modal-content input,
    .modal-content select,
    .modal-content textarea {
        max-width: 100%;
        width: 100%;
    }
    
    /* Grid in modals */
    .modal-content .grid {
        grid-template-columns: 1fr;
    }
    
    .modal-content [class*="grid-cols-2"] {
        grid-template-columns: 1fr;
    }
    
    /* Icons must not block input */
    .modal-content .input-icon {
        pointer-events: none !important;
        z-index: 1;
    }
    
    .modal-content .password-toggle-btn {
        pointer-events: auto !important;
        z-index: 20;
        cursor: pointer;
    }
    
    /* Input fields must be above icons */
    .modal-content input {
        position: relative;
        z-index: 10;
        background: linear-gradient(135deg, #ffffff 0%, #f9fafb 100%) !important;
    }
}

/* Text overflow prevention */
h1, h2, h3, h4, h5, h6, p, span, div {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

/* Image/media overflow prevention */
img, video, iframe, svg {
    max-width: 100% !important;
    height: auto !important;
}

/* Buttons */
button, a {
    max-width: 100%;
}

/* Forms */
input, select, textarea {
    max-width: 100%;
    width: 100%;
}

/* Prevent transform/translate causing overflow */
[class*="translate"],
[class*="transform"] {
    will-change: transform;
}

/* Fix for absolutely positioned elements */
.absolute {
    max-width: 100%;
}

/* Table responsiveness */
table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    display: block;
}

/* Extra small devices (iPhone SE, etc.) */
@media (max-width: 375px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    nav .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    .modal-wrapper {
        padding: 0.25rem;
    }
    
    /* Smaller text on very small screens */
    h1 {
        font-size: 1.5rem !important;
    }
    
    h2 {
        font-size: 1.25rem !important;
    }
}

/* Landscape orientation on mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
    
    nav {
        position: fixed !important;
    }
}

/* Prevent iOS zoom on input focus */
@media (max-width: 640px) {
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Fix radio buttons - MUST BE CIRCULAR on all devices */
input[type="radio"] {
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    width: 1rem !important;
    height: 1rem !important;
    min-width: 1rem !important;
    min-height: 1rem !important;
    border: 2px solid #4b5563 !important;
    border-radius: 50% !important;
    outline: none !important;
    cursor: pointer !important;
    position: relative !important;
    background-color: transparent !important;
    transition: all 0.2s ease !important;
    flex-shrink: 0 !important;
    display: inline-block !important;
    vertical-align: middle !important;
    margin: 0 !important;
}

input[type="radio"]:checked {
    border-color: #3b82f6 !important;
    background-color: #3b82f6 !important;
}

input[type="radio"]:checked::before {
    content: '' !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 0.4rem !important;
    height: 0.4rem !important;
    border-radius: 50% !important;
    background-color: white !important;
    display: block !important;
}

input[type="radio"]:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2) !important;
}

/* Radio button labels */
label:has(input[type="radio"]) {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    cursor: pointer !important;
}

/* Fix for negative margins causing overflow */
[class*="-m"],
[class*="-mx"],
[class*="-ml"],
[class*="-mr"] {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Rounded elements overflow fix */
.rounded,
.rounded-lg,
.rounded-xl,
.rounded-2xl,
.rounded-full {
    overflow: hidden;
}

/* Padding adjustments for mobile */
@media (max-width: 640px) {
    [class*="px-"] {
        padding-left: clamp(0.5rem, 4vw, 1.5rem);
        padding-right: clamp(0.5rem, 4vw, 1.5rem);
    }
}

/* Shadow overflow fix */
[class*="shadow"] {
    overflow: visible;
}

/* Z-index hierarchy */
nav {
    z-index: 9999 !important;
}

.modal-container {
    z-index: 10000 !important;
}

.modal-backdrop {
    z-index: 1 !important;
    position: fixed !important;
}

.modal-wrapper {
    z-index: 2 !important;
    position: relative !important;
}

.modal-content {
    z-index: 3 !important;
    position: relative !important;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Safe area insets for notched devices */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
    }
    
    nav {
        top: env(safe-area-inset-top) !important;
    }
}

/* Prevent pull-to-refresh and overscroll */
body {
    overscroll-behavior-y: none;
    overscroll-behavior-x: none;
}

/* Fix for momentum scrolling on iOS */
main, section, .container {
    -webkit-overflow-scrolling: touch;
}

/* Prevent horizontal scroll from animations/transforms */
.animate-blob,
[class*="animate-"],
[class*="transition-"] {
    will-change: auto;
    backface-visibility: hidden;
}

/* Fix gradient backgrounds extending beyond viewport */
[class*="bg-gradient"] {
    background-attachment: scroll;
    background-size: 100% 100%;
    background-position: center;
}

/* Ensure modals don't cause body overflow */
.modal-container {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

/* Additional mobile-specific fixes */
@media (max-width: 768px) {
    /* Prevent text selection issues */
    * {
        -webkit-user-select: none;
        user-select: none;
    }
    
    input, textarea {
        -webkit-user-select: text;
        user-select: text;
    }
    
    /* Fix for sticky elements */
    .sticky, .fixed {
        position: -webkit-sticky;
        position: sticky;
    }
    
    /* Prevent iOS Safari bottom bar issues */
    section {
        min-height: auto !important;
    }
    
    /* Fix for full-height sections */
    .h-screen {
        height: 100vh;
        height: -webkit-fill-available;
    }
}

/* Hide unnecessary scrollbars on sections */
section::-webkit-scrollbar {
    display: none !important;
}

section {
    -ms-overflow-style: none !important;
    scrollbar-width: none !important;
}

/* Main content should not have scrollbar */
main::-webkit-scrollbar {
    display: none !important;
}

main {
    -ms-overflow-style: none !important;
    scrollbar-width: none !important;
}

/* Only body should have scrollbar (if needed) */
html {
    overflow-y: scroll !important; /* Force scrollbar space */
    overflow-x: hidden !important;
}

/* Prevent sections from creating their own scroll context */
section, main, .container {
    overflow-y: visible !important;
    overflow-x: hidden !important;
}

/* Exception: Modal content can scroll */
.modal-content {
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* Smooth, minimal scrollbar only on body */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.3);
    border-radius: 10px;
    transition: background 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.6);
}

/* Firefox scrollbar styling */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.3) transparent;
}

/* Print styles */
@media print {
    nav, .modal-container {
        display: none !important;
    }
}

