/* =================================================================== */
/* UPDATED RESPONSIVE CSS - HERO LAYOUT DESIGN */
/* =================================================================== */

/* BASE RESPONSIVE STYLES */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    overflow-x: hidden;
}

/* HERO SECTION RESPONSIVE */
.hero-section {
    padding: 2rem 1rem;
}

@media (min-width: 640px) {
    .hero-section {
        padding: 3rem 1.5rem;
    }
}

@media (min-width: 1024px) {
    .hero-section {
        padding: 4rem 2rem;
    }
}

/* VIEWER SECTION RESPONSIVE */
.viewer-section {
    padding: 2rem 1rem;
}

@media (min-width: 640px) {
    .viewer-section {
        padding: 3rem 1.5rem;
    }
}

@media (min-width: 1024px) {
    .viewer-section {
        padding: 4rem 2rem;
    }
}

/* BOOKMARKS GRID RESPONSIVE */
#bookmarksList {
    gap: 1rem;
}

@media (max-width: 640px) {
    #bookmarksList {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
}

@media (min-width: 641px) and (max-width: 768px) {
    #bookmarksList {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    #bookmarksList {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1025px) and (max-width: 1280px) {
    #bookmarksList {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1281px) {
    #bookmarksList {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* MOBILE OPTIMIZATIONS - COMPLETE REWRITE */
@media (max-width: 768px) {
    body {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
        font-size: 14px;
    }
    
    .hero-section {
        padding: 1.5rem 0.75rem;
    }
    
    .viewer-section {
        padding: 1.5rem 0.75rem;
    }
    
    /* Mobile Typography */
    h1 {
        font-size: 1.5rem !important;
        line-height: 1.3;
        margin-bottom: 1rem;
    }
    
    h2 {
        font-size: 1.25rem !important;
        line-height: 1.3;
        margin-bottom: 1rem;
    }
    
    h3 {
        font-size: 1.125rem !important;
        line-height: 1.3;
    }
    
    /* Mobile Buttons */
    .button-mobile {
        min-height: 48px !important;
        font-size: 1rem !important;
        padding: 12px 16px !important;
        width: 100%;
        border-radius: 8px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        -webkit-appearance: none;
    }
    
    /* Mobile Inputs - CRITICAL FIXES */
    .input-mobile {
        min-height: 48px !important;
        font-size: 16px !important; /* Critical: Prevents zoom on iOS */
        padding: 12px 16px !important;
        width: 100%;
        border-radius: 8px;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
        -webkit-touch-callout: default;
        touch-action: manipulation;
        line-height: 1.5;
        border: 2px solid #374151;
        background-color: #f9fafb !important;
        color: #111827 !important;
    }
    
    .input-mobile:focus {
        border-color: #3b82f6 !important;
        outline: none !important;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
        transform: none !important; /* Prevent transform on mobile */
    }
    
    /* Fix for modal inputs */
    #addBookmarkModal input {
        font-size: 16px !important;
        min-height: 48px !important;
        padding: 12px 16px !important;
        -webkit-appearance: none;
        background-color: #374151 !important;
        color: #ffffff !important;
        border: 2px solid #4b5563;
    }
    
    #addBookmarkModal input:focus {
        border-color: #3b82f6 !important;
        background-color: #374151 !important;
        color: #ffffff !important;
    }
    
    /* Mobile viewer height */
    .viewer-height {
        height: 50vh !important;
        min-height: 300px !important;
    }
    
    /* Mobile stats grid */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    
    /* Mobile controls */
    .flex.flex-col.space-y-4.lg\\:flex-row.lg\\:space-y-0.lg\\:space-x-4 {
        gap: 1rem !important;
    }
    
    /* Mobile filter options */
    .flex.flex-wrap.gap-6.mb-6.justify-center {
        gap: 1.5rem !important;
        flex-direction: column !important;
        align-items: center !important;
    }
    
    .flex.flex-wrap.gap-6.mb-6.justify-center label {
        touch-action: manipulation;
        min-height: 44px;
        display: flex !important;
        align-items: center;
        padding: 8px;
    }
    
    .flex.flex-wrap.gap-6.mb-6.justify-center input[type="checkbox"] {
        width: 1.5rem !important;
        height: 1.5rem !important;
        margin-right: 0.75rem !important;
    }
    
    /* Mobile bookmark management controls */
    .flex.flex-wrap.justify-center.gap-4.mb-8 {
        flex-direction: column !important;
        gap: 0.75rem !important;
        align-items: stretch !important;
    }
    
    .flex.flex-wrap.justify-center.gap-4.mb-8 button {
        width: 100% !important;
        margin: 0 !important;
    }
    
    /* Mobile bookmarks */
    .bookmark-item {
        min-height: 100px !important;
        padding: 1rem !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .bookmark-item:hover {
        transform: none !important; /* Disable hover transforms on mobile */
    }
    
    .bookmark-item:active {
        transform: scale(0.98) !important;
        background: linear-gradient(135deg, #4b5563 0%, #6b7280 100%) !important;
    }
    
    /* Mobile fullscreen controls - Always visible */
    .fullscreen-controls {
        opacity: 1 !important;
        background: rgba(0, 0, 0, 0.6) !important;
        border-radius: 8px !important;
        padding: 6px !important;
        top: 10px !important;
        right: 10px !important;
    }
    
    .fullscreen-controls button {
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 10px !important;
        font-size: 1rem !important;
    }
    
    /* Mobile exit fullscreen button */
    .mobile-exit-btn {
        display: block !important;
        top: 10px !important;
        left: 10px !important;
    }
    
    .mobile-exit-btn button {
        min-width: 50px !important;
        min-height: 44px !important;
        padding: 8px 12px !important;
        font-size: 0.75rem !important;
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
        white-space: nowrap !important;
    }
    
    /* Mobile modal */
    #addBookmarkModal {
        padding: 1rem !important;
    }
    
    #addBookmarkModal .bg-gray-800 {
        margin: 0 !important;
        width: 100% !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        border-radius: 12px !important;
    }
    
    /* Mobile activity log */
    #activityLog {
        font-size: 0.75rem !important;
        max-height: 120px !important;
    }
    
    /* Fix mobile text sizing */
    .text-mobile {
        font-size: 0.875rem !important;
        line-height: 1.4 !important;
    }
    
    /* Mobile container fixes */
    .max-w-6xl {
        max-width: 100% !important;
        padding: 0 0.75rem !important;
    }
}

