:root {
  --bg: #f7f2e8;
  --surface: #fffdf8;
  --surface-2: #f1eadc;
  --ink: #2b2620;
  --muted: #7a6f60;
  --line: #e4d9c5;
  --brand: #1f5a4a;
  --brand-ink: #ffffff;
  --gold: #b8862b;
  --deal: #2f7d4f;
  --deal-bg: #e3f2e7;
  --warn: #9a5a12;
  --danger: #a33a2c;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 6px 18px rgba(60, 45, 20, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1915;
    --surface: #24211c;
    --surface-2: #2e2a23;
    --ink: #efe7d8;
    --muted: #a89c88;
    --line: #3a352c;
    --brand: #4fa58a;
    --brand-ink: #10201b;
    --gold: #d9a646;
    --deal: #7fd39d;
    --deal-bg: #1f3a2a;
    --warn: #e0a55a;
    --danger: #e98a7b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, system-ui, -apple-system, sans-serif;
}
h1, h2, h3, h4 { font-family: Fraunces, Georgia, serif; font-weight: 600; margin: 0; }
a { color: var(--brand); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px max(16px, calc((100% - 1200px) / 2));
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { margin: 0; line-height: 0; }
.brand-logo img { height: 96px; width: auto; display: block; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; max-width: 18ch; }
@media (max-width: 600px) {
  .brand-logo img { height: 72px; }
}
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; margin-left: auto; }
.tab {
  border: 0; background: transparent; color: var(--ink); padding: 8px 14px; border-radius: 999px;
  font: 500 14px Inter, sans-serif; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.tab.active { background: var(--surface); box-shadow: var(--shadow); }
.badge { background: var(--gold); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; min-width: 20px; text-align: center; }

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.panel { display: none; }
.panel.active { display: block; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Buttons */
.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 10px 18px; cursor: pointer;
  font: 600 14px Inter, sans-serif; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: var(--surface); }
.btn.danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; }
select, input, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; width: 100%;
}

/* Hero */
.hero { display: flex; justify-content: space-between; gap: 24px; padding: 24px; flex-wrap: wrap; }
.hero h2 { font-size: 28px; margin-bottom: 4px; }
.hero-text { flex: 1 1 380px; }
.hero-actions { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; }

