:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f9fafb; --border: #e3e5e9; --text: #1d2330;
  --muted: #667085; --accent: #1f7a6d; --accent-ink: #ffffff; --danger: #c62828; --ok: #18794e;
  --warn: #b25e09; --star: #c98a00;
  --radius: 8px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1a1e26; --surface-2: #20252f; --border: #2c323d; --text: #e6e8ec;
    --muted: #9aa3b2; --accent: #4cc3b0; --accent-ink: #0d1220; --danger: #ff6b6b; --ok: #4cc38a;
    --warn: #f0a14a; --star: #f5c04a;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* layout */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: .6rem 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--muted); padding: .35rem .65rem; border-radius: 6px; }
.nav a:hover, .nav a.active { color: var(--text); background: var(--surface-2); text-decoration: none; }
.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.row > .grow { flex: 1 1 200px; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

/* forms */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
.field { margin-bottom: .8rem; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number],
input[type=datetime-local], input[type=date], input[type=time], input[type=url], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=file] { font: inherit; max-width: 100%; }
.check { display: flex; gap: .45rem; align-items: center; font-weight: 400; font-size: .9rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.btn { display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .48rem .9rem; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; line-height: 1.2; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .25rem .55rem; font-size: .82rem; }
.btn.block { width: 100%; text-align: center; }
.inline { display: inline; }
.hidden { display: none !important; }

/* alerts */
.alert { padding: .65rem .9rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid var(--border); background: var(--surface); }
.alert.ok { border-color: var(--ok); color: var(--ok); }
.alert.error { border-color: var(--danger); color: var(--danger); }
.alert.warn { border-color: var(--warn); color: var(--warn); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
th a { color: var(--muted); }
th a.sorted { color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
td.num { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* badges */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid currentColor; white-space: nowrap; }
.tag { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* status tabs */
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .9rem; }
.tabs a { padding: .35rem .75rem; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); background: var(--surface); font-size: .88rem; }
.tabs a.active { color: var(--text); border-color: var(--text); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs .count { font-weight: 700; margin-left: .25rem; }

/* key/value */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

details > summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: .75rem; }

/* auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { text-align: center; margin-bottom: 1rem; }
.divider { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .8rem; margin: 1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.qr { background: #fff; padding: .5rem; border-radius: 6px; display: inline-block; }
.codes { display: grid; grid-template-columns: repeat(2, max-content); gap: .4rem 1.5rem; font-size: 1.05rem; }

/* utilità (niente stili inline: la CSP li blocca) */
.mt-05 { margin-top: .5rem; }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }

/* telefono */
@media (max-width: 700px) {
  .topbar-inner { gap: .5rem; }
  .brand { flex: 1; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .hide-sm { display: none; }
  th, td { padding: .5rem .55rem; }
  h1 { font-size: 1.25rem; }
}

/* ---------------------------------------------------------------- Lista */
.shell { max-width: 1200px; margin: 0 auto; display: flex; gap: 0; }
.shell > .container { flex: 1; min-width: 0; margin: 0; }
.sidebar { width: 270px; flex: none; padding: 1.25rem 0 2rem 1rem; }
.navlists { display: flex; flex-direction: column; gap: 1px; position: sticky; top: 4rem; }
.navlists a { display: flex; align-items: center; gap: .4rem; padding: .45rem .6rem; border-radius: 6px; color: var(--text); }
.navlists a:hover { background: var(--surface); text-decoration: none; }
.navlists a.active { background: var(--surface); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.navlists a.in-group { padding-left: 1.3rem; }
.navlists .nl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navlists .count { color: var(--muted); font-size: .85rem; }
.navlists .shared { font-size: .7rem; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 .3rem; }
.navlists .nl-smart { color: var(--accent); }
.navlists .nl-group { margin-top: .8rem; padding: .2rem .6rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.navlists .nl-new { margin-top: .8rem; color: var(--accent); font-weight: 600; }
.narrow { max-width: 560px; }
.pad { padding: .9rem 1.1rem; }
.grid-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 900px) { .grid-even { grid-template-columns: minmax(0, 1fr); } }
.group-title { margin: 1.2rem 0 .2rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.menu-list { display: flex; flex-direction: column; }
.menu-list a { padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); color: var(--text); display: flex; justify-content: space-between; gap: .75rem; align-items: center; }
.menu-list a:last-child { border-bottom: 0; }
.menu-list a:hover { background: var(--surface-2); text-decoration: none; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li, ol.plain li { padding: .35rem 0; border-bottom: 1px solid var(--border); }
ul.plain li:last-child, ol.plain li:last-child { border-bottom: 0; }
ol.plain { padding-left: 1.2rem; margin: 0; }
.preview { max-height: 60vh; overflow-y: auto; }
textarea.tall { min-height: 220px; }
.w-qty { width: 6.5rem; }
.w-price { width: 8rem; }
.big { font-size: 1.1rem; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger); }
.linkbtn { border: 0; background: none; color: var(--danger); font: inherit; font-size: .8rem; cursor: pointer; padding: 0 .2rem; }
.auth-card.wide { max-width: 460px; }
td.best { font-weight: 700; color: var(--ok); }
tr.sel td { background: var(--surface-2); }
.verdict { border-color: var(--accent); }
.verdict strong { color: var(--accent); }
.store-row { padding: .3rem 0; border-bottom: 1px solid var(--border); align-items: center; }

/* intestazione della lista */
.list-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: .75rem; }
.list-head h1 { overflow-wrap: anywhere; }
.list-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.shop-banner { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: .75rem; }
.shop-start { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: .75rem; }
.shop-start[open] > summary { margin-bottom: .5rem; }

/* aggiunta rapida */
.add-form { display: flex; gap: .5rem; margin-bottom: .5rem; position: sticky; top: 3.4rem; z-index: 5; background: var(--bg); padding: .35rem 0; }
.add-form input[type=text] { flex: 1; font-size: 1rem; padding: .65rem .75rem; }

/* elementi */
ul.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: .25rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: .4rem; min-height: 3.2rem; }
.item .tick, .item .star { display: flex; }
.tick-btn { width: 2.9rem; height: 3.1rem; border: 0; background: none; cursor: pointer; position: relative; flex: none; }
.tick-btn::before { content: ""; position: absolute; left: .75rem; top: .9rem; width: 1.35rem; height: 1.35rem; border-radius: 50%;
  border: 2px solid var(--muted); box-sizing: border-box; }
.tick-btn:hover::before { border-color: var(--accent); }
.item.is-done .tick-btn::before { background: var(--muted); border-color: var(--muted); }
.item.is-done .tick-btn::after { content: ""; position: absolute; left: 1.23rem; top: 1.15rem; width: .38rem; height: .7rem;
  border: solid var(--surface); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.item-main { flex: 1; min-width: 0; padding: .5rem .2rem; color: var(--text); display: flex; flex-direction: column; }
.item-main:hover { text-decoration: none; }
.item-title { overflow-wrap: anywhere; font-size: 1rem; }
.item.is-done .item-title { text-decoration: line-through; color: var(--muted); }
.item-meta { display: flex; flex-wrap: wrap; gap: .1rem .6rem; font-size: .78rem; color: var(--muted); }
.item-meta .price { color: var(--accent); font-weight: 600; }
.item-meta .price.stale { color: var(--warn); }
.qty { color: var(--accent); font-weight: 600; }
.star-btn { width: 2.9rem; height: 3.1rem; border: 0; background: none; cursor: pointer; position: relative; }
.star-btn::before { content: ""; position: absolute; left: .85rem; top: .95rem; width: 1.2rem; height: 1.2rem; background: var(--border);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.star-btn.on::before { background: var(--star); }
.star-btn:hover::before { background: var(--muted); }
.star-btn.on:hover::before { background: var(--star); }
.empty-row { padding: 1rem .5rem; }
.done-block { margin-top: 1rem; }
.done-block > summary { padding: .4rem .2rem; }
.items.done .item { opacity: .85; }

/* codice a barre */
.scanner video { width: 100%; max-height: 50vh; border-radius: 6px; background: #000; display: block; }

/* telefono */
.bottomnav { display: none; }
@media (max-width: 700px) {
  .topbar-inner { padding-top: calc(.5rem + env(safe-area-inset-top)); }
  .container { padding: .9rem .75rem 5.5rem; }
  .footer { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
  .add-form { top: 2.9rem; }
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; text-align: center; padding: .85rem .1rem; color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
  .bottomnav a.active { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }
  .bottomnav a:hover { text-decoration: none; }
  .bottomnav .dot { display: inline-block; min-width: 1.1rem; padding: 0 .3rem; margin-left: .25rem; border-radius: 999px;
    background: var(--accent); color: var(--accent-ink); font-size: .7rem; line-height: 1.1rem; }
  .w-qty, .w-price { width: 100%; }
}
@media (display-mode: standalone) { .footer { display: none; } }
