:root {
  --paper: #F3F4F7;
  --surface: #FFFFFF;
  --ink: #1B2030;
  --muted: #5E6577;
  --rule: #DADDE4;
  --modena: #C2306A;
  --bazzano: #12808A;
  --mark: #F2C230;
  --danger: #B3261E;
  --font-display: "Dela Gothic One", "Hiragino Kaku Gothic StdN", "Arial Black", system-ui, sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", -apple-system, "Segoe UI", system-ui, sans-serif;
  --tab-h: 62px;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #13161E;
    --surface: #1C2029;
    --ink: #E8EBF1;
    --muted: #9AA1B2;
    --rule: #2D3240;
    --modena: #E25A8E;
    --bazzano: #2FB2BC;
    --mark: #F2C230;
    --danger: #F2827A;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--mark); outline-offset: 2px; }
a { color: inherit; }

/* ---------- Testata ---------- */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--paper);
  padding: 14px 18px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  background: var(--paper); z-index: 10;
}
.top h1 {
  font-family: var(--font-display); font-weight: 400;
  font-size: 30px; line-height: 1; margin: 0; letter-spacing: -0.01em;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--rule); background: var(--surface);
  display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; }

main { padding: 0 14px calc(var(--tab-h) + 28px); max-width: 640px; margin: 0 auto; }

