.sagra-app-container {
    max-width: 600px;
    margin: 0 auto;
    font-family: system-ui, -apple-system, sans-serif;
    padding-bottom: 20px;
    box-sizing: border-box;
    background: #f8f9fa; /* Sfondo grigio della tab */
}
@media (min-width: 768px) {
    .sagra-app-container {
        max-width: 1200px; /* Su tablet si allarga per far entrare due colonne comode */
    }
}

/* Header standard per TUTTE le schede Frontend (Menu, Cassa, Cucina) */
.sagra-app-header {
    text-align: center;
    padding: 20px;
    background: #e63946; /* Rosso Sagra */
    color: white;
    border-radius: 10px 10px 0 0;
    margin-bottom: 0;
}

.sagra-app-header h2 {
    margin: 0 0 5px 0;
    color: white;
    font-size: 1.8rem;
}
.sagra-app-header p {
    margin: 0;
    font-size: 1rem;
    opacity: 0.9;
}

/* Lista Piatti */
.sagra-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    padding: 6px 10px;
    margin-bottom: 6px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

.sagra-item.is-esaurito {
    opacity: 0.5;
    background: #f8fafc;
}

.sagra-item-title {
    margin: 0 0 2px 0;
    font-size: 0.95rem;
    font-weight: bold;
    color: #1e293b;
}

.sagra-item-price {
    color: #2e7d32;
    font-weight: 800;
    font-size: 0.95rem;
}

/* Pulsanti Quantità */
.sagra-item-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-qty {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    max-width: 28px !important;
    border-radius: 50% !important;
    border: none;
    background: #e2e8f0;
    color: #334155;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex: 0 0 28px !important; /* Blocca dimensioni flex */
    padding: 0 !important;
    line-height: 1;
}

.btn-qty.btn-plus {
    background: #2e7d32;
    color: white;
}

.input-qty {
    width: 28px !important;
    min-width: 28px !important;
    max-width: 28px !important;
    text-align: center;
    border: none !important;
    font-size: 1.1rem;
    font-weight: bold;
    color: #1e293b !important;
    background: transparent !important;
    pointer-events: none;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    flex: 0 0 28px !important;
}

.sagra-item-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1; 
    padding-right: 5px;
    min-width: 0; /* Importantissimo per non eccedere il contenitore flex */
}

.badge-esaurito {
    background: #ef4444;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: bold;
}

/* Footer per Carrello (Non più Sticky) */
.sagra-sticky-footer {
    background: white;
    padding: 20px;
    margin-top: 15px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sagra-cart-summary {
    font-size: 1.1rem;
    color: #475569;
}

.sagra-cart-summary strong {
    color: #b91c1c;
    font-size: 1.5rem;
    margin-left: 8px;
    font-weight: 900;
}

.btn-checkout {
    background: #2e7d32;
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 30px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-checkout:disabled {
    background: #cbd5e1;
    color: #94a3b8;
    cursor: not-allowed;
}

/* Modale Inserimento Nome */
.sagra-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.75);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sagra-modal-content {
    background: white;
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.sagra-modal-content h3 {
    margin-top: 0;
    color: #1e293b;
}

.sagra-modal-content input {
    width: 100%;
    padding: 15px;
    margin: 20px 0;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1.1rem;
    box-sizing: border-box;
    text-align: center;
}

.sagra-modal-content input:focus {
    outline: none;
    border-color: #2e7d32;
}

.btn-confirm {
    background: #2e7d32;
    color: white;
    border: none;
    padding: 15px;
    width: 100%;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 15px;
}

.btn-cancel {
    background: transparent;
    color: #64748b;
    border: none;
    padding: 10px;
    width: 100%;
    cursor: pointer;
    font-weight: bold;
    text-decoration: underline;
}

/* =========================================================================
   STILI CONDIVISI (Dashboard Cassa e Cucina) 
   Adattati al layout "Menu della Sagra" (Sfondo bianco, shadow, header rosso)
   ========================================================================= */

/* Header per Cassa e Cucina (uguale al Menu) */
.sagra-dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: #e63946; /* Rosso Sagra */
    color: white;
    border-radius: 10px 10px 0 0;
    margin-bottom: 20px;
}
.sagra-dashboard-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: white;
}
.sagra-dashboard-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #f1f5f9;
    font-size: 0.9rem;
}

/* Pallino pulsante stato Cassa/Cucina */
.status-dot-active {
    width: 12px;
    height: 12px;
    background-color: #10b981; /* Verde smeraldo */
    border-radius: 50%;
    animation: sagra-pulse 2s infinite;
}
@keyframes sagra-pulse { 
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); } 
    70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); } 
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } 
}

/* Griglia delle Cards */
.sagra-ordini-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    padding: 0 20px;
}
@media (max-width: 1100px) {
    .sagra-ordini-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .sagra-ordini-grid { grid-template-columns: 1fr; }
}

