/* Mobile Optimization Styles */

/* Touch-friendly buttons and links */
@media (max-width: 768px) {

    /* Minimum touch target size: 44px */
    button,
    .btn,
    a.button,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
    }

    /* Larger tap targets for navigation */
    nav a,
    .nav-link,
    .menu-item {
        min-height: 48px;
        display: flex;
        align-items: center;
        padding: 12px 16px;
    }

    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        min-height: 44px;
        font-size: 16px;
        /* Prevents zoom on iOS */
        padding: 12px 16px;
    }

    /* MOBILE HEADER SPECIFIC OVERRIDES - Must come after generic input styles */
    #oldSearchInput {
        min-height: 24px !important;
        height: 24px !important;
        line-height: 24px !important;
        font-size: 13px !important;
        padding: 0 8px !important;
        flex: 1 !important;
        min-width: 0 !important;
    }

    #searchCategory {
        min-height: 24px !important;
        height: 24px !important;
        font-size: 12px !important;
        padding: 0 6px !important;
        max-width: 100px !important;
        flex-shrink: 0 !important;
    }

    .search-box {
        padding: 2px 8px !important;
        border-radius: 12px !important;
        flex: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        gap: 4px !important;
    }

    .header-row1 {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
        overflow: visible !important;
    }

    .search-filter-container {
        display: flex !important;
        gap: 8px !important;
        align-items: center !important;
        width: 100% !important;
        max-width: 100% !important;
        flex: 1 !important;
        order: 1 !important;
    }

    #searchWrapper {
        flex: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    #searchForm {
        flex: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
    }

    /* Filter button should be on the right */
    .filter-toggle-btn,
    #filterToggle,
    .search-filter-btn {
        order: 2 !important;
        flex-shrink: 0 !important;
        margin-left: auto !important;
    }

    /* Ensure header container is full width */
    .header-container {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Redundant toggle styles removed - controlled by header.php */
    /* .mobile-sidebar-toggle { ... } */

    /* Larger font sizes for readability */
    body {
        font-size: 16px;
        line-height: 1.6;
    }

    h1 {
        font-size: 28px;
    }

    h2 {
        font-size: 24px;
    }

    h3 {
        font-size: 20px;
    }

    h4 {
        font-size: 18px;
    }

    /* Spacing improvements */
    .container,
    .content {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* Cards and sections */
    .card,
    .section {
        margin-bottom: 16px;
        padding: 16px;
    }

    /* Tables - make scrollable */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Images responsive */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }

    /* Show mobile-only elements */
    .mobile-only {
        display: block !important;
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 720px;
    }

    /* Adjust grid layouts */
    .grid-3-col {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Landscape phone optimizations */
@media (max-width: 768px) and (orientation: landscape) {

    /* Reduce header height in landscape */
    header {
        min-height: 60px;
    }

    /* Adjust modal heights */
    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* Prevent text selection on buttons (better mobile UX) */
button,
.btn,
a.button {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Smooth scrolling on mobile */
html {
    -webkit-overflow-scrolling: touch;
}

/* Fix viewport issues */
@viewport {
    width: device-width;
    zoom: 1.0;
}

/* ==========================================================================
   NUCLEAR MOBILE COMBAT STYLES (Ported from index-mobile.php - User Request)
   "So this devil will not flash or come out without asking"
   ========================================================================== */
@media (max-width: 980px) {

    /* 1. Global Reset & Tightening */
    body,
    html,
    .main-content,
    main {
        margin: 0 !important;
        padding-top: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        overflow-x: hidden !important;
    }

    /* 2. Remove Header Gaps & Fix Banner */
    #mainHeader {
        margin-bottom: 0 !important;
        padding-bottom: 0 !important;
    }

    #redCrisisBanner {
        margin-top: 10px !important;
        /* Removed negative margin that caused overlap */
        position: relative !important;
        z-index: 995 !important;
    }

    /* 3. Mobile navigator — equal-width tabs across the row (first paint) */
    #navigator-container {
        display: flex !important;
        justify-content: stretch !important;
        gap: 0 !important;
        width: 100% !important;
        margin: 0 auto !important;
        padding: 0 !important;
        pointer-events: auto !important;
        z-index: 20002 !important;
        position: relative !important;
        overflow: visible !important;
    }

    #navigator-container .nav-item:not(.at-nav-mobile-only) {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        pointer-events: auto !important;
        z-index: 20003 !important;
    }

    #navigator-container .nav-btn {
        padding: 2px 4px !important;
        /* Ultra-tight touch target to fit 7+ items */
        cursor: pointer !important;
        pointer-events: auto !important;
        z-index: 20003 !important;

        /* Show Icon + Text tiny */
        font-size: 10px !important;
        color: #111827 !important;
        /* Deep dark color for visibility */
        font-weight: 600 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 2px !important;
        width: auto !important;
        min-width: 25px !important;
        /* Ensure click area */
    }

    /* Ensure Icons are visible and sized correctly */
    #navigator-container .nav-btn i {
        font-size: 18px !important;
        color: #333 !important;
        /* Default dark icon */
        display: block !important;
        visibility: visible !important;
        margin: 0 !important;
    }

    /* Specific colors for specific icons (re-apply if needed) */
    #navigator-container .nav-btn i.fa-home {
        color: #3b82f6 !important;
    }

    #navigator-container .nav-btn i.fa-heart {
        color: #ec4899 !important;
    }

    #navigator-container .nav-btn i.fa-images {
        color: #6366f1 !important;
    }

    #navigator-container .nav-btn i.fa-gavel {
        color: #f97316 !important;
    }

    #navigator-container .nav-btn i.fa-shopping-bag {
        color: #10b981 !important;
    }

    #navigator-container .nav-btn i.fa-chart-line {
        color: #8b5cf6 !important;
    }

    #navigator-container .nav-btn i.fa-globe {
        color: #14b8a6 !important;
    }

    #navigator-container .nav-btn i.fa-tools {
        color: #ef4444 !important;
    }

    /* Show text spans (Match Desktop) */
    #navigator-container .nav-btn span,
    #navigator-container .nav-text {
        display: inline !important;
    }

    /* 4. KILL THE FLASHING DEVIL (UFO Panel)
       But allow it if .mobile-summoned (The Strip) is active. */
    /* DISABLED - Relying on .ufo-mobile-hidden class
    #ufoControlPanel:not(.mobile-summoned),
    .ufo-right-control-panel:not(.mobile-summoned) {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        left: -9999px !important;
        width: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
    }
    */

    /* 5. Sanity Bar (Visual Confidence) */
    .sanity-bar {
        height: 3px !important;
        background: #39ff14 !important;
        /* Neon Green */
        width: 100% !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        z-index: 2147483647 !important;
    }
}
/* Accessibility Improvements */

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #3b82f6;
    color: #fff;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 100000;
    border-radius: 4px;
}

