:root {
    --primary: #1ba4c8;
    --primary-dark: #1892B2;
    --light-bg: #F8FCFF;
    --border: #e1e5f1;
    --text: #1e293b;
    --text-light: #475569;
    --card-bg: #ffffff;
    --preview-bg: #ffffff;
    --success: #10b981;
    --warning: #f59e0b;
    --file-header-bg: #e8f4f8;
    --file-header-bg-dark: #1a3a44;
    --icon-row-bg-dark: #25262e;
}

[data-theme="dark"] {
    --primary: #1EB6DE;
    --primary-dark: #1892B2;
    --light-bg: #2d2f36;
    --border: #4a4a5a;
    --text: #f1f5f9;
    --text-light: #cbd5e1;
    --card-bg: #1e1f28;
    --preview-bg: #08080B;
    --file-header-bg: #1a3a44;
    --file-header-bg-dark: #0d2a33;
    --icon-row-bg-dark: #1e1f28;
}

.container-custom { max-width: 1600px; margin: 0 auto; border-radius: 5px; background: var(--card-bg); box-shadow: 0 20px 35px -12px rgba(0, 0, 0, 0.1); transition: background 0.2s; overflow: hidden; padding: 24px; }
.input-column, .output-column { width: 100%; display: flex; flex-direction: column; min-width: 0; }
.section-title-custom { font-size: 1rem; font-weight: 600; color: var(--primary); margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }

.upload-zone { background: var(--card-bg); border: 2px dashed var(--border); border-radius: 12px; text-align: center; cursor: pointer; transition: all 0.25s ease; margin-bottom: 10px; min-height: 200px; display: flex; align-items: center; justify-content: center; }
.upload-content { padding: 32px 24px; }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--primary); background: rgba(30, 182, 222, 0.05); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); }
.upload-image { font-size: 3rem; color: var(--primary); margin-bottom: 12px; }
.upload-zone h3 { margin: 0 0 8px 0; color: var(--text); font-size: 1rem; }
.upload-zone p { color: var(--text-light); margin: 0; font-size: 0.9rem; text-align: center; }

.preview-panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; overflow: hidden; transition: background 0.2s; }
.preview-panel.hidden { display: none; }
.preview-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--primary); font-size: 0.9rem; }
.preview-canvas-wrapper { padding: 20px; display: flex; justify-content: center; align-items: center; background: var(--preview-bg); min-height: 120px; }
[data-theme="dark"] .preview-canvas-wrapper { background: repeating-conic-gradient(#3a3a4a 0% 25%, #1e1f28 0% 50%) 50% / 16px 16px; }
#previewCanvas { max-width: 100%; max-height: 256px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

.settings-panel { display: flex; flex-wrap: wrap; gap: 20px; padding: 16px; background: var(--light-bg); border-radius: 8px; margin-bottom: 12px; border: 1px solid var(--border); }
.settings-panel.hidden { display: none; }
.setting-group { flex: 1; min-width: 200px; }
.setting-group label { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); margin-bottom: 8px; font-size: 0.9rem; }
.setting-group label i { color: var(--primary); }
.quality-slider-wrapper { display: flex; align-items: center; gap: 12px; }
.quality-slider { flex: 1; height: 6px; border-radius: 3px; background: var(--border); outline: none; -webkit-appearance: none; appearance: none; }
.quality-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--primary); cursor: pointer; transition: transform 0.15s; }
.quality-slider::-webkit-slider-thumb:hover { transform: scale(1.1); }
.quality-badge { color: white; padding: 4px 10px; border-radius: 20px; font-size: 0.95rem; font-weight: 600; min-width: 50px; text-align: center; }

.bg-options { display: flex; gap: 8px; flex-wrap: wrap; }
.bg-option { width: 36px; height: 36px; border: 2px solid var(--border); border-radius: 8px; padding: 0; background: var(--card-bg); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; position: relative; }
.bg-option:hover, .bg-option.active { 
    border-color: var(--primary); 
    box-shadow: 0 0 0 3px rgba(30, 182, 222, 0.15); 
    background: none;
    }