/* Card Ordine (Stile unificato al Menu) */
.sagra-ordine-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

/* Cassa Header Card */
.ordine-card-header {
    display: flex;
    flex-direction: column;
    border-bottom: 2px solid #e63946;
    padding-bottom: 6px;
    margin-bottom: 8px;
    gap: 0;
    align-items: center;
}
.ordine-id {
    font-size: 0.85rem;
    font-weight: 800;
    color: #e63946;
}
.ordine-nome {
    font-size: 1.1rem;
    color: #0f172a;
    font-weight: 900;
    text-align: center;
    word-break: break-word;
    line-height: 1.15;
}

/* Liste Ordini Cassa & Cucina */
.ordine-items {
    flex-grow: 1;
    margin-bottom: 8px;
    font-size: 0.82rem;
    max-height: 320px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.ordine-items::-webkit-scrollbar { width: 4px; }
.ordine-items::-webkit-scrollbar-track { background: transparent; }
.ordine-items::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.ordine-items ul {
    padding-left: 0;
    margin: 0;
    list-style: none;
}
.ordine-items li {
    font-weight: 600;
    margin-bottom: 0;
    padding: 3px 5px;
    border-bottom: 1px solid #f1f5f9;
    line-height: 1.25;
    color: #1e293b;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 3px;
    font-size: 0.82rem;
}
.ordine-items li:nth-child(even) {
    background: #f8fafc;
}
.ordine-items li:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 3px;
}

/* Category group header */
.ordine-cat-header {
    background: #e63946 !important;
    color: #fff !important;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 3px 8px;
    margin: 0;
    border-radius: 0;
    border-bottom: none !important;
}
.ordine-cat-header:first-child {
    border-radius: 3px 3px 0 0;
}

.ordine-qty {
    background: #e63946;
    color: white;
    padding: 0px 5px;
    border-radius: 3px;
    margin-right: 3px;
    display: inline-block;
    font-weight: bold;
    font-size: 0.78rem;
    min-width: 22px;
    text-align: center;
    flex-shrink: 0;
}
.ordine-asporto {
    background: #f59e0b;
    color: white;
    padding: 0px 4px;
    border-radius: 3px;
    font-size: 0.65rem;
    margin-left: 3px;
    display: inline-block;
    vertical-align: middle;
}
.ordine-variante {
    color: #e63946;
    font-weight: 700;
    font-size: 0.75rem;
    display: block;
    width: 100%;
    padding-left: 30px;
    margin-top: 0;
}

