.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;
}

/* Section Number Styles */
.section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #4ecdc4 0%, #0073aa 100%);
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    margin-right: 8px;
    margin-left: 8px;
    box-shadow: 0 2px 4px rgba(0,115,170,0.3);
}

.csd-section-header h4 {
    display: flex;
    align-items: center;
    font-size: 16px;
    margin: 0;
    color: #333;
}
   
.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;
    margin-bottom: 3px;
}

.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-top: 5px;
    display: block;
    font-style: italic;
}

/* Stili specifici per i controlli dimensioni affiancati */
.csd-control-row .csd-control-item label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
    font-size: 14px;
}

.csd-control-row .csd-control-item input[type="number"],
.csd-control-row .csd-control-item select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    margin-bottom: 3px;
}

.csd-control-row .csd-range-info {
    font-size: 11px;
    color: #666;
    margin-top: 3px;
    display: block;
    font-style: italic;
}

/* 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: #4ecdc4;
    background-color: #f9f9f9;
}

.csd-radio-label input[type="radio"] {
    margin-right: 8px;
    width: auto;
}

.csd-radio-label input[type="radio"]:checked {
    accent-color: #4ecdc4;
}

.csd-radio-label input[type="radio"]:checked + span {
    font-weight: bold;
    color: #4ecdc4;
}

.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 - identica al plugin di riferimento */
.csd-gallery-thumbnails {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 0px;
    padding: 0px 0;
    justify-content: flex-start;
}

.csd-thumb {
    flex: 0 0 calc(20% - 8px);
    min-width: 55px;
    max-width: 55px;
    height: 55px;
    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: #4ecdc4;
    transform: scale(1.05);
}

.csd-thumb.active {
    border-color: #4ecdc4;
    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;
    line-height: 1.1;
}

.csd-canvas-thumb i {
    font-size: 24px;
    margin-bottom: 5px;
}

/* Quantity Row Container */
.csd-quantity-row {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-top: 5px;
}

/* Quantity Controls */
.csd-quantity-controls {
    display: flex;
    align-items: center;
}

.csd-quantity-btn {
    background: #4ecdc4;
    color: white;
    border: none;
    border-radius: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: all 0.2s ease;
}

.csd-quantity-btn:hover {
    background: #005a87;
    transform: translateY(-1px);
}

.csd-quantity-btn:active {
    transform: translateY(0);
    background: #004c70;
}

.csd-quantity-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

#csd-quantity {
    font-size: 16px;
    font-weight: bold;
}

/* Quantity Pricing Section */
.csd-quantity-pricing {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    flex: 1;
}

.csd-quantity-info {
    font-size: 14px;
    color: #495057;
    margin: 0;
}

.csd-per-piece-price {
    font-size: 13px;
    font-weight: bold;
    color: #4ecdc4;
    margin: 0;
    white-space: nowrap;
}

.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;
    }

    /* Layout dimensioni responsive - mobile stack */
    .csd-control-row {
        flex-direction: column;
        gap: 20px;
    }

    .csd-control-row .csd-range-info {
        font-size: 12px;
        margin-top: 5px;
    }

    /* Quantity e sconti uno sotto l'altro su mobile */
    .csd-quantity-row {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
        margin-top: 10px;
    }

    /* Quantity controls responsive */
    .csd-quantity-controls {
        justify-content: center;
        gap: 12px;
        flex-wrap: nowrap;
        order: 1;
    }

    .csd-quantity-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        flex-shrink: 0;
    }

    /* Sezione pricing sconti sotto */
    .csd-quantity-pricing {
        order: 2;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 8px;
        padding: 16px 12px;
    }

    .csd-quantity-info {
        font-size: 16px;
        text-align: center;
        justify-content: center;
    }

    .csd-per-piece-price {
        font-size: 15px;
        font-weight: bold;
        text-align: center;
    }
}

