:root {
    --bg-base: #f8fafc;
    --bg-panel: rgba(255, 255, 255, 0.7);
    --bg-panel-solid: #ffffff;
    --bg-darker: #f1f5f9;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: rgba(15, 23, 42, 0.1);
    --border-strong: rgba(15, 23, 42, 0.2);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: rgba(59, 130, 246, 0.1);
    --success: #10b981;
    --danger: #ef4444;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    --glass-blur: blur(12px);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

[data-theme="dark"] {
    --bg-base: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --bg-panel-solid: #1e293b;
    --bg-darker: #0b1120;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --primary-light: rgba(96, 165, 250, 0.15);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    transition: var(--transition);
    min-height: 100vh;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
}

/* Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-auto { margin-top: auto; }
.mb-4 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-1 { margin-bottom: 0.25rem; }
.w-full { width: 100%; }
.clear-margin { margin: 0 !important; }
.block { display: block; }
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.flex-col { flex-direction: column; }
.gap-3 { gap: 0.75rem; }
.p-3 { padding: 0.75rem; }
.bg-darker { background-color: var(--bg-darker); }
.rounded-lg { border-radius: var(--radius-md); }
.border { border: 1px solid var(--border); }
.border-border { border-color: var(--border); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-family: var(--font-heading);
}

.primary-btn {
    background-color: var(--primary);
    color: #fff;
    box-shadow: 0 4px 14px 0 var(--primary-light);
}
.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px 0 var(--primary-light);
}
.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    background-color: var(--bg-panel-solid);
    color: var(--text-main);
    border: 1px solid var(--border);
}
.secondary-btn:hover {
    background-color: var(--bg-darker);
    border-color: var(--border-strong);
}

.outline-btn {
    background-color: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-strong);
}
.outline-btn:hover {
    background-color: var(--bg-panel-solid);
    border-color: var(--primary);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-panel-solid);
    border: 1px solid var(--border);
    color: var(--text-main);
    cursor: pointer;
    font-size: 1.25rem;
    transition: var(--transition);
}
.icon-btn:hover {
    background-color: var(--bg-darker);
    color: var(--primary);
    border-color: var(--primary);
    transform: scale(1.05);
}

/* Layout */
.app-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-glass);
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    margin-bottom: 2rem;
    border-radius: var(--radius-xl);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
}
.logo i {
    color: var(--primary);
    font-size: 2rem;
}
.logo .highlight {
    color: var(--primary);
}

/* Stepper */
.stepper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 3rem;
    padding: 0 2rem;
    gap: 1rem;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    transition: var(--transition);
    opacity: 0.5;
}
.step.active {
    color: var(--primary);
    opacity: 1;
}
.step.completed {
    color: var(--success);
    opacity: 1;
}

.step-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--bg-panel-solid);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: var(--transition);
    z-index: 2;
}
.step.active .step-icon {
    border-color: var(--primary);
    background-color: var(--primary-light);
    color: var(--primary);
}
.step.completed .step-icon {
    border-color: var(--success);
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.step-connector {
    flex: 1;
    height: 2px;
    background-color: var(--border);
    max-width: 100px;
    margin-top: -24px;
    z-index: 1;
}

/* Views Container */
.views-container {
    flex: 1;
    position: relative;
}

.view {
    display: none;
    height: 100%;
    animation: fadeIn 0.4s ease forwards;
}
.view.active {
    display: block;
}

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

/* Upload View */
.upload-area {
    height: calc(100vh - 250px);
    min-height: 400px;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: var(--transition);
    background: var(--bg-panel);
}
.upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-icon-wrapper {
    width: 80px;
    height: 80px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
}

.supported-formats {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* Split Layouts */
.layout-split {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 1.5rem;
    height: calc(100vh - 250px);
    min-height: 500px;
}

.preview-panel, .editor-panel {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xl);
    background-image: linear-gradient(45deg, var(--border) 25%, transparent 25%), linear-gradient(-45deg, var(--border) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--border) 75%), linear-gradient(-45deg, transparent 75%, var(--border) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.controls-panel {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-xl);
}

/* Form Groups & Inputs */
.form-group { margin-bottom: 1.25rem; }
.field-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.select-input, input[type="number"] {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.875rem;
    transition: var(--transition);
}
.select-input:focus, input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Sliders */
.slider-group { margin-bottom: 1.25rem; }
.slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}
input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border-strong);
    border-radius: 3px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: var(--transition);
}
input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Color Picker */
.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}
.color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--primary);
}
.color-custom {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
}
.color-custom input[type="color"] {
    position: absolute;
    top: -10px; left: -10px; width: 60px; height: 60px;
    cursor: pointer; border: none; padding: 0;
}

