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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    background: #f7fafc;
    color: #2d3748;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.app-header {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 15px 30px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    height: 70px;
    display: flex;
    align-items: center;
}

.header-content {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    flex: 1;
}

.header-center {
    flex: 2;
    text-align: center;
}

.header-center h1 {
    font-size: 24px;
    font-weight: 700;
    color: #2d3748;
}

.header-right {
    flex: 1;
}

.toolbar {
    display: flex;
    gap: 10px;
}

.btn-icon {
    width: 42px;
    height: 42px;
    border: 2px solid #e2e8f0;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #667eea;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: #f7fafc;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.btn-icon:active {
    transform: translateY(0);
}

.btn-icon.btn-primary {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

.btn-icon.btn-primary:hover {
    background: #5568d3;
    border-color: #5568d3;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-icon.btn-success {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

.btn-icon.btn-success:hover {
    background: #059669;
    border-color: #059669;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

/* Main Layout */
.main-layout {
    display: flex;
    height: calc(100vh - 70px);
    background: #f7fafc;
    gap: 20px;
    padding: 20px;
}

/* Left Panel */
.sidebar-left {
    width: 320px;
    background: white;
    border-radius: 15px;
    padding: 25px;
    overflow-y: auto;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.product-info-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-row {
    display: flex;
    flex-direction: column;
}

.form-row label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #2d3748;
}

.input-field,
.select-field,
.textarea-field {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e2e8f0;
    background: #fff;
    font-size: 14px;
    font-family: inherit;
    border-radius: 8px;
    transition: border-color 0.2s;
}

.input-field:focus,
.select-field:focus,
.textarea-field:focus {
    outline: none;
    border-color: #667eea;
}

.dimensions-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 15px;
}

.dim-group {
    display: flex;
    flex-direction: column;
}

.dim-group label {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #2d3748;
}

.input-small {
    width: 100%;
    padding: 10px;
}

.dim-group#quantita-group {
	align-items: center; /* centra label e input verticalmente allineati in colonna */
}

#quantita {
	text-align: center; /* centra il valore digitato */
}

#quantita-group label {
	text-align: center; /* centra il testo 'Q.tà' */
}

.dim-range {
    font-size: 11px;
    color: #718096;
    margin-top: 4px;
}

.textarea-field {
    resize: vertical;
    min-height: 80px;
}

/* Center Panel */
.main-content {
    flex: 1;
    background: white;
    border-radius: 15px;
    padding: 25px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.options-header {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.options-header .form-row {
    flex: 1;
}

.options-header .category-tree-container {
    flex: 1;
    width: 100%;
    margin-bottom: 0;
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Option Item */
.option-item {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 15px;
    min-height: 60px;
    transition: all 0.2s;
    position: relative; /* Necessario per il badge ::before */
}

.option-item:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.option-item.selected {
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.option-item.warning {
    border-color: #ff9800;
}

/* Evidenziazione rossa per opzioni non più valide */
.option-item.invalid-selection {
    border: 3px solid #dc3545 !important;
    background: #fff5f5 !important;
    animation: pulse-red 1.5s ease-in-out infinite !important;
}

.option-item.invalid-selection:hover {
    border-color: #dc3545 !important;
    background: #ffe5e5 !important;
}

@keyframes pulse-red {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(220, 53, 69, 0);
    }
}

/* Evidenziazione arancione per caratteristiche obbligatorie mancanti */
.option-item.required-missing {
    border: 3px solid #ff8c00 !important;
    background: #fff8f0 !important;
    animation: pulse-orange 2s ease-in-out infinite !important;
}

.option-item.required-missing:hover {
    border-color: #ff8c00 !important;
    background: #ffe8d0 !important;
}

.option-item.required-missing::before {
    content: "⚠️ Obbligatorio";
    position: absolute;
    top: -12px;
    right: 10px;
    background: #ff8c00;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    z-index: 10;
}

@keyframes pulse-orange {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 140, 0, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(255, 140, 0, 0);
    }
}

.option-item.numeric-input-item {
    cursor: default;
}

.option-item.numeric-input-item:hover {
    transform: none;
    box-shadow: none;
}

.numeric-inputs {
    margin-top: 12px;
    width: 100%;
}

.numeric-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.numeric-input-row:last-child {
    margin-bottom: 0;
}

.numeric-input-row label {
    font-size: 13px;
    color: #718096;
    min-width: 120px;
    font-weight: 500;
}

.numeric-input-row input[type="number"],
.numeric-inputs input[type="number"],
.numeric-input-row input[type="text"],
.numeric-inputs input[type="text"] {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    transition: border-color 0.2s;
}

.numeric-input-row input[type="number"]:focus,
.numeric-inputs input[type="number"]:focus,
.numeric-input-row input[type="text"]:focus,
.numeric-inputs input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
}

/* Free Input Container */
.free-input-container {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid #e2e8f0;
}

.free-input-field {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    transition: border-color 0.2s;
}

.free-input-field:focus {
    outline: none;
    border-color: #667eea;
}

.option-icon {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    background: #f7fafc;
    border-radius: 8px;
    transition: all 0.3s ease;
}

/* Stile per icone SVG */
.option-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    color: #667eea;
    transition: all 0.3s ease;
}

