:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --success-color: #10b981;
    --success-hover: #059669;
    --bg-color: #f3f4f6;
    --sidebar-bg: #ffffff;
    --preview-bg: #e5e7eb;
    --text-main: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --input-bg: #f9fafb;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #e5e7eb; /* Darker background for contrast */
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px; /* Add some breathing room */
    overflow-y: auto; /* Allow body scroll if window is small */
}

/* Main Layout */
.app-container {
    display: flex;
    width: 100%;
    max-width: 1200px; /* Constrain width */
    height: 85vh; /* Fixed height relative to viewport */
    min-height: 600px;
    background-color: #fff;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    overflow: hidden; /* Clip children */
}

/* Sidebar Styling */
.sidebar {
    width: 360px; /* Slightly narrower */
    min-width: 360px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow-y: auto;
    z-index: 10;
}

.sidebar header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 4px;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

.control-group {
    margin-bottom: 24px;
}

.control-group.flex-grow {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.control-group h3 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.05em;
}

/* File Upload */
.file-upload-wrapper {
    background-color: var(--input-bg);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    transition: border-color 0.2s;
}

.file-upload-wrapper:hover {
    border-color: var(--primary-color);
}

input[type="file"] {
    display: none;
}

.file-name {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    word-break: break-all;
}

/* Settings Grid */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.full-width-col {
    grid-column: 1 / -1;
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-item label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
}

/* Select Dropdown */
.select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    background-color: var(--input-bg);
    appearance: none; /* Remove default arrow */
    -webkit-appearance: none;
    cursor: pointer;
    color: var(--text-main);
    font-family: inherit;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.select-arrow {
    position: absolute;
    right: 12px;
    font-size: 10px;
    color: var(--text-secondary);
    pointer-events: none;
}

/* Range Slider */
.range-wrapper {
    padding: 0 4px;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    outline: none;
    margin: 10px 0;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

.range-labels {
    display: flex;
    justify-content: space-between;
    margin-top: -4px;
}

.range-labels span {
    font-size: 10px;
    color: var(--text-secondary);
    width: 30px;
    text-align: center;
}

/* Color Presets */
.color-presets {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
}

.preset-option {
    cursor: pointer;
    border-radius: 6px;
    padding: 2px;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.preset-option.active {
    border-color: var(--primary-color);
    background-color: rgba(59, 130, 246, 0.1);
}

.preset-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.custom-icon {
    background: linear-gradient(135deg, #fce 0%, #cdf 100%);
    border: 1px solid #ddd;
    font-size: 14px;
}

/* Custom Color Panel */
.custom-color-panel {
    display: flex;
    gap: 16px;
    background-color: var(--input-bg);
    padding: 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-top: 4px;
    animation: fadeIn 0.3s ease;
}

.mini-setting {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mini-setting label {
    font-size: 12px;
    color: var(--text-secondary);
}

.color-picker-wrapper.small {
    height: 30px;
    width: 50px;
    padding: 2px 4px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.input-suffix {
    position: relative;
    display: flex;
    align-items: center;
}

.input-suffix input {
    width: 100%;
    padding: 8px 30px 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    background-color: var(--input-bg);
}

.input-suffix span {
    position: absolute;
    right: 10px;
    font-size: 12px;
    color: var(--text-secondary);
    pointer-events: none;
}

/* Color Picker */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--input-bg);
    height: 38px;
}

input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 24px;
    height: 24px;
    cursor: pointer;
    background: none;
    padding: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 4px;
}

.color-value {
    font-size: 12px;
    font-family: monospace;
    color: var(--text-secondary);
}

/* Text Area */
.textarea-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
}

textarea {
    flex: 1;
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--input-bg);
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
}

textarea:focus, input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* Action Buttons */
.action-bar {
    display: flex; /* Changed from grid to flex for single button */
    margin-top: 20px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
}

.btn.full-width {
    width: 100%;
}

.btn.big {
    padding: 12px;
    font-size: 15px;
}

.btn.secondary {
    background-color: #fff;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn.secondary:hover {
    background-color: #f9fafb;
    border-color: #d1d5db;
}

.btn.primary {
    background-color: var(--primary-color);
    color: white;
}

.btn.primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3);
}

.btn.success {
    background-color: var(--success-color);
    color: white;
}

.btn.success:hover:not(:disabled) {
    background-color: var(--success-hover);
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--border-color);
    color: var(--text-secondary);
}

/* Preview Area */
.preview-stage {
    flex: 1;
    background-color: #f3f4f6; /* Lighter grey for stage */
    background-image: radial-gradient(#d1d5db 1px, transparent 1px);
    background-size: 20px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: hidden; /* Hide overflow */
    position: relative;
}

.preview-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Center content if smaller than viewport */
.preview-stage:before {
    display: none;
}

/* Image Stage and Layers - NEW */
.image-stage {
    width: 100%;
    height: 100%;
    position: relative;
}

.preview-layer {
    position: absolute;
    inset: 0;
    margin: auto;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    z-index: 1;
}

.preview-layer.active {
    opacity: 1;
    z-index: 5;
}

.preview-layer.incoming {
    opacity: 1;
    z-index: 10; /* Incoming image is always on top */
}

.hidden {
    display: none !important;
}

/* Empty State */
.empty-state {
    text-align: center;
    color: var(--text-secondary);
}

.placeholder-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Loading State */
.loading-state {
    text-align: center;
    color: var(--text-secondary);
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border-left-color: var(--primary-color);
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
