/* Responsive Design Fixes for IMG-Agent V.1.2 Pro */

/* Fix main content overflow */
.main-content {
    width: calc(100vw - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Desktop optimization */
.generation-layout {
    max-width: 100%;
    width: 100%;
}

.input-panel {
    max-width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    align-self: start;
    padding-bottom: 24px; /* Scroll ile en alta erişim için */
}

.results-panel {
    max-width: 100%;
}

/* Content header */
#generation-tab .content-header {
    position: relative;
    z-index: 100;
    background: var(--bg-primary);
}

/* Container max-width for large screens */
@media (min-width: 1600px) {
    .generation-layout {
        max-width: 100%;
        margin: 0;
    }
}

/* Hide divider line in generation layout */
.generation-layout {
    position: relative;
}

.generation-layout::after {
    display: none !important;
}

/* Fix any vertical lines between panels */
.input-panel,
.results-panel {
    border-right: none !important;
}

/* Large screens - optimize grid */
@media (max-width: 1600px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
}

/* Medium large screens */
@media (max-width: 1400px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* Tablet landscape */
@media (max-width: 1024px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* Tablet screens */
@media (max-width: 992px) {
    .generation-layout {
        grid-template-columns: 1fr;
        gap: var(--spacing-lg);
    }

    .input-panel {
        max-width: 600px;
        margin: 0 auto;
        max-height: none;
        padding-bottom: 24px;
    }

    .results-panel {
        min-height: 400px;
    }
    
    .grid-item {
        flex: 0 0 calc(50% - 8px);
        max-width: calc(50% - 8px);
    }

    .preview-panel {
        min-height: 400px;
    }

    /* Carousel responsive */
    .carousel-container {
        padding: 20px 50px;
        height: auto;
        min-height: 350px;
        max-height: 60vh;
    }

    .carousel-item {
        height: auto;
        min-width: 180px;
    }

    /* Fullscreen modal */
    .fullscreen-modal {
        padding: 0;
    }

    .fullscreen-content {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        padding: 50px 60px 70px;
        gap: 0;
    }

    .fullscreen-image-area {
        max-height: 100%;
        padding: 0;
    }

    .fullscreen-content img {
        max-width: 100%;
        max-height: 100%;
    }
}

/* Mobile and tablet portrait */
@media (max-width: 768px) {

    /* Grid container for mobile */
    .grid-container {
        gap: 12px;
    }
    
    .grid-item {
        flex: 0 0 calc(50% - 6px);
        max-width: calc(50% - 6px);
    }

    /* Fix sidebar width on mobile */
    .sidebar {
        width: var(--sidebar-width);
        max-width: 80vw;
    }

    /* Fix main content on mobile */
    .main-content {
        max-width: 100vw;
        padding: var(--spacing-md);
    }

    /* Generation button adjustments for mobile */
    .upload-menu-popover .compact-select-option {
        height: 32px;
        font-size: 0.75rem;
        padding: 0 10px;
        gap: 6px;
    }

    /* More options container - ensure visibility */
    .more-options-container {
        min-width: 70px;
        flex-shrink: 0;
    }

    .more-options-dropdown {
        min-width: 250px;
        right: -10px;
        z-index: 1002;
    }

    /* Gallery responsive */
    .gallery-actions {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }

    .search-box {
        width: 100%;
        max-width: 100%;
        margin-bottom: var(--spacing-sm);
    }

    .gallery-actions .btn-icon {
        flex-shrink: 0;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: var(--spacing-md);
        padding: var(--spacing-md);
    }

    /* Filter buttons scrollable */
    .filter-group {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: var(--spacing-sm);
    }

    .filter-btn {
        flex-shrink: 0;
    }

    /* Carousel mobile */
    .carousel-container {
        padding: 15px 45px;
        height: clamp(300px, 55vh, 500px);
    }

    .carousel-item {
        height: 100%;
        min-width: 140px;
    }

    /* For mobile, adjust single/double image layout */
    .carousel-container:has(.carousel-item:only-child) .carousel-item,
    .carousel-container:has(.carousel-item:nth-child(2):last-child) .carousel-item {
        max-width: 90%;
    }

    .carousel-nav {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .carousel-prev {
        left: 5px;
    }

    .carousel-next {
        right: 5px;
    }

    /* Grid mobile - responsive columns */
    .grid-container {
        gap: 8px;
    }
    
    .grid-item {
        flex: 0 0 calc(33.333% - 6px);
        max-width: calc(33.333% - 6px);
    }

    /* Fullscreen mobile */
    .fullscreen-modal {
        padding: 0;
    }

    .fullscreen-content {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        padding: 50px 50px 70px;
        gap: 0;
    }

    .fullscreen-image-area {
        max-height: 100%;
        padding: 0;
    }

    .fullscreen-content img {
        max-width: 100%;
        max-height: 100%;
    }

    .fullscreen-nav {
        width: 44px;
        height: 44px;
        font-size: 1.25rem;
    }

    .fullscreen-close {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
        top: 10px;
        right: 10px;
    }

    .fullscreen-actions {
        bottom: 16px;
        gap: 8px;
        padding: 10px 14px;
        flex-wrap: wrap;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {

    /* Reduce header spacing */
    .header-content {
        gap: var(--spacing-sm);
        padding: 0 var(--spacing-sm);
    }

    /* Hide logo text on small screens */
    .logo span:not(.version-badge) {
        display: none;
    }

    /* Hide processing indicator text */
    .processing-indicator span {
        display: none;
    }

    /* Extra small generation buttons */
    .upload-menu-popover .compact-select-option {
        height: 32px;
        font-size: 0.7rem;
        padding: 0 8px;
    }

    /* Compact generation controls */
    .generation-controls-row {
        gap: 4px;
        min-height: 30px;
    }

    .generation-buttons {
        gap: 4px;
    }

    /* Ensure more options dropdown is accessible */
    .more-options-dropdown {
        min-width: 240px;
        right: -20px;
        margin-top: 4px;
    }

    /* Gallery filters full width */
    .gallery-filters {
        width: 100%;
        order: 2;
    }

    /* Gallery actions full width */
    .gallery-actions {
        width: 100%;
        order: 3;
        flex-direction: column;
    }

    /* Smaller gallery grid */
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: var(--spacing-sm);
        padding: var(--spacing-sm);
    }

    /* Smaller text in gallery items */
    .gallery-item .result-info {
        padding: var(--spacing-sm);
    }

    .gallery-item .result-type {
        font-size: 0.75rem;
    }

    .gallery-item .file-size,
    .gallery-item .specific-type {
        font-size: 0.625rem;
    }

    /* Results grid smaller */
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: var(--spacing-sm);
    }

    /* Button text adjustments */
    .filter-btn {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 0.75rem;
    }
}

/* Extra small devices */
@media (max-width: 360px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

/* Fix for MacOS viewport issues */
@supports (-webkit-touch-callout: none) {

    /* iOS/MacOS specific fixes */
    .main-content {
        -webkit-overflow-scrolling: touch;
    }

    .gallery-grid,
    .results-grid {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Prevent horizontal scroll on all devices */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Ensure results grid is the only scrollable element */
.results-content {
    overflow: visible !important;
}

/* Fix card content overflow for input panel only */
.input-panel .panel-card {
    overflow: visible;
    height: auto;
}


/* Ensure images don't cause overflow */
img {
    max-width: 100%;
    height: auto;
}

/* Fix modal and overlay scrolling */
.modal-overlay,
.lightbox-overlay {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Fix filter scrolling */
.filter-scroll-container {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.filter-scroll-container::-webkit-scrollbar {
    display: none;
}

/* Ensure only results-grid has visible scrollbar */
.results-grid::-webkit-scrollbar {
    width: 8px;
}

.results-grid::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

.results-grid::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 4px;
}

.results-grid::-webkit-scrollbar-thumb:hover {
    background: var(--border-dark);
}

/* Desktop Aspect Ratio Options */
@media (min-width: 769px) {
    .aspect-ratio-grid {
        display: grid !important;
        grid-template-columns: repeat(6, 1fr) !important;
        gap: 10px !important;
        padding: 16px 20px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .aspect-ratio-option {
        width: 100% !important;
        max-width: 100% !important;
        padding: 12px 4px !important;
        box-sizing: border-box !important;
        flex-shrink: 0 !important;
    }
}

/* Responsive Aspect Ratio Options */
@media (max-width: 768px) {
    .aspect-ratio-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: var(--spacing-sm) !important;
        padding: var(--spacing-md) !important;
    }

    .aspect-ratio-option {
        width: 100%;
        height: auto;
        padding: var(--spacing-sm) !important;
        flex-direction: column;
        gap: 4px;
    }

    .aspect-ratio-box {
        transform: scale(0.8);
    }

    .aspect-ratio-label {
        font-size: 0.65rem;
    }
}

/* Notification container - removed conflicting styles, using main styles.css */
/* Mobile notification adjustments */
@media (max-width: 768px) {
    .notification-container {
        bottom: 16px;
        right: 16px;
        left: auto;
        max-width: calc(100vw - 32px);
    }

    .notification {
        max-width: 100%;
        font-size: 0.875rem;
    }
}