/* 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%;
    }
}

/* Material Grid Styles */
.csd-material-types.csd-icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.csd-material-card {
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 15px 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    position: relative;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.csd-material-card:hover {
    border-color: #4ecdc4;
    box-shadow: 0 2px 8px rgba(0,115,170,0.2);
    transform: translateY(-2px);
}

.csd-material-card.selected {
    border-color: #4ecdc4;
    background-color: #f0f8ff;
    box-shadow: 0 0 0 2px rgba(0,115,170,0.3);
}

.csd-material-icon {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    margin: 0 auto 10px;
    position: relative;
    background-color: #cccccc;
    border: 2px solid #999;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.15);
}

.csd-material-icon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    background: var(--cuttalo-logo-svg, url('data:image/svg+xml;charset=utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 509.25 509.25"><path fill="%23f0f0f0" d="M262.49,221.77l-8.39,8.96c-1.44,1.54-1.44,3.94,0,5.47l8.4,8.91c7.41,7.86,17.73,12.32,28.54,12.32h0.07c0.22,0,0.43,0.06,0.66,0.06c13.29,0,24.06-10.77,24.06-24.06s-10.77-24.06-24.06-24.06c-0.23,0-0.44,0.06-0.66,0.07v-0.07C280.26,209.37,269.91,213.86,262.49,221.77L262.49,221.77z"/><path fill="%23f0f0f0" d="M406.92,221.77l-8.39,8.96c-1.44,1.54-1.44,3.94,0,5.47l8.39,8.91c7.41,7.86,17.74,12.32,28.54,12.32h0.07c0.22,0,0.44,0.06,0.66,0.06c13.29,0,24.06-10.77,24.06-24.06s-10.77-24.06-24.06-24.06c-0.23,0-0.44,0.06-0.66,0.07v-0.07C424.69,209.37,414.33,213.86,406.92,221.77L406.92,221.77z"/><path fill="%23f0f0f0" d="M297.24,447.25c88.6,0,163.02-59.87,185.48-141.32c1.42-5.13-4.56-9.1-8.59-5.62c-10,8.61-22.36,14.5-35.87,16.31c-24.66,3.32-47.23-6.14-62.12-22.66c-9.11-10.11-21.96-16.04-35.57-16.04h-8.08c-13.81,0-26.63,6.27-35.96,16.45c-14.09,15.39-34.88,24.52-57.79,22.67c-30.92-2.49-60.77-31.25-64.27-62.07c-4.86-42.68,28.4-78.86,70.11-78.86h214.38c6.59,0,10.85-7.06,7.73-12.86C434.16,103,370.54,62,297.24,62c-55,0-104.58,23.09-139.68,60.06V94.02C157.57,76.34,143.23,62,125.54,62H83.57v79.59l0,0v0.2c0.12,23.87,5.95,46.33,16.08,66.23H26.32v33.48c0,14.24,11.55,25.79,25.79,25.79h22.18c11.35-0.26,21.74-4,30.39-10.05C106.09,362.41,191.73,447.25,297.24,447.25L297.24,447.25z"/></svg>')) center center no-repeat;
    background-size: 32px 32px;
    border-radius: 4px;
    opacity: 1.0;
}

.csd-material-label {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-top: 5px;
    text-align: center;
}

.csd-material-card input[type="radio"] {
    display: none;
}

/* Stencil types icon grid - same styling as materials */
.csd-stencil-types.csd-icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.csd-stencil-type-card {
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 15px 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    position: relative;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.csd-stencil-type-card:hover {
    border-color: #4ecdc4;
    box-shadow: 0 2px 8px rgba(0,115,170,0.2);
    transform: translateY(-2px);
}

.csd-stencil-type-card.selected {
    border-color: #4ecdc4;
    background-color: #f0f8ff;
    box-shadow: 0 0 0 2px rgba(0,115,170,0.3);
}

.csd-stencil-type-icon {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    margin: 0 auto 10px;
    position: relative;
    background-color: #f5f5f5;
    border: 2px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.csd-stencil-type-icon img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.csd-stencil-type-label {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-top: 5px;
    text-align: center;
}

.csd-stencil-type-card input[type="radio"] {
    display: none;
}

@media (max-width: 768px) {
    .csd-material-types.csd-icon-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 8px;
    }

    .csd-material-card {
        padding: 12px 8px;
        min-height: 80px;
    }

    .csd-material-icon {
        width: 35px;
        height: 35px;
    }

    .csd-material-label {
        font-size: 12px;
    }

    .csd-stencil-types.csd-icon-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 8px;
    }

    .csd-stencil-type-card {
        padding: 12px 8px;
        min-height: 80px;
    }

    .csd-stencil-type-icon {
        width: 35px;
        height: 35px;
    }

    .csd-stencil-type-label {
        font-size: 12px;
    }
}

/* Fix per touch devices */
@media (hover: none) and (pointer: coarse) {
    .csd-align-btn,
    .csd-thumb,
    .csd-icon,
    .csd-actions button,
    .csd-material-card,
    .csd-stencil-type-card {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    /* Migliora feedback tattile */
    .csd-material-card:active,
    .csd-stencil-type-card:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}