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

:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --accent: #1a1a1a;
    --accent-hover: #333333;
    --border: #e0e0e0;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.12);
    --panel-width: 380px;
    --header-height: 60px;
}

body {
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.viewer-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.header {
    height: var(--header-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
}

.logo-img {
    height: 32px;
    width: auto;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn {
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
}

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

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-orange {
    background: #F44611;
}

.btn-orange:hover {
    background: #D63D0F;
}

#canvas-container {
    flex: 1;
    position: relative;
    background: linear-gradient(180deg, #fafafa 0%, #f0f0f0 100%);
}

#canvas-container canvas {
    display: block;
}

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.viewer-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    box-shadow: var(--shadow);
    opacity: 1;
    transition: opacity 0.5s ease;
}

.viewer-controls.hidden {
    opacity: 0;
    pointer-events: none;
}

.control-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.config-panel {
    width: var(--panel-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.panel-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 4px;
}

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

.config-section {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.config-section h3 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.section-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.color-swatch {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 3px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-swatch:hover {
    transform: scale(1.05);
}

.color-swatch.active {
    border-color: var(--accent);
}

.swatch-inner {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.swatch-inner.metallic {
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1), inset 0 2px 4px rgba(255, 255, 255, 0.5);
}

.check-mark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
}

.color-swatch.active .check-mark {
    display: flex;
}

.selected-info {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.selected-info span:first-child {
    color: var(--text-muted);
}

.selected-info span:last-child {
    font-weight: 500;
}

.custom-color-section {
    background: #fafafa;
}

.custom-color-row {
    display: flex;
    gap: 16px;
}

.color-picker-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.color-picker-wrapper input[type="color"] {
    width: 100%;
    height: 50px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: none;
    padding: 0;
}

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

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border);
    border-radius: 8px;
}

.color-picker-wrapper label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.panel-footer {
    margin-top: auto;
    padding: 24px;
    border-top: 1px solid var(--border);
}

.footer-note {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 16px;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    :root {
        --panel-width: 320px;
    }
}

@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    .logo-img {
        height: 24px;
    }

    .container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .viewer-section {
        height: 50vh;
        min-height: 50vh;
    }

    .config-panel {
        width: 100%;
        height: auto;
        border-left: none;
        border-top: 1px solid var(--border);
        padding-bottom: 80px;
    }

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

    /* Sticky generate button on mobile */
    #generateVisual {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        padding: 16px;
        font-size: 16px;
        border-radius: 0;
        z-index: 100;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    }
}

/* Scrollbar styling */
.config-panel::-webkit-scrollbar {
    width: 6px;
}

.config-panel::-webkit-scrollbar-track {
    background: transparent;
}

.config-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.config-panel::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Visualize in Room Section */
.visualize-section {
    background: #fafafa;
}

.api-key-row {
    margin-bottom: 12px;
}

.api-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
}

.api-input:focus {
    outline: none;
    border-color: var(--accent);
}

.api-hint {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.room-upload-row {
    margin-bottom: 12px;
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all 0.2s ease;
}

.upload-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.room-preview {
    margin-bottom: 12px;
    border-radius: 8px;
    overflow: hidden;
}

.room-preview img {
    width: 100%;
    height: auto;
    display: block;
}

.room-preview.hidden,
.visual-result.hidden,
.generate-loading.hidden,
.error-msg.hidden {
    display: none;
}

.visual-result {
    position: relative;
    margin-top: 12px;
    border-radius: 8px;
    overflow: hidden;
}

.visual-result img {
    width: 100%;
    height: auto;
    display: block;
}

.download-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,0.9);
}

.generate-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}

.generate-loading .spinner {
    width: 24px;
    height: 24px;
}

.error-msg {
    color: #c00;
    font-size: 12px;
    margin-top: 8px;
}

#generateVisual {
    margin-top: 8px;
}

#generateVisual:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 16px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: white;
    transform: scale(1.1);
}

#modalImage {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
}

.modal-cta {
    padding: 24px 32px;
    text-align: center;
    background: var(--bg-secondary);
}

.modal-cta h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.modal-cta p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.btn-cta {
    display: inline-block;
    padding: 16px 32px;
    background: #1a1a1a;
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.2s;
    margin-right: 12px;
}

.btn-cta:hover {
    background: #333;
    transform: translateY(-2px);
}

.btn-secondary {
    padding: 16px 24px;
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-primary);
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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