/* Base mobile styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    line-height: 1.4;
}

/* App Banner */
#app-banner {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    position: relative;
    z-index: 100;
}

.app-banner-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 48px;
    max-width: 1200px;
    margin: 0 auto;
}

.app-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.install-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.install-btn:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.5);
    transform: translateY(-1px);
}

.install-btn:active {
    transform: translateY(0);
}

.install-btn.hidden {
    display: none;
}

/* PWA Update and Install Notifications */
.update-banner, .install-success {
    position: fixed;
    top: 20px; /* Adjust based on app banner visibility */
    left: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s ease;
}

/* When app banner is visible, position below it */
#app-banner:not([style*="display: none"]) ~ * .update-banner,
#app-banner:not([style*="display: none"]) ~ * .install-success {
    top: 60px;
}

.update-content, .success-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.update-btn {
    background: #007AFF;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.update-btn:hover {
    background: #0056CC;
}

.update-dismiss, .success-dismiss {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.update-dismiss:hover, .success-dismiss:hover {
    opacity: 1;
}

.install-success {
    background: rgba(52, 199, 89, 0.9);
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Step Progress */
#step-indicator {
    background: white;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-bottom: 1px solid #e0e0e0;
}

.progress-bar {
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: #007AFF;
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 14%;
}

.step-text {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    text-align: center;
}

/* Main Content Area */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
    position: relative;
}

.step-container {
    display: none;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.step-container.active {
    display: flex;
}

/* Image Display */
#image-canvas, .step-canvas {
    max-width: 100%;
    max-height: 70vh;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    display: none; /* Hidden by default */
}

#image-canvas {
    display: none; /* Step 1 canvas hidden by default */
}

.step-canvas {
    display: block; /* Step canvases visible by default */
    max-width: calc(100vw - 80px);
    max-height: calc(100vh - 300px);
}

.image-preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.image-placeholder {
    width: 280px;
    height: 210px;
    background: #f0f0f0;
    border: 2px dashed #ccc;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.painting-sample {
    width: 200px;
    height: 150px;
    background: linear-gradient(45deg, #8B4513, #D2691E, #F4A460);
    border-radius: 4px;
    position: relative;
    border: 2px solid #654321;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.painting-sample::before {
    content: '';
    position: absolute;
    inset: -6px;
    background: #8B4513;
    border-radius: 8px;
    z-index: -1;
}

.painting-sample.enhanced {
    background: linear-gradient(45deg, #CD853F, #F4A460, #FFE4B5);
    border-color: #8B4513;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* Upload Area */
.upload-area {
    width: 280px;
    height: 210px;
    border: 2px dashed #007AFF;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(0, 122, 255, 0.05);
}

.upload-area:hover {
    background: rgba(0, 122, 255, 0.1);
    border-color: #0056CC;
}

.upload-icon {
    width: 48px;
    height: 48px;
    background: #007AFF;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    margin-bottom: 12px;
}

.upload-text {
    text-align: center;
    color: #333;
}

.upload-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.upload-subtitle {
    font-size: 14px;
    color: #666;
}

/* Canvas-based grid - no CSS positioning needed */
.step-canvas {
    cursor: crosshair;
}

.step-canvas.dragging {
    cursor: none; /* Hide cursor during precise dragging */
}

/* Before/After Toggle */
.before-after-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.before-after-toggle:hover {
    background: rgba(0,0,0,0.9);
}

/* Enhancement Badge */
.enhancement-badge {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(52, 199, 89, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

/* Controls Panel */
#controls-panel {
    background: white;
    padding: 16px;
    border-top: 1px solid #e0e0e0;
    min-height: 80px;
    max-height: 140px;
    overflow-y: auto;
}

.controls-container {
    display: none;
}

.controls-container.active {
    display: block;
}

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

/* Inline control layout for compact display */
.control-group.inline-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.control-label.inline-label {
    font-size: 13px;
    font-weight: 500;
    color: #333;
    margin-bottom: 0;
    flex-shrink: 0;
    white-space: nowrap;
}

.size-selector.inline-select {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    padding: 10px;
}

/* Step 3 specific layout - compact four-column layout */
#controls-3 .control-group {
    margin-bottom: 12px;
}

#controls-3 .control-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

#controls-3 .control-third {
    flex: 1;
    min-width: 0; /* Allow flex items to shrink below content size */
}

#controls-3 .control-third .control-label {
    font-size: 11px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

#controls-3 .control-third .control-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0;
    flex-shrink: 0;
}

#controls-3 .control-third .slider {
    width: 100%;
}

#controls-3 .control-third .slider:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#controls-3 .reset-btn {
    width: 100%;
    margin-top: 12px;
    font-size: 13px;
    padding: 8px 12px;
}

.control-label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-bottom: 8px;
    display: block;
}

