/* =========================================================
   BLOCCO 1: VARIABILI GLOBALI E RESET
   ========================================================= */
:root {
    --bg-color: #eef2f7; --header-bg: #2c3e50;
    --accent-blue: #007bff; --accent-green: #28a745;
    --accent-red: #dc3545; --accent-orange: #e67e22;
    --accent-purple: #9b59b6; --accent-teal: #16a085;
    --accent-dark: #34495e; --accent-grey: #7f8c8d;
    --department-bg: #17a2b8; --product-bg: #fff;
}

body { font-family: 'Segoe UI', sans-serif; background-color: var(--bg-color); margin: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* =========================================================
   BLOCCO 2: NAVBAR E INFO SISTEMA TOP
   ========================================================= */
.navbar { flex: 0 0 60px !important; background: var(--header-bg); color: white; padding: 0 20px; height: 60px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 5px rgba(0,0,0,0.2); z-index: 100; }
.nav-tabs { display: flex; gap: 10px; height: 100%; }
.nav-item { display: flex; align-items: center; padding: 0 20px; cursor: pointer; font-weight: bold; opacity: 0.7; color: #ddd; border-bottom: 4px solid transparent; }
.nav-item.active { opacity: 1; border-bottom-color: var(--accent-orange); color: #fff; background: rgba(255,255,255,0.1); }
.main-clock { 
    font-size: 18px; 
    font-weight: bold; 
    color: #f1c40f; 
    text-shadow: 1px 1px 2px #000; 
    margin-right: 10px; /* Spazio dal pallino verde */
}
.system-info { font-size: 14px; padding: 5px 10px; background: rgba(0,0,0,0.2); border-radius: 4px; display: flex; align-items: center; gap: 10px; }
.connection-status { width: 15px; height: 15px; border-radius: 50%; background: red; display: inline-block; }
.connected { background: #0f0; box-shadow: 0 0 5px #0f0; }

/* =========================================================
   BLOCCO 3: LAYOUT VISUALIZZAZIONI (VIEWS) E POS
   ========================================================= */
.view-container { display: none; flex: 1 !important; height: auto !important; min-height: 0 !important; width: 100%; position: relative; z-index: 1; overflow: hidden; box-sizing: border-box; background-color: #f4f6f8; }
.view-container.active { display: block; }
#view-pos[style*="display: block"] { display: flex !important; flex-direction: column; }
.pos-layout { display: flex; flex: 1; height: 100%; min-height: 0; min-width: 0; max-width: 100vw; gap: 15px; padding-bottom: 10px; overflow: hidden; }

/* PANNELLO SCONTRINO (SINISTRA) */
.receipt-panel { flex: 0 0 350px; background: white; border-right: 1px solid #ccc; display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; flex-shrink: 0; }
.receipt-header { background: #f8f9fa; padding: 15px; text-align: center; border-bottom: 1px solid #ddd; flex-shrink: 0; }
#posHeaderInfo { font-size: 20px; font-weight: bold; color: var(--header-bg); margin: 0; }
#posHeaderSub { font-size: 14px; color: #666; margin: 0; }
.receipt-list { flex-grow: 1; overflow-y: auto; padding: 10px; min-height: 0; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
#view-receipts, #receiptsGrid, #view-kitchen, .stats-container, .modal-content { -webkit-overflow-scrolling: touch; touch-action: pan-y; }

/* RIGHE SCONTRINO */
.receipt-line { padding: 8px; border-bottom: 1px solid #eee; cursor: pointer; font-size: 15px; display: flex; flex-direction: column; }
.receipt-line:active { background-color: #e8f0fe; }
.rl-top { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.rl-qty { font-weight: bold; background: var(--accent-blue); color: white; padding: 2px 6px; border-radius: 4px; margin-right: 5px; font-size: 14px; }
.rl-name { font-weight: bold; flex-grow: 1; }
.rl-price { font-weight: bold; font-size: 16px; color: #333; }
.rl-vars { font-size: 12px; color: #666; padding-left: 30px; margin-top: 2px; }
.rl-discount { font-size: 13px; color: var(--accent-red); font-style: italic; text-align: right; }
.total-box { background: var(--header-bg); color: white; padding: 20px; text-align: right; font-size: 52px; font-weight: bold; flex-shrink: 0; }

/* PANNELLO PRODOTTI E REPARTI (CENTRO) */
.product-panel { flex: 1; padding: 10px; display: flex; flex-direction: column; gap: 10px; background: #e9ecef; min-height: 0; min-width: 0 !important; max-width: 100%; overflow: hidden; }
.pos-departments { display: flex; gap: 5px; overflow-x: auto !important; width: 100%; max-width: 100%; min-width: 0 !important; padding-bottom: 5px; flex-shrink: 0; height: 60px; min-height: 60px; scroll-behavior: smooth; cursor: grab; user-select: none; flex-grow: 1; }
.pos-departments:active { cursor: grabbing; }
.btn-dept { padding: 0 25px; border: 1px solid #aaa; background: var(--department-bg); color: white; border-radius: 6px; cursor: pointer; font-weight: bold; white-space: nowrap; font-size: 14px; }
.btn-dept.active { background: var(--accent-orange); transform: scale(1.05); border: 2px solid white; }

.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; overflow-y: auto; align-content: start; height: 100%; }
.btn-pos-prod { background: #fff; border: 1px solid #ccc; border-bottom: 3px solid #bbb; border-radius: 8px; min-height: 80px; cursor: pointer; font-weight: bold; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 13px; transition: 0.1s; word-wrap: break-word; text-align: center; padding: 5px; }
.btn-pos-prod:active { transform: translateY(2px); border-bottom: 0; }
.prod-price-tag { color: var(--accent-orange); font-size: 18px; font-weight: 800; margin-top: 4px; } 

/* DESIGN MODE ANIMATIONS */
.design-mode { border: 2px dashed red !important; animation: pulse 2s infinite; cursor: alias !important; }
@keyframes pulse { 0% { border-color: red; box-shadow: 0 0 5px red; } 50% { border-color: yellow; box-shadow: 0 0 15px yellow; } 100% { border-color: red; box-shadow: 0 0 5px red; } }

/* =========================================================
   BLOCCO 4: PANNELLO DI CONTROLLO (DESTRA)
   ========================================================= */
.control-panel { flex: 0 0 350px; background: #dce1e6; padding: 15px; display: flex; flex-direction: column; gap: 10px; border-left: 1px solid #ccc; min-height: 0; }
.display-input { background: #fff; border: 2px solid #ccc; border-radius: 8px; height: 60px; font-size: 32px; text-align: right; padding: 0 15px; display: flex; align-items: center; justify-content: flex-end; font-family: monospace; flex-shrink: 0; }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; flex-shrink: 0; margin-bottom: 10px; }

.btn-num { padding: 15px; background: #fff; border: 1px solid #ccc; border-radius: 6px; font-size: 20px; font-weight: bold; cursor: pointer; height: 60px; }

/* GRIGLIA TASTI AZIONE */
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex-grow: 1; align-content: start; }
.btn-action { border: none; border-radius: 8px; color: white; font-weight: bold; font-size: 16px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; min-height: 75px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); transition: transform 0.1s; }
.btn-action i { font-size: 24px; margin-bottom: 5px; }
.span-2 { grid-column: span 2; }

/* COLORI TASTI */
.btn-purple { background: var(--accent-purple); }
.btn-orange { background: var(--accent-orange); }
.btn-dark { background: var(--accent-dark); }
.btn-grey { background: var(--accent-grey); }
.btn-green { background: var(--accent-green); }
.btn-blue { background: var(--accent-blue); }
.btn-red { background: var(--accent-red); }
.btn-teal { background: var(--accent-teal); }

/* =========================================================
   BLOCCO 5: STATISTICHE E VARIE
   ========================================================= */
.stats-container { padding: 20px; height: 100%; overflow-y: auto; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.stat-card { background: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.stat-val { font-size: 36px; font-weight: bold; color: var(--header-bg); }
.stat-label { font-size: 16px; color: #666; text-transform: uppercase; }
.stat-table { width: 100%; border-collapse: collapse; margin-top: 15px; }
.stat-table th { text-align: left; border-bottom: 2px solid #eee; padding: 5px; }
.stat-table td { border-bottom: 1px solid #eee; padding: 5px; }

/* MODALI */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); display: none; justify-content: center; align-items: center; z-index: 5000; }
.modal-content { background: #fff; padding: 20px; border-radius: 10px; width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 50px rgba(0,0,0,0.5); }
.large-modal { width: 90% !important; max-width: 900px !important; height: 85vh !important; display: flex; flex-direction: column; padding: 0 !important; overflow: hidden; }
.modal-header-touch { background: #f8f9fa; padding: 20px; border-bottom: 2px solid #ddd; display: flex; justify-content: space-between; align-items: center; }
.btn-close-touch { background: var(--accent-red); color: white; border: none; padding: 15px 30px; font-size: 20px; font-weight: bold; border-radius: 8px; cursor: pointer; }
.list-item-row { display:flex; justify-content:space-between; align-items:center; padding:15px; border-bottom:1px solid #eee; font-size:18px; }
.btn-icon { width:40px; height:40px; border-radius:50%; border:none; color:white; font-size:16px; cursor:pointer; margin-left:5px; }
.config-input { width: 100%; padding: 12px; margin: 8px 0; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; box-sizing: border-box; }
.btn-config { padding: 15px; border: none; border-radius: 8px; color: white; cursor: pointer; font-weight: bold; }

/* GRIGLIA VARIANTI */
#varModal .modal-content { width: 95%; max-width: 800px; }
.var-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 15px; margin-top: 15px; }
.var-card { border: 1px solid #ddd; border-radius: 12px; padding: 10px; display: flex; justify-content: space-between; align-items: center; background: #fff; box-shadow: 0 4px 8px rgba(0,0,0,0.05); transition: transform 0.1s; }
.var-card:active { transform: scale(0.98); background: #f0f0f0; }
.btn-var-control { width: 50px; height: 50px; border: none; border-radius: 10px; font-weight: 800; font-size: 24px; cursor: pointer; color: white; display: flex; align-items: center; justify-content: center; }
.btn-var-minus { background: #e74c3c; box-shadow: 0 4px 0 #c0392b; }
.btn-var-plus { background: #27ae60; box-shadow: 0 4px 0 #219150; }
.var-name { font-weight: bold; flex-grow: 1; text-align: center; font-size: 18px; color: #333; padding: 0 10px; }

/* PLANNING E MONITOR */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; padding: 20px; }
.cal-day { background: #fff; height: 120px; border-radius: 8px; padding: 10px; cursor: pointer; border: 1px solid #ddd; display: flex; flex-direction: column; justify-content: space-between; }
.cal-day:hover { border-color: var(--accent-blue); transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
.cal-day.today { border: 2px solid var(--accent-orange); background: #fff3cd; }
.cal-day.has-orders { background: #d4edda; border: 2px solid #28a745; }
.cal-day.today.has-orders { background: #c3e6cb; border: 2px solid var(--accent-orange); }
.slot-container { margin-bottom: 20px; border: 1px solid #ccc; padding: 15px; border-radius: 8px; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.order-chip { display: inline-block; padding: 10px 15px; margin: 5px; border-radius: 6px; font-size: 16px; cursor: pointer; box-shadow: 0 2px 3px rgba(0,0,0,0.2); color:white; }
.btn-add-slot { width: 60px; height: 60px; background: #fff; border: 2px dashed #999; font-size: 30px; font-weight: bold; color: #666; cursor: pointer; border-radius: 8px; vertical-align: middle; margin: 5px; }

.kitchen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 15px; padding: 20px; }
.kitchen-ticket { background: #fff5e6; border: 1px solid #ccc; border-radius: 8px; padding: 0; display: flex; flex-direction: column; box-shadow: 0 4px 6px rgba(0,0,0,0.1); overflow: hidden; }
.k-header { padding: 10px; font-weight: bold; display: flex; justify-content: space-between; color: white; }
.k-body { padding: 10px; flex-grow: 1; font-size: 18px; line-height: 1.4; }
.k-footer { padding: 10px; background: #eee; text-align: center; }
.k-var { color: var(--accent-red); font-size: 0.85em; display: block; padding-left: 10px; font-style: italic; }
@keyframes pulseChiamata { 0%, 100% { box-shadow: 0 0 15px rgba(241, 196, 15, 0.4); } 50% { box-shadow: 0 0 35px rgba(241, 196, 15, 0.8); } }

/* CONFIG DASHBOARD */
.config-dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 25px; height: 100%; align-content: center; max-width: 1200px; margin: 0 auto; padding: 20px; }
.config-dash-btn { padding: 20px; font-size: 18px; font-weight: bold; border: none; border-radius: 16px; color: white; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 15px; box-shadow: 0 8px 20px rgba(0,0,0,0.15); transition: all 0.2s ease; height: 180px; text-transform: uppercase; letter-spacing: 0.5px; }
.config-dash-btn:hover { transform: translateY(-5px); box-shadow: 0 12px 25px rgba(0,0,0,0.25); filter: brightness(1.1); }
.config-dash-btn:active { transform: scale(0.98); box-shadow: 0 4px 10px rgba(0,0,0,0.1); }

/* TASTIERA E LIVE EDITOR */
#keyboardModal { z-index: 6000; }
.keyboard-row { display: flex; justify-content: center; gap: 5px; margin-bottom: 5px; }
.key-btn { padding: 15px; min-width: 40px; font-size: 18px; border-radius: 5px; border: 1px solid #ccc; background: #fff; cursor: pointer; font-weight: bold; flex: 1; }
.key-btn:active { background: #ddd; transform: translateY(2px); }
.key-btn.space { flex: 4; }

/* =========================================================
   STAMPANTI E HUB ALERT 
   ========================================================= */
.printer-tabs { display: flex; border-bottom: 1px solid #ccc; background: #eee; }
.printer-tab { flex: 1; padding: 15px; text-align: center; cursor: pointer; font-weight: bold; color: #555; border-bottom: 3px solid transparent; }
.printer-tab.active { background: white; color: var(--accent-blue); border-bottom-color: var(--accent-blue); }
.printer-content { display: none; padding: 20px; }
.printer-content.active { display: block; }
.config-checkbox-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-bottom: 1px solid #eee; font-size: 16px; }

.hub-alert-content { text-align: center; padding: 30px; }
.hub-alert-icon { font-size: 80px; color: #e67e22; margin-bottom: 20px; }
.hub-alert-title { font-size: 32px; font-weight: bold; color: #2c3e50; margin-bottom: 15px; }
.hub-alert-msg { font-size: 22px; color: #555; margin-bottom: 30px; }
.hub-btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.closed-days-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 10px; }
.day-check { background: #f8f9fa; padding: 5px; border-radius: 4px; font-size: 12px; display: flex; align-items: center; gap: 5px; }

/* =========================================================
   OTTIMIZZAZIONE PER RISOLUZIONE 1024x768
   ========================================================= */
@media screen and (max-width: 1024px) {
    .pos-layout { 
        grid-template-columns: 280px 1fr 300px !important; /* Stringe i pannelli laterali */
    }
    .nav-item { 
        padding: 0 10px !important; 
        font-size: 13px !important; 
    }
    .total-box { font-size: 38px !important; }
    .btn-pos-prod { font-size: 11px !important; }
}

/* =========================================================
   AVVISI RT HARDWARE
   ========================================================= */
.rt-alert-banner {
    position: absolute;
    top: 60px; /* Sotto la navbar */
    left: 0;
    width: 100%;
    padding: 15px;
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    color: white;
    z-index: 4000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    animation: slideDown 0.3s ease-out;
}
.rt-alert-error { background-color: var(--accent-red); }
.rt-alert-warning { background-color: var(--accent-orange); color: #000; }
@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

/* =========================================================
   PRODOTTI COMPOSTI TOUCH (GRANDI E CHIARI)
   ========================================================= */
.btn-comp-item {
    background: #ffffff;
    border: 2px solid #b0bec5;
    border-radius: 10px;
    padding: 12px 10px;
    min-height: 90px;
    cursor: pointer;
    font-family: inherit;
    color: #263238;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: all 0.15s ease-in-out;
    user-select: none;
    box-shadow: 0 3px 6px rgba(0,0,0,0.08);
}
.btn-comp-item:hover {
    border-color: #0288d1;
    background: #f0f7fa;
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(0,0,0,0.12);
}
.btn-comp-item.selected {
    background: #e8f8f0 !important;
    border-color: #27ae60 !important;
    border-width: 3px !important;
    color: #1e7e34 !important;
    font-weight: 900;
    box-shadow: 0 0 12px rgba(39, 174, 96, 0.4) !important;
    position: relative;
}
.btn-comp-item.selected::after {
    content: '✔';
    position: absolute;
    top: 6px;
    right: 8px;
    color: #27ae60;
    font-size: 18px;
    font-weight: 900;
}