:root { /* Light Mode Colors */
    --primary-color: #6366f1; --primary-hover: #4f46e5; --success-color: #16a34a; --success-hover: #15803d; --danger-color: #dc2626;
    --background-color: #f8fafc; --card-background: #ffffff; --text-primary: #1e293b; --text-secondary: #64748b; --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
}
body.dark-mode { /* Dark Mode Colors */
    --background-color: #0f172a; --card-background: #1e293b; --text-primary: #f1f5f9; --text-secondary: #94a3b8; --border-color: #334155;
}

/* === Global App Styles === */
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: var(--background-color); color: var(--text-primary); margin: 0; }
.container { max-width: 1600px; margin: 0 auto; padding: 0 2rem; }

/* === App Navbar === */
.app-navbar { background: var(--card-background); border-bottom: 1px solid var(--border-color); padding: 0.75rem 0; }
.app-navbar .container { display: flex; justify-content: space-between; align-items: center; }
.logo { font-size: 1.25rem; font-weight: 700; text-decoration: none; color: var(--primary-color); }
.app-navbar nav { display: flex; align-items: center; gap: 1rem; }
.nav-link { text-decoration: none; color: var(--text-secondary); font-weight: 500; transition: color 0.2s; }
.nav-link:hover { color: var(--primary-color); }

/* === App Layouts === */
.app-container { display: flex; gap: 2rem; width: 100%; padding: 2rem; box-sizing: border-box; height: calc(100vh - 65px); }

