/* ============================================================
   1. STRUTTURA E CONTENITORI GENERALI
   ============================================================ */
#tb-teatro-container {
    max-width: 800px;
    margin: 20px auto;
    font-family: sans-serif;
    text-align: center;
}

.tb-mappa-griglia {
    display: inline-block;
    padding: 20px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.tb-palco {
    width: 80%;
    margin: 0 auto 40px;
    padding: 15px;
    background: #333;
    color: #fff;
    border-radius: 0 0 50px 50px;
    font-weight: bold;
    letter-spacing: 2px;
}

/* ============================================================
   2. MAPPA POSTI (POLTRONCINE E STATI)
   ============================================================ */
.tb-fila {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

.tb-label-fila {
    width: 25px;
    text-align: center;
    font-weight: bold;
    color: #777;
    flex-shrink: 0;
}

.tb-posto {
    width: 24px;
    height: 24px;
    margin: 3px;
    border-radius: 50% 50% 5px 5px;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s, background 0.3s;
    border: 1px solid rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.tb-posto-libero { background-color: #ffffff; border: 2px solid #4CAF50; }
.tb-posto-libero:hover { background-color: #e8f5e9; transform: scale(1.2); z-index: 5; }

.tb-posto-occupato { 
    background-color: #ddd;
    border: 2px solid #999; 
    cursor: not-allowed; 
    opacity: 0.6; 
}

.tb-posto-bloccato {
    background: repeating-linear-gradient(
        135deg,
        #5f6b73,
        #5f6b73 6px,
        #77838c 6px,
        #77838c 12px
    );
    border: 2px solid #465058;
    cursor: not-allowed;
    opacity: 0.85;
    pointer-events: none;
}

.backend-seat.tb-posto-bloccato {
    pointer-events: auto;
}

.tb-seat-mutation-pending .backend-seat {
    pointer-events: none !important;
    cursor: wait !important;
}

.tb-seat-mutation-pending .tb-popup-tariffe-backend {
    pointer-events: none;
    opacity: 0.9;
}

body.tb-seat-mutation-pending {
    overflow: hidden !important;
}

.tb-posto.selected {
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
    transform: scale(1.1);
}

.tb-posto.selected-intero { 
    background-color: #2196F3 !important; 
    border-color: #0d47a1 !important; 
    color: white !important; 
}

.tb-posto.selected-ridotto { 
    background-color: #FF9800 !important; 
    border-color: #e65100 !important; 
    color: white !important; 
}

.tb-posto.selected-omaggio {
    background-color: #46b450 !important;
    border-color: #2e7d32 !important;
    color: white !important;
}

.tb-posto.tb-corridoio { margin-right: 35px; }

/* Tooltip numerato */
.tb-tooltip {
    visibility: hidden;
    background-color: #333;
    color: #fff;
    text-align: center;
    padding: 2px 5px;
    border-radius: 4px;
    position: absolute;
    z-index: 10;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    white-space: nowrap;
}
.tb-posto:hover .tb-tooltip { visibility: visible; }

/* ============================================================
   3. POPUP TARIFFE E RIEPILOGO SELEZIONE
   ============================================================ */
/* Container del popup delle tariffe */
.tb-popup-tariffe {
    position: absolute;
    z-index: 9999;
    background: #ffffff;
    border: 1px solid #ccc;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    width: 180px;
    text-align: center;
}

/* Stile per i bottoni Intero/Ridotto nel popup */
.tb-btn-tariffa {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.tb-btn-tariffa[data-type="Intero"] {
    background: #2271b1;
    color: white;
}

.tb-btn-tariffa[data-type="Ridotto"] {
    background: #FF9800;
    color: white;
}

.tb-btn-tariffa[data-type="Omaggio"] {
    background: #46b450;
    color: white;
}

.tb-btn-tariffa:hover {
    filter: brightness(1.1);
}

/* Stile per il checkbox Socio ARCI */
.tb-popup-tariffe label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 10px;
    cursor: pointer;
    color: #333;
}

#tb-selection-summary { margin-top: 30px; padding: 20px; border-top: 2px solid #eee; }

#tb-list-seats {
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.tb-selected-item {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
}
.item-intero { background-color: #2271b1; border-left: 5px solid #0d47a1; }
.item-ridotto { background-color: #FF9800; border-left: 5px solid #e65100; }

/* ============================================================
   4. MODULO DI PRENOTAZIONE (FORM)
   ============================================================ */
.tb-form-row { display: flex; gap: 10px; margin-bottom: 15px; }
.tb-form-row input { flex: 1; padding: 10px; border: 1px solid #ccc; border-radius: 4px; }

#tb-final-summary { background: #f1f1f1; padding: 15px; margin: 15px 0; text-align: left; border-radius: 4px; }

#tb-confirm-booking {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 12px 25px;
    cursor: pointer;
    font-size: 16px;
    border-radius: 4px;
    font-weight: bold;
}
#tb-confirm-booking:disabled { background-color: #ccc !important; cursor: not-allowed; }

/* ============================================================
   5. LOADER MODALE (RISOLUZIONE CENTRATURA)
   ============================================================ */
#tb-booking-loader {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.8) !important;
    z-index: 999999 !important;
    display: none; /* Gestito via JS con display: flex */
    align-items: center !important;
    justify-content: center !important;
    margin: 0 !important;
}

.tb-loader-content {
    background: #fff !important;
    padding: 40px !important;
    border-radius: 15px !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
    text-align: center !important;
    width: 300px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
}

/* Spinner personalizzato per evitare conflitti con temi/WP */
.tb-custom-spinner,
.tb-spinner {
    width: 50px !important;
    height: 50px !important;
    border: 5px solid #f3f3f3 !important;
    border-top: 5px solid #2271b1 !important;
    border-radius: 50% !important;
    animation: tb-spin 1s linear infinite !important;
    margin-bottom: 20px !important;
}

@keyframes tb-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================================
   6. ADMIN DASHBOARD & TABELLE
   ============================================================ */
.wp-list-table.prenotazioni-table {
    table-layout: fixed !important;
    width: 100% !important;
}

.wp-list-table.prenotazioni-table th, 
.wp-list-table.prenotazioni-table td {
    padding: 6px 4px !important;
    font-size: 11px !important;
    vertical-align: middle !important;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-do-checkin { background: #4caf50 !important; color: #fff !important; border-color: #388e3c !important; }
.btn-undo-checkin { background: #f44336 !important; color: #fff !important; border-color: #d32f2f !important; }

.btn-whatsapp-single {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

.tb-icon-whatsapp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    vertical-align: middle;
}

.tb-icon-whatsapp svg {
    display: block;
}

.tb-icon-whatsapp-disabled {
    opacity: 0.6;
}

/* ============================================================
   7. RESPONSIVE
   ============================================================ */
/* Stile per i numeri delle colonne in alto */
.tb-header-numeri {
    margin-bottom: 5px;
}

.tb-label-numero {
    width: 24px;      /* Identico a .tb-posto */
    margin: 3px;      /* Identico a .tb-posto */
    border: 2px solid transparent; /* Compensa il bordo dei posti per l'allineamento */
    font-size: 11px;
    font-weight: bold;
    color: #777;
    text-align: center;
    display: inline-block;
    flex-shrink: 0;
    box-sizing: border-box;
}

/* ============================================================
   7.bis RESPONSIVE DESIGN (Ottimizzazione Mobile)
   ============================================================ */

@media screen and (max-width: 600px) {
    #tb-teatro-container {
        box-sizing: border-box;
        max-width: 100%;
        padding: 5px;
        margin: 10px auto;
        width: 100%;
    }

    /* La scala include posti, numeri, etichette e corridoio: la mappa non viene tagliata. */
    .tb-responsive-wrapper {
        --tb-mobile-seat-size: clamp(16px, 5vw, 20px);
        box-sizing: border-box;
        max-width: 100%;
        background: #f9f9f9;
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: 12px 4px;
    }

    .tb-mappa-griglia {
        box-sizing: border-box;
        width: 100%;
        max-width: 100%;
        padding: 0;
        border: none;
        display: block;
        min-width: 0;
    }

    .tb-fila {
        width: 100%;
        min-width: 0;
        margin-bottom: 6px;
    }

    /* Ogni posto resta toccabile, ma la sala standard fino a 12 posti entra nel display. */
    .tb-posto {
        flex: 0 0 var(--tb-mobile-seat-size);
        width: var(--tb-mobile-seat-size);
        height: var(--tb-mobile-seat-size);
        margin: 1px;
        font-size: 9px;
    }

    .tb-posto[style*="margin-right"],
    .tb-label-numero[style*="margin-right"] {
        margin-right: 10px !important;
    }

    .tb-label-fila {
        flex: 0 0 18px;
        width: 18px;
        font-size: 10px;
    }

    .tb-label-numero {
        flex: 0 0 var(--tb-mobile-seat-size);
        width: var(--tb-mobile-seat-size);
        margin: 1px;
        font-size: 9px;
    }

    .tb-palco {
        box-sizing: border-box;
        width: 100%;
        font-size: 13px;
        padding: 10px;
        margin-bottom: 20px;
    }

    /* Le sale eccezionalmente larghe restano consultabili senza rimpicciolire i posti sotto la soglia touch. */
    .tb-mappa-griglia.tb-mappa-wide {
        width: max-content;
        min-width: 100%;
    }
    .tb-mappa-griglia.tb-mappa-wide .tb-fila {
        width: max-content;
    }

    /* Legenda e Riepilogo: disposti in verticale */
    .tb-legenda {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 15px;
    }

    /* Form di prenotazione: input a larghezza intera */
    .tb-form-row {
        flex-direction: column;
        gap: 10px;
    }

    .tb-form-row input {
        width: 100% !important;
        box-sizing: border-box;
        height: 45px; /* Più alto per facilitare il touch */
    }

    .tb-btn-submit {
        width: 100%;
        padding: 15px;
        font-size: 16px;
    }

    /* Popup tariffe più grande per il pollice */
    .tb-popup-tariffe {
        width: 180px;
        padding: 12px;
    }

    .tb-popup-tariffe button {
        padding: 12px;
        margin: 5px 0;
        font-size: 14px;
    }

    /* Adattamento modali admin e loader */
    .tb-loader-content, .tb-modal-content {
        width: 95% !important;
        margin: 10px;
    }
}

/* ============================================================
   8. MODALE ADMIN RIEPILOGO CHECK-IN
   ============================================================ */
.tb-modal { 
    position: fixed; 
    z-index: 99999; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.7); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    backdrop-filter: blur(3px); 
}

.tb-modal-content { 
    background: #fff; 
    border-radius: 8px; 
    width: 450px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.3); 
    overflow: hidden; 
    animation: tbSlideDown 0.3s ease-out; 
}

@keyframes tbSlideDown { 
    from { transform: translateY(-50px); opacity: 0; } 
    to { transform: translateY(0); opacity: 1; } 
}

.tb-modal-header { 
    background: #2271b1; 
    color: #fff; 
    padding: 15px 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

.tb-modal-header h2 { 
    color: #fff !important; 
    margin: 0 !important; 
    font-size: 18px !important; 
}

.tb-close-modal-btn { 
    font-size: 28px; 
    cursor: pointer; 
    line-height: 1; 
}

.tb-modal-body { 
    padding: 20px; 
}

.tb-info-row { 
    margin-bottom: 15px; 
    border-bottom: 1px dashed #eee; 
    padding-bottom: 10px; 
    text-align: left;
}

.tb-info-row strong { 
    display: block; 
    color: #666; 
    font-size: 11px; 
    text-transform: uppercase; 
    margin-bottom: 5px; 
}

.tb-info-row p { 
    margin: 0; 
    font-size: 16px; 
    font-weight: 500; 
    color: #222; 
}

.tb-total-row { 
    border: none; 
    background: #f0f6fb; 
    padding: 15px; 
    border-radius: 6px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

.tb-total-row strong { 
    font-size: 14px; 
    color: #2271b1; 
    text-transform: none;
}

#modal-totale { 
    font-size: 24px; 
    font-weight: bold; 
    color: #2271b1; 
}

.tb-modal-footer { 
    padding: 15px 20px; 
    background: #f9f9f9; 
    text-align: right; 
    border-top: 1px solid #eee; 
    display: flex; 
    gap: 10px; 
    justify-content: flex-end; 
}

#btn-modal-confirm { 
    font-weight: bold; 
}