/* Cassa - Spazio Totale e Bottoni */
.ordine-totale {
    font-size: 1.3rem;
    font-weight: 800;
    color: #e63946;
    text-align: center;
    margin-bottom: 8px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
}
.btn-paga {
    background: #2e7d32; /* Verde M-Electronics per cassa positiva */
    color: white;
    border: none;
    padding: 14px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 30px; /* Bordi arrotondati come Menu */
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
    margin-bottom: 8px;
}
.btn-paga:hover { background: #1b5e20; }
.btn-annulla {
    background: transparent;
    color: #94a3b8;
    border: 1px solid #cbd5e1;
    padding: 10px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}
.btn-annulla:hover {
    background: #f1f5f9;
    color: #ef4444;
    border-color: #ef4444;
}

/* Bottoni Cucina */
.btn-pronto {
    background: #e63946; /* Rosso al posto del blu */
    color: white;
    border: none;
    padding: 16px;
    font-size: 1.2rem;
    font-weight: 800;
    border-radius: 30px;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
    text-transform: uppercase;
}
.btn-pronto:hover { background: #b91c1c; }

/* Titoli Sezione Sagra */
.sagra-section-title {
    margin: 25px 20px 0px;
    padding-bottom: 2px;
    border-bottom: 2px solid #e63946;
    color: #1e293b;
    font-size: 1.7rem;
    break-after: avoid-column;
    page-break-after: avoid;
    break-inside: avoid;
}
.sagra-item {
    break-inside: avoid;
    page-break-inside: avoid;
}

/* Pillole Serate nel Menu */
.sagra-serate-selector {
    padding: 15px 20px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    text-align: center;
}
.sagra-serate-selector p {
    margin: 0 0 10px 0;
    font-weight: 800;
    color: #475569;
    font-size: 1.1rem;
}
.sagra-btn-serata {
    padding: 8px 20px;
    border: 2px solid #e63946;
    border-radius: 30px; /* Pill più arrotondato */
    background: #fff;
    color: #e63946;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.2s;
}
.sagra-btn-serata.active {
    background: #e63946;
    color: #fff;
}

/* =========================================================================
   RESPONSIVE LAYOUT & DASHBOARD FULL-WIDTH
   ========================================================================= */

/* Container specifico per le Dashboard. Usa la griglia in tutto il suo splendore sui monitor larghi */
.sagra-dashboard-container {
    max-width: 1800px;
    width: 96%;
    margin: 0 auto;
    font-family: system-ui, -apple-system, sans-serif;
    padding-bottom: 20px;
    box-sizing: border-box;
    background: #f8f9fa;
}

/* Container interno della riga piatto */
.sagra-item-inner {
    display: flex;
    flex-wrap: wrap; /* GESTISCE LA FINESTRA RISTRETTA EVITANDO CLIPPING */
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 10px;
}

.sagra-serate-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

/* Ottimizzazioni per schermi molto stretti (Mobile / iPhone SE / etc) */
@media (max-width: 540px) {
    /* Il wrapper interno del piatto si adatta mettendo titolo/prezzo sopra e i comandi (+/-) sotto */
    .sagra-item-inner {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .sagra-item-actions {
        width: 100%;
        justify-content: space-between;
        margin-top: 6px;
        border-top: 1px dashed #e2e8f0;
        padding-top: 6px;
    }
    
    /* Footer Carrello PWA Mobile */
    .sagra-sticky-footer {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .btn-checkout {
        width: 100%;
    }
    
    /* Le serate diventano bottoni impilati */
    .sagra-serate-wrapper {
        flex-direction: column;
    }
    .sagra-btn-serata {
        width: 100%;
    }
}

/* =========================================================================
   TEMA CASSA (OVERRIDE COLORI A VERDE)
   ========================================================================= */
.theme-cassa .sagra-dashboard-header { background: #2e7d32; }
.theme-cassa .ordine-card-header { border-bottom-color: #2e7d32; }
.theme-cassa .ordine-id { color: #2e7d32; }
.theme-cassa .ordine-cat-header { background: #2e7d32 !important; }
.theme-cassa .ordine-qty { background: #2e7d32; }
.theme-cassa .ordine-variante { color: #2e7d32; }
.theme-cassa .ordine-totale { color: #2e7d32; }
.theme-cassa .sagra-section-title { border-bottom-color: #2e7d32; }

/* =========================================================================
   MODALE CASSA XL (TABLET) — RESPONSIVE FULLSCREEN
   ========================================================================= */
#cassa-manual-order-modal {
    padding: 0 !important;
}

#cassa-manual-order-modal .sagra-modal-content {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
}

/* Override del max-width:600px del container menu dentro il modale */
#cassa-manual-order-modal .sagra-app-container {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

#cassa-manual-order-modal .sagra-app-header {
    display: none !important;
}

#cassa-manual-order-modal .sagra-serate-selector {
    margin-bottom: 8px !important;
    padding: 8px 15px !important;
}

/* Menu list: layout a colonne fluido */
.sagra-menu-list {
    column-count: 1;
    padding: 0 10px;
}

#cassa-manual-order-modal .sagra-item {
    margin-bottom: 4px !important;
    padding: 5px 8px !important;
}

#cassa-manual-order-modal .sagra-section-title {
    font-size: 1.2rem !important;
    margin-bottom: 2px !important;
    margin-top: 8px !important;
    padding-bottom: 3px !important;
}

#cassa-manual-order-modal .sagra-item-title,
#cassa-manual-order-modal .sagra-item-price,
#cassa-manual-order-modal .sagra-cart-summary {
    font-size: 1.15rem !important;
}

#cassa-manual-order-modal .btn-checkout {
    font-size: 1.3rem !important;
    padding: 14px 24px !important;
}

#cassa-manual-order-modal .btn-qty {
    width: 36px !important;
    height: 36px !important;
    max-width: 36px !important;
    flex: 0 0 36px !important;
    font-size: 1.4rem !important;
}

#cassa-manual-order-modal .input-qty {
    width: 34px !important;
    max-width: 34px !important;
    flex: 0 0 34px !important;
    font-size: 1.3rem !important;
}

#cassa-manual-order-modal .sagra-sticky-footer {
    border-radius: 0 !important;
    position: sticky;
    bottom: 0;
    z-index: 50;
}

/* ---- RESPONSIVE BREAKPOINTS (GLOBAL MENU + MODAL) ---- */

/* Tablet Landscape e Desktop (>800px) -> 2 Colonne Larghe */
@media (min-width: 800px) {
    .sagra-menu-list, #cassa-manual-order-modal .sagra-menu-list {
        column-count: 2;
        column-gap: 20px;
        padding: 0 15px;
    }
}

/* Landscape Desktop/Monitor Enorme (>=1500px) → 3 colonne */
@media (min-width: 1500px) {
    .sagra-menu-list, #cassa-manual-order-modal .sagra-menu-list {
        column-count: 3;
        column-gap: 30px;
        padding: 0 20px;
    }
}