:root {
  --bg: #faf4e6;
  --card: #fffcf4;
  --ink: #23301f;
  --muted: #776f60;
  --line: #e6dcc6;
  --accent: #24371f;
  --accent-ink: #fbf5e8;
  --accent-soft: #e2e8d9;
  --mustard: #b08a3e;
  --rust: #b8523f;
  --good: #2f7a4f;
  --bad: #b23b3b;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1d17; --card: #242820; --ink: #f2ecdd; --muted: #a8a08f; --line: #383d32;
    --accent: #a9c29a; --accent-ink: #18221a; --accent-soft: #2e3829; --mustard: #d6b066; --rust: #e0806a;
    --good: #6cc792; --bad: #ef7a7a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; }
body { padding-top: calc(env(safe-area-inset-top) + 52px); padding-bottom: calc(env(safe-area-inset-bottom) + 76px); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h2 { font-size: 1.25rem; margin: 18px 0 8px; }
h3 { font-size: 1.05rem; margin: 0 0 6px; }

.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: var(--accent); color: var(--accent-ink); min-height: 52px; }
.topbar h1 { font-size: 1.2rem; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar .back { background: none; border: 0; color: inherit; font-size: 2rem; line-height: 1; padding: 0 6px 4px 0; cursor: pointer; }

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

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px;
  text-decoration: none; color: var(--muted); font-size: 0.7rem; }
.tabbar a .ti { font-size: 1.3rem; line-height: 1.2; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.scan .ti { background: var(--accent); color: var(--accent-ink); border-radius: 50%; width: 40px; height: 40px;
  display: grid; place-items: center; margin-top: -14px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.center { text-align: center; }
.hidden, [hidden] { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 11px 16px; border-radius: 12px; font-size: 1rem; font-weight: 600;
  text-decoration: none; cursor: pointer; font-family: inherit; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.big { padding: 18px; font-size: 1.15rem; border-radius: 16px; }
.btn.sm { padding: 6px 10px; font-size: 0.85rem; border-radius: 9px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btns .btn { flex: 1 1 auto; }

label { display: block; font-size: 0.8rem; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: auto; transform: scale(1.3); margin-right: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 600px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .v { font-family: var(--serif); font-size: 1.4rem; font-weight: 600; }
.stat .l { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.list { display: flex; flex-direction: column; gap: 8px; }
.li { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; text-decoration: none; color: inherit; }
.li .thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--accent-soft); flex: none;
  display: grid; place-items: center; color: var(--muted); font-size: 1.4rem; }
.li .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .s { font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .price { text-align: right; font-weight: 600; white-space: nowrap; }

.badge { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .04em; background: var(--accent-soft); color: var(--accent); }
.badge.sold { background: #e6dccb; color: #6b5a3c; }
.badge.passed { background: #eee; color: #777; }
.badge.researching { background: #f4e6c4; color: #8a6514; }
.badge.listed { background: #d8eadf; color: var(--good); }
.badge.unpaid { background: #f6d8cc; color: var(--rust); }
.badge.void { background: #eee; color: #888; }
.badge.buy { background: #d8eadf; color: var(--good); }
.badge.maybe { background: #f4e6c4; color: #8a6514; }
.badge.pass { background: #f3d6d6; color: var(--bad); }
@media (prefers-color-scheme: dark) {
  .badge.sold, .badge.passed, .badge.researching, .badge.listed, .badge.unpaid, .badge.void, .badge.buy, .badge.maybe, .badge.pass { background: var(--accent-soft); }
}

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin: 8px 0; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px;
  padding: 6px 12px; font-size: 0.85rem; cursor: pointer; font-family: inherit; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.photos { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin-bottom: 10px; }
.photos .ph { position: relative; flex: none; scroll-snap-align: start; }
.photos img { height: 220px; max-width: 85vw; border-radius: 12px; object-fit: cover; display: block; background: var(--accent-soft); }
.photos .ph .x { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.55); color: #fff; border: 0;
  border-radius: 99px; width: 28px; height: 28px; font-size: 1rem; cursor: pointer; }
.photos .ph .star { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.55); color: #fff; border: 0;
  border-radius: 99px; padding: 3px 8px; font-size: .75rem; cursor: pointer; }
.shots { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.shots img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 0.95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

.hero-price { font-family: var(--serif); font-size: 2rem; font-weight: 700; }
.good { color: var(--good); }
.bad { color: var(--bad); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 0.85rem; }
.bar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { height: 12px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.bar .val { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }

table.t { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.t th, table.t td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

.spinner { width: 42px; height: 42px; border: 4px solid var(--accent-soft); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 86px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50; font-size: .9rem;
  max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.25); }

.score { display: inline-flex; gap: 2px; }
.score i { width: 10px; height: 10px; border-radius: 2px; background: var(--line); display: inline-block; }
.score i.on { background: var(--mustard); }

.cart-line { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cart-line input { width: 96px; text-align: right; }
.total-box { text-align: center; padding: 18px; }
.total-box .hero-price { font-size: 2.6rem; }

.search-results { max-height: 260px; overflow-y: auto; margin-top: 6px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
ul.tight { margin: 4px 0; padding-left: 18px; }
.login { max-width: 360px; margin: 40px auto; text-align: center; }
.login .logo { width: 240px; height: 240px; border-radius: 50%; margin-bottom: 8px; mix-blend-mode: multiply; }
.home-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.home-head img { width: 64px; height: 64px; border-radius: 50%; mix-blend-mode: multiply; }
.home-head h2 { margin: 0; }
@media (prefers-color-scheme: dark) { .login .logo, .home-head img { mix-blend-mode: normal; } }

/* invoice */
.invoice { background: #fff; color: #222; }
.invoice h1 { font-size: 1.6rem; }
.invoice table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.invoice td, .invoice th { padding: 6px 0; border-bottom: 1px solid #ddd; text-align: left; }
.invoice .n { text-align: right; }
@media print {
  body { padding: 0; background: #fff; }
  .topbar, .tabbar, .no-print, .toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .card { border: 0; }
}