/* TABLET STYLES */
@media (min-width: 769px) and (max-width: 1023px) {
    .hero-section {
        padding: 2.5rem 1.5rem;
    }
    
    .viewer-section {
        padding: 2.5rem 1.5rem;
    }
    
    .viewer-height {
        height: 65vh !important;
        min-height: 450px;
    }
    
    .button-mobile {
        min-height: 44px;
        padding: 10px 20px;
    }
    
    .input-mobile {
        min-height: 44px;
        font-size: 1rem;
        padding: 10px 16px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }
    
    /* Tablet fullscreen controls */
    .fullscreen-controls {
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .fullscreen-container:hover .fullscreen-controls {
        opacity: 1;
    }
}

/* DESKTOP STYLES */
@media (min-width: 1024px) {
    .hero-section {
        padding: 3rem 2rem;
    }
    
    .viewer-section {
        padding: 3rem 2rem;
    }
    
    .viewer-height {
        height: 75vh !important;
        min-height: 600px;
    }
    
    .button-mobile {
        min-height: 48px;
        padding: 12px 24px;
        width: auto;
    }
    
    .input-mobile {
        min-height: 48px;
        font-size: 1rem;
        padding: 12px 16px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.5rem;
    }
    
    /* Desktop fullscreen controls */
    .fullscreen-controls {
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .fullscreen-container:hover .fullscreen-controls,
    .fullscreen-container:focus-within .fullscreen-controls {
        opacity: 1;
    }
    
    /* Hide mobile exit button on desktop */
    .mobile-exit-btn {
        display: none !important;
    }
    
    /* Desktop bookmark management controls */
    .flex.flex-wrap.justify-center.gap-4.mb-8 {
        flex-direction: row !important;
        gap: 1rem !important;
    }
    
    .flex.flex-wrap.justify-center.gap-4.mb-8 button {
        width: auto !important;
        flex: none !important;
    }
}

/* LARGE DESKTOP AND TV */
@media (min-width: 1200px) {
    .hero-section {
        padding: 4rem 2rem;
    }
    
    .viewer-section {
        padding: 4rem 2rem;
    }
    
    .viewer-height {
        height: 80vh !important;
        min-height: 700px;
    }
    
    /* TV optimizations */
    .tv-optimized {
        font-size: 1.25rem;
    }
    
    .tv-button {
        min-height: 60px;
        min-width: 120px;
        font-size: 1.1rem;
        border: 2px solid transparent;
        transition: all 0.3s ease;
    }
    
    .tv-button:focus {
        border-color: #3b82f6;
        box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.3);
        outline: none;
        transform: scale(1.05);
    }
    
    .tv-input {
        min-height: 60px;
        font-size: 1.1rem;
        padding: 1rem;
    }
}

/* TOUCH DEVICE OPTIMIZATIONS */
@media (pointer: coarse) {
    .touch-target {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 12px !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
    }
    
    .bookmark-item {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    button, input[type="checkbox"] {
        min-height: 44px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Improve scrolling on touch devices */
    .scrollbar-thin {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
}

/* ORIENTATION FIXES */
@media (orientation: landscape) and (max-height: 500px) {
    .viewer-height {
        height: 35vh !important;
        min-height: 250px !important;
    }
    
    .hero-section {
        padding: 1rem !important;
    }
    
    .viewer-section {
        padding: 1rem !important;
    }
    
    /* Reduce bookmark grid in landscape */
    #bookmarksList {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
        gap: 0.5rem !important;
    }
    
    .bookmark-item {
        min-height: 80px !important;
        padding: 0.5rem !important;
    }
}

/* HIGH DPI DISPLAYS */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .fullscreen-controls button {
        border-width: 0.5px;
    }
    
    .bookmark-item {
        border-width: 0.5px;
    }
}

/* PRINT STYLES */
@media print {
    .fullscreen-controls,
    .mobile-exit-btn {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
    
    .viewer-height {
        height: auto !important;
        min-height: 50vh;
        border: 1px solid #000;
    }
    
    .hero-section,
    .viewer-section {
        padding: 1rem !important;
    }
}

/* ACCESSIBILITY IMPROVEMENTS */
@media (prefers-reduced-motion: reduce) {
    .bookmark-item,
    .fullscreen-controls button,
    button,
    input,
    .viewer-height {
        transition: none !important;
        animation: none !important;
    }
}

/* HIGH CONTRAST MODE */
@media (prefers-contrast: high) {
    .fullscreen-controls button {
        border: 2px solid #ffffff !important;
        background: rgba(0, 0, 0, 0.9) !important;
    }
    
    .bookmark-item:focus,
    button:focus,
    input:focus {
        outline: 3px solid #ffffff !important;
        outline-offset: 2px !important;
    }
}

/* SAFE AREA INSETS FOR MOBILE DEVICES */
@supports (padding: max(0px)) {
    .hero-section,
    .viewer-section {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-top: max(1.5rem, env(safe-area-inset-top));
    }
    
    @media (min-width: 640px) {
        .hero-section,
        .viewer-section {
            padding-left: max(1.5rem, env(safe-area-inset-left));
            padding-right: max(1.5rem, env(safe-area-inset-right));
        }
    }
    
    @media (min-width: 1024px) {
        .hero-section,
        .viewer-section {
            padding-left: max(2rem, env(safe-area-inset-left));
            padding-right: max(2rem, env(safe-area-inset-right));
        }
    }
}

/* VIEWPORT HEIGHT FIXES FOR MOBILE BROWSERS */
@supports (-webkit-touch-callout: none) {
    .viewer-height {
        height: -webkit-fill-available;
    }
}

/* CONTAINER MAX WIDTH ADJUSTMENTS */
.max-w-6xl {
    max-width: 72rem;
}

@media (max-width: 640px) {
    .max-w-6xl {
        max-width: 100%;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .max-w-6xl {
        max-width: 100%;
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}

@media (min-width: 1025px) {
    .max-w-6xl {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}