/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .prompt-edit-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        font-size: 12px;
        padding: 6px;
    }

    .start-main-controls {
        gap: 6px;
    }

    .prompt-status {
        font-size: 10px;
        max-width: 150px;
    }
}

@media (max-width: 768px) {
    .modal-body-content {
        flex-direction: column;
        gap: 15px;
    }

    .prompts-section,
    .input-section {
        max-width: none;
        min-width: auto;
    }

    .modal-content {
        width: 95%;
        max-width: none;
        margin: 10px;
        padding: 20px;
    }

    /* Fix prompt edit modal similar to upload modal */
    .prompt-edit-modal-content {
        width: calc(100% - 30px);
        max-width: calc(100vw - 30px);
        margin: 15px;
        padding: 0;
        box-sizing: border-box;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        max-height: 85vh;
    }

    .prompt-edit-modal-content .modal-header {
        padding: 12px;
        flex-shrink: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .prompt-edit-modal-content .modal-body {
        padding: 8px 12px 0 12px;
        margin-bottom: 0;
        flex: 1;
        overflow-y: auto;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
    }

    /* Reduce gap in prompt-input-section on mobile */
    .prompt-input-section {
        gap: 8px !important;
    }

    .prompt-input-section textarea {
        height: 120px;
        padding: 8px;
        font-size: 16px !important; /* Prevent zoom on iOS/Android */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        resize: none; /* Disable manual resize on mobile */
    }

    .prompt-edit-modal-content .modal-footer {
        padding: 10px 12px;
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
        flex-shrink: 0;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    #generate-prompt-btn {
        width: 100%;
        order: -1; /* Move AI Generate button to top */
    }

    .prompt-edit-modal-content .modal-actions-right {
        display: flex;
        width: 100%;
        gap: 10px;
    }

    .prompt-edit-modal-content .modal-actions-right button {
        flex: 1;
    }

    .input-hint {
        padding: 10px 12px;
        font-size: 12px;
    }

    .modal-subtitle {
        font-size: 13px;
    }
}

/* Responsive adjustments for image panel */
@media (max-width: 768px) {
    /* Hide badge on mobile portrait - panel is always visible inline */
    .mobile-portrait .image-count-badge {
        display: none !important;
    }

    #image-selector-panel {
        width: 180px;
        max-height: calc(100% - 80px);
    }

    #image-selector-panel.collapsed {
        display: none;
    }

    #image-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }

    #image-grid-container {
        padding: 8px;
        padding-bottom: 0;
        max-height: 250px;
        min-height: 150px;
    }

    #upload-section {
        padding: 8px;
    }

    .action-buttons {
        gap: 4px;
    }

    .action-btn {
        padding: 6px 10px;
        font-size: 10px;
        max-width: 80px;
        border-radius: 16px;
    }

    .action-btn .btn-icon {
        width: 12px;
        height: 12px;
    }

    .action-btn .btn-text {
        font-size: 9px;
        letter-spacing: 0.3px;
    }

    /* Bottom bar responsive */
    #info-panel {
        flex-wrap: wrap;
        height: auto;
        min-height: 40px;
    }

    #info-panel .panel-header {
        padding: 8px 12px;
    }

    #info-panel .info-section {
        padding: 8px 12px;
    }

    #info-panel .controls-section {
        margin-left: 0;
    }

    .bottom-bar-arrows {
        gap: 2px;
    }

    .kb-arrow {
        width: 22px;
        height: 18px;
        font-size: 10px;
    }
}

