:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #14181d;
  --muted: #5d6a78;
  --line: #dde3ea;
  --brand: #0b5cab;
  --brand-ink: #ffffff;
  --good: #0a7d3f;
  --good-bg: #e6f5ec;
  --warn: #a4521a;
  --warn-bg: #fdf0e4;
  --danger: #b3261e;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151a;
    --surface: #1a2027;
    --text: #eef2f6;
    --muted: #9aa8b6;
    --line: #2b333c;
    --brand: #4b9bff;
    --brand-ink: #08121e;
    --good: #4ad07f;
    --good-bg: #10301f;
    --warn: #f0a868;
    --warn-bg: #33230f;
    --danger: #ff6b60;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px calc(12px + env(safe-area-inset-top)) 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar-actions { display: flex; gap: 8px; }

main { padding: 16px; max-width: 720px; margin: 0 auto; }

button {
  font: inherit;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 9px 15px;
  cursor: pointer;
  min-height: 40px;
}
button.primary { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.ghost { background: transparent; color: var(--brand); border-color: var(--line); }
button.danger { background: transparent; color: var(--danger); border-color: var(--line); }
button:disabled { opacity: .55; cursor: default; }

.status {
  margin: 0 0 14px;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--good-bg);
  color: var(--good);
  font-size: .93rem;
}
.status.is-error { background: var(--warn-bg); color: var(--warn); }

.empty { text-align: center; padding: 44px 18px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 8px 0; font-size: 1.15rem; }
.empty-icon { font-size: 2.6rem; margin: 0; }
.empty p { max-width: 42ch; margin: 0 auto 18px; }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  cursor: pointer;
}
.item:hover { border-color: var(--brand); }
.item h3 { margin: 0; font-size: 1rem; }
.item .meta { color: var(--muted); font-size: .82rem; grid-column: 1; }
.item .price { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.item .was {
  text-align: right;
  color: var(--muted);
  text-decoration: line-through;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
.item .alert { grid-column: 1 / -1; color: var(--good); font-size: .87rem; font-weight: 600; }

.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; grid-column: 1 / -1; }
.badge {
  font-size: .71rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
  letter-spacing: .01em;
}
.badge.clearance { background: var(--warn-bg); color: var(--warn); }
.badge.markdown { background: var(--warn-bg); color: var(--warn); }
.badge.deal { background: var(--good-bg); color: var(--good); }
.badge.down { background: var(--good-bg); color: var(--good); }

dialog {
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  width: min(94vw, 470px);
  background: var(--surface);
  color: var(--text);
  max-height: 88vh;
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin: 0 0 14px; font-size: 1.1rem; }

label { display: block; margin-bottom: 12px; font-size: .87rem; color: var(--muted); }
label.row { display: flex; align-items: center; gap: 9px; color: var(--text); }
input[type="text"], input:not([type]), input[type="date"] {
  width: 100%;
}
input {
  margin-top: 5px;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 100%;
}
input[type="checkbox"] { width: auto; margin: 0; min-width: 20px; min-height: 20px; }
input.low-confidence { border-color: var(--warn); background: var(--warn-bg); }

.req { color: var(--danger); font-size: .74rem; }
.opt { color: var(--muted); font-size: .74rem; }
.hint { color: var(--muted); font-size: .84rem; margin: 0 0 12px; }
.error { color: var(--danger); font-size: .87rem; margin: 0 0 12px; }

.photo-drop {
  display: block;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 14px;
  color: var(--muted);
}
.photo-drop img { max-width: 100%; max-height: 190px; border-radius: 10px; margin-top: 10px; }

menu {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 0;
  margin: 16px 0 0;
}

.detail-price { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.detail-section { margin-top: 18px; }
.detail-section h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; }
.history li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  background: var(--bg);
  border-radius: 10px;
  font-size: .89rem;
}
.history .when { color: var(--muted); }
.deal-note {
  font-size: .82rem;
  color: var(--muted);
  margin: 8px 0 0;
  padding: 9px 11px;
  background: var(--bg);
  border-radius: 10px;
}
.spark { width: 100%; height: 64px; display: block; }

footer {
  max-width: 720px;
  margin: 26px auto 0;
  padding: 16px 16px 30px;
  color: var(--muted);
  font-size: .8rem;
  border-top: 1px solid var(--line);
}
footer a { color: var(--brand); }

.photo-sub { display: block; font-size: .78rem; margin-top: 4px; opacity: .8; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; justify-content: center; }
.thumb { position: relative; width: 84px; height: 84px; }
.thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}
.thumb button {
  position: absolute;
  top: -7px; right: -7px;
  width: 24px; height: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--surface);
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.gallery a { display: block; width: 92px; height: 92px; }
.gallery img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.alert.alert-rise { color: var(--warn); font-weight: 600; }
#toggle-push[data-on="yes"] { color: var(--good); border-color: var(--good); }

.item .move { grid-column: 1 / -1; font-size: .85rem; font-weight: 600; }
.item .move-down { color: var(--good); }
.item .move-up { color: var(--warn); }

.warehouse-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 15px; margin-bottom: 14px;
}
.wb-label { display: block; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.warehouse-bar strong { font-size: 1.02rem; }

.panel { margin-bottom: 18px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.panel-head h2 { font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0; }
.panel-sub { font-size: .76rem; color: var(--muted); }
.panel-note { font-size: .78rem; color: var(--muted); margin: 0 0 10px; }

.savings-list { display: grid; gap: 8px; }
.saving {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 13px;
}
.saving-name { font-size: .93rem; font-weight: 600; }
.saving-meta { grid-column: 1; font-size: .76rem; color: var(--muted); }
.saving-price { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.saving-off { text-align: right; font-size: .76rem; color: var(--good); font-weight: 700; }
.saving.tracked { border-color: var(--good); }
.saving-tracked-note { grid-column: 1 / -1; font-size: .78rem; color: var(--good); font-weight: 600; }
button.wide { width: 100%; margin-top: 10px; }

.wh-results { max-height: 260px; overflow-y: auto; display: grid; gap: 4px; margin-bottom: 10px; }
.wh-results button {
  width: 100%; text-align: left; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); padding: 9px 12px; min-height: 0;
}
.wh-results button:hover { border-color: var(--brand); }

.badge.here { background: var(--good-bg); color: var(--good); }
.alert.alert-here { text-decoration: none; }