.skip-to-main:focus {
    top: 0;
}

/* Focus indicators */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Remove outline for mouse users, keep for keyboard users */
*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    * {
        border-color: currentColor !important;
    }

    a {
        text-decoration: underline;
    }
}

/* Reduced motion support */
@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;
    }
}

/* 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-width: 0;
}

.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Ensure sufficient color contrast */
a {
    color: #2563eb;
    /* WCAG AA compliant */
}

a:hover {
    color: #1d4ed8;
}

/* Button contrast */
.btn-primary {
    background: #3b82f6;
    color: #fff;
    border: none;
}

.btn-secondary {
    background: #6b7280;
    color: #fff;
    border: none;
}

/* Form labels */
label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    color: #374151;
}

/* Required field indicator */
.required::after {
    content: " *";
    color: #ef4444;
}

/* Error messages */
.error-message,
.form-error {
    color: #dc2626;
    font-size: 14px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.error-message::before {
    content: "⚠";
}

/* Success messages */
.success-message {
    color: #059669;
    font-size: 14px;
    margin-top: 4px;
}

/* Disabled state */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading state */
[aria-busy="true"] {
    cursor: wait;
    opacity: 0.7;
}

/* Tooltips */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    margin-bottom: 4px;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
    opacity: 1;
}

/* Ensure images have alt text */
img:not([alt]) {
    outline: 2px solid #ef4444;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1f2937;
        --text-color: #f3f4f6;
        --border-color: #374151;
    }

    body {
        background: var(--bg-color);
        color: var(--text-color);
    }

    a {
        color: #60a5fa;
    }
}