.bg-preview { width: 28px; height: 28px; border-radius: 4px; display: block; }
.bg-preview.blur-bg { display: flex; align-items: center; justify-content: center; color: var(--text-light); font-size: 0.9rem; }
.bg-preview.gradient-bg { background: linear-gradient(135deg, #1ba4c8, #f27323); }
.custom-bg-wrapper { position: relative; }
.bg-color-input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; top: 0; left: 0; }

.layers-panel { background: var(--light-bg); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 0; }
.layers-header { padding: 14px 16px; background: var(--card-bg); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--primary); }
.layer-count-badge { background: rgba(30, 182, 222, 0.1); padding: 4px 10px; border-radius: 20px; font-size: 0.9rem; font-weight: 500; color: var(--primary); }
.layers-table-wrapper { overflow: visible !important; max-height: none !important; }
.layers-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.layers-table tbody tr:not(.file-group-header) { height: 68px; }
.file-group-header { height: auto; }
.layers-table th { text-align: left; padding: 10px 12px; background: var(--light-bg); color: var(--text); font-weight: 600; border-bottom: 1px solid var(--border); height: auto; }
.layers-table th:last-child { text-align: right; }
.layers-table tbody tr:not(.file-group-header):not(.empty-row) { background: var(--card-bg); }
[data-theme="dark"] .layers-table tbody tr:not(.file-group-header):not(.empty-row) { background: var(--icon-row-bg-dark); }
.layers-table td { padding: 8px 12px; color: var(--text); vertical-align: middle; border-bottom: 1px solid var(--border); }
.layers-table thead td { border-bottom: none; }
.file-group-header td { background: var(--file-header-bg) !important; border-bottom: 1px solid var(--border); padding: 10px 12px; font-weight: 600; }
[data-theme="dark"] .file-group-header td { background: var(--file-header-bg-dark) !important; }
.layers-table tbody tr:not(.file-group-header):not(.empty-row):hover { background: rgba(30, 182, 222, 0.1); }
[data-theme="dark"] .layers-table tbody tr:not(.file-group-header):not(.empty-row):hover { background: rgba(30, 182, 222, 0.15); }
.empty-row td { text-align: center !important; padding: 40px !important; color: var(--text-light); background: transparent !important; }
.empty-row td:last-child { text-align: center !important; }
.file-group-header i { margin-right: 8px; color: var(--primary); }
.format-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.9rem; font-weight: 600; }
.format-badge.png { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.format-badge.bmp { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.alpha-yes { color: var(--success); }
.alpha-no { color: var(--warning); }
.layers-table td:last-child { text-align: right; }
.layers-table td:last-child .action-btn { background: var(--card-bg); border: 1px solid var(--border); padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 0.9rem; color: var(--text); transition: all 0.2s; display: inline-flex; align-items: center; gap: 4px; }
.layers-table td:last-child .action-btn i { font-size: 0.9rem; }
.layers-table td:last-child .action-btn.download-btn { color: white; background: #00B093; }
.layers-table td:last-child .action-btn:hover { background: var(--primary); border-color: var(--primary); color: white; }
.layers-table td:last-child .action-btn.download-btn:hover { background: var(--success); border-color: var(--success); color: white; }
.layers-table td:first-child { width: 64px; text-align: center; }

/* FIXED: Natural sizing within row limits */
.preview-thumb {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 48px; /* Fits safely inside 68px row with padding */
    object-fit: contain;
    background: var(--preview-bg);
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
    margin: 0 auto;
}

button { font-family: inherit; font-size: 13px; font-weight: 600; padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; gap: 8px; background: var(--light-bg); color: var(--text); border: 1px solid var(--border); text-shadow: none; }
button i { text-shadow: none; }
.success-btn { background: rgba(16, 185, 129, 0.15); border-color: var(--success); color: var(--success); }
.secondary-btn.small { padding: 6px 12px; font-size: 0.85rem; }
.export-buttons-container { display: flex; gap: 8px; }
.export-buttons-container.hidden { display: none; }

@media (max-width: 900px) {
    .container-custom { padding: 16px; }
    .layers-table td:last-child { text-align: left; }
    .layers-table td:last-child .action-btn { width: 100%; justify-content: center; }
    .layers-table th, .layers-table td { padding: 8px 6px; }
    .layers-table { font-size: 0.75rem; }
    .preview-thumb { max-height: 36px; }
    .layers-table td:first-child { width: 50px; }
    .layers-table tbody tr:not(.file-group-header) { height: 56px; }
}

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: var(--card-bg); border-radius: 12px; width: 90%; max-width: 460px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h4 { margin: 0; color: var(--text); font-size: 1.1rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; color: var(--text-light); cursor: pointer; padding: 4px 8px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.gradient-type-selector { display: flex; gap: 16px; margin-bottom: 16px; }
.gradient-type-selector label { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; cursor: pointer; }
.angle-slider { width: 100%; height: 6px; border-radius: 3px; background: var(--border); outline: none; -webkit-appearance: none; margin: 8px 0; }
.angle-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--primary); cursor: pointer; }
.gradient-preview-container { margin: 16px 0; display: flex; justify-content: center; }
.gradient-preview { border-radius: 8px; border: 1px solid var(--border); }
.color-stops-container { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.color-stop-item { display: flex; align-items: center; gap: 10px; padding: 8px; background: var(--light-bg); border-radius: 6px; }
.color-stop-item input[type="color"] { width: 32px; height: 32px; border: none; border-radius: 4px; cursor: pointer; background: none; }
.color-stop-slider { flex: 1; height: 6px; border-radius: 3px; background: var(--border); outline: none; -webkit-appearance: none; }
.color-stop-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: white; border: 2px solid var(--primary); cursor: pointer; }
.color-stop-percent { font-size: 0.8rem; color: var(--text-light); min-width: 36px; text-align: right; }
.remove-color-stop { background: none; border: none; color: var(--warning); cursor: pointer; font-size: 1.2rem; padding: 0 4px; }



/* Row selection highlight */
.layers-table tbody tr.selectable-row { 
    cursor: pointer; 
    transition: background 0.15s ease; 
}
.layers-table tbody tr.selectable-row.selected { 
    background: rgba(30, 182, 222, 0.12) !important; 
    border-left: 3px solid var(--primary); 
}
[data-theme="dark"] .layers-table tbody tr.selectable-row.selected { 
    background: rgba(30, 182, 222, 0.18) !important; 
}
.layers-table tbody tr.selectable-row:hover:not(.selected) { 
    background: rgba(30, 182, 222, 0.06) !important; 
}

.layers-table .output-size-cell, 
.layers-table .reduction-cell { 
    font-size: 0.85rem; 
    font-weight: 500; 
    white-space: nowrap;
}
.layers-table .reduction-cell { text-align: right; padding-right: 16px !important; }

.format-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; }
.format-badge.png  { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.format-badge.webp { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.format-badge.avif { background: rgba(168, 85, 247, 0.15); color: #a855f7; }
.format-badge.gif  { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.format-badge.jpg, 
.format-badge.jpeg { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.format-badge.bmp  { background: rgba(107, 114, 128, 0.15); color: #6b7280; }
.format-badge.default { background: rgba(30, 182, 222, 0.15); color: var(--primary); }


/* Size Columns Visual Distinction */
.original-size-cell { 
    color: var(--text-light); 
    font-size: 0.85rem; 
}
.output-size-cell { 
    color: var(--success); 
    font-weight: 700; 
    font-size: 0.85rem; 
}
.reduction-cell { 
    font-size: 0.85rem; 
    font-weight: 600; 
    text-align: right;
}
[data-theme="dark"] .output-size-cell {
    color: #34d399; /* Brighter green for better dark mode contrast */
}

.quality-slider-wrapper { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.quality-slider { flex: 1; min-width: 120px; max-width: 160px; height: 6px; border-radius: 3px; background: var(--border); outline: none; -webkit-appearance: none; appearance: none; }
.quality-presets { display: flex; gap: 6px; }
.preset-btn { padding: 10px 12px; font-size: 0.85rem; font-weight: 600; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); color: var(--text-light); cursor: pointer; transition: all 0.2s; line-height: 1; }
.preset-btn:hover { border-color: var(--primary); color: var(--primary); background: rgba(30, 182, 222, 0.05); }
.preset-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
[data-theme="dark"] .preset-btn { background: var(--icon-row-bg-dark); border-color: var(--border); }
[data-theme="dark"] .preset-btn:hover { border-color: var(--primary); color: var(--primary); }
[data-theme="dark"] .preset-btn.active { background: var(--primary); color: white; }



/* ==========================================
   RESPONSIVE FIX: Prevents settings overlap
   ========================================== */
@media (max-width: 700px) {
    .settings-panel {
        flex-direction: column;
        gap: 16px;
    }
    .setting-group {
        flex: none;
        width: 100%;
        min-width: auto;
    }
    .quality-slider-wrapper { gap: 8px; }
    .preset-btn { padding: 8px 10px; font-size: 0.8rem; }
    .bg-options { gap: 6px; }
    .bg-option { width: 32px; height: 32px; }
    .bg-preview { width: 24px; height: 24px; }
}

/* 🔍 Also noticed your quality badge is missing its background color. 
   Replace your existing .quality-badge rule with this: */
.quality-badge { 
    color: white; 
    padding: 4px 10px; 
    border-radius: 20px; 
    font-size: 0.95rem; 
    font-weight: 600; 
    min-width: 50px; 
    text-align: center; 
}


/* Mobile: Download button shows icon only */
@media (max-width: 900px) {
    .layers-table td:last-child .action-btn.download-btn {
        width: 36px !important;
        padding: 6px 0 !important;
        font-size: 0; /* Hides "Download" text */
        min-width: 36px;
        justify-content: center;
    }
    .layers-table td:last-child .action-btn.download-btn i {
        font-size: 0.9rem;
        margin: 0;
    }
}