/* ====================================================================
   KAYAK DESIGNER - MAIN STYLESHEET
==================================================================== */

/* --------------------------------------------------------------------
   1. General Layout & Structure
-------------------------------------------------------------------- */
#kayak-designer-container {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
}

#kayak-preview-area {
    flex: 1 1 100%;
    min-width: 400px;
}

#kayak-color-controls {
    flex: 1 1 100%;
    min-width: 300px;
}

/* --------------------------------------------------------------------
   2. Kayak 2D View & Color Layers
-------------------------------------------------------------------- */
#kayak-top-view-container,
#kayak-side-view-container {
    position: relative;
    margin-bottom: 20px;
    border: 1px solid #ddd;
    background: #ffffff;
    max-width: 100%;
    overflow: hidden;
}

#kayak-top-view-container > img,
#kayak-side-view-container > img {
    max-width: 100%;
    height: auto;
    display: block;
}

.color-layer {
    z-index: 10; /* Default z-index */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    pointer-events: none;
}

.hardware-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-width: 100%;
    z-index: 100;
    pointer-events: none;
}

/* --------------------------------------------------------------------
   3. CSS Mask Definitions
-------------------------------------------------------------------- */
/* Z-Index Stacking Order */
/* Base Layers */
#kayak-top-view-deck-color, #kayak-side-view-deck-color { z-index: 10; }
#kayak-top-view-hull-color, #kayak-side-view-hull-color { z-index: 11; }

#kayak-side-view-deck-seam-tape-color { z-index: 30; }
#kayak-top-view-accent-front-color, #kayak-top-view-accent-rear-color, #kayak-side-view-accent-front-color, #kayak-side-view-accent-rear-color { z-index: 20; }
#kayak-top-view-seat-color { z-index: 45; }
#kayak-top-view-cockpit-rim-color, #kayak-side-view-cockpit-rim-color { z-index: 48; }
#kayak-top-view-logo-color, #kayak-side-view-logo-color { z-index: 50; }
#kayak-top-view-lines-color, #kayak-side-view-lines-color { z-index: 60; }

/* CSS masks are now applied dynamically via kayak-designer.js to support multiple models. */

/* --------------------------------------------------------------------
   4. Interactive RAL Color Palette
-------------------------------------------------------------------- */
.ral-palette-container {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    
}

.selected-color-wrapper {
    display: flex;
    align-items: center;
    gap: 10px; /* Space between circle and text */
    cursor: pointer;
}

.selected-color-preview {
    width: 30px;
    height: 30px;
    border: 1px solid #ccc;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
    background-clip: padding-box;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1) inset;
}

.ral-palette-grid-wrapper {
    position: absolute;
    z-index: 100;
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    padding: 10px;
    display: none; /* Hidden by default, toggled by JS */
    max-height: 220px;
    overflow-y: auto;
    margin-top: 2px;
}

.ral-palette-grid-wrapper:not(.is-hidden) {
    display: block;
}

.ral-palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
    gap: 5px;
    max-width: 300px;
}

.ral-swatch {
    width: 24px;
    height: 24px;
    border: 1px solid #eee;
    cursor: pointer;
    transition: transform 0.1s ease-in-out;
}

.ral-swatch:hover {
    transform: scale(1.15);
    border-color: #000;
}

/* --------------------------------------------------------------------
   5. Controls Section (Right Panel)
-------------------------------------------------------------------- */

.controls-grid {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr; /* Default to 1 column for mobile */
}

.control-section {
    background-color: rgba(253, 253, 253, 0.2);
    padding: 1em;
    border: 1px solid rgba(100, 100, 100, 0.2);
    border-radius: 4px;
}

.control-section h4 {
    margin-top: 1em;
    padding-bottom: 1em;
    border-bottom: 1px solid rgba(100, 100, 100, 0.2);
    margin-bottom: 1em;
}

/* Responsive grid columns */
@media (min-width: 768px) {
    .controls-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1200px) {
    .controls-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
#kayak-color-controls h3, #kayak-color-controls h4 {
    margin-top: 20px;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(100, 100, 100, 0.2);
    padding-bottom: 5px;
}

.control-group-horizontal {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-start;
}

.control-group-horizontal > div {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 130px; /* Ensures items wrap nicely */
}

.control-group-horizontal label {
    margin-bottom: 5px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.grid-2-col {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

#kayak-color-controls h2:first-of-type, #kayak-color-controls h3:first-of-type {
    margin-top: 0;
}

/* --------------------------------------------------------------------
   8. Manage Saved Designs
-------------------------------------------------------------------- */
#saved-designs-container {
    margin-bottom: 20px;
}

.select-container {
    margin-bottom: 15px;
}

