* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #020617; color: #fff; }
body {
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.screen { position: relative; height: 100dvh; overflow: hidden; }
#reader { position: absolute; inset: 0; z-index: 1; background: #020617; }
#reader * { pointer-events: none !important; }
#reader video, #reader__scan_region video {
    width: 100% !important;
    height: 100dvh !important;
    object-fit: cover !important;
}
#reader__dashboard,
#reader__header_message,
#reader__dashboard_section,
#reader__dashboard_section_csr,
#reader > div:not(#qr-shaded-region) { display: none !important; }

.topbar, .ghost, #recenti, #open-camera, #toast, #db, #coda, #codice-form { z-index: 20; }
#sheet { z-index: 30; }

.topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: calc(12px + env(safe-area-inset-top)) 14px 28px;
    background: linear-gradient(#020617, transparent);
}
#hint {
    margin: 0;
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#conteggio {
    margin: 0;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: #16a34a;
    font-weight: 800;
}
.link, #torch {
    border: 0;
    background: rgba(15, 23, 42, .72);
    color: #fff;
    border-radius: 999px;
    min-height: 36px;
    padding: 0 12px;
}
.quiet {
    color: rgba(255, 255, 255, .55);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .04em;
    text-decoration: none;
    padding: 8px 2px;
    background: transparent;
    border: 0;
}
#pulisci-sheet {
    position: absolute;
    z-index: 40;
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    background: #fff;
    color: #0f172a;
    color-scheme: light;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
#pulisci-sheet p { margin: 0 0 4px; text-align: center; font-size: 18px; font-weight: 700; }
#pulisci-si {
    height: 52px;
    border: 0;
    border-radius: 12px;
    background: #b91c1c;
    color: #fff;
    font-size: 18px;
    font-weight: 800;
}
#pulisci-no {
    height: 44px;
    border: 0;
    background: transparent;
    color: #475569;
    font-size: 16px;
}

.ghost {
    position: absolute;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    border: 0;
    color: #fff;
    background: rgba(15, 23, 42, .78);
    border-radius: 999px;
    padding: 12px 18px;
    font-size: 16px;
}
body:has(#sheet:not([hidden])) .ghost,
body:has(#sheet:not([hidden])) #recenti,
body:has(#pulisci-sheet:not([hidden])) .ghost,
body:has(#pulisci-sheet:not([hidden])) #recenti,
body:has(#sheet:not([hidden])) #installa,
body:has(#pulisci-sheet:not([hidden])) #installa,
body:has(#codice-form:not([hidden])) #installa { display: none; }
body:has(#installa:not([hidden])) #recenti { visibility: hidden; }

#installa {
    position: absolute;
    z-index: 22;
    left: 12px;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    background: #fff;
    color: #0f172a;
    color-scheme: light;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
#installa p { margin: 0; text-align: center; font-size: 16px; font-weight: 700; }
#installa-si {
    height: 48px;
    border: 0;
    border-radius: 12px;
    background: #16a34a;
    color: #fff;
    font-size: 18px;
    font-weight: 800;
}
#installa-no {
    height: 36px;
    border: 0;
    background: transparent;
    color: #475569;
    font-size: 15px;
}

#open-camera {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 42%;
    height: 68px;
    border: 0;
    border-radius: 16px;
    background: #16a34a;
    color: #fff;
    font-size: 20px;
    font-weight: 800;
}

#toast, #db, #coda {
    position: absolute;
    left: 16px;
    right: 16px;
    top: calc(72px + env(safe-area-inset-top));
    margin: 0;
    padding: 12px 14px;
    border-radius: 12px;
    text-align: center;
    font-size: 16px;
}
#toast { background: #052e16; color: #dcfce7; }
#toast.error { background: #7f1d1d; color: #fee2e2; }
#db { background: #7f1d1d; }
#coda { background: #1e293b; color: #e2e8f0; }
body:has(#coda:not([hidden])) #toast,
body:has(#coda:not([hidden])) #db {
    top: calc(128px + env(safe-area-inset-top));
}

#recenti {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    display: flex;
    gap: 8px;
    margin: 0;
    padding: 0 16px;
    list-style: none;
    overflow-x: auto;
}
#recenti li {
    background: rgba(15, 23, 42, .78);
    border-radius: 999px;
    padding: 8px 12px;
    white-space: nowrap;
    font-size: 14px;
}

#sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
    background: #fff;
    color: #0f172a;
    color-scheme: light;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, .35);
}
#sheet label { font-size: 14px; color: #64748b; font-weight: 700; }
.ean, #ean-input, #prezzo {
    width: 100%;
    border: 0;
    border-radius: 16px;
    background: #f1f5f9;
    color: #0f172a;
    text-align: center;
}
.ean {
    margin: 0;
    padding: 14px 8px;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 28px;
    letter-spacing: .04em;
}
#ean-input { font-size: 28px; padding: 14px 8px; }
#prezzo { font-size: 48px; font-weight: 800; padding: 8px; }
#usa-ultimo {
    min-height: 48px;
    border: 0;
    border-radius: 12px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 16px;
    font-weight: 700;
}
#salva {
    height: 72px;
    border: 0;
    border-radius: 16px;
    background: #16a34a;
    color: #fff;
    font-size: 26px;
    font-weight: 800;
}
#salva:disabled { background: #94a3b8; }
#annulla {
    height: 44px;
    border: 0;
    background: transparent;
    color: #475569;
    font-size: 18px;
}

#codice-form {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#codice-form input {
    font-size: 20px;
    padding: 14px;
    border: 0;
    border-radius: 12px;
}
#codice-form button {
    height: 56px;
    border: 0;
    border-radius: 14px;
    background: #16a34a;
    color: #fff;
    font-size: 20px;
    font-weight: 800;
}
body:has(#codice-form:not([hidden])) #mostra-codice { display: none; }
