: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;
}

/* ---------- 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__right { display: flex; align-items: center; gap: 10px; font-size: .9rem; }

.content { padding: 16px; max-width: 1200px; 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; }
.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); }

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

/* ---------- Menu ---------- */
.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__info { flex: 1; min-width: 0; }
.product__name { font-weight: 600; }
.product__meta { font-size: .82rem; color: var(--muted); }
.product__price { font-weight: 700; white-space: nowrap; }

/* ---------- 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;
}
.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); }

/* ---------- 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; }
.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; }
.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); }
.toast--ok { background: var(--green-dark); }
.toast--err { background: var(--red-dark); }

/* ---------- Admin ---------- */
.admin-nav {
    display: flex; flex-wrap: wrap; gap: 6px;
    background: var(--paper); border: 1px solid var(--line);
    border-radius: 12px; padding: 8px; margin-bottom: 16px;
}
.admin-nav a {
    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; }

.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 { display: inline; margin: 0; }
.link-danger { background: none; border: none; color: #b71c1c; font-weight: 600; cursor: pointer; padding: 0; font-size: 1rem; }

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

.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: 2rem; }
.kpi small { color: var(--muted); }

/* ---------- 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; }
}
