/* Mobile first: grundstilarna gäller små skärmar, större skärmar läggs på med min-width. */
:root {
  --bg: #edf4ee; --surface: #ffffff; --ink: #17251b; --muted: #607267; --line: #cbd9ce;
  --brand: #14532d; --brand-ink: #ffffff; --owned: #198754; --owned-soft: #dff3e5;
  --danger: #b42318; --focus: #e2b52b; --radius: 12px; --tap: 44px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #101b14; --surface: #18271d; --ink: #edf5ee; --muted: #a5b7a9; --line: #34493a;
    --brand: #236b3d; --owned: #6ad28c; --owned-soft: #1f3b29; --danger: #ff887d; --focus: #d2f86a; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); -webkit-tap-highlight-color: transparent;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: env(safe-area-inset-bottom); }
button, input, select { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; min-height: var(--tap); }
input, select { font-size: 16px; min-height: var(--tap); } /* 16 px hindrar iOS från att zooma in */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.primary { min-height: 48px; padding: 0 20px; border: 0; border-radius: 10px; background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.primary:disabled { opacity: .6; }
.error { color: var(--danger); margin: 0 0 12px; font-size: .92rem; }

/* Inloggning */
.auth { min-height: 100dvh; display: grid; align-items: center; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); background: var(--brand); }
.auth-box { width: min(420px, 100%); margin: 0 auto; background: var(--surface); border-radius: 16px; padding: 22px; }
.auth-box h1 { margin: 0 0 4px; font-size: 1.7rem; letter-spacing: -0.02em; }
.lede { margin: 0 0 18px; color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
form label, .sheet-body label { display: block; margin-bottom: 14px; font-weight: 600; font-size: .92rem; }
form input, .sheet-body select { display: block; width: 100%; margin-top: 6px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.auth form .primary { width: 100%; }

/* Topp */
.top { background: var(--brand); color: var(--brand-ink); padding: calc(10px + env(safe-area-inset-top)) 14px 12px; }
.top-inner { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.brand strong { display: block; font-size: 1.15rem; letter-spacing: -0.01em; line-height: 1.2; }
.brand span { font-size: .8rem; opacity: .8; }
.progress { grid-column: 1 / -1; }
.progress-text { font-size: .88rem; margin-bottom: 6px; }
.bar { height: 10px; border-radius: 99px; background: rgba(255,255,255,.22); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: #b7ef45; border-radius: 99px; transition: width .35s ease; }
.user { position: relative; }
.user summary { list-style: none; cursor: pointer; display: grid; place-items: center; min-height: var(--tap); padding: 0 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.35); font-size: .85rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user summary::-webkit-details-marker { display: none; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: min(280px, calc(100vw - 28px)); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 0 12px; border-radius: 8px; }
.menu button:hover { background: var(--bg); }
.menu .danger { color: var(--danger); }

/* Verktygsrad: sökfält + filter + Alla/Har/Saknas, fastnar överst när man scrollar */
.toolbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.toolbar-inner { max-width: 1100px; margin: 0 auto; padding: 8px 12px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.search input { width: 100%; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.filterbtn { padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.count { min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; background: var(--brand); color: var(--brand-ink); font-size: .75rem; display: inline-grid; place-items: center; }
.seg { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: var(--bg); border: 0; border-right: 1px solid var(--line); border-radius: 0; font-weight: 500; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px; scrollbar-width: none; max-width: 1100px; margin: 0 auto; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 0 14px; min-height: 40px; font-size: .9rem; }
.chip[aria-pressed="true"] { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); font-weight: 600; }
.chip small { color: var(--muted); margin-left: 6px; }

/* Lista */
.content { max-width: 1100px; margin: 0 auto; padding: 4px 12px 24px; }
.listhead { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin: 4px 0 10px; font-size: .88rem; }
.listhead p { margin: 0; color: var(--muted); }
.linkbtn { color: var(--brand); font-weight: 600; padding: 10px 0; }
@media (prefers-color-scheme: dark) { .linkbtn, .links a { color: #b7ef45; } }
.binder { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* Kortplatser: saknade kort syns som tomma, streckade platser i en pärm */
.slot { background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius); padding: 6px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.slot.owned { border: 2px solid var(--owned); }
.slot.missing .art { filter: grayscale(1); opacity: .5; }
.art-btn { all: unset; display: block; cursor: pointer; border-radius: 8px; }
.art-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.art { position: relative; aspect-ratio: 5 / 7; border-radius: 8px; overflow: hidden; background: var(--bg); }
.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.art .ex { position: absolute; left: 6px; bottom: 6px; font-size: .68rem; padding: 2px 7px; border-radius: 99px; background: rgba(23,37,27,.85); color: #fff; }
.art.mine .ex { background: var(--owned); }
.ph { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; padding: 8px; background: repeating-linear-gradient(135deg, var(--bg), var(--bg) 10px, var(--surface) 10px, var(--surface) 20px); color: var(--muted); overflow: hidden; }
.ph strong { font-size: 1.4rem; color: var(--ink); }
.ph span { font-size: .75rem; overflow-wrap: anywhere; }
.info { padding: 0 2px; font-size: .84rem; line-height: 1.25; }
.info b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .92rem; }
.info span { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rookie { display: inline-block; margin-left: 6px; font-size: .66rem; font-weight: 700; padding: 1px 6px; border-radius: 99px; background: #f2c94c; color: #17251b; vertical-align: 1px; }
.tick { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; padding: 0 4px; font-weight: 600; font-size: .92rem; text-align: left; }
.box { flex: 0 0 auto; width: 26px; height: 26px; border: 2px solid var(--muted); border-radius: 7px; display: grid; place-items: center; background: var(--surface); }
.tick[aria-pressed="true"] .box { background: var(--owned); border-color: var(--owned); }
.tick[aria-pressed="true"] .box::after { content: ""; width: 6px; height: 12px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }
.actbtn { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: none; padding: 0 10px; font-size: .88rem; font-weight: 600; color: var(--brand); }
@media (prefers-color-scheme: dark) { .actbtn { color: #b7ef45; } }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty button { margin-top: 12px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.more { text-align: center; padding: 18px 0 32px; }
.more button { min-width: 60%; padding: 0 28px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }

/* Dialoger: bottenark på mobil (helskärm för kortdetaljer), centrerade rutor på större skärmar */
dialog { border: 0; padding: 0; background: var(--surface); color: var(--ink); overscroll-behavior: contain; }
dialog::backdrop { background: rgba(7, 18, 11, .65); }
.sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92dvh; }
.sheet.big { height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; overflow-y: auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 18px; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.sheet-body { padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-actions { display: grid; gap: 10px; margin-top: 18px; }
.sheet-actions button:not(.primary) { border: 1px solid var(--line); background: none; border-radius: 10px; }
.close { width: var(--tap); height: var(--tap); border-radius: 50%; border: 0; background: var(--bg); font-size: 1.6rem; line-height: 1; }
.close.floating { position: sticky; top: 8px; float: right; margin: 8px 8px -52px 0; z-index: 3; }

.detail { display: grid; gap: 16px; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.detail .art { width: min(58vw, 260px); margin: 8px auto 0; }
.art.mine img { object-fit: contain; background: #07120b; }
.detail h2 { margin: 0 0 4px; font-size: 1.4rem; line-height: 1.15; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail .notes { color: var(--muted); font-size: .88rem; }
.actions { display: grid; gap: 10px; margin-top: 12px; }
.actions .primary { width: 100%; }
.actions .secondary { border: 1px solid var(--line); background: none; border-radius: 10px; font-weight: 600; }
.actions .danger { border: 1px solid var(--line); background: none; border-radius: 10px; color: var(--danger); font-weight: 600; }

/* Leta online */
.offers { border-top: 1px solid var(--line); padding-top: 16px; }
.offers h3 { margin: 0 0 10px; font-size: 1.05rem; }
.offers .row { display: grid; gap: 10px; }
.offers .primary { width: 100%; }
.off-status { margin: 10px 0 0; color: var(--muted); font-size: .88rem; }
.off-status.err { color: var(--danger); }
.lowtoggle { font-size: .9rem; color: var(--muted); display: flex; gap: 10px; align-items: center; min-height: var(--tap); margin: 0 !important; font-weight: 400 !important; }
.lowtoggle input { width: 22px; height: 22px; min-height: 0; margin: 0; display: inline-block; }
.offer-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.offer { display: grid; grid-template-columns: 52px 1fr; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.offer img, .offer .noimg { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.offer a.t { color: var(--ink); font-weight: 600; text-decoration: none; display: block; line-height: 1.25; overflow-wrap: anywhere; }
.offer .meta { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.offer .price { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.offer .price b { font-size: 1.1rem; }
.offer .price small { color: var(--muted); font-size: .8rem; }
.offer .open { margin-left: auto; display: inline-grid; place-items: center; min-height: var(--tap); padding: 0 18px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); font-size: .9rem; text-decoration: none; font-weight: 600; }
.badge { font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; margin-left: 6px; white-space: nowrap; }
.badge.high { background: var(--owned-soft); color: var(--owned); }
.badge.medium { background: #fff2c2; color: #695000; }
.badge.low { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { .badge.medium { background: #4b3b0c; color: #ffe38a; } }
.sources { margin: 10px 0 0; font-size: .8rem; color: var(--muted); }
.links { margin: 14px 0 0; font-size: .9rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.links a { color: #176b3a; font-weight: 600; padding: 12px 10px; }

/* Skanna: helskärm */
#scan { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; background: #07120b; color: #fff; border-radius: 0; }
#scan[open] { display: flex; flex-direction: column; }
.scan-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; }
.scan-top button { background: none; border: 0; color: #fff; justify-self: start; padding: 0 12px; font-size: 1rem; }
.scan-stage { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; overflow: hidden; }
.scan-view { position: relative; display: inline-block; line-height: 0; overflow: hidden; }
.scan-view video { display: block; max-width: 100vw; max-height: calc(100dvh - 190px); }
.scan-frame { position: absolute; border: 3px solid #b7ef45; border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.55); pointer-events: none; }
#scan-preview { max-width: 100vw; max-height: calc(100dvh - 190px); object-fit: contain; }
.scan-hint { position: absolute; left: 0; right: 0; bottom: 8px; margin: 0; text-align: center; font-size: .85rem; color: #fff; text-shadow: 0 1px 3px #000; padding: 0 16px; }
.scan-msg { margin: 0; padding: 24px; text-align: center; line-height: 1.4; }
.scan-bar { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
.scan-live-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.scan-review-bar { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
.sbtn { border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.12); color: #fff; border-radius: 10px; padding: 0 12px; font-size: .92rem; }
.shutter { width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff; background: rgba(255,255,255,.25); padding: 0; position: relative; }
.shutter::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: #fff; }
.shutter:active::after { inset: 9px; }
.shutter:disabled { opacity: .4; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 1000; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- Större skärmar ---- */
@media (min-width: 560px) {
  .binder { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .offers .row { display: flex; align-items: center; }
  .offers .primary { width: auto; }
  .offer { grid-template-columns: 56px 1fr auto; align-items: center; }
  .offer .price { grid-column: auto; flex-direction: column; align-items: flex-end; gap: 0; text-align: right; }
  .offer .open { margin: 6px 0 0; min-height: 36px; }
}
@media (min-width: 760px) {
  .top-inner { grid-template-columns: auto 1fr auto; gap: 20px; }
  .progress { grid-column: auto; grid-row: auto; }
  .top-inner .user { order: 3; }
  .toolbar-inner { grid-template-columns: 1fr auto auto; }
  .seg { grid-column: auto; min-width: 260px; }
  .binder { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
  .sheet { width: min(460px, calc(100vw - 32px)); margin: auto; border-radius: 16px; }
  .sheet.big { width: min(780px, calc(100vw - 32px)); height: auto; max-height: 90dvh; border-radius: 16px; margin: auto; }
  .detail { grid-template-columns: minmax(180px, 260px) 1fr; gap: 24px; padding: 24px; }
  .detail .art { width: auto; margin: 0; }
  .detail .offers { grid-column: 1 / -1; }
  .actions { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  #scan { width: min(560px, 100vw); height: min(100dvh, 860px); margin: auto; border-radius: 16px; }
}