.design-select {
    width: 100%;
    padding: 8px;
    margin-top: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.design-action-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.design-action-buttons .button {
    flex: 1;
    padding: 8px 10px;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
    border: none;
    border-radius: 4px;
}

.load-design-button {
    background-color: #2271b1;
    color: white;
}

.delete-design-button {
    background-color: #d63638 !important;
    color: white;
}

.load-design-button:hover {
    background-color: #135e96;
}

.delete-design-button:hover {
    background-color: #b32d2e !important;
}

.load-design-button:disabled,
.delete-design-button:disabled {
    background-color: #a7a7a7;
    cursor: not-allowed;
    opacity: 0.7;
}

#kayak-color-controls label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

#kayak-color-controls input[type="radio"] + label {
    display: inline-block;
    font-weight: normal;
    margin-right: 15px;
}

#kayak-color-controls select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

/* --------------------------------------------------------------------
   6. Public Design Gallery
-------------------------------------------------------------------- */

.kayak-gallery-sorting {
    margin-bottom: 20px;
}

.kayak-gallery-sorting select {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

.kayak-design-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

/* Responsive layout for mobile */
@media (max-width: 600px) {
    .kayak-design-gallery {
        grid-template-columns: 1fr; /* Single column on small screens */
    }
}

.gallery-item {
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 15px;
    text-align: center;
    background-color: #f9f9f9;
}

.gallery-item h3 {
    margin-top: 0;
    font-size: 1.2em;
}

.gallery-item-preview {
    position: relative;
    width: 100%;
    height: auto;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    background-color: #fff;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.gallery-item-preview:hover {
    opacity: 0.8;
}


.gallery-item-preview .zoom-icon {
    position: absolute;
    bottom: 10px;
    right: 10px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    z-index: 10;
}

.gallery-item-preview:hover .zoom-icon {
    opacity: 1;
}

.gallery-item-preview img {
    width: 100%;
    height: auto;
    object-fit: contain;
}

.kayak-preview-placeholder {
    width: 100%;
    height: 150px;
    background-color: #eee;
    border: 1px solid #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    margin-bottom: 15px;
}

.vote-button {
    padding: 8px 15px;
    border: none;
    background-color: #0073aa;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.vote-button:hover {
    background-color: #005177;
}

.vote-button:disabled {
    background-color: #a0a5aa;
    cursor: not-allowed;
}

.guest-vote-form {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.guest-vote-form input[type="email"] {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.guest-vote-form button {
    padding: 8px 15px;
    border: none;
    background-color: #2271b1;
    color: white;
    border-radius: 4px;
    cursor: pointer;
}

.guest-vote-form button:disabled {
    background-color: #a0a5aa;
}

/* --------------------------------------------------------------------
   7. Full-Screen Modal & Zoom Controls
-------------------------------------------------------------------- */
.kayak-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Dark mode is default */
.kayak-modal.light-mode {
    background-color: rgba(255, 255, 255, 0.85);
}

/* Light/dark mode toggle */
.modal-theme-toggle {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background-color: #444;
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 8px 15px;
    font-size: 14px;
    cursor: pointer;
    z-index: 1010;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s ease;
}

.modal-theme-toggle:hover {
    background-color: #555;
}

.modal-theme-toggle-icon {
    font-size: 16px;
}

/* Adjust text colors for light mode */
.kayak-modal.light-mode .kayak-modal-close {
    color: #333;
}

.kayak-modal.light-mode #kayak-gallery-modal-title {
    color: #333;
}

.kayak-modal.modal-visible {
    opacity: 1;
}

.kayak-modal-content-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.kayak-modal-content-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.modal-image-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 90%;
    max-height: 90vh;
}

/* Fix for modal kayak containers to ensure proper layer stacking */
#modal-top-view-container,
#modal-side-view-container {
    position: relative;
    overflow: hidden;
}

/* Ensure all color layers are positioned absolutely in the modal view */
#modal-top-view-container .color-layer,
#modal-side-view-container .color-layer,
#modal-top-view-container .hardware-layer,
#modal-side-view-container .hardware-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.modal-kayak-image {
    max-width: 100%;
    max-height: 45vh;
    object-fit: contain;
}

.kayak-modal-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    z-index: 10;
}

.kayak-modal-close:hover,
.kayak-modal-close:focus {
    color: #bbb;
    text-decoration: none;
}

#kayak-gallery-modal .kayak-modal-content-wrapper figure {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
}

#kayak-gallery-modal-title {
    color: #ccc;
    padding-top: 15px;
    font-size: 1.2em;
    font-weight: bold;
    text-align: center;
}

.view-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
}

.zoom-icon {
    font-size: 24px;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.4);
    padding: 5px 8px;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s ease;
    line-height: 1;
    display: inline-block;
}

.zoom-icon:hover {
    background-color: rgba(0, 0, 0, 0.7);
}
