/* ---------- theme tokens ---------- */
:root {
  --bg: #0e1016; --surface: #171a22; --surface-2: #0b0d12; --raised: #1d212b;
  --border: #262b37; --border-soft: #1e222c;
  --text: #e7e9ee; --muted: #9aa2b4; --faint: #626a7d;
  --accent: #5b8cff; --accent-ink: #fff;
  --link: #8ab4f8; --visited: #c58af9;
  --ok: #57cc7d; --warn: #e0a35a; --err: #ff6b6b;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.24);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
html[data-theme="light"] {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f1f3f6; --raised: #ffffff;
  --border: #e2e5ea; --border-soft: #edeff3;
  --text: #171a1f; --muted: #5b6472; --faint: #97a0b0;
  --accent: #2f6bff; --accent-ink: #fff;
  --link: #1a54d1; --visited: #6b2fb3;
  --ok: #1a7f37; --warn: #a35a00; --err: #d1242f;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans);
       -webkit-font-smoothing: antialiased; }
.wrap { max-width: 1140px; margin: 0 auto; padding: 0 22px; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
select, input { font: inherit; color: var(--text); }

/* ---------- top bar ---------- */
.topbar { border-bottom: 1px solid var(--border-soft); background: color-mix(in srgb, var(--bg) 86%, transparent);
          backdrop-filter: saturate(1.2) blur(8px); position: sticky; top: 0; z-index: 20; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 24px; height: 24px; border-radius: 6px; object-fit: contain; display: block; }
.brand-name { font-size: 17px; letter-spacing: -.01em; }
.brand-name b { font-weight: 700; }
.topnav { display: flex; align-items: center; gap: 16px; }
.topnav a { color: var(--muted); font-size: 14px; }
.icon-btn { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { color: var(--text); border-color: var(--faint); }
.icon-btn::before { content: "◑"; font-size: 16px; }
html[data-theme="light"] .icon-btn::before { content: "◐"; }
/* API-key lock: own glyph (id beats the .icon-btn rule), tinted when a key is set */
#lock::before { content: "🔓"; font-size: 14px; }
#lock.set::before { content: "🔒"; }
#lock.set { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, var(--surface)); }

/* ---------- composer ---------- */
.composer { margin: 26px 0 8px; }
.field { position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.chips { display: contents; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px 5px 10px; font-size: 13.5px; }
.chip b { font-weight: 500; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .x { border: 0; background: transparent; color: var(--faint); font-size: 15px; line-height: 1; padding: 0 2px; }
.chip .x:hover { color: var(--err); }
.q { flex: 1; min-width: 200px; border: 0; background: transparent; outline: none; padding: 8px 6px; font-size: 15px; }
.field-btn { flex: none; align-self: center; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); border-radius: 8px; padding: 7px 13px; font-size: 13px; white-space: nowrap; }
.field-btn:hover { color: var(--text); border-color: var(--faint); }
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-top: 14px; }
.ctl { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.ctl span { text-transform: uppercase; letter-spacing: .05em; font-size: 11px; }
.ctl select, .ctl input { background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 10px; font-size: 14px; min-width: 130px; }
.ctl.key { flex: 1; min-width: 180px; }
.ctl.key input { min-width: 0; width: 100%; }
.ctl select:focus, .ctl input:focus { outline: none; border-color: var(--accent); }
/* Anchor Search to the right so it never shifts when controls show/hide. */
#go { margin-left: auto; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 9px;
  padding: 10px 20px; font-weight: 600; font-size: 14px; height: 38px; }
.primary:hover { filter: brightness(1.06); }
.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 16px; font-weight: 500; font-size: 14px; height: 38px; }
.ghost:hover { border-color: var(--faint); }
.note { color: var(--faint); font-size: 12.5px; margin: 12px 2px 0; }
.empty { color: var(--faint); text-align: center; margin: 60px 0; font-size: 14px; }

/* ---------- results grid of search cards ---------- */
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 18px;
  margin: 26px 0 80px; align-items: start; }
.scard { background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.scard-h { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); }
.fold { border: 0; background: transparent; color: var(--faint); font-size: 11px; padding: 2px 3px; line-height: 1; }
.fold:hover { color: var(--text); }
.scard-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; }
.scard-q { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; cursor: pointer; }
.scard-copy { flex: none; width: 24px; height: 24px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); border-radius: 6px; font-size: 13px; line-height: 1; cursor: pointer; display: grid; place-items: center; }
.scard-copy:hover { color: var(--text); border-color: var(--accent); }
.scard.folded .bar, .scard.folded .scard-body { display: none; }
.scard.folded .scard-h { border-bottom: 0; }
.scard-x { border: 0; background: transparent; color: var(--faint); font-size: 16px; padding: 2px 4px; border-radius: 6px; }
.scard-x:hover { color: var(--err); background: var(--surface-2); }
/* header action button (Group / Copy) — kept out of the body so it never blocks results */
.scard-act { display: flex; align-items: center; }
.scard.folded .scard-act { display: none; }
.hact { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 12px; padding: 5px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.hact:hover { color: var(--text); border-color: var(--faint); }
.hact.on { color: var(--text); background: color-mix(in srgb, var(--accent) 15%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.hact.done { color: var(--ok); border-color: var(--ok); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font-size: 12.5px; padding: 4px 10px; border-radius: 6px; }
.seg button.on { background: var(--raised); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.scard-tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 0; }
.scard.folded .scard-tags { display: none; }
.tag { font-size: 11px; line-height: 1; padding: 4px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.tag-prov { background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); color: var(--text); font-weight: 600; }
.scard-meta { display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: 12.5px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.dot.spin { animation: pulse 1s ease-in-out infinite; }
.dot.ok { background: var(--ok); } .dot.err { background: var(--err); } .dot.warn { background: var(--warn); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }
.bar { height: 3px; background: var(--surface-2); }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.scard-body { padding: 6px 14px 16px; max-height: 620px; overflow: auto; }

/* ---------- organized result sections ---------- */
.blk { margin-top: 20px; }
.blk:first-child { margin-top: 8px; }
/* group-by-type toggle above web results */
.rtools { display: flex; justify-content: flex-end; margin: 2px 0 4px; }
.rtools + .blk, .rtools + .rlist { margin-top: 6px; }
.group-toggle { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 12px; padding: 5px 11px; border-radius: 8px; cursor: pointer; }
.group-toggle:hover { color: var(--text); border-color: var(--faint); }
.group-toggle.on { color: var(--text); background: color-mix(in srgb, var(--accent) 15%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.blkh { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 8px; }
.blkh .cnt { color: var(--faint); }
.gresult { margin-bottom: 18px; }
.gresult.has-thumb { display: flex; gap: 14px; align-items: flex-start; }
.gresult.has-thumb .gmain { flex: 1; min-width: 0; }
.gthumb { flex: none; width: 150px; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: var(--surface-2); }
.gthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gsrc { display: flex; align-items: center; gap: 9px; margin-bottom: 3px; }
.gfav { width: 22px; height: 22px; border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  color: #fff; font: 700 11px/1 var(--sans); text-transform: uppercase; }
.gdomain { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gtitle { display: inline-block; color: var(--link); font-size: 17px; line-height: 1.3; margin: 1px 0 3px; }
.gtitle:visited { color: var(--visited); }
.gsnippet { color: var(--muted); font-size: 13.5px; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.faq { padding: 9px 2px; border-bottom: 1px solid var(--border-soft); font-size: 14px; }
.kp, .aiov { font-size: 13.5px; line-height: 1.6; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 11px 13px; }
.aiov { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.grid a { aspect-ratio: 1/1; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- app results (Google Play / App Store) ---------- */
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.appcard { display: flex; gap: 12px; align-items: center; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
  text-decoration: none; transition: border-color .12s, background .12s; }
.appcard:hover { border-color: var(--accent); background: var(--raised); }
.app-icon { width: 52px; height: 52px; border-radius: 13px; object-fit: cover; flex: none;
  background: var(--surface); border: 1px solid var(--border-soft); }
.app-ph { display: grid; place-items: center; color: var(--accent-ink); font: 700 22px/1 var(--sans);
  background: var(--accent); border: none; }
.app-body { min-width: 0; flex: 1; }
.app-name { color: var(--text); font-size: 14.5px; font-weight: 600; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-meta { color: var(--muted); font-size: 12px; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-foot { display: flex; gap: 10px; align-items: center; margin-top: 5px; font-size: 12px; }
.app-rate { color: var(--warn); font-weight: 600; }
.app-rate .app-rc { color: var(--faint); font-weight: 400; }
.app-price { color: var(--ok); font-weight: 600; }
#prov-note { color: var(--warn); }

/* ---- place results (maps / local) — laid out with the .apps grid ---- */
.placecard { display: block; padding: 12px 13px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); text-decoration: none; transition: border-color .12s, background .12s; }
.placecard:hover { border-color: var(--accent); background: var(--raised); }
.place-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; font-size: 12.5px; }
.place-meta { color: var(--muted); }
.place-addr { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.place-hours { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.place-svc { color: var(--faint); font-size: 12px; margin-top: 3px; }
.place-phone { color: var(--faint); font-size: 12px; margin-top: 3px; }
.place-review { color: var(--text); font-size: 12.5px; font-style: italic; margin-top: 7px; opacity: .8;
  border-left: 2px solid var(--border); padding-left: 8px; }
.place-ad { display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 600; color: var(--warn);
  border: 1px solid var(--warn); border-radius: 4px; padding: 0 4px; vertical-align: middle; }

/* ---- rank (global position) + page indicators on every result ---- */
.rank { margin-left: auto; flex: none; color: var(--faint); font-size: 11px;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.appcard, .placecard, .grid a { position: relative; }
.rank-badge { position: absolute; top: 7px; right: 7px; z-index: 1; pointer-events: none;
  background: color-mix(in srgb, var(--surface) 80%, transparent); border: 1px solid var(--border);
  color: var(--muted); font-size: 10px; line-height: 1.5; padding: 0 5px; border-radius: 6px;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.appcard .app-name, .placecard .app-name { padding-right: 48px; }   /* reserve room for the badge */
.grid .rank-badge.on-img { top: 4px; right: 4px; background: rgba(0,0,0,.6); border-color: transparent; color: #fff; }

/* ---------- json view ---------- */
.json-tools { display: flex; justify-content: flex-end; gap: 8px; position: sticky; top: 0;
  padding: 2px 0 8px; background: var(--surface); z-index: 1; }
.json-copy { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  border-radius: 7px; padding: 4px 12px; font-size: 12px; }
.json-copy:hover { color: var(--text); border-color: var(--faint); }
.json-copy.done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.json { font: 12.5px/1.65 var(--mono); color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-soft); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.j-det > summary { list-style: none; cursor: pointer; border-radius: 4px; }
.j-det > summary:hover { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.j-det > summary::-webkit-details-marker { display: none; }
.j-det > summary::before { content: "▾"; color: var(--faint); display: inline-block; width: 13px; }
.j-det:not([open]) > summary::before { content: "▸"; }
.j-body { padding-left: 15px; border-left: 1px solid var(--border); margin-left: 6px; }
.j-row { white-space: pre-wrap; word-break: break-word; padding: 0 3px; border-radius: 4px; }
.j-key { color: var(--accent); }
.j-str { color: var(--ok); }
.j-num { color: var(--warn); }
.j-bool { color: #c58af9; }
.j-null { color: var(--faint); }
.j-punc { color: var(--faint); }
.j-info { color: var(--faint); font-style: italic; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(3,6,12,.55); backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 22px 22px 18px; width: min(370px, 92vw); animation: pop .12s ease-out; }
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-title { margin: 0 0 4px; font-size: 16px; }
.modal-sub { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; }
.modal-num { display: flex; align-items: center; gap: 10px; }
.modal-input { flex: 1; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 13px; font-size: 17px; }
.modal-input:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.modal-hint { color: var(--faint); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (max-width: 520px) {
  .results { grid-template-columns: 1fr; }
  .controls { gap: 10px; }
}
