/* =========================================
   BINARYPH IMAGE GENERATOR
   Matches BinaryPH Chatbot Theme
   ========================================= */

.binaryph-image-generator-container {
    /* --- THEME VARIABLES --- */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    
    /* Colors - Light Mode */
    --bg-light-main: #ffffff;
    --bg-light-secondary: #f9f9f9;
    --border-light: #e5e7eb;
    --text-light: #374151;
    --input-bg-light: #ffffff;
    
    /* Colors - Dark Mode */
    --bg-dark-main: #212121;
    --bg-dark-secondary: #171717;
    --border-dark: #404040;
    --text-dark: #e5e7eb;
    --input-bg-dark: #2f2f2f;

    /* Accent */
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --accent-text: #ffffff;
    
    /* Secondary Button (Choose File) */
    --btn-sec-light-bg: #e5e7eb;
    --btn-sec-light-text: #374151;
    --btn-sec-light-hover: #d1d5db;
    
    --btn-sec-dark-bg: #404040;
    --btn-sec-dark-text: #e5e7eb;
    --btn-sec-dark-hover: #525252;

    --danger-color: #ef4444;

    /* Dimensions */
    --radius-main: 12px;
    --radius-sm: 8px;

    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-light); 
    border-radius: var(--radius-main); 
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); 
    margin: 20px auto;
    font-family: var(--font-family); 
    background: var(--bg-light-main); 
    color: var(--text-light); 
    transition: all 0.3s ease;
    box-sizing: border-box;
    
    /* IMPORTANT: Allow container to expand based on content */
    height: auto !important; 
    overflow: visible !important; 
    max-width: 100%;
}

.binaryph-image-generator-container * {
    box-sizing: border-box;
}

/* --- DARK MODE --- */
.binaryph-image-generator-dark {
    background: var(--bg-dark-main); 
    color: var(--text-dark); 
    border-color: var(--border-dark); 
}

/* --- INPUT AREA --- */
.binaryph-image-generator-input {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px;
    background: var(--bg-light-secondary); 
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.binaryph-image-generator-dark .binaryph-image-generator-input {
    background: var(--bg-dark-secondary); 
    border-color: var(--border-dark);
}

/* Top Row Controls */
.binaryph-controls-top-row {
    display: flex;
    /* CHANGED: Align items to the left (start) instead of spacing them out */
    justify-content: flex-start;
    align-items: center;
    gap: 20px; /* Increased gap for better visual separation */
    flex-wrap: wrap;
}

/* Radio Toggles */
.binaryph-mode-toggle {
    display: flex;
    gap: 16px;
    background: rgba(0,0,0,0.05);
    padding: 4px;
    border-radius: var(--radius-sm);
}
.binaryph-image-generator-dark .binaryph-mode-toggle {
    background: rgba(255,255,255,0.05);
}

.binaryph-mode-toggle label {
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}
.binaryph-mode-toggle label:hover {
    background: rgba(0,0,0,0.05);
}
.binaryph-image-generator-dark .binaryph-mode-toggle label:hover {
    background: rgba(255,255,255,0.1);
}
.binaryph-mode-toggle input[type="radio"] {
    accent-color: var(--accent-color);
}

/* Duration Control */
.binaryph-video-duration-control {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
}

/* Duration Stepper */
.duration-stepper {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-light-main);
    overflow: hidden;
}
.binaryph-image-generator-dark .duration-stepper {
    border-color: var(--border-dark);
    background: var(--input-bg-dark);
}