.notice { margin-top: 16px; padding: 12px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.notice.error { border-color: var(--danger); color: var(--danger); }
.notice.stale { border-color: var(--gold); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Progress */
.progress { margin-top: 16px; padding: 18px 20px; }
.progress-head { display: flex; gap: 14px; align-items: center; }
.progress-head p { margin: 2px 0 0; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--gold); animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.log { list-style: none; margin: 14px 0 0; padding: 0; max-height: 220px; overflow: auto; font-size: 13px; }
.log li { padding: 3px 0; color: var(--muted); overflow-wrap: anywhere; }
.log li:last-child { color: var(--ink); }
.log li::before { margin-right: 8px; }
.log li.search::before { content: "🔍"; }
.log li.fetch::before { content: "📄"; }
.log li.results::before { content: "✨"; }
.log li.info::before { content: "🗝️"; }

/* Results */
.summary { font-size: 16px; margin: 24px 0 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 28px 0 12px; flex-wrap: wrap; }
.section-head h3 { font-size: 20px; }
.section-actions { display: flex; align-items: center; gap: 10px; }
.section-actions select { width: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.empty { padding: 24px 0; }

.deal { overflow: hidden; display: flex; flex-direction: column; }
.deal-img { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.deal-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.deal-img.noimg::after { content: "🗝️"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 48px; opacity: .4; }
.pill { position: absolute; top: 10px; left: 10px; padding: 3px 9px; border-radius: 999px; font: 700 12px Inter, sans-serif; }
.pill.discount { background: var(--deal); color: #fff; }
.pill.discount:empty { display: none; }
.pill.demo { left: auto; right: 10px; background: var(--gold); color: #fff; }
.deal-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.deal-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); gap: 8px; }
.conf.high { color: var(--deal); }
.conf.low { color: var(--warn); }
.deal h4 { font-size: 17px; line-height: 1.3; }
.prices { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.price { font: 700 22px Fraunces, Georgia, serif; }
.value { color: var(--muted); font-size: 13px; }
.price-note, .desc, .where { margin: 0; }
.desc { font-size: 14px; }
details { font-size: 14px; background: var(--surface-2); border-radius: 10px; padding: 6px 10px; }
details summary { cursor: pointer; font-weight: 500; }
details p { margin: 6px 0 0; }
.risks { color: var(--warn); }
.match { margin: 0; color: var(--muted); }
.match.hit { color: var(--deal); font-weight: 600; }
.dates, .distance { margin: 0; }
.distance { color: var(--muted); }
.distance:empty { display: none; }
.also a { color: inherit; }
.link-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.link-group { padding: 14px 16px; }
.link-group h4 { font-size: 16px; margin-bottom: 6px; }
.link-group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.link-group li span { color: var(--muted); font-size: 12px; margin-left: 6px; }
.risks:empty, .basis:empty, .price-note:empty, .where:empty { display: none; }
.deal-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; flex-wrap: wrap; }
.deal.added .add { background: var(--deal-bg); color: var(--deal); }

/* Shopping list */
.totals { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.total { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; }
.total b { display: block; font: 700 22px Fraunces, Georgia, serif; }
.list { display: flex; flex-direction: column; gap: 12px; }
.item { display: grid; grid-template-columns: 140px 1fr auto; gap: 16px; padding: 14px; align-items: start; }
.item img, .item .ph { width: 140px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.item h4 { font-size: 17px; }
.item p { margin: 4px 0; font-size: 14px; }
.item-side { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; min-width: 150px; }
.item-side select { width: 150px; }
.item textarea { margin-top: 6px; font-size: 13px; }
.item.bought { opacity: .7; }
.item.passed { opacity: .45; }
.linkish { background: none; border: 0; color: var(--danger); cursor: pointer; font: inherit; font-size: 13px; padding: 0; }
.deal-actions .hide { color: var(--muted); margin-left: auto; align-self: center; }
.deal-actions .hide:hover { color: var(--danger); }
.live { margin: 2px 0 4px; font-size: 13px; }
.live .soon { color: var(--warn); font-weight: 600; }
.live .over { color: var(--danger); font-weight: 600; }
.live .up { color: var(--warn); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; display: flex; gap: 14px;
  align-items: center; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); }
.toast .linkish { color: var(--gold); font-weight: 600; font-size: 14px; }
.hidden-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow: auto; font-size: 14px; }
.hidden-list li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.hidden-list li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Manage hunts */
.hunts-dialog { width: min(520px, calc(100vw - 32px)); padding: 22px 24px; color: var(--ink); }
.hunts-dialog::backdrop { background: rgba(20, 16, 10, .45); }
.hunts-dialog h3 { font-size: 22px; margin-bottom: 4px; }
.hunts-dialog p { margin: 0 0 12px; }
.hunts-dialog label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.hunts-dialog input[type=checkbox] { width: auto; }
.select-all { padding: 6px 0; border-bottom: 1px solid var(--line); font-weight: 600 !important; }
.hunts-checklist { display: flex; flex-direction: column; max-height: 50vh; overflow: auto; padding: 4px 0 12px; }
.hunts-checklist label { padding: 7px 0; border-bottom: 1px solid var(--line); }
.hunts-checklist label.disabled { color: var(--muted); }
.hunts-checklist .empty { padding: 12px 0; }

/* One estate sale, opened */
.sale-dialog { width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 20px 24px; color: var(--ink); }
.sale-dialog::backdrop { background: rgba(20, 16, 10, .45); }
.sale-dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.sale-dialog-head h3 { font-size: 22px; }
.sale-dialog h4 { font-size: 16px; margin: 18px 0 8px; }
.sale-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.sale-item { margin: 0; background: var(--surface-2); border-radius: 12px; overflow: hidden; }
.sale-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--line); }
.sale-item figcaption { padding: 8px 10px 10px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.sale-item .why { font-size: 12px; color: var(--muted); }
.sale-item.match .why { color: var(--deal); font-weight: 600; }
.sale-mentions { margin: 0; padding-left: 18px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.sale-mentions mark { background: var(--deal-bg); color: inherit; border-radius: 3px; padding: 0 2px; }
#sale-photos-wrap { margin-top: 16px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; margin-top: 10px; }
.photo-grid a { display: block; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: var(--line); }
.hint { margin: -8px 0 0; }
.alert-status { margin: 0; }
.alert-status .ok { color: var(--deal); font-weight: 600; }
.alert-status .wait { color: var(--warn); font-weight: 600; }
.alert-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Sign in */
.login-body { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; }
.login { width: min(420px, 100%); padding: 32px 16px 48px; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.login-logo { width: min(360px, 100%); height: auto; display: block; }
.login-card { width: 100%; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 24px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.login-card .btn { justify-content: center; margin-top: 4px; }
.login-error { margin: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--danger); color: var(--danger); font-size: 14px; }

/* Preferences */
.form { padding: 24px; display: flex; flex-direction: column; gap: 14px; max-width: 760px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.form label.check input { width: auto; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
legend { font-weight: 600; padding: 0 6px; }
.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.source-grid label { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.source-grid input { width: auto; }
.sub { font: 600 15px Inter, sans-serif; margin: 6px 0 0; }
fieldset p { margin: 0; }
.custom-sites { display: flex; flex-direction: column; gap: 8px; }
.custom-site { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 2.4fr) auto; gap: 8px; align-items: center; }
.add-site { align-self: flex-start; }
.form-error { color: var(--danger); }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }

@media (max-width: 640px) {
  .item { grid-template-columns: 96px 1fr; }
  .item img, .item .ph { width: 96px; }
  .item-side { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; min-width: 0; }
  .hero-actions { width: 100%; }
  .custom-site { grid-template-columns: 1fr auto; }
  .custom-site .cs-url { grid-column: 1 / -1; grid-row: 2; }
}

@media print {
  .topbar .tabs, #sign-out, .toast, .deal-actions .hide, .section-actions, .item-side select, .linkish, .item textarea { display: none !important; }
  .topbar { position: static; }
  .card { box-shadow: none; }
}
