/* ============================================================
   FORM EVENTO - CSS COMPLETO (VERSIONE OTTIMIZZATA)
   ============================================================ */

/* ============================================================
   LAYOUT GENERALE
   ============================================================ */
.fe-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.fe-two-columns {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

/* COLONNA SINISTRA - FORM (2/3) - SCORREVOLE */
.fe-col-form {
    flex: 0 0 66.666%;
    max-width: 66.666%;
    max-height: 90vh;
    overflow-y: auto;
    padding-right: 10px;
}

.fe-col-form::-webkit-scrollbar {
    width: 6px;
}
.fe-col-form::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}
.fe-col-form::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}
.fe-col-form::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* COLONNA DESTRA - LIMITI (1/3) - FISSA */
.fe-col-limits {
    flex: 0 0 33.333%;
    max-width: 33.333%;
    position: sticky;
    top: 20px;
    align-self: flex-start;
}

.fe-limits-sidebar {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 20px;
}
.fe-limits-sidebar h3 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 18px;
    color: #111;
    border-bottom: 2px solid #111;
    padding-bottom: 10px;
}

/* ============================================================
   CAMPI FORM
   ============================================================ */
.fe-form {
    width: 100%;
}
.fe-fields-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}
.fe-field {
    margin-bottom: 4px;
}
.fe-field label {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
}
.fe-required {
    color: #b00000;
}
.fe-field input,
.fe-field textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-sizing: border-box;
    font-size: 15px;
}
.fe-field textarea {
    resize: vertical;
}

/* ============================================================
   PRODOTTI - LAYOUT A LISTA VERTICALE (DESKTOP)
   ============================================================ */
.fe-products-section {
    margin-top: 28px;
}
.fe-products-section h3 {
    margin-bottom: 12px;
}

.fe-products-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.fe-small-button {
    background: #ededed;
    color: #111;
    border: 1px solid #ccc;
    padding: 8px 14px;
    border-radius: 5px;
    cursor: pointer;
}
.fe-small-button:hover {
    background: #ddd;
}

/* Griglia: su desktop diventa lista verticale */
.fe-products-grid {
    display: block;
}

/* Singolo prodotto - layout a lista */
.fe-product-item {
    display: flex;
    flex-direction: column;
    padding: 0px 12px;
    margin-bottom: 4px;
    border-radius: 0px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: background 0.2s ease;
    background: rgba(255, 255, 255, 0.5);
}
.fe-product-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

.fe-product-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    direction: ltr;
}

.fe-product-code-wrap {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-align: left;
    justify-content: flex-start;
}

.fe-product-code {
    font-weight: 700;
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
    text-align: left;
}

.fe-product-description {
    font-weight: 400;
    font-size: 12px;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    text-align: left;
    flex-shrink: 1;
}

.fe-product-price {
    font-weight: 700;
    font-size: 14px;
    min-width: 80px;
    text-align: right;
    flex-shrink: 0;
}

.fe-product-qty-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ============================================================
   SELEZIONE QUANTITÀ
   ============================================================ */
.fe-qty-selector {
    display: flex;
    align-items: center;
    gap: 2px;
}
.fe-qty-btn {
    width: 24px;
    height: 24px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: transparent;
    color: #333;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}
.fe-qty-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}
.fe-qty-btn:active {
    background: rgba(0, 0, 0, 0.15);
}
.fe-qty-input {
    width: 40px;
    height: 24px;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: transparent;
    color: #333;
    font-size: 13px;
    padding: 0;
    -moz-appearance: textfield;
}
.fe-qty-input::-webkit-outer-spin-button,
.fe-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Sfondo scuro per categorie speciali */
.fe-product-category[style*="background-color"] .fe-product-item {
    background: rgba(255, 255, 255, 0.12);
}
.fe-product-category[style*="background-color"] .fe-product-item:hover {
    background: rgba(255, 255, 255, 0.2);
}
.fe-product-category[style*="background-color"] .fe-qty-btn {
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
}
.fe-product-category[style*="background-color"] .fe-qty-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}
.fe-product-category[style*="background-color"] .fe-qty-input {
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
}
.fe-product-category[style*="background-color"] .fe-qty-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.6);
}

/* Prodotto disabilitato */
.fe-product-item.fe-product-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.fe-product-item.fe-product-disabled:hover {
    transform: none !important;
    box-shadow: none !important;
}
.fe-product-item.fe-product-disabled .fe-qty-selector {
    opacity: 0.5;
    pointer-events: none;
}

/* ============================================================
   CATEGORIE
   ============================================================ */