.stepper-btn {
    border: none;
    background: transparent;
    color: inherit;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.stepper-btn:hover { background: rgba(0,0,0,0.05); }
.binaryph-image-generator-dark .stepper-btn:hover { background: rgba(255,255,255,0.1); }

.duration-stepper input {
    width: 40px;
    text-align: center;
    border: none;
    background: transparent;
    color: inherit;
    font-family: inherit;
    font-size: 13px;
    -moz-appearance: textfield;
}
.duration-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* --- CUSTOM DROPDOWN (Aspect Ratio) --- */
.binaryph-aspect-ratio-control {
    position: relative;
    min-width: 220px;
    /* CHANGED: Removed flex-grow to prevent it from pushing right */
    flex-grow: 0;
    max-width: 300px;
}

.binaryph-custom-select {
    position: relative;
    width: 100%;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-light-main);
    color: inherit;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    height: 36px;
    display: flex;
    align-items: center;
}
.binaryph-custom-select:hover { border-color: #9ca3af; }
.binaryph-image-generator-dark .binaryph-custom-select {
    background: var(--input-bg-dark);
    border-color: var(--border-dark);
}

.binaryph-select-selected {
    padding: 0 12px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.binaryph-select-selected:after {
    content: "";
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
    opacity: 0.5;
}

.binaryph-select-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    z-index: 100;
    background: var(--bg-light-main);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    display: none;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.binaryph-custom-select.active .binaryph-select-options { display: block; }

.binaryph-image-generator-dark .binaryph-select-options {
    background: #262626;
    border-color: var(--border-dark);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

.binaryph-option {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}
.binaryph-option:hover { background: rgba(0,0,0,0.05); }
.binaryph-image-generator-dark .binaryph-option:hover { background: rgba(255,255,255,0.1); }
.binaryph-option.selected { font-weight: 600; color: var(--accent-color); background: rgba(59, 130, 246, 0.1); }

/* Icons */
.binaryph-ratio-icon {
    border: 1.5px solid currentColor;
    margin-right: 8px;
    display: inline-block;
    vertical-align: middle;
    opacity: 0.7;
}
.ratio-1-1 { width: 12px; height: 12px; }
.ratio-4-5 { width: 10px; height: 12px; }
.ratio-2-3 { width: 9px;  height: 13px; }
.ratio-9-16 { width: 8px;  height: 14px; }
.ratio-16-9 { width: 14px; height: 8px; }
.ratio-3-2 { width: 13px; height: 9px; }
.ratio-4-3 { width: 12px; height: 9px; }
.ratio-21-9 { width: 16px; height: 7px; }

/* Prompt Input */
.image-generator-prompt .wide-input {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 15px;
    line-height: 1.5;
    background: var(--input-bg-light);
    color: inherit;
    resize: none;
    font-family: inherit;
    outline: none;
    transition: all 0.2s;
}
.image-generator-prompt .wide-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}
.binaryph-image-generator-dark .image-generator-prompt .wide-input {
    background: var(--input-bg-dark);
    border-color: transparent;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.binaryph-image-generator-dark .image-generator-prompt .wide-input:focus {
    background: #3a3a3a;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* File Upload & Buttons Wrapper */
.image-generator-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 4px;
}

/* --- MODERN FILE UPLOAD BUTTON --- */
.binaryph-file-upload-container {
    position: relative;
    display: flex;
    align-items: center;
    flex-grow: 1;
    gap: 10px;
}

/* Hide actual input */
.binaryph-file-upload-container input[type="file"] {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}

/* The Styled Label (Button) */
.binaryph-file-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    background: var(--btn-sec-light-bg);
    color: var(--btn-sec-light-text);
    white-space: nowrap;
    border: 1px solid transparent;
}

.binaryph-file-label:hover {
    background: var(--btn-sec-light-hover);
}

.binaryph-image-generator-dark .binaryph-file-label {
    background: var(--btn-sec-dark-bg);
    color: var(--btn-sec-dark-text);
}

.binaryph-image-generator-dark .binaryph-file-label:hover {
    background: var(--btn-sec-dark-hover);
}

/* Filename Display */
.uploaded-filename {
    font-size: 13px;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
    display: none;
}

/* Clear Button */
.clear-file-button {
    background: transparent;
    border: none;
    color: var(--text-light);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    opacity: 0.6;
    transition: all 0.2s;
}
.binaryph-image-generator-dark .clear-file-button {
    color: var(--text-dark);
}
.clear-file-button:hover {
    opacity: 1;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

/* Generate Button */
#binaryph-generate-image {
    padding: 10px 24px;
    border: none;
    background: var(--accent-color);
    color: var(--accent-text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.2);
}
#binaryph-generate-image:hover { 
    background: var(--accent-hover); 
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.4);
}

/* --- RESULTS AREA --- */
.binaryph-generated-image {
    padding: 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    min-height: 0;
}

.binaryph-image-generator-image {
    position: relative;
    max-width: 100%;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 4px 15px -1px rgba(0, 0, 0, 0.2);
    background: #000;
    line-height: 0;
    display: flex;
    flex-direction: column;
}

.binaryph-image-generator-image img, 
.binaryph-image-generator-image video {
    display: block;
    max-width: 100%;
    height: auto;
    object-fit: contain;
}

/* Messages */
.binaryph-image-generator-message {
    font-size: 14px;
    opacity: 0.7;
    text-align: center;
    width: 100%;
    margin: 10px 0;
}
.binaryph-image-generator-error {
    color: var(--danger-color);
    font-size: 14px;
    text-align: center;
    width: 100%;
    margin: 10px 0;
    background: rgba(239, 68, 68, 0.1);
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* --- BIGGER DOWNLOAD BUTTON --- */
.download-image-btn {
    width: 100%;
    padding: 15px 20px;
    background: #262626;
    color: #fff;
    border: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    transition: background 0.2s, transform 0.1s;
    line-height: 1.5;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.download-image-btn:hover { 
    background: #000; 
}
.binaryph-image-generator-dark .download-image-btn {
    background: #404040;
}
.binaryph-image-generator-dark .download-image-btn:hover {
    background: #525252;
}

/* Loader */
.binaryph-image-loader {
    width: 40px; 
    height: 40px; 
    margin: 20px auto; 
    display: block;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .binaryph-image-generator-container {
        border-radius: 0;
        border-left: none;
        border-right: none;
        margin: 0;
        box-shadow: none;
        width: 100% !important; /* Force full width on mobile */
        max-width: 100% !important;
    }
    
    .binaryph-image-generator-input {
        padding: 16px;
    }

    .binaryph-controls-top-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .binaryph-aspect-ratio-control, 
    .binaryph-video-duration-control {
        width: 100%;
        max-width: 100%;
    }
    
    .image-generator-controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .binaryph-file-upload-container {
        width: 100%;
        justify-content: flex-start;
    }
    
    .binaryph-file-label {
        width: 100%;
    }

    #binaryph-generate-image {
        width: 100%;
        padding: 14px;
    }
}