:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --bg-color: #f8fafc;
    --sidebar-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--sidebar-bg);
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow);
    text-align: center;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.container {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Sidebar Styles */
.sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    transition: var(--transition);
    box-shadow: var(--shadow);
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Sidebar scrollbar styling */
.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: var(--bg-color);
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-sidebar {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.close-sidebar:hover {
    color: var(--text-primary);
}

.menu-section {
    margin-bottom: 2rem;
    padding: 0;
}

.menu-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.menu-section h4 {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.color-picker-wrapper {
    margin-bottom: 1.5rem;
}

.color-picker-wrapper label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

#colorPicker {
    width: 100%;
    height: 50px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

#colorPicker:hover {
    border-color: var(--primary-color);
}

.preset-colors {
    margin-top: 1rem;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.color-btn {
    aspect-ratio: 1;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.color-btn:hover {
    transform: scale(1.1);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
}

.color-btn.active {
    border-color: var(--primary-color);
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.texture-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.texture-btn {
    aspect-ratio: 1;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    background-size: cover;
    background-position: center;
    transition: var(--transition);
}

.texture-btn:hover {
    transform: scale(1.05);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
}

.texture-btn.active {
    border-color: var(--primary-color);
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.texture-note {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
    grid-column: 1 / -1;
}

.btn-reset {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-reset:hover {
    background: #475569;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

/* Preview Section */
.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

.preview-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: center;
}

.menu-toggle {
    display: none;
    padding: 0.5rem 1rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition);
}

.menu-toggle:hover {
    background: var(--bg-color);
}

.btn-toggle-grid {
    padding: 0.5rem 1rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition);
    color: var(--text-primary);
}

.btn-toggle-grid:hover {
    background: var(--bg-color);
}

.btn-toggle-grid.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-demo {
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
}

.btn-demo:hover {
    background: var(--bg-color);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.btn-upload-control {
    padding: 0.5rem 1.25rem;
    background: var(--primary-color);
    color: white;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: var(--transition);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
    position: relative;
}

.btn-upload-control:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.btn-upload-control:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

/* Mobile Color Picker */
.mobile-color-picker {
    display: none;
    margin-bottom: 1rem;
    padding: 0.75rem 0;
}

.mobile-color-scroll {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.5rem 1rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.mobile-color-scroll::-webkit-scrollbar {
    height: 6px;
}

.mobile-color-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.mobile-color-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.mobile-color-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.mobile-color-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.mobile-color-btn:hover {
    transform: scale(1.1);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
}

.mobile-color-btn.active {
    border-color: var(--primary-color);
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.btn-upload {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
}

.btn-upload:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.preview-area {
    flex: 1;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    background: white;
    outline: none;
    min-height: 0;
    height: 100%;
}

.preview-area:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.drop-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    transition: var(--transition);
    z-index: 2;
}

.drop-zone.drag-over {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.drop-zone.hidden {
    display: none;
}

.drop-zone-content {
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.drop-zone-content svg {
    margin: 0 auto;
    color: var(--text-secondary);
}

.drop-text {
    font-size: 1.125rem;
    font-weight: 500;
    margin: 0;
    color: var(--text-primary);
}

.drop-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

.drop-zone-content .btn-upload {
    margin-top: 0.5rem;
}

.preview-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    transition: var(--transition);
}

.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    background-image: 
        linear-gradient(to right, rgba(0, 0, 0, 0.15) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.15) 1px, transparent 1px);
    background-size: 50px 50px;
}

.grid-overlay.visible {
    opacity: 1;
}

.preview-image {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 80%;
    max-height: 80%;
    width: auto;
    height: auto;
    object-fit: contain;
    z-index: 2;
    border-radius: 8px;
    transition: var(--transition);
}

footer {
    background: var(--sidebar-bg);
    padding: 1rem 2rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .container {
        position: relative;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        height: 100vh;
        z-index: 1000;
        width: 85%;
        max-width: 320px;
        box-shadow: var(--shadow-lg);
        transition: left 0.3s ease;
        display: flex;
        flex-direction: column;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-header {
        position: sticky;
        top: 0;
        background: var(--sidebar-bg);
        z-index: 10;
        padding-top: 1rem;
        margin-bottom: 1rem;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .close-sidebar {
        display: block;
    }

    .menu-toggle {
        display: block;
    }

    .preview-section {
        padding: 1rem;
    }

    .preview-controls {
        flex-wrap: wrap;
    }

    .mobile-color-picker {
        display: block;
    }

    .btn-upload-control {
        display: block !important;
    }

    .color-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .texture-options {
        grid-template-columns: repeat(2, 1fr);
    }

    .drop-text {
        font-size: 1rem;
    }

    .drop-hint {
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    .color-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
    }
}

/* Loading state */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Smooth transitions */
* {
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

