:root {
  --brand: #0b3a6e;
  --brand-2: #1560b0;
  --accent: #ffd34d;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #667085;
  --line: #e3e7ee;
  --ok-bg: #e7f6ec; --ok-fg: #1c6b3a;
  --err-bg: #fdecec; --err-fg: #a12828;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--brand-2); }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h2.inline { display: inline; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Barra superiore */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem 16px; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; display: flex; align-items: center; gap: .5rem; }
.brand img { width: 28px; height: 28px; flex: none; }
@media (max-width: 520px) { .brand-text { display: none; } .nav > a, .menu > summary { padding: .45rem .5rem; } }
.nav { display: flex; align-items: center; gap: .25rem; }
.nav > a, .menu > summary {
  color: #dbe6f3; text-decoration: none; padding: .45rem .6rem; border-radius: 8px; cursor: pointer; list-style: none; font-size: .95rem;
}
.menu > summary::-webkit-details-marker { display: none; }
.nav > a.on, .menu > summary.on, .nav > a:hover, .menu > summary:hover { background: rgba(255,255,255,.14); color: #fff; }
.menu { position: relative; }
.menu-pop {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 210px;
  background: var(--card); color: var(--text); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  padding: .4rem; display: flex; flex-direction: column;
}
.menu-pop.right { left: auto; right: 0; }
.menu-pop > a, .menu-pop .linklike { padding: .55rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; text-align: left; }
.menu-pop > span { padding: .4rem .7rem; }
.menu-pop > a:hover, .menu-pop .linklike:hover { background: var(--bg); }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 8vh auto 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }

/* Messaggi */
.flash { padding: .7rem .9rem; border-radius: 10px; margin-bottom: 12px; transition: opacity .6s; }
.flash.ok { background: var(--ok-bg); color: var(--ok-fg); }
.flash.err { background: var(--err-bg); color: var(--err-fg); }
.flash.fade { opacity: 0; }

/* Moduli */
label { display: block; font-size: .9rem; font-weight: 600; color: #344054; }
input, select {
  display: block; width: 100%; margin-top: .3rem; padding: .65rem .75rem;
  font: inherit; font-weight: 400; color: var(--text);
  border: 1px solid #cfd6e0; border-radius: 10px; background: #fff; min-height: 46px;
}
input:focus, select:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; border-color: transparent; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
label.check input { width: auto; margin: 0; }
.stack > * + * { margin-top: .9rem; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.grid-form .span2 { grid-column: 1 / -1; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }
@media (max-width: 640px) { .grid-form { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid #cfd6e0;
  background: #fff; color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:active { background: var(--brand); }
.btn.big { width: 100%; padding: .9rem 1rem; font-size: 1.1rem; }
.btn.small { padding: .35rem .65rem; font-size: .85rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err-fg); }

/* Schermata Registra */
.store-bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 12px; }
.store-form { flex: 1; max-width: 420px; }
.store-form select { margin: 0; font-weight: 600; }
.store-name { font-weight: 700; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tiles-cat { grid-column: 1 / -1; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: .5rem 0 0; }
.tile { position: relative; }
.tile-main {
  width: 100%; min-height: 108px; padding: 12px 10px 42px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  background: var(--card); border: 2px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  font: inherit; font-weight: 650; font-size: 1.02rem; color: var(--text); cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; transition: transform .06s;
}
.tile-main:active { transform: scale(.97); }
.tile.in-draft .tile-main { border-color: var(--brand-2); background: #eef4fb; }
.tile.bump .tile-main { animation: bump .18s ease-out; }
@keyframes bump { 50% { transform: scale(.95); } }
.tile-today { font-size: .75rem; font-weight: 500; color: var(--muted); }
.tile-draft {
  position: absolute; bottom: 8px; right: 8px; min-width: 34px; height: 30px; padding: 0 8px; pointer-events: none;
  border-radius: 15px; background: var(--brand-2); color: #fff; font-size: .95rem; font-weight: 700; line-height: 30px; text-align: center;
}
.tile-minus {
  position: absolute; bottom: 6px; left: 6px; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid #cfd6e0; background: #fff; color: var(--text); font-size: 1.3rem; line-height: 1; cursor: pointer;
  touch-action: manipulation;
}
.hint { margin: 0 0 10px; }

.draft-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: .6rem;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: var(--card); box-shadow: 0 -6px 20px rgba(16, 24, 40, .12);
}
.draft-bar .draft-sum { flex: 1; }
.draft-bar .draft-sum strong { font-size: 1.3rem; color: var(--brand); }
.draft-bar .btn.primary { padding: .75rem 1.4rem; font-size: 1.05rem; }
body.has-draft .wrap { padding-bottom: 96px; }
.draft-lines { max-height: 55vh; overflow-y: auto; }
.draft-line { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; padding: .6rem 0; border-top: 1px solid var(--line); }
.draft-line:first-child { border-top: 0; }
.draft-name { font-weight: 650; }
.draft-qty { display: flex; align-items: center; gap: .4rem; }
.draft-qty .qty-btn { width: 42px; height: 42px; font-size: 1.4rem; }
.draft-val { min-width: 2ch; text-align: center; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.draft-amount { grid-column: 1 / -1; font-weight: 500; font-size: .85rem; }
@media (max-width: 380px) { .tiles { grid-template-columns: 1fr 1fr; } }

.sheet {
  border: 0; padding: 18px 16px max(18px, env(safe-area-inset-bottom)); width: 100%; max-width: 480px;
  border-radius: 18px 18px 0 0; margin: auto auto 0; box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
@media (min-width: 640px) { .sheet { border-radius: 18px; margin: auto; } }
.sheet::backdrop { background: rgba(10, 20, 35, .45); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.x { background: none; border: 0; font-size: 2rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 .25rem; }
.qty { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; }
.qty input { margin: 0; text-align: center; font-size: 1.6rem; font-weight: 700; }
.qty-btn { font-size: 1.8rem; border: 1px solid #cfd6e0; background: var(--bg); border-radius: 12px; cursor: pointer; color: var(--text); }
.more summary { cursor: pointer; color: var(--brand-2); font-weight: 600; font-size: .9rem; }
.more[open] summary { margin-bottom: .6rem; }
.more label + label { margin-top: .6rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .65rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }

/* Report */
.filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; align-items: end; }
.filters-actions { display: flex; gap: .5rem; }
@media (max-width: 900px) { .filters { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .filters { grid-template-columns: 1fr; } }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; }
.kpi-v { font-size: 1.6rem; font-weight: 750; color: var(--brand); font-variant-numeric: tabular-nums; }
.kpi-l { color: var(--muted); font-size: .85rem; }
details > summary { cursor: pointer; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tfoot th { border-top: 2px solid var(--line); border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.zero { color: #c0c7d2; }
.pivot .sticky { position: sticky; left: 0; background: var(--card); z-index: 1; }
tr.inactive td { opacity: .55; }
.actions { display: flex; gap: .3rem; justify-content: flex-end; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; background: #eef0f3; color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