/* Image Comparing Slider */
.image-compare {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
.image-compare img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.compare-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    overflow: hidden;
    border-right: 2px solid #fff;
}
.compare-overlay img {
    left: 0;
    transform: translate(0, -50%);
    width: 200%;
    max-width: none;
}
.slider-handle {
    position: absolute;
    top: 50%;
    right: -15px;
    width: 30px;
    height: 30px;
    background: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    transform: translateY(-50%);
    cursor: ew-resize;
    z-index: 10;
}

/* Loading & Toast */
.hidden { display: none !important; }

.ai-loader {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* Cropper specific */
.cropper-container {
    width: 100%;
    height: 100%;
}
.cropper-view-box, .cropper-face {
    border-radius: 0;
}
.cropper-dashed, .cropper-line {
    border-color: var(--primary);
}

/* Switch / Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider.round {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-strong);
    transition: .4s;
    border-radius: 24px;
}
.slider.round:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider.round { background-color: var(--primary); }
input:checked + .slider.round:before { transform: translateX(20px); }

/* Custom Scrollbar for panels */
.scrollable { overflow-y: auto; }
.scrollable::-webkit-scrollbar { width: 6px; }
.scrollable::-webkit-scrollbar-track { background: transparent; }
.scrollable::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* A4 Preview */
.a4-preview-wrapper {
    background: #fff;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    /* Standard A4 aspect ratio representation */
    aspect-ratio: 1 / 1.414;
    max-height: 90%;
    width: auto;
}
.a4-preview-wrapper canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}
.toast {
    background: var(--bg-panel-solid);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    margin-top: 10px;
    border-left: 4px solid var(--primary);
    animation: slideIn 0.3s ease forwards;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Radio Group & Cards */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.radio-card {
    flex: 1 1 calc(33.333% - 0.5rem);
    min-width: 80px;
    padding: 0.75rem 0.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    cursor: pointer;
    background: var(--bg-panel-solid);
    transition: var(--transition);
    font-size: 0.875rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.2;
}
.radio-card small {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.radio-card:hover {
    border-color: var(--primary);
}
.radio-card:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

/* =========================================
   RESPONSIVE DESIGN (MOBILE & TABLET)
   ========================================= */

@media (max-width: 992px) {
    .app-container {
        height: auto;
        min-height: 100vh;
        padding: 1rem;
    }

    .layout-split {
        grid-template-columns: 1fr;
        height: auto;
        min-height: auto;
        gap: 1rem;
    }
    
    .editor-panel {
        aspect-ratio: 1; /* Keep cropper square on mobile */
        width: 100%;
        min-height: 350px;
    }

    .preview-panel {
        aspect-ratio: 0.8; /* Slightly taller for A4 portrait preview */
        width: 100%;
        min-height: 350px;
    }

    .controls-panel {
        /* Allow controls panel to expand fully with its contents */
        overflow-y: visible;
        max-height: none;
    }
    
    .upload-area {
        height: auto;
        min-height: 300px;
        padding: 2rem 1rem;
    }

    .views-container {
        position: relative;
        flex: 1 1 auto;
        height: auto;
        padding-bottom: 2rem;
    }
    
    .view, .processing-container {
        height: auto;
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }
    
    .stepper {
        padding: 0;
        margin-bottom: 2rem;
        gap: 0.5rem;
    }

    .step span {
        display: none; /* Hide labels on mobile for cleaner look */
    }

    .step-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }

    .step-connector {
        margin-top: -20px;
    }
    
    .color-picker-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .radio-card {
        flex: 1 1 calc(50% - 0.5rem);
    }
    
    .step.active .step-icon {
        box-shadow: 0 0 10px var(--primary-light);
    }
}

@media (max-width: 480px) {
    .editor-panel, .preview-panel {
        min-height: 280px;
    }
    
    .color-picker-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .radio-card {
        flex: 1 1 100%;
    }
}
