:root {
  --bg: #f6f6f4; --card: #ffffff; --ink: #18181b; --mute: #6b6b70; --line: #e6e6e2;
  --accent: #1d7a4a; --accent-soft: #e8f4ec; --save: #c8362b; --warn: #a35d00; --chip: #efefec;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214; --card: #1c1c1f; --ink: #ececee; --mute: #9d9da3; --line: #2c2c30;
    --accent: #5cc48c; --accent-soft: #1d2e24; --save: #e0594e; --warn: #e0a347; --chip: #26262a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121214; --card: #1c1c1f; --ink: #ececee; --mute: #9d9da3; --line: #2c2c30;
  --accent: #5cc48c; --accent-soft: #1d2e24; --save: #e0594e; --warn: #e0a347; --chip: #26262a;
  --shadow: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }
button, input, select { font: inherit; color: inherit; }

/* header */
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-inner { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--mute); font-size: 13px; }
.icon-btn { background: var(--chip); border: 0; border-radius: 999px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; }
.tabs { display: flex; gap: 4px; margin-top: 10px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; color: var(--mute); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* controls */
.controls { margin: 16px 0 10px; display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap-row { flex-wrap: wrap; }
#q { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); max-width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--chip); border: 1px solid transparent; border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.toggles { gap: 16px; font-size: 14px; color: var(--mute); }
.toggles label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.count { margin-left: auto; font-size: 13px; }

/* best deals */
.best { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin: 6px 0 18px; }
.best-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.best-card.fav { border-color: var(--accent); }
.best-card h3 { margin: 0 0 6px; font-size: 13px; color: var(--mute); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.best-card .bp { font-size: 22px; font-weight: 700; color: var(--accent); }
.best-card .bn { font-weight: 600; }
.best-card .bs { color: var(--mute); font-size: 13px; }

/* list */
h2.group { font-size: 17px; margin: 22px 0 8px; display: flex; align-items: baseline; gap: 8px; }
h2.group small { color: var(--mute); font-weight: 400; font-size: 13px; }
.item { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: start; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.item.top { border-color: var(--accent); }
.thumb { width: 64px; height: 64px; border-radius: 8px; background: #fff; object-fit: contain; }
.ph { width: 64px; height: 64px; border-radius: 8px; background: var(--chip); display: grid; place-items: center; color: var(--mute); font-weight: 700; font-size: 20px; }
.name { font-weight: 600; }
.brand { color: var(--mute); font-weight: 400; }
.stores { font-size: 13px; margin-top: 2px; }
.plink { color: inherit; text-decoration: none; }
.plink:hover { text-decoration: underline; }
.src { font-size: 12.5px; margin-top: 2px; color: var(--mute); }
.src a { color: var(--accent); text-decoration: none; overflow-wrap: anywhere; }
.src a:hover { text-decoration: underline; }
a.best-card { display: block; color: inherit; text-decoration: none; }
a.best-card:hover { border-color: var(--accent); }
.details { color: var(--mute); font-size: 12.5px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.details.open { -webkit-line-clamp: unset; }
.tags { margin-top: 5px; display: flex; gap: 5px; flex-wrap: wrap; }
.tag { font-size: 11px; border-radius: 5px; padding: 1px 6px; background: var(--chip); color: var(--mute); }
.tag.tag-best { background: var(--accent); color: var(--card); }
.tag.low { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: transparent; color: var(--warn); border: 1px solid var(--warn); font-weight: 600; }
.price { text-align: right; white-space: nowrap; }
.each { font-size: 19px; font-weight: 700; color: var(--accent); }
.was { font-size: 12.5px; color: var(--mute); }
.disc { display: inline-block; background: var(--save); color: #fff; border-radius: 5px; padding: 0 6px; font-weight: 700; font-size: 12px; margin-left: 4px; }
.nodisc { color: var(--warn); font-size: 12px; font-weight: 600; }
.unknown { color: var(--mute); font-size: 11.5px; font-style: italic; }
.printed, .pl, .hist { font-size: 12px; color: var(--mute); }
.star { background: none; border: 0; cursor: pointer; font-size: 20px; line-height: 1; color: var(--mute); padding: 2px; margin-top: 6px; }
.star[aria-pressed="true"] { color: #e2a400; }
.empty { text-align: center; color: var(--mute); padding: 40px 0; }
.more { text-align: center; margin: 12px 0; }
.more button { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 18px; cursor: pointer; }
.foot { color: var(--mute); font-size: 12.5px; margin: 24px 0 40px; }

@media (max-width: 560px) {
  .item { grid-template-columns: 48px 1fr; }
  .thumb, .ph { width: 48px; height: 48px; }
  .price { grid-column: 2; text-align: left; display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; }
  .star { margin-top: 0; }
}

/* Veckans recept */
.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-bottom: 8px; }
.rgrid.small { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.rcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.rimg { position: relative; display: block; aspect-ratio: 16 / 10; background: var(--chip); }
.rimg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rph { width: 100%; height: 100%; display: grid; place-items: center; font-size: 34px; }
.day { position: absolute; left: 10px; top: 10px; background: var(--card); color: var(--ink); font-weight: 700; font-size: 13px; padding: 3px 9px; border-radius: 999px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.rbody { padding: 10px 12px 12px; }
.rcard h3 { margin: 0 0 3px; font-size: 16px; line-height: 1.3; }
.rgrid.small .rcard h3 { font-size: 14.5px; }
.rlink { color: inherit; text-decoration: none; }
.rlink:hover { text-decoration: underline; }
.rmeta, .rest { color: var(--mute); font-size: 12.5px; }
.rscale { color: var(--warn); font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.rsale-h { font-size: 12px; color: var(--mute); margin: 8px 0 4px; text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.rsale { display: flex; flex-wrap: wrap; gap: 5px; }
.sale { font-size: 12.5px; background: var(--accent-soft); color: var(--accent); border-radius: 7px; padding: 2px 7px; text-decoration: none; }
.sale b { font-weight: 600; }
a.sale:hover { text-decoration: underline; }
.rest { margin-top: 6px; }
.shop { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px 12px; margin: 18px 0; }
.shop-head { display: flex; align-items: center; gap: 8px; }
.shop-head h2 { margin-right: auto; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; cursor: pointer; }
.shop-tip { margin: 0 0 8px; font-size: 14px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 4px 24px; }
.shop-store h4 { margin: 10px 0 4px; font-size: 14.5px; }
.shop-store h4 small, .muted { color: var(--mute); font-weight: 400; }
.shop-item { display: flex; gap: 8px; align-items: baseline; font-size: 13.5px; padding: 3px 0; cursor: pointer; }
.shop-item.done span { text-decoration: line-through; color: var(--mute); }
@media print {
  body.print-shop .top, body.print-shop .rgrid, body.print-shop h2.group:not(.shop h2), body.print-shop .foot, body.print-shop .ghost, body.print-shop .rintro { display: none !important; }
  body.print-shop .shop { border: 0; }
}

/* the hidden attribute wins over display:grid/flex above */
[hidden] { display: none !important; }

/* "Nästa vecka" note */
.next-note { margin: 4px 0 14px; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft);
  color: var(--ink); font-size: .92rem; line-height: 1.45; }
.next-note a, .foot a, .panel a { color: var(--accent); }

/* header: who is logged in */
.top-right { display: flex; align-items: center; gap: 10px; }
.who { font-size: 13px; color: var(--mute); }

/* buttons and forms */
.primary { background: var(--accent); color: var(--card); border: 0; border-radius: 9px; padding: 8px 14px; font-weight: 600; cursor: pointer; }
.primary.small { padding: 4px 10px; font-size: 13px; }
.primary:disabled, .ghost:disabled { opacity: .5; cursor: default; }
.ghost.danger { color: var(--save); border-color: var(--save); }
.mini { background: none; border: 1px solid var(--line); border-radius: 7px; padding: 2px 8px; font-size: 12px; color: var(--mute); cursor: pointer; }
.mini:hover { border-color: var(--accent); color: var(--accent); }
.acts { display: flex; gap: 6px; margin-top: 6px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px 14px; margin: 12px 0; box-shadow: var(--shadow); }
.panel h3 { margin: 10px 0 4px; font-size: 16px; }
.panel input:not([type=checkbox]), .panel textarea, .panel select, .add-row input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.panel textarea { resize: vertical; font: inherit; color: inherit; }
.panel label { display: grid; gap: 4px; font-size: 13.5px; color: var(--mute); }
.panel label small, .field-label small { font-weight: 400; color: var(--mute); }
.panel label.inline, .panel .toggles label, .panel .switch { display: inline-flex; align-items: center; gap: 6px; }
.panel label.block { margin-top: 10px; }
.share select { width: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; margin: 8px 0; align-items: start; }
.grid2 .wide { grid-column: 1 / -1; }
.field-label { font-size: 13.5px; color: var(--mute); margin: 12px 0 6px; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.form-row.end { justify-content: flex-end; }
.add-row { display: flex; gap: 8px; margin: 8px 0; }
.add-row input { flex: 1; min-width: 0; }
.small { font-size: 12.5px; }
.steps { margin: 6px 0 10px; padding-left: 20px; font-size: 14px; }
code { background: var(--chip); border-radius: 5px; padding: 0 5px; font-size: 12.5px; overflow-wrap: anywhere; }
.form-msg { color: var(--save); min-height: 1.2em; margin: 4px 0 0; font-size: 14px; }

/* real-deal check */
.tag.v-low, .tag.v-good { background: var(--accent-soft); color: var(--accent); }
.tag.v-stock { background: var(--accent); color: var(--card); font-weight: 600; }
.tag.v-fake, .tag.v-inflated { background: transparent; color: var(--save); border: 1px solid var(--save); }

/* price alerts */
.alert-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.alert.off { opacity: .6; }
.switch { white-space: nowrap; margin-top: 12px; }
.hits-h { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--mute); margin: 10px 0 2px; }
.hits { margin: 0; padding-left: 18px; font-size: 14px; }
.hits li { margin: 2px 0; }
.hits b { color: var(--accent); }

/* shopping lists */
.list-picker { margin: 16px 0 4px; }
.items { list-style: none; margin: 4px 0; padding: 0; }
.li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 7px 0; }
.panel .li label { display: flex; gap: 10px; align-items: baseline; flex: 1; cursor: pointer; font-size: 15px; color: var(--ink); }
.li input { width: 18px; height: 18px; flex: none; transform: translateY(3px); }
.li.done .li-text { text-decoration: line-through; color: var(--mute); }
.by { font-size: 11px; background: var(--chip); color: var(--mute); border-radius: 5px; padding: 0 5px; }
.x { background: none; border: 0; color: var(--mute); font-size: 18px; cursor: pointer; padding: 0 6px; line-height: 1; }
.done-h { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--mute); margin-top: 14px; }
.empty-li { padding: 14px 0; border: 0; }
.share { margin-top: 14px; font-size: 13.5px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.member { background: var(--chip); border-radius: 999px; padding: 2px 4px 2px 10px; }

/* watchlist editor */
.wl { border-top: 1px solid var(--line); padding: 8px 0 10px; }

/* status */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.stat.bad { border-color: var(--save); }
.stat h3 { margin: 0 0 4px; font-size: 12px; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
.stat .muted { font-size: 12.5px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.toast.bad { background: var(--save); color: #fff; }

/* login */
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.login-box form { display: grid; gap: 12px; margin-top: 14px; }
.login-box label { display: grid; gap: 4px; font-size: 13.5px; color: var(--mute); }
.login-box input { padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font: inherit; color: var(--ink); }
.login-box .primary { padding: 10px; }
.login-box .foot { margin: 14px 0 0; }

@media (max-width: 560px) {
  .who { display: none; }
  .alert-head { flex-direction: column; }
  .switch { margin-top: 0; }
}
