/* ========================================
   MOBILE-FIRST ENHANCED STYLES
   Complete mobile UI redesign following best practices
   ======================================== */

/* ========================================
   1. MOBILE-FIRST VIEWPORT & BASE STYLES
   ======================================== */

@media (max-width: 768px) {
    /* Enhanced viewport meta is in HTML, but ensure proper scaling */
    @viewport {
        width: device-width;
        zoom: 1.0;
    }

    /* Prevent text size adjustment on orientation change */
    html {
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    /* Smooth scrolling for better mobile UX */
    html {
        scroll-behavior: smooth;
    }

    /* Better touch scrolling on iOS */
    body {
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   2. ENHANCED MOBILE NAVIGATION
   ======================================== */

@media (max-width: 768px) {
    /* Navigation bar - sticky with better shadow */
    nav {
        position: sticky !important;
        top: 0;
        z-index: 100000 !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        clip-path: none !important;
        min-height: 60px !important;
        padding: 0.75rem 1rem !important;
        margin-bottom: 0 !important;
        background: linear-gradient(135deg, var(--primary-green), var(--secondary-green)) !important;
    }

    /* Hamburger menu button - positioned top right */
    .nav-toggle {
        display: flex !important;
        position: absolute !important;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        width: 48px;
        height: 48px;
        min-height: 48px;
        min-width: 48px;
        padding: 12px;
        background: rgba(255, 255, 255, 0.25) !important;
        border: 2px solid rgba(255, 255, 255, 0.5) !important;
        color: #ffffff !important;
        font-size: 1.5rem;
        cursor: pointer;
        z-index: 100002 !important;
        transition: all 0.3s ease;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
        align-items: center;
        justify-content: center;
    }

    .nav-toggle:hover,
    .nav-toggle:focus {
        background: rgba(255, 255, 255, 0.35) !important;
        border-color: rgba(255, 255, 255, 0.7) !important;
        outline: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }

    .nav-toggle:active {
        background: rgba(255, 255, 255, 0.45) !important;
        transform: translateY(-50%) scale(0.95);
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    }

    /* Mobile menu container - MUST be above everything */
    .nav-container {
        display: none;
        position: fixed !important;
        top: 60px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        background: linear-gradient(180deg, #005500, #003300) !important;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 100001 !important;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .nav-container.active {
        display: flex !important;
        flex-direction: column;
        animation: slideInFromTop 0.3s ease-out;
    }

    @keyframes slideInFromTop {
        from {
            opacity: 0;
            transform: translateY(-20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Navigation sections */
    .nav-section {
        display: flex !important;
        flex-direction: column;
        padding: 1.5rem 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    }

    .nav-section:last-child {
        border-bottom: none;
        padding-bottom: 2rem;
    }

    /* Navigation section labels */
    .nav-section-label {
        display: block !important;
        font-size: 0.75rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        color: #FFD700 !important;
        margin-bottom: 1rem;
        padding-left: 1rem;
    }

    /* Navigation links - HIGH CONTRAST */
    nav a {
        display: flex !important;
        align-items: center;
        width: 100%;
        min-height: 52px;
        padding: 1rem 1.25rem;
        margin: 0.35rem 0;
        border-radius: 12px;
        font-size: 1.1rem;
        font-weight: 600;
        text-align: left;
        transition: all 0.2s ease;
        color: #ffffff !important;
        background: rgba(255, 255, 255, 0.1) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }

    nav a:hover,
    nav a:focus {
        background: rgba(255, 255, 255, 0.25) !important;
        transform: translateX(4px);
        outline: none;
        border-color: rgba(255, 255, 255, 0.4) !important;
    }

    nav a:active {
        background: rgba(255, 255, 255, 0.35) !important;
        transform: translateX(2px) scale(0.98);
    }

    nav a.active {
        background: rgba(255, 215, 0, 0.3) !important;
        border-left: 4px solid #FFD700 !important;
        color: #FFD700 !important;
    }
}

/* ========================================
   3. MOBILE-OPTIMIZED TYPOGRAPHY
   ======================================== */

@media (max-width: 768px) {
    /* Enhanced heading sizes for mobile */
    h1 {
        font-size: 2rem !important;
        line-height: 1.2;
        margin-bottom: 1rem;
    }

    h2 {
        font-size: 1.65rem !important;
        line-height: 1.3;
        margin-bottom: 0.875rem;
    }

    h3 {
        font-size: 1.35rem !important;
        line-height: 1.4;
        margin-bottom: 0.75rem;
    }

    h4 {
        font-size: 1.15rem !important;
        line-height: 1.4;
    }

    /* Body text optimization */
    p {
        font-size: 1rem;
        line-height: 1.6;
        margin-bottom: 1rem;
    }

    /* Better readability for small text */
    small,
    .small-text {
        font-size: 0.875rem;
        line-height: 1.5;
    }
}

/* ========================================
   4. TOUCH-FRIENDLY BUTTONS & INTERACTIONS
   ======================================== */

@media (max-width: 768px) {
    /* All buttons - minimum 48x48px touch target */
    button,
    .action-btn,
    input[type="submit"],
    input[type="button"],
    input[type="reset"],
    .btn {
        min-height: 48px;
        min-width: 48px;
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
        font-weight: 600;
        border-radius: 12px;
        cursor: pointer;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
    }

    /* Button hover and active states */
    button:active,
    .action-btn:active {
        transform: scale(0.97);
    }

    /* Full-width buttons for mobile */
    .action-btn-mobile-full,
    .hero-actions .action-btn {
        width: 100%;
        margin: 0.5rem 0;
    }

    /* Icon buttons */
    .icon-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 48px;
        min-height: 48px;
        padding: 0.75rem;
        border-radius: 50%;
    }

    /* Links with better touch targets */
    a {
        min-height: 44px;
        padding: 0.5rem;
        -webkit-tap-highlight-color: transparent;
    }
}

/* ========================================
   5. MOBILE-OPTIMIZED FORMS
   ======================================== */

@media (max-width: 768px) {
    /* Form inputs - prevent zoom on iOS */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    select,
    textarea {
        min-height: 48px;
        padding: 0.875rem 1rem;
        font-size: 16px !important; /* Prevents iOS zoom */
        border-radius: 10px;
        border: 2px solid rgba(0, 0, 0, 0.1);
        width: 100%;
        transition: all 0.2s ease;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    /* Focus states for better accessibility */
    input:focus,
    select:focus,
    textarea:focus {
        border-color: var(--primary-green);
        outline: none;
        box-shadow: 0 0 0 3px rgba(0, 100, 0, 0.1);
    }

    /* Textarea specific */
    textarea {
        min-height: 120px;
        resize: vertical;
    }

    /* Select dropdown */
    select {
        background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
        background-repeat: no-repeat;
        background-position: right 1rem center;
        background-size: 1.25rem;
        padding-right: 3rem;
    }

    /* Form labels */
    label {
        display: block;
        font-weight: 600;
        margin-bottom: 0.5rem;
        font-size: 0.95rem;
        color: var(--text-dark);
    }

    /* Form groups */
    .form-group {
        margin-bottom: 1.25rem;
    }

    /* Checkbox and radio */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
        margin-right: 0.75rem;
    }
}

/* ========================================
   6. MOBILE HERO SECTION ENHANCEMENTS
   ======================================== */

@media (max-width: 768px) {
    .calc-section,
    .hero-section {
        padding: 2.5rem 1rem !important;
        min-height: auto;
    }

    /* Logo sizing */
    .logo {
        width: 140px !important;
        height: 140px !important;
        margin-bottom: 1.5rem;
    }

    /* Hero actions */
    .hero-actions {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        width: 100%;
        margin: 1.5rem 0;
    }

    .hero-actions .action-btn {
        width: 100%;
        text-align: center;
    }

    /* Pills and badges */
    .pill-row {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin: 1.5rem 0;
    }

    .pill {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        white-space: normal;
        text-align: center;
    }

    .pill i {
        margin-right: 0.5rem;
        flex-shrink: 0;
    }

    /* Hero insight grid */
    .hero-insight-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
        margin-top: 1.5rem;
    }

    .hero-insight {
        padding: 1rem 1.25rem;
        text-align: center;
    }
}

/* ========================================
   7. MOBILE CARD & CONTENT LAYOUTS
   ======================================== */

@media (max-width: 768px) {
    /* Content sections */
    .content-section {
        padding: 2rem 1rem !important;
    }

    /* Cards */
    .content-card,
    .customer-card,
    .panel-card,
    .floating-shell {
        padding: 1.5rem !important;
        margin-bottom: 1.25rem;
        border-radius: 16px;
    }

    /* Content grids */
    .content-grid,
    .steps-grid {
        grid-template-columns: 1fr !important;
        gap: 1.25rem;
    }

    /* Step cards */
    .step-card {
        padding: 1.5rem;
        border-radius: 16px;
    }

    .step-number {
        width: 48px;
        height: 48px;
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    /* Detail grids */
    .detail-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    /* Metrics and stats */
    .metrics-grid,
    .crm-metrics {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .mini-stat {
        padding: 1.25rem;
        text-align: center;
    }

    .mini-stat strong {
        font-size: 2rem;
        display: block;
        margin-bottom: 0.5rem;
    }
}

/* ========================================
   8. MOBILE TABLE IMPROVEMENTS
   ======================================== */

@media (max-width: 768px) {
    /* Table wrapper with horizontal scroll */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 1rem -1rem;
        width: calc(100% + 2rem);
        border-radius: 12px;
    }

    /* Table styling */
    table {
        min-width: 600px;
        font-size: 0.9rem;
        border-collapse: separate;
        border-spacing: 0;
    }

    table th,
    table td {
        padding: 0.875rem 0.75rem;
        white-space: nowrap;
    }

    table th {
        position: sticky;
        top: 0;
        background: var(--primary-green);
        color: white;
        z-index: 10;
    }

    /* Scroll indicator */
    .table-wrapper::after {
        content: '← Scroll →';
        position: absolute;
        bottom: 0.5rem;
        right: 0.5rem;
        background: rgba(0, 0, 0, 0.7);
        color: white;
        padding: 0.25rem 0.75rem;
        border-radius: 4px;
        font-size: 0.75rem;
        pointer-events: none;
        opacity: 0.8;
    }
}

/* ========================================
   9. MOBILE MODALS & DIALOGS
   ======================================== */

@media (max-width: 768px) {
    /* Modal containers */
    .modal-content,
    .crm-modal {
        width: 95% !important;
        max-width: 95vw !important;
        margin: 1rem auto !important;
        padding: 1.5rem !important;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: 16px;
    }

    /* Modal headers */
    .modal-header {
        padding-bottom: 1rem;
        margin-bottom: 1rem;
        border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    }

    /* Modal actions */
    .modal-actions,
    .crm-modal-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 1.5rem;
    }

    .modal-actions button,
    .crm-modal-actions button {
        width: 100%;
    }

    /* Close button */
    .modal-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.1);
    }
}

/* ========================================
   10. MOBILE PERFORMANCE & ANIMATIONS
   ======================================== */

@media (max-width: 768px) {
    /* Reduce motion for users who prefer it */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* Optimized animations for mobile */
    .fadeInUp {
        animation: fadeInUpMobile 0.4s ease-out;
    }

    @keyframes fadeInUpMobile {
        from {
            opacity: 0;
            transform: translateY(15px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Hardware acceleration for smooth animations */
    .animated,
    .transition {
        will-change: transform, opacity;
        transform: translateZ(0);
        backface-visibility: hidden;
    }
}

/* ========================================
   11. MOBILE SPACING & LAYOUT UTILITIES
   ======================================== */

@media (max-width: 768px) {
    /* Container padding */
    .container {
        padding: 1.25rem !important;
        max-width: 100%;
    }

    /* Section spacing */
    section {
        margin-bottom: 2rem;
    }

    /* Row and column resets */
    .row {
        flex-direction: column;
        gap: 1rem;
    }

    .col-1, .col-2, .col-3, .col-4, .col-5, .col-6,
    .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 {
        width: 100% !important;
        flex: none;
    }

    /* Margin utilities */
    .mt-mobile { margin-top: 1rem; }
    .mb-mobile { margin-bottom: 1rem; }
    .my-mobile { margin-top: 1rem; margin-bottom: 1rem; }
    .mx-mobile { margin-left: 1rem; margin-right: 1rem; }

    /* Padding utilities */
    .pt-mobile { padding-top: 1rem; }
    .pb-mobile { padding-bottom: 1rem; }
    .py-mobile { padding-top: 1rem; padding-bottom: 1rem; }
    .px-mobile { padding-left: 1rem; padding-right: 1rem; }

    /* Hide on mobile */
    .hide-mobile {
        display: none !important;
    }

    /* Show only on mobile */
    .show-mobile {
        display: block !important;
    }
}

/* ========================================
   12. MOBILE FOOTER ENHANCEMENTS
   ======================================== */

@media (max-width: 768px) {
    footer {
        padding: 2rem 1rem !important;
        text-align: center;
    }

    footer .footer-links {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        margin: 1rem 0;
    }

    footer a {
        display: block;
        padding: 0.75rem;
        min-height: 44px;
    }
}

/* ========================================
   13. MOBILE CTA & ACTION PANELS
   ======================================== */

@media (max-width: 768px) {
    .cta-panel {
        padding: 2rem 1.5rem !important;
        border-radius: 16px;
        margin: 1.5rem 0;
    }

    .cta-panel h2 {
        font-size: 1.75rem !important;
        margin-bottom: 1rem;
    }

    .cta-panel p {
        font-size: 1rem;
        margin-bottom: 1.25rem;
    }

    .cta-panel .hero-actions {
        margin-top: 1.5rem;
    }
}

/* ========================================
   14. MOBILE-SPECIFIC IMPROVEMENTS
   ======================================== */

@media (max-width: 768px) {
    /* Better image handling */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden;
    }

    /* Better select appearance */
    select {
        cursor: pointer;
    }

    /* Improved focus visibility */
    :focus-visible {
        outline: 3px solid var(--accent-gold);
        outline-offset: 2px;
    }

    /* Better link styling */
    a:not(.action-btn):not(.nav-link) {
        text-decoration: underline;
        text-decoration-color: rgba(0, 100, 0, 0.3);
        text-underline-offset: 3px;
    }

    /* Loading states */
    .loading {
        pointer-events: none;
        opacity: 0.6;
    }

    /* Toast/notification positioning */
    .toast,
    .notification {
        position: fixed;
        bottom: 1rem;
        left: 1rem;
        right: 1rem;
        z-index: 9999;
        padding: 1rem;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }
}

/* ========================================
   15. MOBILE PWA ENHANCEMENTS
   ======================================== */

@media (max-width: 768px) {
    /* PWA install button */
    #pwa-install-btn {
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        min-width: 48px;
        min-height: 48px;
        padding: 0.875rem 1.25rem;
        border-radius: 24px;
        background: linear-gradient(135deg, var(--primary-green), var(--secondary-green));
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        font-weight: 600;
        z-index: 1000;
    }

    /* Safe area insets for notched devices */
    @supports (padding: max(0px)) {
        body {
            padding-left: max(0px, env(safe-area-inset-left));
            padding-right: max(0px, env(safe-area-inset-right));
        }

        nav {
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
        }

        .nav-toggle {
            right: max(1rem, env(safe-area-inset-right));
        }
    }
}

/* ========================================
   16. SMALLER MOBILE DEVICES (< 375px)
   ======================================== */

@media (max-width: 374px) {
    /* Extra small devices adjustments */
    h1 { font-size: 1.75rem !important; }
    h2 { font-size: 1.5rem !important; }
    h3 { font-size: 1.25rem !important; }

    .logo {
        width: 120px !important;
        height: 120px !important;
    }

    .container {
        padding: 1rem !important;
    }

    .action-btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.95rem;
    }

    .content-card,
    .panel-card {
        padding: 1.25rem !important;
    }
}

/* ========================================
   17. LANDSCAPE MODE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    .calc-section,
    .content-section {
        padding: 1.5rem 1rem !important;
    }

    .logo {
        width: 100px !important;
        height: 100px !important;
        margin-bottom: 1rem;
    }

    h1 { font-size: 1.75rem !important; }
    h2 { font-size: 1.5rem !important; }

    /* Better use of horizontal space */
    .hero-insight-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.75rem;
    }

    .pill-row {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

/* ========================================
   18. ACCESSIBILITY ENHANCEMENTS
   ======================================== */

@media (max-width: 768px) {
    /* Skip to content link */
    .skip-to-content {
        position: absolute;
        top: -100px;
        left: 0;
        background: var(--primary-green);
        color: white;
        padding: 1rem;
        z-index: 9999;
        transition: top 0.3s;
    }

    .skip-to-content:focus {
        top: 0;
    }

    /* Better focus indicators */
    button:focus-visible,
    a:focus-visible,
    input:focus-visible,
    select:focus-visible,
    textarea:focus-visible {
        outline: 3px solid var(--accent-gold);
        outline-offset: 2px;
    }

    /* Screen reader only content */
    .sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

/* ========================================
   19. BACK TO TOP BUTTON (MOBILE ONLY)
   ======================================== */

@media (max-width: 768px) {
    /* Back to top button - mobile specific positioning */
    .back-to-top {
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--primary-green), var(--secondary-green));
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        cursor: pointer;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 999;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
    }

    .back-to-top.visible {
        opacity: 1;
        visibility: visible;
    }

    .back-to-top:hover {
        transform: translateY(-4px);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
    }

    .back-to-top:active {
        transform: translateY(-2px) scale(0.95);
    }
}

/* ========================================
   20. ENHANCED FOOTER STYLES (MOBILE ONLY)
   ======================================== */

@media (max-width: 768px) {
    /* Override footer styles on mobile only */
    footer {
        background: linear-gradient(135deg, var(--primary-green), var(--secondary-green));
        color: white;
        padding: 2rem 1rem;
        text-align: center;
    }

    .footer-content {
        max-width: 1200px;
        margin: 0 auto;
    }

    .footer-social {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
        margin-bottom: 1.5rem;
    }

    .footer-social a {
        color: white;
        text-decoration: none;
        font-size: 1rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        min-height: 44px;
        width: 100%;
        padding: 0.875rem 1rem;
        border-radius: 8px;
        transition: all 0.2s ease;
        background: rgba(255, 255, 255, 0.1);
    }

    .footer-social a:hover {
        background: rgba(255, 255, 255, 0.15);
        transform: translateY(-2px);
    }

    .footer-links {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin: 1rem 0;
    }

    .footer-links a {
        color: rgba(255, 255, 255, 0.9);
        text-decoration: none;
        font-size: 0.95rem;
        min-height: 44px;
        padding: 0.75rem;
        width: 100%;
        display: block;
        transition: all 0.2s ease;
    }

    .footer-links a:hover {
        color: var(--accent-gold);
    }

    .footer-copyright {
        margin-top: 1.5rem;
        font-size: 0.85rem;
        line-height: 1.6;
        color: rgba(255, 255, 255, 0.8);
    }
}