/* === UPDATED: Sidebar Layout === */
.sidebar { 
    width: 380px; 
    flex-shrink: 0; 
    display: flex; /* Changed back to flex */
    flex-direction: column;
    gap: 0; /* Gap is now handled by the splitter */
    overflow: hidden;
}
.upload-card { 
    flex-shrink: 0; /* Prevent from shrinking */
    height: 35vh; /* Initial height, JS will change this */
    min-height: 150px; /* Minimum drag height */
    display: grid; 
    grid-template-rows: auto auto 1fr; /* Header, Dropzone, List */
    overflow: hidden; 
}
.settings-card { 
    flex-grow: 1; /* Fill remaining space */
    min-height: 0; /* Allow it to shrink */
    overflow-y: auto; 
    margin-top: 0; /* Remove gap */
}
/* === NEW: Splitter Handle === */
.splitter {
    height: 1.5rem; /* This is the clickable area */
    background-color: var(--background-color);
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.splitter::before {
    content: '';
    width: 50px;
    height: 6px;
    background-color: var(--border-color);
    border-radius: 3px;
}
.splitter:hover::before {
    background-color: var(--primary-color);
}
/* === END OF FIX === */

.main-content { flex-grow: 1; background: var(--card-background); border-radius: 1rem; box-shadow: var(--shadow); border: 1px solid var(--border-color); display: flex; flex-direction: column; overflow: hidden; }
.app-wrapper { background: var(--card-background); padding: 2rem 2.5rem; border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 900px; margin: 2rem auto; }

/* === Cards & Forms === */
.card { background: var(--card-background); border-radius: 1rem; padding: 1.5rem; box-shadow: var(--shadow); border: 1px solid var(--border-color); }
.upload-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-shrink: 0; }
.settings-card label, .app-wrapper label, .editor-controls label { font-weight: 500; margin-bottom: 0.5rem; display: block; font-size: 0.9rem; }
.control-group { margin-bottom: 1.25rem; }
input, select, textarea { width: 100%; padding: 0.5rem; box-sizing: border-box; border: 1px solid var(--border-color); border-radius: 0.5rem; background-color: var(--background-color); color: var(--text-primary); font-family: inherit; font-size: 0.95rem; }
input[type="color"] { padding: 0; height: 40px; border: none; background: none; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2); }
textarea { resize: vertical; min-height: 120px; }
.inline-group { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.radio-group { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem; }
.radio-group input { display: none; }
.radio-group label { text-align: center; padding: 0.65rem 0.5rem; cursor: pointer; border: 1px solid var(--border-color); border-radius: 0.5rem; font-size: 0.85rem; transition: all 0.2s; }
.radio-group input:checked + label { background-color: var(--primary-color); color: white; font-weight: 500; border-color: var(--primary-color); }
.info-text { font-size: 0.85rem; color: var(--text-secondary); background-color: var(--background-color); padding: 0.75rem; border-radius: 0.5rem; margin-top: -0.75rem; margin-bottom: 1.25rem; }
.segmented-control { display: flex; border: 1px solid var(--border-color); border-radius: 0.5rem; overflow: hidden; }
.segmented-control input { display: none; }
.segmented-control label { flex: 1; text-align: center; padding: 0.65rem 0.5rem; cursor: pointer; border-right: 1px solid var(--border-color); font-size: 0.9rem; }
.segmented-control label:last-child { border-right: none; }
.segmented-control input:checked + label { background-color: var(--primary-color); color: white; font-weight: 500; }
.advanced-options { margin-top: 1rem; border-top: 1px solid var(--border-color); padding-top: 1rem; }
.advanced-options summary { cursor: pointer; font-weight: 500; list-style: revert; }
.toggle-group { display: flex; justify-content: space-between; align-items: center; }
input[type="checkbox"].toggle { -webkit-appearance: none; appearance: none; width: 40px; height: 22px; background: var(--border-color); border-radius: 20px; position: relative; cursor: pointer; }
input[type="checkbox"].toggle::before { content: ''; position: absolute; width: 18px; height: 18px; background: white; border-radius: 50%; top: 2px; left: 2px; transition: transform 0.3s; }
input[type="checkbox"].toggle:checked { background: var(--success-color); }
input[type="checkbox"].toggle:checked::before { transform: translateX(18px); }
.preset-group { display: flex; gap: 0.5rem; margin-bottom: 1rem; }

/* === API Provider Controls === */
.api-key-input { display: none; } /* Hide both by default */
.api-key-input.active { display: block; } /* Show the active one */
.token-inputs { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1rem;}
.token-inputs .segmented-control { grid-column: 1 / -1; } /* Make segmented control span full width */

/* === Buttons === */
.button, .button-secondary, .button-icon { border: none; border-radius: 0.5rem; cursor: pointer; font-weight: 600; transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center; }
.button { padding: 0.75rem; font-size: 1rem; color: #fff; background-color: var(--primary-color); }
.button:hover:not(:disabled) { background-color: var(--primary-hover); }
.button:disabled { background-color: #9ca3af; cursor: not-allowed; }
.button-secondary { background-color: var(--background-color); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.5rem 1rem; font-size: 0.9rem; }
.button-icon { background: transparent; color: var(--text-secondary); padding: 0.25rem; width: 32px; height: 32px; font-size: 1.5rem; }
.button-icon:hover { color: var(--text-primary); background-color: var(--background-color); }
.button-container { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.5rem; }
.button-container .button-secondary { background-color: var(--slate); color: var(--white); }
.button-container .button-secondary:hover { background-color: var(--danger-color); border-color: var(--danger-color); }

/* === Drop Zones & Previews === */
#drop-zone { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; border: 2px dashed var(--border-color); border-radius: 0.75rem; cursor: pointer; min-height: 80px; flex-grow: 1; }
#drop-zone.active { border-color: var(--primary-color); background-color: rgba(79, 70, 229, 0.05); }
#drop-zone p { margin: 0; font-weight: 500; font-size: 1rem; color: var(--text-secondary); }
#drop-zone span { font-size: 0.9rem; color: var(--text-secondary); }
.drop-zone { border: 2px dashed var(--border-color); border-radius: 8px; padding: 1.5rem; text-align: center; cursor: pointer; transition: all 0.2s; margin-bottom: 1rem; background-color: var(--white); }
.drop-zone:hover { border-color: var(--primary-color); }
.drop-zone p { margin: 0; font-weight: 500; font-size: 0.9rem; color: var(--slate); }
.drop-zone.drag-over { background-color: rgba(99, 102, 241, 0.05); border-color: var(--primary-color); }

#file-preview-list { min-height: 0; overflow-y: auto; display: none; flex-direction: column; gap: 0.75rem; margin-top: 1rem; flex-grow: 1; }
.file-preview-item { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem; border-radius: 0.5rem; background: var(--background-color); }
.file-preview-item img { width: 40px; height: 40px; border-radius: 0.25rem; object-fit: cover; }
.thumbnail-preview-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 1rem; padding: 1rem; background-color: var(--light-gray); border-radius: 8px; min-height: 140px; }
.thumbnail-item { position: relative; width: 65px; height: 65px; border-radius: 8px; overflow: hidden; cursor: grab; background-color: var(--white); border: 2px solid transparent; }
.thumbnail-item.active { border-color: var(--primary-color); }
.thumbnail-item img { width: 100%; height: 100%; object-fit: cover; }

/* === Results & Progress === */
#results-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.results-controls { display: flex; gap: 0.5rem; align-items: center; }
#downloadAllSection { padding: 1rem 1.5rem 0; }
#progress-bar-container, #progress-container { padding: 1rem 1.5rem 0; }
#progress-bar-bg { background: var(--border-color); border-radius: 4px; overflow: hidden; }
#progress-bar { width: 0%; height: 8px; background: var(--primary-color); border-radius: 4px; transition: width 0.3s; }
#progress-text { font-size: 0.9rem; text-align: center; margin-bottom: 0.5rem; color: var(--text-secondary); }
#results-grid-wrapper { flex-grow: 1; overflow-y: auto; padding: 1.5rem; }
#results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.5rem; }
.comparison-slider { position: relative; width: 100%; height: 150px; overflow: hidden; user-select: none; }
.comparison-slider img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.comparison-slider .img-original { clip-path: polygon(0 0, 50% 0, 50% 100%, 0 100%); }
.comparison-slider .slider-handle { position: absolute; top: 0; left: 50%; width: 4px; height: 100%; background: var(--primary-color); cursor: ew-resize; transform: translateX(-50%); }
.comparison-slider .slider-handle::before { content: ''; position: absolute; top: 50%; left: 50%; width: 24px; height: 24px; border: 2px solid var(--primary-color); background: var(--card-background); border-radius: 50%; transform: translate(-50%, -50%); }
.slider-label { position: absolute; bottom: 8px; font-size: 0.75rem; font-weight: 600; color: white; background-color: rgba(0,0,0,0.5); padding: 2px 6px; border-radius: 4px; pointer-events: none; }
.slider-label.original { left: 8px; } .slider-label.resized { right: 8px; }
#empty-state { flex-grow: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; color: var(--text-secondary); }
#empty-state svg { width: 48px; height: 48px; margin-bottom: 1rem; }
#empty-state p { font-size: 1rem; }
.result-box { margin-top: 1.5rem; }
.result-box textarea { min-height: 140px; }
.result-box .button-container { grid-template-columns: 1fr 1fr; }
.result-box .button-container .button-secondary { background-color: var(--background-color); color: var(--text-primary); }
.result-box .button-container .button-secondary:hover { background-color: var(--border-color); }

/* === Modals === */
.modal-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal-content { background: var(--card-background); border-radius: 1rem; width: 90%; max-width: 1200px; height: 90vh; display: flex; flex-direction: column; }
.modal-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { flex-grow: 1; padding: 1.5rem; overflow: hidden; display: flex; gap: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; align-items: center; }
.cropper-container { flex-grow: 1; }
.editor-controls { width: 280px; flex-shrink: 0; overflow-y: auto; padding-right: 1rem; }
.editor-controls h4 { margin-top: 0; margin-bottom: 1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.editor-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.position-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-bottom: 1rem; }
.position-grid input { display: none; }
.position-grid label { height: 40px; border: 1px solid var(--border-color); border-radius: 0.5rem; cursor: pointer; }
.position-grid input:checked + label { background-color: var(--primary-color); border-color: var(--primary-color); }

/* === Styles from Ad-Lister (Specific) === */
.app-wrapper h1 { color: var(--primary-color); margin-bottom: 2rem; text-align: center; font-weight: 700; letter-spacing: -1px; }
fieldset { border: 1px solid var(--border-color); border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; }
fieldset:disabled { opacity: 0.5; }
legend { font-size: 1.25rem; font-weight: 600; color: var(--primary-color); padding: 0 10px; }
input[readonly] { background-color: #e9ecef; cursor: not-allowed; }
.thumbnail-delete { position: absolute; top: -5px; right: -5px; width: 20px; height: 20px; background-color: rgba(30, 41, 59, 0.7); color: var(--white); border: 2px solid var(--white); border: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: bold; line-height: 1; cursor: pointer; opacity: 0; transition: opacity 0.2s; z-index: 10; }
.thumbnail-item:hover .thumbnail-delete { opacity: 1; }
.ai-checkbox-label { display: flex; align-items: center; gap: 5px; font-size: 0.8rem; color: var(--slate); }
.ai-checkbox { accent-color: var(--primary-color); }
.thumbnail-wrapper { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.sortable-ghost { opacity: 0.4; background: #c8ebfb; }
button#generateButton { background-color: var(--primary-color); }
button#generateButton:hover { background-color: var(--primary-hover); }
button#clearFormButton { background-color: var(--slate); }
button#clearFormButton:hover { background-color: var(--danger-color); }
#progress-log { margin-top: 10px; font-size: 0.85em; max-height: 150px; overflow-y: auto; background: var(--white); padding: 10px; border-radius: 6px; border: 1px solid var(--border-color); color: var(--slate);}

/* === Styles from Clothing-Lister (Specific) === */
.details-inputs { display: grid; grid-template-columns: 1fr 2fr; gap: 1.5rem; align-items: flex-start; }
.condition-fields { margin-bottom: 1.5rem; }
.condition-checkboxes { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; padding: 12px 15px; background-color: var(--light-gray); border-radius: 8px;}
.condition-checkboxes label { margin: 0; font-weight: 500; display: flex; align-items: center; gap: 6px; cursor: pointer; color: var(--slate); font-size: 0.9rem;}
.condition-checkboxes input[type="checkbox"] { accent-color: var(--primary-color); width: 16px; height: 16px; cursor: pointer;}
.image-upload-areas { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; }
.size-thumbnail-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); min-height: 140px; align-items: center; }
.listing-field { border-bottom: 1px solid var(--border-color); margin-bottom: 2.5rem; padding-bottom: 2.5rem; }
.listing-field:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

/* === Responsive Tweaks for App Wrappers === */
@media (max-width: 768px) {
    .app-container { display: block; height: auto; padding: 0.5rem; }
    .sidebar { width: 100%; height: auto; }
    .main-content { margin-top: 1.5rem; }
    .upload-card { max-height: 250px; } /* Set fixed max-height on mobile */
    .app-wrapper { padding: 1.5rem; margin: 0; border-radius: 0; box-shadow: none; }
    .app-navbar nav { display: none; }
    .token-inputs, .details-inputs, .image-upload-areas { grid-template-columns: 1fr; }
    .button-container { grid-template-columns: 1fr; }
}