.option:hover .option-icon {
    background: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.option:hover .option-icon svg {
    color: white;
}

.option.disabled .option-icon {
    background: #f1f5f9;
    opacity: 0.6;
}

.option.disabled .option-icon svg {
    color: #94a3b8;
}

.option-content {
    flex: 1;
    min-width: 0;
}

.option-title {
    font-size: 14px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 4px;
}

.option-value {
    font-size: 13px;
    color: #718096;
}

.option-arrow {
    color: #718096;
    font-size: 18px;
    flex-shrink: 0;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #718096;
    font-size: 14px;
}

/* Right Panel */
.sidebar-right {
    width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

/* Preview */
.preview-card {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.preview-title {
    font-size: 16px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 2px solid #e2e8f0;
}

.preview-image {
    width: 100%;
    height: 450px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f8fafc 0%, #edf2f7 100%);
    border-radius: 10px;
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
}

.window-svg {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

/* Quote dimensioni nell'SVG */
.dimensioni-quote text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Summary */
.summary-card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    flex: 1;
}

.summary-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.summary-table td {
    padding: 14px 12px;
    font-size: 14px;
    border-bottom: 1px solid #e2e8f0;
}

.summary-table tbody tr:last-child td {
    border-bottom: 2px solid #cbd5e0;
}

.supplement-row td {
    color: #667eea;
    font-size: 13px;
    padding: 10px 12px;
}

.supplement-row .price-cell {
    color: #48bb78;
}

.price-cell {
    text-align: right;
    font-weight: 600;
    color: #2d3748;
}

.summary-table tfoot {
    background: transparent;
}

.summary-table tfoot td {
    border: none;
}

.total-row td {
    padding: 16px 12px;
    font-weight: 600;
    font-size: 15px;
}

.total-row:first-child {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.total-row:first-child td:first-child {
    border-radius: 8px 0 0 0;
}

.total-row:first-child td:last-child {
    border-radius: 0 8px 0 0;
}

.total-row:last-child {
    background: linear-gradient(135deg, #5568d3 0%, #6438a0 100%);
    color: white;
    font-size: 17px;
    font-weight: 700;
}

.total-row:last-child td:first-child {
    border-radius: 0 0 0 8px;
}

.total-row:last-child td:last-child {
    border-radius: 0 0 8px 0;
}

.total-row .price-cell {
    color: white;
    font-weight: 700;
}

/* Feature Dropdown */
.feature-dropdown {
    background: white;
    border: 2px solid #667eea;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    margin-top: 8px;
    max-height: 450px;
    overflow: hidden;
    position: relative;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

/* Stile per option-item quando il dropdown è aperto */
.option-item.dropdown-open {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.option-item.dropdown-open .option-title,
.option-item.dropdown-open .option-value,
.option-item.dropdown-open .option-arrow {
    color: white;
}

.option-item.dropdown-open .option-icon {
    filter: brightness(0) invert(1);
}

.dropdown-search-container {
    padding: 12px;
    border-bottom: 2px solid #e2e8f0;
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 10;
}

.dropdown-search-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

.dropdown-search-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.dropdown-options-container {
    overflow-y: auto;
    max-height: 350px;
}

.feature-option {
    padding: 12px 20px;
    border-bottom: 1px solid #e2e8f0;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
}

.no-results-message {
    padding: 20px;
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
    font-style: italic;
}

.feature-option:last-child {
    border-bottom: none;
}

.feature-option:hover {
    background: #f7fafc;
}

.feature-option.selected {
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    font-weight: 600;
    color: #667eea;
}

.feature-option img {
    height: 40px;
    width: auto;
    margin-right: 10px;
    object-fit: contain;
    border-radius: 4px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #f7fafc;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Toggle Button */
.btn-toggle {
    width: 100%;
    padding: 14px 20px;
    border: 2px solid #e2e8f0;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
}

.btn-toggle:hover {
    border-color: #667eea;
    background: #f7fafc;
}

.btn-toggle[data-active="true"] {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-toggle[data-active="true"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.toggle-icon {
    font-size: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.toggle-icon svg {
    width: 20px;
    height: 20px;
}

.toggle-text {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Notifiche */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 24px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateX(100px);
    transition: all 0.3s ease;
}

.notification.show {
    opacity: 1;
    transform: translateX(0);
}

.notification-success {
    border-left: 4px solid #10b981;
    color: #059669;
}

.notification-error {
    border-left: 4px solid #ef4444;
    color: #dc2626;
}

/* Responsive */
@media (max-width: 1400px) {
    .sidebar-left {
        width: 280px;
    }
    
    .sidebar-right {
        width: 350px;
    }
}

/* ========================================
   CATEGORY TREE VIEW
   ======================================== */

.category-tree-container {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

.category-tree-container label {
    display: flex;
    align-items: center;
    font-size: 16px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 15px;
}

.category-tree-container label svg {
    color: #f59e0b;
    stroke: currentColor;
}

.category-tree {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    background: #f8fafc;
}

.tree-loading {
    text-align: center;
    padding: 40px;
    color: #94a3b8;
    font-style: italic;
}

.tree-node {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    margin: 2px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.tree-node:hover {
    background: #e0e7ff;
}

.tree-node[style*="cursor: pointer"]:hover {
    background: #c7d2fe;
    transform: translateX(2px);
}

.tree-expand {
    display: inline-block;
    width: 20px;
    text-align: center;
    font-size: 12px;
    color: #64748b;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.tree-expand.expanded {
    transform: rotate(90deg);
}

.tree-spacer {
    display: inline-block;
    width: 20px;
}

.tree-icon {
    margin: 0 8px;
    font-size: 16px;
}

.tree-folder-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.tree-folder-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    color: #f59e0b;
    transition: all 0.3s ease;
}

.tree-node:hover .tree-folder-icon svg {
    color: #d97706;
    transform: scale(1.1);
}

.tree-expand.expanded + .tree-folder-icon svg {
    color: #ea580c;
}

.tree-product-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin: 0 8px;
}

.tree-product-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    color: #667eea;
    transition: all 0.3s ease;
}

.tree-product:hover .tree-product-icon svg {
    color: #5568d3;
    transform: scale(1.1);
}

.tree-product.selected .tree-product-icon svg {
    color: white;
    filter: drop-shadow(0 0 2px rgba(255,255,255,0.5));
}

.tree-label {
    flex: 1;
    font-size: 14px;
    color: #334155;
    font-weight: 500;
}

.tree-count {
    font-size: 12px;
    color: #94a3b8;
    margin-left: 8px;
}

.tree-children {
    overflow: hidden;
}

.tree-product {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    margin: 2px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.tree-product:hover {
    background: #dbeafe;
}

.tree-product.selected {
    background: #667eea;
    color: white;
}

.tree-product.selected .tree-label {
    color: white;
    font-weight: 600;
}

.tree-product.selected .tree-icon {
    filter: brightness(0) invert(1);
}

/* Scrollbar per il tree */
.category-tree::-webkit-scrollbar {
    width: 8px;
}

.category-tree::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.category-tree::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.category-tree::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

@media (max-width: 1200px) {
    .sidebar-left {
        width: 250px;
    }
    
    .sidebar-right {
        width: 300px;
    }
    
    .category-tree {
        max-height: 300px;
    }
}

/* ========================================
   VALIDAZIONE DIMENSIONI FUORI MISURA
   ======================================== */

/* Bordo rosso per campi fuori misura */
.input-field.fuori-misura {
    border-color: #dc3545 !important;
    border-width: 3px !important;
    background: #fff5f5 !important;
}

/* Messaggio di avviso fuori misura */
.fuori-misura-warning {
    margin-top: -10px;
    margin-bottom: 15px;
    padding: 10px 15px;
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    color: #856404;
    font-weight: 600;
    font-size: 14px;
    text-align: center;
    animation: pulse-warning 2s ease-in-out infinite;
}

@keyframes pulse-warning {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(255, 193, 7, 0);
    }
}
