/* ============================================
=== COMPRESS IMAGE - MODERN STYLES (FIXED) ===
============================================
*/
/* This file now controls the entire modal and its contents */


/* FIX 2: Modern Modal Z-Index & Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100; /* Higher than header (50) */
    padding: 1rem;
    opacity: 1;
    transition: opacity 0.3s ease;
    visibility: visible;
}
.modal-overlay.ct-hidden { /* Use .ct-hidden */
    opacity: 0;
    visibility: hidden;
}


/* Modal Content - Modern Card Style */
#tool-modal .modal-content {
    max-width: 90%;
    width: 1400px;
    padding: 0;
    border-radius: 24px;
    background: linear-gradient(145deg, rgba(255,255,255,0.95), rgba(248,250,252,0.98));
    border: 1px solid rgba(107,70,255,0.08);
    box-shadow: 0 40px 100px rgba(11,23,50,0.15), 0 0 0 1px rgba(255,255,255,0.5) inset;
    overflow: hidden;
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 40px); /* Responsive height */
}
body.dark #tool-modal .modal-content {
    background: linear-gradient(145deg, rgba(15,23,42,0.98), rgba(8,10,14,0.95));
    border: 1px solid rgba(139,92,246,0.12);
    box-shadow: 0 40px 100px rgba(0,0,0,0.8), 0 0 0 1px rgba(107,70,255,0.1) inset;
    color: var(--text-dark);
}

/* Modal Header */
#tool-modal .modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Prevents header from shrinking */
}
body.dark #tool-modal .modal-header {
    border-bottom-color: var(--border-dark);
}
#tool-modal h2 {
    font-size: 1.5rem;
    font-weight: 700;
}
#tool-modal .modal-close-btn {
    background: var(--bg-light);
    color: var(--text-light);
    border: 1px solid var(--border-light);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
body.dark #tool-modal .modal-close-btn {
    background: var(--bg-dark);
    color: var(--text-dark);
    border-color: var(--border-dark);
}
#tool-modal .modal-close-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    transform: rotate(90deg);
}

/* Modal Body */
#tool-modal .modal-body {
    display: grid;
    grid-template-columns: 3fr 1fr;
    overflow: hidden; /* Allows child scrolling */
    flex-grow: 1; /* Takes remaining height */
}

/* Preview Section */
#tool-modal .preview-section {
    padding: 1.5rem;
    overflow-y: auto; /* Scroll only this section */
}
#tool-modal .preview-container-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

/* Options Container */
#tool-modal .options-container {
    padding: 1.5rem;
    border-left: 1px solid var(--border-light);
    background: rgba(0,0,0,0.01);
    overflow-y: auto; /* Scroll only this section */
}
body.dark #tool-modal .options-container {
    border-left-color: var(--border-dark);
    background: rgba(0,0,0,0.1);
}

/* Modal Footer */
#tool-modal .modal-footer {
    padding: 1rem 1.5rem; /* Smaller padding */
    border-top: 1px solid var(--border-light);
    background: rgba(255,255,255,0.5);
    display: flex;
    justify-content: center; /* FIX 3: Center buttons */
    align-items: center;
    gap: 1rem;
    flex-shrink: 0; /* Prevents footer from shrinking */
}
body.dark #tool-modal .modal-footer {
    border-top-color: var(--border-dark);
    background: rgba(15,23,42,0.5);
}
/* FIX 3: Size and position of footer buttons */
#tool-modal .status-text {
    flex-grow: 1; /* Take up space on left */
    text-align: left;
    display: none; /* Hide by default */
}
#tool-modal .btn-compress {
    flex-shrink: 0;
    flex-grow: 0;
    width: auto; /* Don't force full width */
    min-width: 200px; /* Min width */
    padding: 0.75rem 1.5rem;
}
#tool-modal .download-options {
    display: flex;
    gap: 1rem;
    flex-shrink: 0;
    flex-grow: 0;
    width: auto;
    min-width: 200px;
}
#tool-modal .btn-download {
    width: 100%; /* Make button inside download-options full width */
}