.control-description {
    text-align: center;
    color: #666;
    font-size: 14px;
    margin: 0;
}

/* Form Controls */
.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #007AFF;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #007AFF;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.size-selector, .format-selector {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    background: white;
    color: #333;
    cursor: pointer;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 8px;
    cursor: pointer;
}

/* File Info & Warnings */
.file-info {
    background: #f0f8ff;
    border: 1px solid #007AFF;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    color: #0056CC;
    margin-top: 8px;
}

.warning-box {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    color: #856404;
    margin-top: 8px;
}

/* Buttons */
.btn {
    padding: 14px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    user-select: none;
}

.btn-primary {
    background: #007AFF;
    color: white;
}

.btn-primary:hover {
    background: #0056CC;
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-success {
    background: #34C759;
    color: white;
}

.btn-success:hover {
    background: #28a745;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:disabled:hover {
    background: inherit;
}

.reset-btn {
    width: 100%;
    margin-top: 8px;
}

.auto-detect-btn {
    width: 100%;
    margin-bottom: 12px;
}

.generate-btn {
    width: 100%;
    margin-top: 8px;
    background: #FF9500;
    color: white;
    font-weight: 600;
}

.generate-btn:hover {
    background: #e8850a;
}

/* Navigation */
#navigation {
    background: white;
    padding: 16px;
    display: flex;
    gap: 12px;
    border-top: 1px solid #e0e0e0;
}

#navigation .btn {
    flex: 1;
}

/* When back button is hidden, other buttons take full width */
#navigation .btn:only-child {
    flex: 1;
}

#navigation .btn + .btn {
    flex: 1;
}

/* Startup Loading Screen */
.startup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.startup-content {
    text-align: center;
    color: white;
    max-width: 300px;
    padding: 40px 20px;
}

.startup-content h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 30px;
    color: white;
}

.startup-progress {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 20px;
}

.startup-progress-fill {
    height: 100%;
    background: white;
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

#startup-message {
    font-size: 16px;
    margin-top: 20px;
    opacity: 0.9;
}

/* Processing Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

/* Startup spinner - centered properly */
.startup-content .spinner {
    margin: 0 auto 20px auto;
    display: block;
}

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

#loading-message {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 20px;
}

#loading-overlay .progress-bar {
    width: 200px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    overflow: hidden;
}

#loading-overlay .progress-fill {
    background: white;
    transition: width 0.3s ease;
}

#error-toast, #success-toast {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    padding: 16px;
    border-radius: 8px;
    z-index: 1001;
    animation: slideDown 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#error-toast {
    background: #FF3B30;
    color: white;
}

#success-toast {
    background: #34C759;
    color: white;
}

#error-close, #success-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 320px) {
    .upload-area, .image-placeholder {
        width: 260px;
        height: 195px;
    }
    
    .painting-sample {
        width: 180px;
        height: 135px;
    }
    
    #controls-panel {
        padding: 16px;
    }
    
    #navigation {
        padding: 12px;
    }
}

/* Desktop PWA Optimizations */
@media (min-width: 1024px) and (display-mode: standalone) {
    /* Optimize for 1200x900 PWA window */
    body {
        max-width: 1200px;
        margin: 0 auto;
        background: #f0f0f0;
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
    }
    
    .app-banner-content {
        padding: 0 40px;
    }
    
    #main-content {
        padding: 40px;
    }
    
    #step-indicator {
        padding: 20px 40px;
    }
    
    #controls-panel {
        padding: 20px 40px;
    }
    
    #navigation {
        padding: 20px 40px;
    }
    
    /* Larger touch targets for desktop */
    .btn {
        padding: 12px 24px;
        font-size: 16px;
    }
    
    .corner-handle {
        width: 24px;
        height: 24px;
    }
    
    /* Better canvas sizing for desktop */
    #image-canvas, .step-canvas {
        max-width: 800px;
        max-height: 600px;
    }
    
    /* Enhanced desktop controls */
    #controls-3 .control-third {
        min-width: 200px;
    }
    
    .size-selector.inline-select {
        min-width: 300px;
    }
}

/* General desktop optimizations */
@media (min-width: 768px) {
    /* Hover effects for desktop */
    .btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    }
    
    .corner-handle:hover {
        transform: translate(-50%, -50%) scale(1.1);
    }
    
    /* Better spacing on larger screens */
    .control-group {
        margin-bottom: 24px;
    }
    
    .step-text {
        font-size: 18px;
    }
    
    .app-title {
        font-size: 22px;
    }
    
    /* Keyboard navigation support */
    .btn:focus-visible {
        outline: 2px solid #007AFF;
        outline-offset: 2px;
    }
    
    .slider:focus-visible {
        outline: 2px solid #007AFF;
        outline-offset: 2px;
    }
}