/* ---------- Selettore negozio ---------- */
.stores { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 4px 18px; }
.store {
  border: 2px solid var(--rule); background: var(--surface); border-radius: 14px;
  padding: 10px 14px; text-align: left; display: flex; align-items: baseline; justify-content: space-between;
}
.store b { font-family: var(--font-display); font-weight: 400; font-size: 19px; }
.store span { color: var(--muted); font-weight: 700; }
.store[aria-pressed="true"].modena { border-color: var(--modena); background: var(--modena); color: #fff; }
.store[aria-pressed="true"].bazzano { border-color: var(--bazzano); background: var(--bazzano); color: #fff; }
.store[aria-pressed="true"] span { color: #fff; opacity: .9; }

h2.section {
  font-size: 15px; font-weight: 700; color: var(--muted);
  margin: 22px 6px 8px; display: flex; justify-content: space-between;
}

/* ---------- Volume: il dorso ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.vol {
  display: grid; grid-template-columns: 64px 1fr auto; align-items: stretch;
  background: var(--surface); border-radius: 6px 14px 14px 6px; overflow: hidden;
  min-height: 74px;
  box-shadow: 0 1px 0 var(--rule);
}
.spine {
  --c: var(--muted);
  background-color: var(--c);
  background-image: radial-gradient(rgba(255,255,255,.28) 1.1px, transparent 1.3px);
  background-size: 6px 6px;
  color: #fff; display: grid; place-items: center; text-align: center; padding: 6px 4px;
  font-family: var(--font-display); line-height: 1;
}
.spine.modena { --c: var(--modena); }
.spine.bazzano { --c: var(--bazzano); }
.spine .n { font-size: 26px; }
.spine .n.long { font-size: 15px; }
.spine.none { --c: #8A90A0; }
.vol .body { padding: 10px 12px; min-width: 0; align-self: center; }
.vol .title { font-weight: 700; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.vol .meta { color: var(--muted); font-size: 14px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 2px 12px; }
.vol .actions { display: flex; align-items: center; gap: 4px; padding-right: 8px; }
.vol.done { opacity: .55; }

.check {
  width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--rule);
  background: transparent; display: grid; place-items: center; padding: 0;
  transition: background-color .15s, border-color .15s, transform .15s;
}
.check svg { width: 22px; height: 22px; opacity: .35; }
.check:active { transform: scale(.92); }
.check.on { background: var(--mark); border-color: var(--mark); }
.check.on svg { opacity: 1; color: #1B2030; }
.more { width: 36px; height: 48px; border: 0; background: transparent; color: var(--muted); padding: 0; }
.more svg { width: 20px; height: 20px; }

.follow {
  border: 2px solid var(--ink); background: transparent; border-radius: 999px;
  padding: 6px 14px; font-weight: 700; font-size: 14px; white-space: nowrap;
}
.follow.on.modena { background: var(--modena); border-color: var(--modena); color: #fff; }
.follow.on.bazzano { background: var(--bazzano); border-color: var(--bazzano); color: #fff; }

.tag { font-weight: 700; }
.tag.modena { color: var(--modena); }
.tag.bazzano { color: var(--bazzano); }

/* ---------- Campi ---------- */
.search {
  width: 100%; border: 1px solid var(--rule); background: var(--surface);
  border-radius: 12px; padding: 12px 14px; margin: 4px 0 12px;
}
.row-toggle { display: flex; align-items: center; gap: 10px; margin: 0 4px 6px; color: var(--muted); font-size: 15px; }
.row-toggle input { width: 20px; height: 20px; accent-color: var(--ink); }
input[type="date"].date {
  border: 1px solid var(--rule); background: transparent; border-radius: 8px;
  padding: 2px 6px; font-size: 14px; color: var(--muted);
}

/* ---------- Filtri delle uscite ---------- */
.chips {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--rule); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 15px; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 700; }
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 10px; }
.range label { display: grid; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.range input {
  border: 1px solid var(--rule); background: var(--surface); border-radius: 10px;
  padding: 9px 10px; font-size: 15px; color: var(--ink); min-width: 0; width: 100%;
}
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 4px; }
.toolbar .row-toggle { margin: 0 4px; }
.sort {
  flex: none; display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent;
  font-weight: 700; font-size: 14px; padding: 8px 4px; color: var(--ink);
}
.sort svg { width: 20px; height: 20px; }
.hint { color: var(--muted); font-size: 14px; margin: 6px 6px 0; }
.more-rows { width: 100%; margin-top: 14px; }

/* ---------- Avvisi e vuoti ---------- */
.banner {
  background: var(--surface); border-left: 6px solid var(--mark);
  border-radius: 6px 12px 12px 6px; padding: 12px 14px; margin: 0 4px 16px; font-size: 15px;
}
.banner a { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }
.total { color: var(--ink); }

/* ---------- Barra in basso ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--surface); border-top: 1px solid var(--rule);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs button {
  height: var(--tab-h); border: 0; background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 700; display: grid; place-items: center; align-content: center; gap: 3px; position: relative;
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--ink); }
.tabs button[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; background: var(--ink); border-radius: 0 0 3px 3px;
}
.badge {
  position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--mark); color: #1B2030; font-size: 11px; display: grid; place-items: center; padding: 0 5px;
}

/* ---------- Pannello ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10,12,18,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--paper); width: 100%; max-width: 640px; max-height: 88vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(24px + env(safe-area-inset-bottom, 0px));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .check { transition: none; } }
.sheet h3 { font-family: var(--font-display); font-weight: 400; font-size: 22px; margin: 4px 0 6px; }
.sheet p { margin: 6px 0 12px; color: var(--muted); }
.sheet .choices { display: grid; gap: 10px; margin-top: 14px; }
.btn {
  border: 0; border-radius: 12px; padding: 14px 16px; font-weight: 700; font-size: 16px;
  background: var(--ink); color: var(--paper); text-align: center; text-decoration: none; display: block;
}
.btn.modena { background: var(--modena); color: #fff; }
.btn.bazzano { background: var(--bazzano); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid var(--rule); }
.btn.danger { background: transparent; color: var(--danger); border: 2px solid var(--rule); }
.sheet section { border-top: 1px solid var(--rule); padding-top: 14px; margin-top: 18px; }
.sheet h4 { margin: 0 0 6px; font-size: 16px; }
.sheet ol { padding-left: 20px; color: var(--muted); margin: 6px 0 12px; }
.sheet textarea { width: 100%; min-height: 90px; border: 1px solid var(--rule); border-radius: 10px; padding: 10px; background: var(--surface); font-size: 13px; }
.log { list-style: none; padding: 0; margin: 0; font-size: 14px; display: grid; gap: 6px; }
.log li { display: flex; justify-content: space-between; gap: 10px; }
.log .ko { color: var(--danger); font-weight: 700; }

/* ---------- Accesso ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login .logo {
  font-family: var(--font-display); font-size: 46px; line-height: .95; margin: 0 0 14px;
}
.login .logo span { display: block; }
.login label { font-weight: 700; font-size: 14px; display: grid; gap: 6px; }
.login input { border: 1px solid var(--rule); background: var(--surface); border-radius: 12px; padding: 13px 14px; }
.login .err { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 15px; }
.tone {
  height: 10px; border-radius: 5px; margin-bottom: 18px;
  background: linear-gradient(90deg, var(--modena) 50%, var(--bazzano) 50%);
}

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom, 0px)); z-index: 15;
  background: var(--ink); color: var(--paper); border-radius: 12px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 14px; width: max-content; max-width: calc(100% - 28px); font-size: 15px;
}
#toast[hidden] { display: none; }
#toast button { border: 0; background: transparent; color: var(--mark); font-weight: 700; padding: 6px 8px; }
.loading { padding: 60px 20px; text-align: center; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