/* === FIX 2: MODERN PREVIEW CARD (MODAL) === */
.image-card {
    background: var(--card-light);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0,0,0,0.03);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
}
body.dark .image-card {
    background: var(--card-dark);
    border-color: var(--border-dark);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.image-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.05);
}
body.dark .image-card:hover {
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

/* FIX 1 & 2: Smaller Card Header/Footer */
.image-card-header, .image-card-footer {
    padding: 0.5rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem; /* Smaller font */
    flex-shrink: 0;
}
.image-card-header {
    background: var(--bg-light);
}
body.dark .image-card-header {
    background: var(--bg-dark);
}
.image-size {
    font-weight: 600;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    background: rgba(0,0,0,0.05);
}
body.dark .image-size {
    background: rgba(255,255,255,0.05);
}
.original-size { color: var(--text-secondary); }
.compressed-size { color: #10b981; }

/* FIX 2: Modern Rotate Button */
.rotate-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.rotate-btn:hover {
    transform: rotate(90deg);
    color: var(--brand-primary);
}

.image-preview {
    height: 150px;
    padding: 0.5rem;
    background: var(--bg-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-grow: 1; /* Allow preview to take space */
    overflow: hidden;
}
body.dark .image-preview { background: var(--bg-dark); }

/* FIX 2: Image Fit to Card */
.preview-canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* FIX 1: Center footer content */
.image-card-footer {
    flex-direction: column; /* Stack name and size */
    align-items: center; /* Center horizontally */
    gap: 0.25rem;
    text-align: center;
}
.image-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%; /* Ensure it respects center align */
}
/* Single Download Button */
.download-single-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.7rem;
    border-radius: 6px;
    background: var(--brand-primary); /* Match theme */
    color: white;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.download-single-btn:hover {
    opacity: 0.8;
}
/* FIX 1: Center Download Button */
.download-placeholder {
    padding: 0.5rem 0.75rem;
    display: flex;
    justify-content: center; /* Center button */
    align-items: center;
    min-height: 36px; /* Reserve space for button */
    border-top: 1px solid var(--border-light);
}
body.dark .download-placeholder {
    border-top-color: var(--border-dark);
}


/* === OPTIONS & TABS (MODAL) === */
.option-tabs {
    display: flex;
    background-color: var(--bg-light);
    border-radius: 10px;
    padding: 0.25rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-light);
}
body.dark .option-tabs {
    background-color: var(--bg-dark);
    border-color: var(--border-dark);
}
.tab-btn {
    flex: 1;
    padding: 0.6rem 0.5rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    gap: 0.5rem;
}
.tab-btn:hover:not(.active) {
    color: var(--text-light);
}
body.dark .tab-btn:hover:not(.active) {
    color: var(--text-dark);
}
.tab-btn.active {
    background: var(--card-light);
    color: var(--brand-primary);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}
body.dark .tab-btn.active {
    background: var(--card-dark);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* Tab Panels */
.tab-panel {
    display: none;
    animation: fadeInTab 0.3s ease;
}
.tab-panel.active {
    display: block;
}
@keyframes fadeInTab {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Option Groups */
.option-group { margin-bottom: 1.25rem; }
.option-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}
.option-input,
.option-group input[type="number"] {
    width: 100%;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-light);
    background: var(--bg-light);
    color: var(--text-light);
    transition: all 0.2s ease;
}
body.dark .option-input,
body.dark .option-group input[type="number"] {
    background: var(--bg-dark);
    border-color: var(--border-dark);
    color: var(--text-dark);
}
.option-input:focus,
.option-group input[type="number"]:focus {
    outline: none;
    border-color: var(--brand-primary);
    background-color: var(--card-light);
}
body.dark .option-input:focus,
body.dark .option-group input[type="number"]:focus {
    background-color: var(--card-dark);
}

/* Adjustment Section */
.adjustment-section {
    border-top: 1px solid var(--border-light);
    padding-top: 1.5rem;
    margin-top: 1.5rem;
}
body.dark .adjustment-section { border-top-color: var(--border-dark); }
.adjustment-section .section-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

/* Sliders */
.slider-group { display: flex; align-items: center; gap: 0.75rem; }
.slider-group input[type="range"] { flex: 1; }
.slider-value {
    display: inline-block;
    min-width: 40px;
    text-align: center;
    font-weight: 600;
    color: var(--brand-primary);
    font-size: 0.9rem;
}

/* FIX 2: Small Reset Button */
.btn-reset {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.6rem 1rem; /* Smaller padding */
    font-size: 0.85rem;
}

/* Status Text */
.status-text {
    text-align: left;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
}
.status-text.success { color: #10b981; }
.status-text.error { color: #ef4444; }
.status-text .loader {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-light);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 1024px) {
    #tool-modal .modal-body {
        grid-template-columns: 1fr;
        max-height: 60vh; /* Allow body to scroll on medium screens */
    }
    #tool-modal .options-container {
        border-left: none;
        border-top: 1px solid var(--border-light);
    }
    body.dark #tool-modal .options-container {
        border-top-color: var(--border-dark);
    }
}
@media (max-width: 768px) {
    #tool-modal .modal-content {
        border-radius: 18px;
        max-height: calc(100vh - 40px);
        width: 100%;
    }
    #tool-modal .modal-header { padding: 1.25rem 1.5rem; }
    
    /* FIX 2: Smaller modal title on mobile */
    #tool-modal h2 {
        font-size: 1.15rem; 
    }
    #tool-modal .modal-body {
        max-height: calc(100vh - 200px); /* Adjust based on header/footer */
    }
    #tool-modal .preview-container-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    #tool-modal .modal-footer {
        flex-direction: column;
        align-items: center; /* Center on mobile */
    }
    /* FIX 2: Smaller Download/Compress buttons on mobile */
    #tool-modal .modal-footer .btn-primary,
    #tool-modal .modal-footer .download-options {
        flex-basis: auto; /* Allow natural width */
        width: 100%; /* Full width on mobile */
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    #tool-modal .modal-footer .download-options {
        flex-direction: column;
    }
    #tool-modal .status-text {
        text-align: center;
        margin-bottom: 0.5rem;
        width: 100%;
        justify-content: center;
    }
}
@media (max-width: 480px) {
    #tool-modal .preview-container-grid {
        grid-template-columns: 1fr 1fr; /* 2 columns on small phones */
    }
}