/* Responsive adjustments for action buttons */
@media (max-width: 768px) {
    #action-buttons-container {
        bottom: 10px;
        gap: 10px;
    }

    .button-group {
        padding: 6px;
    }

    .action-button {
        width: 42px;
        height: 42px;
    }

    .direction-button {
        width: 30px;
        height: 30px;
        font-size: 10px;
    }

    .action-button img {
        width: 18px;
        height: 18px;
    }

    .action-button .key-label {
        font-size: 9px;
    }

    .direction-button.arrow-up::before,
    .direction-button.arrow-down::before,
    .direction-button.arrow-left::before,
    .direction-button.arrow-right::before {
        font-size: 14px;
    }

    /* Download panel responsive */
    .download-panel {
        width: 95%;
        padding: 10px 12px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .video-action-button {
        padding: 8px 14px;
        font-size: 12px;
    }

    .video-action-button svg {
        width: 16px;
        height: 16px;
    }

    .controls-option {
        width: 100%;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .download-divider {
        display: none;
    }

    /* Video player responsive */
    .video-player-container {
        width: 95%;
        padding: 15px;
    }

    .video-player-title {
        font-size: 16px;
    }

    .video-player-close {
        width: 32px;
        height: 32px;
    }

    /* Fix upload modal width on mobile */
    .upload-modal-content {
        width: calc(100% - 30px);
        max-width: calc(100vw - 30px);
        margin: 15px;
        box-sizing: border-box;
        overflow: hidden;
    }

    /* Ensure header fits properly */
    .upload-modal-content .modal-header {
        flex-direction: row;
        justify-content: space-between;
        gap: 10px;
        padding: 12px;
    }

    .header-left {
        flex: 1;
        min-width: 0; /* Allow flex item to shrink below content size */
        margin-right: 10px;
    }

    .header-right {
        flex-shrink: 0;
    }

    /* Make thumbnail smaller on mobile */
    .upload-image-thumbnail {
        width: 70px;
        height: 70px;
    }

    /* Adjust modal body for mobile */
    .upload-modal-content .modal-body {
        padding: 8px 12px 6px 12px;
        margin-bottom: 10px;
        max-height: 40vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Container for textarea to prevent expansion */
    .prompt-input-section {
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    /* Ensure textarea doesn't expand beyond container */
    .upload-prompt-textarea {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 16px !important; /* Prevent zoom on iOS/Android */
        min-height: 80px;
        resize: none; /* Disable manual resize on mobile */
    }

    /* Stack footer buttons vertically */
    .upload-modal-content .modal-footer {
        flex-direction: column;
        gap: 10px;
        padding: 10px 15px;
    }

    #upload-generate-prompt-btn {
        width: 100%;
    }

    .modal-actions-right {
        display: flex;
        width: 100%;
        gap: 10px;
    }

    .modal-actions-right button {
        flex: 1;
    }

    /* Ensure name container wraps properly */
    .image-name-container {
        flex-wrap: wrap;
        gap: 8px;
    }

    .image-name-display {
        min-width: auto;
        flex: 0 1 auto; /* Don't grow, can shrink, use auto width */
        max-width: 100%;
        padding: 4px 10px; /* Smaller padding on mobile */
        font-size: 12px;
    }

    .image-name-tag {
        padding: 3px 8px;
        font-size: 10px;
    }

    /* Extra small screens (like Galaxy Z Fold 5: 344px) */
    @media (max-width: 360px) {
        .upload-modal-content,
        .prompt-edit-modal-content {
            width: calc(100% - 16px);
            max-width: calc(100vw - 16px);
            margin: 8px;
        }

        .upload-modal-content .modal-header {
            padding: 10px;
            gap: 8px;
        }

        .modal-subtitle {
            font-size: 11px;
        }

        .header-right {
            align-self: flex-start;
        }

        .upload-image-thumbnail {
            width: 50px;
            height: 50px;
        }

        .upload-modal-content .modal-body {
            padding: 6px 10px 4px 10px;
            margin-bottom: 8px;
        }

        .upload-prompt-textarea {
            min-height: 60px;
            padding: 6px 8px;
        }

        .upload-modal-content .modal-footer {
            padding: 8px 10px;
        }

        .image-name-container {
            font-size: 12px;
        }

        /* Prompt edit modal on very small screens */
        .prompt-edit-modal-content .modal-header {
            padding: 10px;
        }

        .prompt-edit-modal-content .modal-body {
            padding: 6px 10px 0 10px;
        }

        .prompt-input-section {
            gap: 6px !important;
        }

        .prompt-input-section textarea {
            height: 100px;
            padding: 6px 8px;
            min-height: 80px;
        }

        .prompt-edit-modal-content .modal-footer {
            padding: 8px 10px;
        }

        .input-hint {
            font-size: 11px;
            padding: 8px 10px;
        }
    }
}

/* Android-specific fixes */
.android.mobile .upload-modal-content,
.android.mobile .prompt-edit-modal-content {
    width: calc(100% - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    position: relative !important;
}

/* Fix image name input positioning on Android */
.android .image-name-container {
    flex-wrap: nowrap !important;  /* Prevent wrapping on Android */
    align-items: center;
}

.android .image-name-input {
    position: relative !important;
    margin: 0 !important;
}

/* Only when input is shown (not display: none) */
.android .image-name-input:not([style*="display: none"]) {
    display: inline-flex !important;
}

/* Container control for Android */
.android .prompt-input-section {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    position: relative !important;
}

/* Prevent textarea from expanding beyond container on Android */
.android .upload-prompt-textarea,
.android #prompt-input {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    font-size: 16px !important;
    transform: none !important;
    zoom: 1 !important;
    position: relative !important;
    margin: 0 !important;
}

/* Fix for Android when keyboard is open */
.android .upload-prompt-textarea:focus,
.android #prompt-input:focus {
    width: 100% !important;
    max-width: 100% !important;
    position: relative !important;
    transform: none !important;
    zoom: 1 !important;
}

/* Chrome mobile specific (including emulator) */
.chrome.mobile .upload-modal-content,
.chrome.mobile .prompt-edit-modal-content {
    contain: layout style;
}

.chrome.mobile .upload-prompt-textarea,
.chrome.mobile #prompt-input {
    width: -webkit-fill-available !important;
    width: -moz-available !important;
    width: fill-available !important;
    max-width: 100% !important;
}

/* Galaxy Z Fold 5 specific fix (344px width) */
@media (max-width: 344px) {
    .upload-modal-content,
    .prompt-edit-modal-content {
        width: calc(100vw - 16px) !important;
        max-width: calc(100vw - 16px) !important;
    }

    .upload-prompt-textarea,
    #prompt-input {
        width: 100% !important;
        max-width: 100% !important;
    }
}