:root {
  --petrolio: #0b4f63;
  --acqua: #1e9e97;
  --acqua-chiaro: #4fc7bb;
  --grad: linear-gradient(135deg, #062f3b 0%, #0b4f63 45%, #1e9e97 100%);
  --grad-btn: linear-gradient(135deg, #0b4f63 0%, #137a82 60%, #1e9e97 100%);
  --bg: #e6eff0;
  --bg-grad: linear-gradient(180deg, #d9e7e9 0%, #eef5f5 260px);
  --card: #ffffff;
  --text: #0a3541;
  --muted: #5d7c83;
  --line: #cfe0e2;
  --soft: #e3f3f2;
  --input: #eaf2fd;
  --ok: #138a63;
  --warn: #d14343;
  --radius: 22px;
  --radius-sm: 16px;
  --shadow: 0 4px 18px rgba(6, 47, 59, .10);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #052630;
    --bg-grad: linear-gradient(180deg, #041d25 0%, #052630 260px);
    --card: #0b3844;
    --text: #e6f4f4;
    --muted: #9dbcc1;
    --line: #17505d;
    --soft: #0f4754;
    --input: #0a2f39;
    --shadow: 0 4px 18px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: "Jost", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg) var(--bg-grad) no-repeat;
  color: var(--text);
  font-size: 16px;
  min-height: 100vh;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Barra superiore */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  background: var(--grad); color: #fff;
  border-radius: 0 0 24px 24px;
  box-shadow: 0 6px 20px rgba(6, 47, 59, .30);
}
.brand { flex: 1; display: flex; align-items: center; gap: 12px; font-weight: 500; font-size: 21px; min-width: 0; letter-spacing: .3px; }
.brand #title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 14px;
  background: #fff; color: var(--petrolio); font-weight: 800; letter-spacing: -1px; flex: none;
}
.icon-btn { background: rgba(255,255,255,.16); border: 0; color: #fff; width: 42px; height: 42px; border-radius: 14px; font-size: 20px; cursor: pointer; flex: none; }

main { padding: 16px 14px 24px; max-width: 760px; margin: 0 auto; }

/* Barra in basso */
.tabbar {
  position: fixed; bottom: 10px; left: 10px; right: 10px; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border: 1px solid var(--line); border-radius: 24px;
  box-shadow: 0 6px 22px rgba(6, 47, 59, .18);
  margin-bottom: env(safe-area-inset-bottom);
  max-width: 640px; margin-left: auto; margin-right: auto;
}
.tabbar button {
  border: 0; background: none; padding: 8px 2px 9px; font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; border-radius: 20px;
}
.tabbar button span { font-size: 22px; filter: grayscale(.7); }
.tabbar button.active { color: var(--petrolio); font-weight: 700; background: var(--soft); }
@media (prefers-color-scheme: dark) { .tabbar button.active { color: var(--acqua-chiaro); } }
.tabbar button.active span { filter: none; }

/* Elementi generali */
h2 { font-size: 18px; font-weight: 600; margin: 20px 6px 10px; }
h2:first-child { margin-top: 4px; }
.muted { color: var(--muted); font-size: 14px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px; border: 1px solid var(--line);
}
.card.click { cursor: pointer; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .big { font-size: 46px; }

.btn {
  border: 0; border-radius: var(--radius-sm); padding: 14px 16px; font-weight: 600; cursor: pointer;
  background: var(--soft); color: var(--petrolio); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
@media (prefers-color-scheme: dark) { .btn { color: var(--acqua-chiaro); } }
.btn.primary { background: var(--grad-btn); color: #fff; box-shadow: 0 6px 16px rgba(11, 79, 99, .30); text-transform: uppercase; letter-spacing: .5px; }
.btn.danger { background: #fde4e4; color: var(--warn); }
.btn.wa { background: #22c55e; color: #fff; }
.btn.block { width: 100%; }
.btn.small { padding: 8px 13px; font-size: 14px; border-radius: 12px; text-transform: none; letter-spacing: 0; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

label.field { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; margin-top: 5px; padding: 13px 14px; border-radius: 14px; border: 1.5px solid transparent;
  background: var(--input); outline: none;
}
.input:focus { border-color: var(--acqua); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; background: var(--soft); color: var(--petrolio); font-size: 12px; font-weight: 700; }
.pill.ok { background: #d8f3ea; color: var(--ok); }
.pill.warn { background: #fde4e4; color: var(--warn); }

.progress { height: 10px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--grad-btn); border-radius: 99px; transition: width .3s; }

.fab {
  position: fixed; right: 20px; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 15;
  width: 62px; height: 62px; border-radius: 22px; border: 0; background: var(--grad-btn); color: #fff;
  font-size: 32px; box-shadow: 0 8px 20px rgba(11, 79, 99, .40); cursor: pointer;
}

/* Ricerca e chips */
.search-wrap { position: relative; }
.suggest {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 10; margin-top: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  max-height: 280px; overflow: auto;
}
.suggest button { display: flex; width: 100%; text-align: left; gap: 8px; padding: 12px 14px; border: 0; background: none; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.suggest button:last-child { border-bottom: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none; border: 1.5px solid var(--line); background: var(--card); border-radius: 99px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--grad-btn); color: #fff; border-color: transparent; }
.chip.added { background: var(--soft); color: var(--petrolio); border-color: var(--acqua); }
@media (prefers-color-scheme: dark) { .chip.added { color: var(--acqua-chiaro); } }

/* Articoli */
.cat-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--acqua); margin: 14px 6px 6px; }
.group { break-inside: avoid; }
.item {
  display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 10px 12px; margin-bottom: 7px;
}
.item .name { font-weight: 600; }
.item .meta { font-size: 13px; color: var(--muted); }
.item .x { border: 0; background: none; font-size: 20px; color: var(--muted); cursor: pointer; padding: 4px 6px; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 32px; height: 32px; border-radius: 11px; border: 0; background: var(--soft); color: var(--petrolio); font-weight: 800; cursor: pointer; }
.qty span { min-width: 46px; text-align: center; font-size: 14px; font-weight: 700; }
.price-tag {
  border: 1.5px dashed var(--acqua); background: var(--soft); color: var(--petrolio); border-radius: 12px;
  padding: 5px 9px; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap; flex: none;
}
@media (prefers-color-scheme: dark) { .price-tag, .qty button { color: var(--acqua-chiaro); } }

/* Modalità spesa */
.check-item { cursor: pointer; padding: 14px 12px; user-select: none; }
.check-item .box {
  width: 30px; height: 30px; border-radius: 10px; border: 2.5px solid var(--acqua); flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 900;
}
.check-item.done { opacity: .55; }
.check-item.done .box { background: var(--grad-btn); border-color: transparent; }
.check-item.done .name { text-decoration: line-through; }
.shop-head { position: sticky; top: 74px; z-index: 5; }

/* Pannello in basso */
.backdrop { position: fixed; inset: 0; background: rgba(4, 29, 37, .55); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88vh; overflow: auto;
  background: var(--card); border-radius: 28px 28px 0 0; padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; animation: up .2s ease-out;
}
.sheet h3 { margin: 0 0 12px; font-weight: 600; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 60;
  background: #062f3b; color: #fff; padding: 12px 20px; border-radius: 16px; font-size: 14px; max-width: 90vw;
}

/* Messaggio spesa fatta */
.celebrate { text-align: center; padding: 10px 0; }
.celebrate .emoji { font-size: 70px; animation: pop .6s ease-out; }
.celebrate h3 { font-size: 26px; background: var(--grad-btn); -webkit-background-clip: text; background-clip: text; color: transparent; }
@keyframes pop { 0% { transform: scale(.2); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* Prezzo rapido */
.price-big { font-size: 40px; font-weight: 700; text-align: center; color: var(--petrolio); margin: 6px 0 12px; }
@media (prefers-color-scheme: dark) { .price-big { color: var(--acqua-chiaro); } }
.price-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

/* Promemoria */
.rem .when { font-weight: 700; color: var(--acqua); font-size: 14px; }
.rem.past { opacity: .55; }
.rem .check { width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid var(--acqua); background: none; cursor: pointer; flex: none; color: #fff; }
.rem .check.on { background: var(--grad-btn); border-color: transparent; }
.rem.fatto .title { text-decoration: line-through; }

.today-box { background: var(--grad); color: #fff; border: 0; }

.stat { text-align: center; }
.stat b { display: block; font-size: 22px; color: var(--acqua); }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0; }
.bar-row .lbl { width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar { flex: 1; height: 10px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.bar-row .bar > div { height: 100%; background: var(--grad-btn); border-radius: 99px; }

/* Gestione prodotti */
details.cat-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; box-shadow: var(--shadow); overflow: hidden; }
details.cat-box summary { list-style: none; padding: 14px 16px; cursor: pointer; display: flex; align-items: center; gap: 10px; font-weight: 600; }
details.cat-box summary::-webkit-details-marker { display: none; }
details.cat-box summary::after { content: '›'; font-size: 22px; color: var(--muted); transition: transform .2s; }
details.cat-box[open] summary::after { transform: rotate(90deg); }
details.cat-box.off { opacity: .5; }
.cat-body { padding: 0 12px 12px; }
.prod-row { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-top: 1px solid var(--line); }

/* Tablet e schermi larghi (anche in orizzontale) */
@media (min-width: 760px) {
  main { max-width: 1100px; padding: 22px 26px 30px; }
  .cols { columns: 2; column-gap: 18px; }
  .list-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
  .sheet { border-radius: 28px; bottom: 16px; left: 16px; right: 16px; }
  .fab { right: max(26px, calc(50% - 530px)); }
  .shop-head { top: 80px; }
}
@media (min-width: 1200px) {
  .cols { columns: 3; }
  .list-cards { grid-template-columns: repeat(3, 1fr); }
}
/* Telefono in orizzontale: barra superiore più bassa */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { padding-top: 6px; padding-bottom: 6px; }
  .shop-head { position: static; }
}
