.csd-wrapper {
    margin: 0px auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    position: relative;
    max-width: 1400px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#csd-loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.csd-loader {
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

.csd-controls {
    margin-bottom: 20px;
}

/* Stili per le sezioni */
.csd-section {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #e1e1e1;
    margin-bottom: 10px;

}

.csd-section-header {
    background: linear-gradient(135deg,rgb(216, 216, 216) 0%,rgb(206, 206, 206) 100%);
    color: white;
    padding: 12px 15px;
    border-radius: 7px 7px 0 0;
    margin: 0;
}

.csd-section-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
   
.csd-section-content {
    padding: 10px;
}

.csd-section:last-child {
    margin-bottom: 0;
}


.csd-control-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

.csd-control-group select,
.csd-control-group textarea,
.csd-control-group input[type="number"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.csd-control-group textarea {
    min-height: 50px;
    resize: vertical;
}

.csd-control-row {
    display: flex;
    gap: 15px;

}

.csd-control-item {
    flex: 1;
}

.csd-line-height input,
.csd-letter-spacing input {
    width: 100%;
}

.csd-align-buttons {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.csd-align-btn {
    font-size: 20px;
    cursor: pointer;
    color: #555;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: all 0.3s;
}

.csd-align-btn:hover {
    background-color: #f0f0f0;
}

.csd-align-btn.active {
    color: #0073aa;
    border-color: #0073aa;
    background-color: rgba(0, 115, 170, 0.1);
}

.csd-range-info {
    font-size: 12px;
    color: #666;
    margin-left: 10px;
}

/* Stili per tipi di stencil */
.csd-stencil-types {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.csd-radio-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 5px;
    transition: all 0.3s;
    flex: 1;
    min-width: 120px;
}

.csd-radio-label:hover {
    border-color: #0073aa;
    background-color: #f9f9f9;
}

.csd-radio-label input[type="radio"] {
    margin-right: 8px;
    width: auto;
}

.csd-radio-label input[type="radio"]:checked {
    accent-color: #0073aa;
}

.csd-radio-label input[type="radio"]:checked + span {
    font-weight: bold;
    color: #0073aa;
}

.csd-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.csd-actions button {
    flex: 1;
    padding: 15px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: #0073aa;
    color: white;
    transition: all 0.3s;
    font-size: 16px;
    font-weight: bold;
}

.csd-actions button:hover {
    background: #005a87;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.csd-actions button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#csd-konva-container, #csd-gallery-container {
    width: 100%;
    border-radius: 4px;
}

#csd-gallery-container {
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

#csd-gallery-main-image {
    max-width: 100%;
    max-height: 500px;
    object-fit: contain;
}

/* Gallery thumbnails - OTTIMIZZATA PER ANDARE A CAPO */
.csd-gallery-thumbnails {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
    padding: 10px 0;
    justify-content: flex-start;
}

.csd-thumb {
    flex: 0 0 calc(20% - 8px);
    min-width: 80px;
    max-width: 80px;
    height: 80px;
    border: 2px solid #ddd;
    border-radius: 5px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9f9f9;
}

.csd-thumb:hover {
    border-color: #0073aa;
    transform: scale(1.05);
}

.csd-thumb.active {
    border-color: #0073aa;
    box-shadow: 0 0 10px rgba(0, 115, 170, 0.5);
}

.csd-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.csd-canvas-thumb {
    flex-direction: column;
    font-size: 11px;
    color: #555;
    /* text-align: center; */
    padding: 5px;
}

.csd-canvas-thumb i {
    font-size: 24px;
    margin-bottom: 5px;
}

.csd-canvas-container {
    position: relative;
}

.csd-dimensions-info {
    text-align: center;
    padding: 15px 0;
    font-size: 16px;
    color: #333;
    background-color: #f9f9f9;
    border-radius: 8px;
    margin-top: 10px;
}

.csd-dimensions-info .text-dimensions {
    color: #ff6b6b;
}

.csd-dimensions-info .total-dimensions {
    color: #4ecdc4;
}

.csd-ruler-legend {
    margin-top: 10px;
    font-size: 14px;
    color: #666;
}

.text-ruler-indicator {
    color: #ff6b6b;
    font-weight: bold;
    border-bottom: 2px dashed #ff6b6b;
    padding-bottom: 2px;
}

.total-ruler-indicator {
    color: #4ecdc4;
    font-weight: bold;
    border-bottom: 2px solid #4ecdc4;
    padding-bottom: 2px;
}

.csd-info {
    margin-top: 10px;
    text-align: center;
    position: relative;
}

.csd-info span {
    font-weight: bold;
}

.csd-info-lungo {
    margin-top: 10px;
    padding-right: 10px;
    padding-left: 10px;
    text-align: center;
    color: #fff;
    background-color: #4ecdc4;
    padding: 15px 0;
    font-weight: bold;
    font-size: 25px;
    border-radius: 8px;
}

.csd-estimated-cost {
    position: absolute;
    top: 0px;
    right: 0px;
    background-color: #4ecdc4;
    padding: 10px 20px;
    border-radius: 0 0 0 24px;
    font-weight: bold;
    font-size: 22px;
    color: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.csd-estimated-cost small,
.csd-estimated-cost-lungo small {
    font-size: 14px;
    margin-left: 5px;
}

.csd-icons {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    gap: 10px;
    z-index: 998;
}

.csd-icon {
    font-size: 24px;
    color: green;
    cursor: pointer;
    transition: all 0.3s;
    padding: 8px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
}

.csd-icon:hover {
    background-color: rgba(255, 255, 255, 1);
    transform: scale(1.1);
}

.csd-promo-text {
    text-align: center;
    padding: 15px 10px;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
    background-color: #fff3cd;
    border-radius: 8px;
    margin: 15px 0;
}

/* OTTIMIZZAZIONI MOBILE */
@media (max-width: 768px) {
    .csd-wrapper {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 10px;
    }

    .csd-canvas-container {
        order: 1;
    }

    .csd-control-group {
        order: 2;
    }

    .csd-controls {
        padding: 15px;
    }

    #csd-konva-container {
        height: auto !important;
        aspect-ratio: 1 / 1;
    }

    .csd-control-row {
        flex-direction: column;
        gap: 10px;
    }

    .csd-control-item {
        width: 100%;
    }

    .csd-align-buttons {
        justify-content: center;
    }

    .csd-align-btn {
        flex: 1;
        text-align: center;
        padding: 12px;
        font-size: 18px;
    }
    
    .csd-stencil-types {
        flex-direction: column;
    }

    .csd-radio-label {
        width: 100%;
        padding: 15px;
    }

    /* Ottimizzazioni gallery per mobile */
    .csd-gallery-thumbnails {
        justify-content: center;
    }

    .csd-thumb {
        flex: 0 0 calc(33.333% - 7px);
        height: 70px;
    }

    .csd-canvas-thumb {
        font-size: 10px;
    }

    .csd-canvas-thumb i {
        font-size: 20px;
    }

    /* Dimensioni info mobile */
    .csd-dimensions-info {
        font-size: 14px;
        padding: 10px;
    }
    
    .csd-ruler-legend {
        font-size: 12px;
        margin-top: 8px;
    }

    /* Prezzi mobile */
    .csd-estimated-cost {
        position: absolute;
        top: 0;
        right: 0;
        display: inline-block;
        font-size: 20px;
    }

    .csd-info-lungo {
        font-size: 22px;
        padding: 12px 0;
    }

    /* Pulsanti mobile */
    .csd-actions button {
        padding: 12px 15px;
        font-size: 15px;
    }

    /* Icone mobile */
    .csd-icons {
        top: 5px;
        left: 5px;
    }

    .csd-icon {
        font-size: 20px;
        padding: 6px;
    }

    /* Promo text mobile */
    .csd-promo-text {
        font-size: 13px;
        padding: 12px 8px;
    }

    /* Input e textarea mobile */
    .csd-control-group input,
    .csd-control-group select,
    .csd-control-group textarea {
        font-size: 16px; /* Previene lo zoom su iOS */
        padding: 10px;
    }

    .csd-range-info {
        display: block;
        margin-left: 0;
        margin-top: 5px;
    }
}

/* Ulteriori ottimizzazioni per schermi molto piccoli */
@media (max-width: 480px) {
    .csd-thumb {
        flex: 0 0 calc(50% - 5px);
        height: 60px;
    }

    h1 {
        font-size: 24px;
    }

    h3 {
        font-size: 18px;
    }

    .csd-canvas-thumb span {
        display: none;
    }

    .csd-canvas-thumb i {
        margin-bottom: 0;
    }
}

/* Ottimizzazioni per tablet in landscape */
@media (min-width: 769px) and (max-width: 1024px) {
    .csd-thumb {
        flex: 0 0 calc(25% - 7.5px);
    }

    .csd-control-row {
        flex-wrap: wrap;
    }

    .csd-control-item {
        flex: 0 0 calc(50% - 7.5px);
    }

    .csd-alignment,
    .csd-letter-spacing {
        flex: 0 0 100%;
    }
}

/* Fix per touch devices */
@media (hover: none) and (pointer: coarse) {
    .csd-align-btn,
    .csd-thumb,
    .csd-icon,
    .csd-actions button {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
}