:root {
    --red: #8a1c1c;
    --red-dark: #6d1414;
    --green: #2e7d32;
    --green-dark: #1b5e20;
    --cream: #fbf6ec;
    --paper: #ffffff;
    --ink: #22201d;
    --muted: #6b6560;
    --line: #e6ded0;
    --amber: #e08a00;
    --shadow: 0 2px 8px rgba(0, 0, 0, .08);
    --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--cream);
    color: var(--ink);
    font-size: 17px;
    /* Niente zoom da doppio tap (resta il pinch-zoom) e nessun ritardo sui tap. */
    touch-action: manipulation;
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: var(--red);
    color: #fff;
    box-shadow: var(--shadow);
}
.topbar__brand { font-weight: 700; font-size: 1.1rem; }
.topbar__home { text-decoration: none; color: inherit; }
.hdr-covers { font-size: .95rem; font-weight: 700; margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.16); white-space: nowrap; }
.topbar__right { display: flex; align-items: center; gap: 10px; font-size: .9rem; }

.content { padding: 16px; max-width: 1260px; margin: 0 auto; padding-bottom: 140px; }

/* ---------- Connection badge ---------- */
.conn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    background: rgba(255, 255, 255, .18);
}
.conn__dot { width: 9px; height: 9px; border-radius: 50%; background: #7CFC7C; }
.conn.is-offline { background: rgba(0, 0, 0, .25); }
.conn.is-offline .conn__dot { background: #ffb020; }
/* Variante solo-pallino (header operatore): verde online / rosso offline. */
.conn--dot { background: transparent !important; padding: 0; }
.conn--dot .conn__dot { width: 14px; height: 14px; background: #29d34a; box-shadow: 0 0 0 3px rgba(41,211,74,.25); }
.conn--dot.is-offline .conn__dot { background: #e53935; box-shadow: 0 0 0 3px rgba(229,57,53,.3); }
.conn__queue { background: var(--amber); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: .75rem; }

/* ---------- Setup / fields ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.input, select, textarea {
    width: 100%;
    padding: 14px;
    font-size: 1.05rem;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    color: var(--ink);
}
.input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); }

/* Barra filtri compatta (es. cameriere/ordini): tutto su una riga, controlli piccoli. */
.filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.filterbar .input--sm { width: auto; }
.input--sm { padding: 7px 9px; font-size: .9rem; border-radius: 9px; }
.btn--sm { padding: 7px 12px; font-size: .9rem; border-radius: 9px; }
.filterbar__lbl { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; color: var(--muted); }
.filterbar__lbl .input--sm { width: auto; }

.card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

/* ---------- Menu ---------- */
/* ---------- Accordion menu (operatore) ---------- */
.acc { border: 1px solid var(--line); border-radius: 12px; background: var(--paper); margin-bottom: 10px; overflow: hidden; }
.acc__head {
    width: 100%;
    display: flex; align-items: center; justify-content: start; gap: 10px;
    padding: 14px 16px;
    background: var(--cream);
    border: none;
    font-size: 1rem; font-weight: 800; color: var(--red);
    text-transform: uppercase; letter-spacing: .04em;
    cursor: pointer;
}
.acc__head::before { content: '▸'; margin-right: 8px; transition: transform .15s ease; display: inline-block; }
.acc.open .acc__head::before { transform: rotate(90deg); }
.acc__count { background: var(--red); color: #fff; border-radius: 999px; font-size: .8rem; padding: 1px 9px; font-weight: 700; }
.acc__body { display: none; padding: 10px 12px; }
.acc.open .acc__body { display: block; }

.cat-title {
    margin: 22px 0 10px;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--red);
    font-weight: 800;
}
.product {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
}
.product.is-out { opacity: .5; }
.product__info { flex: 1 1 auto; min-width: 0; }
.product__name { font-weight: 600; overflow-wrap: anywhere; }
.product__meta { font-size: .82rem; color: var(--muted); }
.product__price { font-weight: 700; white-space: nowrap; flex-shrink: 0; margin-left: auto; }
.product__actions { flex-shrink: 0; }
/* Badge giacenza residua (solo prodotti a quantità finita). */
.stock-badge { display: inline-block; margin-top: 4px; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: #e8f5e9; color: #1b7a34; border: 1px solid #a5d6b0; }
.stock-badge--low { background: #fff4e0; color: #a15c00; border-color: #f0c675; }
.stock-badge--out { background: #fdecea; color: #c0392b; border-color: #f5b7b1; }
/* Su schermi stretti: nome a tutta larghezza, prezzo+controlli sotto. */
@media (max-width: 520px) {
    .product { flex-wrap: wrap; }
    .product__info { flex-basis: 100%; }
}

/* ---------- Selettore tavolo ---------- */
.tablepick__btn { text-align: left; cursor: pointer; }
.tablepick__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; max-height: 55vh; overflow: auto; margin-top: 12px; }
.tablepick__chip {
    border: 1.5px solid var(--line); background: var(--paper); border-radius: 10px;
    padding: 12px 6px; font-weight: 700; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 20px;
}
.tablepick__chip small { font-weight: 400; color: var(--muted); font-size: .72rem; }
.tablepick__chip.is-sel { border-color: var(--red); background: #fff0ef; }
/* Pannello selettore: colonna con griglia scrollabile e ricerca ancorata in fondo
   (così la tastiera non copre i risultati mentre si digita). */
.sheet--picker { display: flex; flex-direction: column; height: 85vh; overflow: hidden; }
.sheet__pickhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
.sheet--picker .tablepick__grid { flex: 1 1 auto; min-height: 0; max-height: none; margin: 12px 0; }
.sheet--picker .tablepick__search { flex: 0 0 auto; margin-top: 4px; }
.sheet--picker .cartbar__row { flex: 0 0 auto; }
.tablepick__chip:active { background: var(--cream); }
.tablepick__chip.is-sel { border-color: var(--red); background: #fdecec; color: var(--red); }

/* ---------- Product actions ---------- */
.product__actions { display: flex; align-items: center; gap: 8px; }
.btn-note {
    width: 42px; height: 42px;
    border-radius: 12px;
    border: 1.5px solid var(--line);
    background: var(--cream);
    font-size: 1.2rem;
    cursor: pointer;
    display: grid;
    place-items: center;
}
.btn-note:active { background: #f0e7d6; }
.line-del {
    border: none; background: none; color: #b71c1c;
    font-size: 1.1rem; cursor: pointer; padding: 6px; line-height: 1;
}

/* ---------- Quantity stepper ---------- */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
    width: 42px; height: 42px;
    border-radius: 50%;
    border: none;
    font-size: 1.4rem;
    font-weight: 700;
    background: var(--red);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
}
.stepper button:disabled { opacity: .35; }
.stepper .qty { min-width: 26px; text-align: center; font-weight: 700; font-size: 1.15rem; }

/* ---------- Cart bar (sticky) ---------- */
.cartbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    background: var(--paper);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .12);
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.cartbar__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cartbar__summary { font-weight: 700; }
.cartbar__total { color: var(--red); }

.btn {
    border: none;
    border-radius: 12px;
    padding: 15px 18px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    margin-bottom: 4px;
}
.btn:disabled { opacity: .5; }
.btn--primary { background: var(--red); color: #fff; }
.btn--cash { background: var(--green); color: #fff; }
.btn--pos { background: #1565c0; color: #fff; }
.btn--ghost { background: transparent; color: var(--red); border: 1.5px solid var(--red);}
.btn--block { width: 100%; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }

/* ---------- Cart review sheet ---------- */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(0, 0, 0, .45);
    display: none;
}
.sheet-backdrop.open { display: block; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
    background: var(--paper);
    border-radius: 18px 18px 0 0;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px 16px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform .22s ease;
}
.sheet.open { transform: translateY(0); }
.sheet h2 { margin: 0 0 12px; }
.line {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0; border-bottom: 1px solid var(--line);
}
.line--note { align-items: flex-start; }
.line__name { font-weight: 600; }
.line__note { font-size: .82rem; color: var(--muted); }
.line-note-toggle { margin-top: 6px; background: none; border: none; padding: 2px 0; color: var(--red); font-weight: 600; font-size: .85rem; cursor: pointer; }
.line-note-toggle[hidden] { display: none; }

/* Riga compatta con le info principali dell'ordine (hostess). */
.ordexp__line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-weight: 600; }
.ordexp__line .ordercard__num { font-size: 1.05rem; }
.ordexp__line .ordexp__name { color: var(--muted); }

/* Espansione dettagli ordine (es. hostess): riepilogo compatto, resto a scomparsa. */
.ordexp { margin: 8px 0; }
.ordexp__toggle { cursor: pointer; color: var(--red); font-weight: 600; font-size: .9rem; list-style: none; user-select: none; }
.ordexp__toggle::-webkit-details-marker { display: none; }
.ordexp[open] .ordexp__toggle { margin-bottom: 6px; }
.ordexp__body { border-top: 1px dashed var(--line); padding-top: 8px; }

/* ---------- Cashier / Monitor grid ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}
.ordercard { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; }
/* Allinea in basso il pulsante d'azione anche con schede di altezza diversa. */
.ordercard > .btn--block:last-child { margin-top: auto; }
.ordercard--pronto { border-color: var(--green); background: #f2fbf2; }
.ordercard__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.ordercard__num { font-size: 1.6rem; font-weight: 800; color: var(--red); }
.ordercard__table { font-weight: 700; }
.ordercard__meta { font-size: .82rem; color: var(--muted); margin-bottom: 10px; }
.ordercard ul { list-style: none; margin: 0 0 12px; padding: 0; }
.ordercard li { padding: 4px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; }
.ordercard li .q { font-weight: 800; color: var(--red); min-width: 28px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.badge--pos { background: #e3f0ff; color: #1565c0; }
.badge--pronto { background: var(--green); color: #fff; }
.badge--status { background: #eee; color: #444; }
.badge--fail { background: #c0392b; color: #fff; }
/* Ordine online NON pagato (stato "nuovo"): evidenza forte. */
.badge--nuovo { background: #ffb300; color: #3a2a00; border: 1px solid #c98800; animation: pulse-nuovo 1.6s ease-in-out infinite; }
@keyframes pulse-nuovo { 0%,100% { box-shadow: 0 0 0 0 rgba(255,179,0,.55); } 50% { box-shadow: 0 0 0 6px rgba(255,179,0,0); } }
/* Riga tabella (admin/ordini) per ordine non pagato. */
tr.is-nuovo > td { background: #fff6e0 !important; }
tr.is-nuovo > td:first-child { box-shadow: inset 4px 0 0 #ffb300; }
/* Card ordine (operatore) per ordine non pagato. */
.ordercard--nuovo { border: 2px solid #ffb300; background: #fff9ec; box-shadow: 0 0 0 3px rgba(255,179,0,.18); }
/* Banner dettaglio ordine non pagato. */
.alert-nuovo { display: flex; align-items: center; gap: 10px; background: #fff6e0; border: 2px solid #ffb300; color: #6b4b00; border-radius: 12px; padding: 12px 14px; font-weight: 700; margin-bottom: 14px; }
/* Ordine pagato in attesa di accomodamento (raccolto, senza tavolo). */
.badge--accomodare { background: #1565c0; color: #fff; }
tr.is-accomodare > td { background: #e8f1fc !important; }
tr.is-accomodare > td:first-child { box-shadow: inset 4px 0 0 #1565c0; }
.ordercard--accomodare { border: 2px solid #1565c0; background: #f2f7fe; box-shadow: 0 0 0 3px rgba(21,101,192,.15); }
.alert-accomodare { display: flex; align-items: center; gap: 10px; background: #e8f1fc; border: 2px solid #1565c0; color: #0d3c78; border-radius: 12px; padding: 12px 14px; font-weight: 700; margin-bottom: 14px; }
.status-nuovo { background: #eef; color: #33489e; }
.status-parcheggiato { background: #fff3e0; color: #b26a00; }
.status-pagato { background: #e3f2fd; color: #1565c0; }
.status-in_preparazione { background: #fff8e1; color: #a06a00; }
.status-pronto { background: #e8f5e9; color: var(--green-dark); }
.status-chiuso { background: #eceff1; color: #546e7a; }
.status-annullato { background: #fdecea; color: #b71c1c; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.toast {
    position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(20px);
    background: var(--ink); color: #fff;
    padding: 12px 18px; border-radius: 12px;
    opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 60;
    max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast--ok { background: var(--green-dark); }
.toast--err { background: var(--red-dark); }

/* ---------- Admin ---------- */
.admin-nav {
    display: flex; flex-wrap: nowrap; gap: 6px;
    background: var(--paper); border: 1px solid var(--line);
    border-radius: 12px; padding: 8px; margin-bottom: 16px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.admin-nav a {
    flex: 0 0 auto; white-space: nowrap;
    text-decoration: none; color: var(--ink);
    padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
.admin-nav a:hover { background: var(--cream); }
.admin-nav a.is-active { background: var(--red); color: #fff; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 14px; }
.admin-head h2 { margin: 0; }

/* Contenitore tabelle: scroll orizzontale su mobile */
.table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-card .table { min-width: 560px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: var(--cream); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
/*.table .actions { display: flex; gap: 12px; align-items: flex-start; white-space: nowrap; }*/
.table .actions a { color: var(--red); text-decoration: none; font-weight: 600;}
.table .actions form:before { content: "|";}
.table .actions form { display: inline; margin: 0; }
.link-danger { background: none; border: none; color: #b71c1c; font-weight: 600; cursor: pointer; padding: 0; font-size: 1rem; }

/* Azioni compatte a icone (es. lista utenti): evita l'affollamento di link testuali. */
.rowactions { display: flex; gap: 6px; align-items: center; }
.rowactions form { display: inline; margin: 0; }
.rowactions form:before { content: none; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: inherit; text-decoration: none; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0; transition: background .12s, border-color .12s; }
.iconbtn:hover { background: var(--cream); border-color: var(--muted); }
.iconbtn--danger:hover { background: #fdecea; border-color: #e79b94; }

.admin-form .field label { font-weight: 600; }
.admin-form .field { margin-bottom: 14px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 16px 0; color: var(--muted); }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.flash--success { background: #e8f5e9; color: var(--green-dark); }
.flash--error { background: #fdecea; color: #b71c1c; }

/* KPI cards nella dashboard/stats */
.kpi { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi .ordercard { text-align: center; }
.kpi .ordercard__num { font-size: 1.5rem; }
.kpi small { color: var(--muted); }

/* ---------- Banco: griglia prodotti compatta su schermi grandi ---------- */
@media (min-width: 700px) {
    /* Solo accordion aperti (specificità > .acc.open .acc__body) per non rompere apri/chiudi. */
    .banco-menu .acc.open .acc__body {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 8px;
    }
    .banco-menu .product {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin: 0;
        padding: 10px;
        text-align: center;
    }
    .banco-menu .product__info { flex: none; }
    .banco-menu .product__price { font-size: .95rem; }
    /* Controlli più piccoli per stare nel riquadro. */
    .banco-menu .product__actions { justify-content: center; gap: 6px; flex-wrap: nowrap; }
    .banco-menu .btn-note { width: 34px; height: 34px; font-size: 1rem; border-radius: 10px; }
    .banco-menu .stepper { gap: 6px; }
    .banco-menu .stepper button { width: 34px; height: 34px; font-size: 1.15rem; }
    .banco-menu .stepper .qty { min-width: 18px; font-size: 1rem; }
}

/* ---------- Public menu ---------- */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 8px; }
.menu-item { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
/* Foto quadrata (le immagini prodotto sono più quadrate che orizzontali). */
.menu-item__photo { width: 100%; aspect-ratio: 1 / 1; background-size: cover; background-position: center; background-color: #eee; }
.menu-item__body { padding: 12px 14px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.menu-item__name { font-weight: 600; }
.menu-item__desc { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.menu-item__price { font-weight: 700; color: var(--red); white-space: nowrap; }

/* ---------- Receipt (printable) ---------- */
.receipt { max-width: 380px; margin: 0 auto; background: #fff; padding: 20px; font-family: "Courier New", monospace; }
.receipt h1 { text-align: center; font-size: 1.2rem; margin: 0 0 4px; }
.receipt .r-line { display: flex; justify-content: space-between; padding: 3px 0; }
.receipt .r-sep { border-top: 1px dashed #000; margin: 8px 0; }
.receipt .r-total { font-weight: 800; font-size: 1.15rem; }
@media print {
    .topbar, .no-print { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; }
}
