/* Estilos generales y de responsive design */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Roboto", sans-serif;
    background: #f4f4f4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: start;
    min-height: 100vh;
    padding: 20px;
}

.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background-color: #c53945;
    color: white;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border-radius: 50%;
    text-decoration: none;
    z-index: 10;
}

.container-logo {
    position: absolute;
    top: 20px;
    right: 20px;
}

/* Contenedor principal de la vista previa */
#wall-preview-container {
    position: relative;
    width: 100%;
    max-width: 1080px;
    height: 550px;
    display: flex;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin-top: 60px;
    margin-bottom: 25px;
    margin-left: auto;
    margin-right: auto;
    background-color: #fff;
}

.wall-preview-half {
    height: 100%;
    background-color: #e0e0e0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    overflow: hidden;
    flex-shrink: 0;
}

/* Divisor arrastrable */
#divider {
    position: absolute;
    width: 4px;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.7);
    border-left: 1px solid rgba(0, 0, 0, 0.2);
    border-right: 1px solid rgba(0, 0, 0, 0.2);
    cursor: ew-resize;
    z-index: 20;
    left: 50%;
    transform: translateX(-50%);
}

#habitacion-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("https://i.imgur.com/gUQ9oPH.png"); /* Imagen de la habitación sin el mueble principal */
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 5; /* Se asegura que esté sobre las paredes */
}

/* ***** CAMBIO CLAVE: AHORA ES UN CANVAS ***** */
#furniture-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    z-index: 15; /* Sobre la habitación y las paredes */
}

/* Display de colores seleccionados para las paredes */
#current-wall-colors-display {
    width: 100%;
    max-width: 1080px;
    padding: 8px 5px;
    display: flex;
    align-items: stretch;
    justify-content: center;
    border: 1px solid #ccc;
    margin: 15px auto 25px auto;
    border-radius: 35px;
    background-color: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    height: 70px;
    overflow: hidden;
}

.color-half {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    color: #333;
    transition: background-color 0.5s ease;
    border-radius: 30px;
    margin: 3px;
    text-align: center;
    padding: 0 5px;
}

.color-half span {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
    padding: 2px 5px;
    border-radius: 5px;
    background-color: rgba(255, 255, 255, 0.2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Botones de selección de objetivo (Pared/Mueble) */
#wall-selector {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 25px;
}

.wall-btn {
    padding: 12px 25px;
    border: none;
    border-radius: 30px;
    background: #e0e0e0;
    cursor: pointer;
    font-weight: bold;
    color: #333;
    transition: all 0.3s ease;
    text-transform: uppercase;
    font-size: 1.1em;
}

#btn-mueble.active {
    background: #ff5722;
    color: #fff;
    box-shadow: 0 2px 8px rgba(255, 87, 34, 0.4);
}

.wall-btn.active {
    background: #007bff;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.4);
}

/* Controles de categorías y colores para paredes */
#categories {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-bottom: 25px;
    width: 100%;
    max-width: 1080px;
}

.cat-btn {
    padding: 12px 22px;
    border: none;
    border-radius: 28px;
    background: #e0e0e0;
    cursor: pointer;
    font-weight: bold;
    color: #333;
    transition: all 0.3s ease;
}

.cat-btn.active {
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(120, 121, 120, 0.4);
}

#carousel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 12px;
    padding: 20px;
    width: 100%;
    max-width: 1080px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.color-swatch {
    width: 70px;
    height: 70px;
    border-radius: 8px;
    border: 3px solid #ccc;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-swatch.selected {
    border-color: #27ae60;
    box-shadow: 0 0 0 4px rgba(39, 174, 96, 0.4);
    transform: scale(1.05);
}

/* ---- Estilos para el nuevo SELECTOR DE COLOR ---- */
#color-picker-container {
    display: none;
    flex-direction: column;
    align-items: center;
    margin-bottom: 25px;
    width: 100%;
    max-width: 350px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
    padding: 20px;
    user-select: none; /* Evita selección de texto al arrastrar */
}

#color-picker-container label {
    font-weight: bold;
    color: #333;
    margin-bottom: 15px;
    font-size: 1.1em;
}

#hue-slider {
    width: 100%;
    height: 25px;
    background: linear-gradient(
        to right,
        red,
        yellow,
        lime,
        cyan,
        blue,
        magenta,
        red
    );
    border-radius: 12px;
    margin-bottom: 20px;
    cursor: pointer;
    position: relative;
}

#hue-handle {
    position: absolute;
    top: -5px;
    width: 16px;
    height: 35px;
    background-color: #fff;
    border: 2px solid #555;
    border-radius: 8px;
    cursor: grab;
    transform: translateX(-50%); /* Centra el handle */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

#saturation-brightness-area {
    position: relative;
    width: 100%;
    height: 250px;
    border-radius: 8px;
    cursor: crosshair;
    overflow: hidden; /* Asegura que los gradientes no se salgan */
}

#saturation-brightness-area::before,
#saturation-brightness-area::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

#saturation-brightness-area::before {
    background: linear-gradient(to right, white, transparent);
}

#saturation-brightness-area::after {
    background: linear-gradient(to top, black, transparent);
}

#sb-indicator {
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid #fff;
    border-radius: 50%;
    box-sizing: border-box;
    pointer-events: none;
    box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.5),
        inset 0 0 0 1.5px rgba(0, 0, 0, 0.5);
    transform: translate(-50%, -50%); /* Centra el indicador */
}

#selected-color-preview {
    width: 80px;
    height: 40px;
    border-radius: 5px;
    margin-top: 20px;
    border: 1px solid #ccc;
}

/* Media Queries para Responsividad */
@media (max-width: 768px) {
    #wall-preview-container {
        height: 400px;
    }
    .wall-btn,
    .cat-btn {
        font-size: 1em;
        padding: 10px 20px;
    }
    #color-picker-container {
        max-width: 300px;
    }
    #saturation-brightness-area {
        height: 200px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    #wall-preview-container {
        height: 250px;
    }
    .wall-btn,
    .cat-btn {
        font-size: 0.8em;
        padding: 8px 15px;
    }
    #current-wall-colors-display {
        height: 60px;
    }
    #color-picker-container {
        max-width: 95%;
        padding: 15px;
    }
    #saturation-brightness-area {
        height: 180px;
    }
}

#capture {
    width: 100%;
}

#btnCapture {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #c53945; /* Green background */
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

#btnCapture:hover {
    background-color: #e91f30; /* Darker green on hover */
    transform: scale(1.05);
}

#btnCapture:active {
    transform: scale(0.95);
}