.fe-product-category {
    margin-bottom: 12px;
    padding: 8px 0;
}
.fe-category-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 8px;
    padding-bottom: 4px;
    opacity: 0.85;
}

/* Gruppo limite */
.fe-limit-group {
    border-radius: 10px;
    padding: 16px 16px 12px;
    margin-bottom: 20px;
}
.fe-limit-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #111;
    padding-bottom: 8px;
    margin-bottom: 14px;
    font-size: 16px;
    font-weight: 700;
}

/* ============================================================
   COLONNA LIMITI (DESTRA)
   ============================================================ */
.fe-limits-container {
    background: transparent;
    padding: 0;
    margin: 0;
}
.fe-limits-container h4 {
    display: none;
}
.fe-limits-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.fe-limits-list li {
    display: block;
    padding: 12px 14px;
    border-bottom: 1px solid #e9ecef;
    background: #fff;
    border-radius: 6px;
    margin-bottom: 8px;
    transition: background 0.3s ease;
}
.fe-limits-list li:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.fe-limit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    margin-bottom: 4px;
}
.fe-limit-name {
    font-size: 14px;
    color: #333;
}
.fe-limit-amount {
    font-size: 14px;
    color: #111;
}

.fe-limit-total {
    font-size: 13px;
    color: #333;
    margin-top: 2px;
}
.fe-limit-total strong {
    color: #111;
}

.fe-limit-residuo {
    font-size: 13px;
    color: #2e7d32;
    margin: 4px 0 2px;
}
.fe-limit-residuo strong {
    color: #111;
}
.fe-residuo-esaurito {
    color: #a40000;
    font-weight: 700;
    font-size: 12px;
}

.fe-limit-progress {
    width: 100%;
    height: 6px;
    background: #e9ecef;
    border-radius: 3px;
    margin: 6px 0 4px;
    overflow: hidden;
}
.fe-limit-progress-bar {
    height: 100%;
    background: #2e7d32;
    border-radius: 3px;
    transition: width 0.3s ease;
}
.fe-limits-list li.fe-category-exceeded .fe-limit-progress-bar {
    background: #a40000;
}

/* Limite superato */
.fe-limits-list li.fe-category-exceeded {
    background: #fdeaea !important;
    border: 1px solid #a40000 !important;
}
.fe-limits-list li.fe-category-exceeded .fe-limit-name {
    color: #a40000;
}
.fe-limits-list li.fe-category-exceeded .fe-limit-total strong {
    color: #a40000;
}
.fe-limits-list li.fe-category-exceeded .fe-limit-amount {
    color: #a40000;
}
.fe-limits-list li.fe-category-exceeded {
    color: #a40000;
}

.fe-category-exceeded-badge {
    background: #a40000;
    color: #fff;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 8px;
}

.fe-limits-total-sidebar {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 2px solid #111;
    text-align: right;
}
.fe-total-selezionato {
    font-size: 16px;
}
.fe-total-selezionato strong {
    color: #111;
}

/* ============================================================
   MESSAGGI DI ERRORE REGOLE SPECIALI
   ============================================================ */
.fe-special-error-message {
    display: none;
    font-size: 13px;
    font-weight: 700;
    color: #ff0000;
    background: #fdeaea;
    padding: 4px 12px;
    border-radius: 4px;
    margin-left: 12px;
    border: 1px solid #a40000;
    white-space: normal;
    max-width: 100%;
}
.fe-special-error-message.is-visible {
    display: inline-block;
}

.fe-special-rule-violation {
    border: 2px solid #e65100 !important;
    background: #390000 !important;
    border-radius: 6px;
    padding: 10px !important;
}
.fe-special-rule-violation .fe-category-title {
    color: #e65100;
}

/* ============================================================
   MESSAGGIO LIMITE GENERALE
   ============================================================ */
.fe-limit-message {
    display: none;
    color: #a40000;
    font-weight: 800;
    background: #fdeaea !important;
    border-left: 4px solid #a40000;
    padding: 8px 12px;
    border-radius: 4px;
    margin-bottom: 10px;
}
.fe-limit-message.is-visible {
    display: block;
}

/* ============================================================
   PRIVACY E SUBMIT
   ============================================================ */
