:root {
  --bg: #f7f8fc;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #5a6070;
  --line: #dfe2ec;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --low: #b45309;
  --ok: #15803d;
  --focus: #1d4ed8;
  --tag-bg: #e7f0ff;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101218;
    --surface: #181b23;
    --text: #eceef4;
    --muted: #a3a9ba;
    --line: #2a2f3c;
    --accent: #6b9bff;
    --accent-text: #0c1020;
    --low: #f0a24b;
    --ok: #5fd08a;
    --focus: #9db9ff;
    --tag-bg: #1f2b45;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.sheet-open, body.map-open { overflow: hidden; }
.top, main, .foot { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 18px; }
.brand-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
h1 { margin: 0; font-size: 1.35rem; line-height: 1.2; letter-spacing: -0.01em; }
h2 { margin: 0 0 8px; font-size: 1.05rem; }
h3 { margin: 0 0 8px; font-size: 1rem; }
.city { color: var(--ok); font-weight: 700; }
.locate {
  margin-left: auto;
  min-height: 40px;
  padding: 6px 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.locate[aria-pressed="true"] { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.note { margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); }
.muted { color: var(--muted); margin: 0; }
button { font: inherit; cursor: pointer; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.link { padding: 6px 0; color: var(--accent); background: none; border: 0; text-decoration: underline; text-underline-offset: 3px; }

/* the search box: one field, the button inside, suggestions under it */
.searchbox {
  position: relative;
  display: flex;
  gap: 8px;
  margin: 14px 0 6px;
  padding: 6px 6px 6px 14px;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 16px;
}
.searchbox input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  font: inherit;
  font-size: 1.05rem;
  color: var(--text);
  background: transparent;
  border: 0;
}
.searchbox input:focus-visible { outline: none; }
.go {
  min-height: 44px;
  padding: 8px 16px;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 12px;
}
.go[disabled] { opacity: 0.6; cursor: progress; }
.suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 1000;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}
.suggest li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; cursor: pointer; }
.suggest li:hover { background: var(--bg); }
.s-name { font-weight: 600; }
.s-meta { color: var(--muted); white-space: nowrap; font-size: 0.92rem; }

/* before the first search */
.start { display: grid; gap: 18px; margin: 14px 0; }
.start[hidden] { display: none; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 38px;
  padding: 6px 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.chip:hover { border-color: var(--accent); }

.status { margin: 12px 0 10px; color: var(--muted); }
.status.error { color: #c62828; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .status.error { color: #ff8a80; } }

/* results; every grid here is held to the screen width, or one long name widens the whole page */
.start, .results-wrap, .shop-list, .shop-more, .sheet-list { grid-template-columns: minmax(0, 1fr); }
.results-wrap { display: grid; gap: 12px; margin-bottom: 20px; }
.results-wrap[hidden] { display: none; }
.sortbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.seg-group { display: inline-flex; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.seg { min-height: 36px; padding: 6px 16px; color: var(--muted); background: none; border: 0; border-radius: 9px; }
.seg[aria-pressed="true"] { color: var(--accent-text); background: var(--accent); font-weight: 700; }
.seg[hidden] { display: none; }

.map-box { position: relative; }
.map {
  height: 30vh;
  min-height: 200px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  transition: height 0.28s ease;
}
.map-toggle {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 500;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.map-box.full { position: fixed; inset: 0; z-index: 2000; background: var(--bg); }
.map-box.full .map { height: 100vh; border-radius: 0; border: 0; }
.pin-label { font-weight: 700; padding: 2px 6px; }

.block h3 { color: var(--text); }
.shop-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.shop-row { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.shop-row.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
/* name and its tag stacked, so a tag never squeezes the name on a narrow phone */
.shop-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "dot name dist price" "dot tag dist price";
  align-items: center;
  gap: 2px 10px;
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
}
.dot { grid-area: dot; flex: none; width: 10px; height: 10px; border-radius: 50%; }
.dot-ok { background: var(--ok); }
.dot-low { background: var(--low); }
.dot-svc { background: var(--accent); }
.link.small { font-size: 0.9rem; color: var(--muted); justify-self: start; }
.btn.reason { width: 100%; justify-content: flex-start; }
.shop-name { grid-area: name; grid-row: 1 / span 2; flex: 1; min-width: 0; font-weight: 700; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
.shop-head:has(.tag) .shop-name { grid-row: auto; align-self: end; }
.tag { grid-area: tag; justify-self: start; flex: none; padding: 2px 8px; font-size: 0.8rem; color: var(--accent); background: var(--tag-bg); border-radius: 8px; }
.shop-dist { grid-area: dist; flex: none; color: var(--muted); font-size: 0.92rem; white-space: nowrap; }
.shop-price { grid-area: price; flex: none; min-width: 64px; text-align: right; font-weight: 800; font-size: 1.05rem; white-space: nowrap; }
.shop-more { padding: 0 14px 12px; display: grid; gap: 10px; }
.shop-more[hidden] { display: none; }
.shop-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 8px 14px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.primary-btn { color: var(--accent-text); background: var(--ok); border-color: var(--ok); }
.avail-ok { color: var(--ok); font-weight: 600; }
.avail-low { color: var(--low); font-weight: 600; }
.error { color: #c62828; }

/* a shop's other goods: a sheet from below over a dimmed page */
.sheet { position: fixed; inset: 0; z-index: 3000; display: flex; align-items: flex-end; justify-content: center; background: rgb(0 0 0 / 0.45); }
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%;
  max-width: 760px;
  max-height: 80vh;
  overflow: auto;
  padding: 16px;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  animation: rise 0.25s ease;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet-card { animation: none; } .map { transition: none; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.close { width: 40px; height: 40px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.sheet-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 4px; }
.sheet-list li { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.p-name { font-weight: 600; }
.p-price { font-weight: 800; text-align: right; white-space: nowrap; }
.p-meta { grid-column: 1 / -1; font-size: 0.9rem; }

.leaflet-popup-content { margin: 10px 12px; font: 14px/1.4 system-ui, sans-serif; }

.foot { padding-bottom: 28px; color: var(--muted); font-size: 0.88rem; }
.foot p { margin: 4px 0; }