.fe-privacy {
    margin-top: 24px;
    margin-bottom: 20px;
}
.fe-privacy label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.fe-submit {
    background: #111;
    color: #fff;
    border: none;
    padding: 13px 28px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.fe-submit:hover {
    background: #333;
}
.fe-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.fe-submit-spinner {
    display: none;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: fe-spin 0.8s linear infinite;
}
.fe-submit.is-loading .fe-submit-spinner {
    display: inline-block;
}
@keyframes fe-spin {
    to {
        transform: rotate(360deg);
    }
}
.fe-over-limit .fe-submit {
    opacity: 0.55;
}

/* ============================================================
   RISULTATO FORM
   ============================================================ */
.fe-result-box {
    margin-bottom: 20px;
    padding: 16px;
    border-radius: 8px;
    border-left: 4px solid transparent;
}
.fe-result-box.is-success {
    background: #e8f7e8;
    border-left-color: #207520;
    color: #207520;
}
.fe-result-box.is-error {
    background: #fdeaea;
    border-left-color: #a40000;
    color: #a40000;
}
.fe-result-message {
    font-weight: 700;
    margin-bottom: 12px;
}
.fe-result-actions {
    margin-top: 10px;
}
.fe-form.is-hidden {
    display: none;
}

/* ============================================================
   POPUP PRIVACY
   ============================================================ */
.fe-privacy-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
}
.fe-privacy-popup-content {
    background: #fff;
    max-width: 600px;
    width: 100%;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-height: 80vh;
    overflow-y: auto;
    font-family: Arial, sans-serif;
    color: #333;
    line-height: 1.6;
    margin: 20px;
}
.fe-privacy-popup-content h3 {
    margin-top: 0;
    font-size: 22px;
}
.fe-privacy-popup-actions {
    margin-top: 20px;
    text-align: right;
}
.fe-privacy-popup-actions .fe-button {
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}
.fe-privacy-popup-actions .fe-button#fe-privacy-accept {
    background: #111;
    color: #fff;
}
.fe-privacy-popup-actions .fe-button#fe-privacy-accept:hover {
    background: #333;
}
.fe-privacy-popup-actions .fe-button-secondary {
    background: #ccc;
    color: #111;
    margin-left: 10px;
}
.fe-privacy-popup-actions .fe-button-secondary:hover {
    background: #aaa;
}

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 768px) {
    .fe-col-limits {
        display: none !important;
    }
    .fe-col-form {
        flex: 0 0 100%;
        max-width: 100%;
        max-height: none;
        overflow-y: visible;
        padding-right: 0;
        padding-bottom: 90px;
    }
    .fe-fields-grid {
        grid-template-columns: 1fr;
    }
    .fe-products-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .fe-product-item {
        flex-direction: column;
        padding: 8px 10px;
    }
    .fe-product-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    .fe-product-code-wrap {
        flex-wrap: wrap;
        overflow: visible;
    }
    .fe-product-description {
        white-space: normal;
        text-overflow: clip;
        overflow: visible;
    }
    .fe-product-price {
        text-align: left;
        min-width: auto;
    }
    .fe-limits-list li {
        font-size: 13px;
        padding: 8px 10px;
    }
    .fe-limit-header {
        flex-wrap: wrap;
    }
    .fe-special-error-message {
        font-size: 12px;
        margin-left: 0;
        display: block;
        margin-top: 6px;
    }
    .fe-special-error-message.is-visible {
        display: block;
    }
    .fe-wrapper {
        padding: 12px;
    }
    .fe-privacy-popup-content {
        margin: 15px;
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .fe-products-grid {
        grid-template-columns: 1fr;
    }
    .fe-products-actions {
        flex-direction: column;
    }
    .fe-two-columns {
        gap: 15px;
    }
    .fe-wrapper {
        padding: 10px;
    }
}

/* ============================================================
   MOBILE - ACCORDION
   ============================================================ */
.fe-accordion-toggle {
    display: none;
    background: none;
    border: none;
    border-bottom: 2px solid #111;
    font-size: 18px;
    font-weight: 800;
    color: #111;
    cursor: pointer;
    width: 100%;
    text-align: left;
    padding: 14px 0;
    margin-bottom: 0;
    position: relative;
    font-family: inherit;
}
.fe-accordion-toggle::after {
    content: '▼';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    transition: transform 0.3s ease;
}
.fe-accordion-toggle.active::after {
    transform: translateY(-50%) rotate(180deg);
}
.fe-accordion-content {
    display: block;
    padding: 12px 0;
}
.fe-accordion-content.collapsed {
    display: none;
}
@media (max-width: 768px) {
    .fe-accordion-toggle {
        display: block;
    }
    .fe-product-category .fe-category-title {
        display: none !important;
    }
    .fe-product-category {
        margin-bottom: 8px;
    }
}

/* ============================================================
   MOBILE - SCHEDA LIMITI IN BASSO
   ============================================================ */
.fe-limits-bottom-sheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #f8f9fa;
    border-top: 2px solid #111;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 80vh;
    overflow-y: auto;
}
.fe-limits-bottom-sheet.open {
    transform: translateY(0);
    max-height: 80vh;
}
.fe-limits-bottom-sheet.closed {
    transform: translateY(calc(100% - 56px));
}
.fe-limits-bottom-sheet::-webkit-scrollbar {
    width: 4px;
}
.fe-limits-bottom-sheet::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 2px;
}
.fe-limits-bottom-sheet::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}
.fe-limits-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px 16px 8px;
    cursor: pointer;
    user-select: none;
    touch-action: none;
    flex-wrap: wrap;
    gap: 6px;
}
.fe-limits-handle-bar {
    width: 40px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
    flex-shrink: 0;
}
.fe-limits-handle-text {
    font-size: 14px;
    font-weight: 700;
    color: #111;
    margin-left: 12px;
    flex: 1;
}
.fe-limits-handle-arrow {
    font-size: 12px;
    color: #666;
    margin-left: 4px;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}
.fe-limits-bottom-sheet.open .fe-limits-handle-arrow {
    transform: rotate(180deg);
}
.fe-limits-close-btn {
    display: block;
    width: 100%;
    padding: 10px;
    background: transparent;
    border: none;
    border-top: 1px solid #e9ecef;
    color: #666;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    font-family: inherit;
}
.fe-limits-close-btn:hover {
    background: #f1f1f1;
}
.fe-limits-sheet-content {
    padding: 0 16px 10px;
}
.fe-limits-sheet-content .fe-limits-container {
    max-height: 50vh;
    overflow-y: auto;
}
.fe-limits-sheet-content .fe-limits-container::-webkit-scrollbar {
    width: 4px;
}
.fe-limits-sheet-content .fe-limits-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 2px;
}
.fe-limits-sheet-content .fe-limits-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}
@media (max-width: 768px) {
    .fe-limits-bottom-sheet {
        display: block;
    }
}

/* ============================================================
   LAYOUT PRODOTTI A LISTA (DESKTOP) - CON ALLINEAMENTO FORZATO
   ============================================================ */
@media (min-width: 769px) {
    .fe-products-grid {
        display: block !important;
    }
    .fe-product-item {
        display: flex !important;
        flex-direction: column !important;
        padding: 0px 12px !important;
        margin-bottom: 4px !important;
        border-radius: 0px !important;
        border: 1px solid rgba(0,0,0,0.06) !important;
        background: rgba(255,255,255,0.5) !important;
    }
    .fe-product-row {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        width: 100% !important;
        direction: ltr !important;
    }
    .fe-product-code-wrap {
        display: flex !important;
        align-items: baseline !important;
        gap: 4px !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        overflow: hidden !important;
        text-align: left !important;
        justify-content: flex-start !important;
    }
    .fe-product-code {
        font-weight: 700 !important;
        font-size: 14px !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        text-align: left !important;
    }
    .fe-product-description {
        font-weight: 400 !important;
        font-size: 12px !important;
        opacity: 0.8 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        min-width: 0 !important;
        text-align: left !important;
        flex-shrink: 1 !important;
    }
    .fe-product-price {
        font-weight: 700 !important;
        font-size: 14px !important;
        min-width: 80px !important;
        text-align: right !important;
        flex-shrink: 0 !important;
    }
    .fe-product-qty-row {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
    }
}

/* ============================================================
   MOBILE: prodotto in colonna
   ============================================================ */
@media (max-width: 768px) {
    .fe-products-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    .fe-product-item {
        flex-direction: column !important;
        padding: 8px 10px !important;
    }
    .fe-product-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 4px !important;
    }
    .fe-product-code-wrap {
        flex-wrap: wrap !important;
        overflow: visible !important;
    }
    .fe-product-description {
        white-space: normal !important;
        text-overflow: clip !important;
        overflow: visible !important;
    }
    .fe-product-price {
        text-align: left !important;
        min-width: auto !important;
    }
}

@media (max-width: 480px) {
    .fe-products-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================================
   EVIDENZIA LIMITE SUPERATO (colonna sinistra)
   ============================================================ */
.fe-limit-exceeded {
    border: 2px solid #a40000 !important;
    background-color: #fdeaea !important;
    border-radius: 8px;
    transition: background-color 0.3s ease;
}

.fe-limit-exceeded .fe-limit-group-header {
    border-bottom-color: #a40000 !important;
}

.fe-limit-exceeded .fe-limit-group-header span {
    color: #a40000 !important;
}

.fe-limit-exceeded .fe-limit-group-header span .fe-limit-amount {
    color: #a40000 !important;
}

.fe-result-box.is-info {
    background: #e3f2fd;
    border-left-color: #2196f3;
    color: #0d47a1;
}