:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1b1f24;
  --muted: #667085;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fe;
  --danger: #c4320a;
  --danger-soft: #fdeee8;
  --warn: #8a5a00;
  --warn-soft: #fff5db;
  --ok: #157f3c;
  --ok-soft: #e6f6ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f38;
    --text: #e7e9ee;
    --muted: #98a2b3;
    --accent: #4c8dff;
    --accent-ink: #0b1220;
    --accent-soft: #1b2a45;
    --danger: #ff8a65;
    --danger-soft: #3a1f17;
    --warn: #f5c451;
    --warn-soft: #33290f;
    --ok: #5fd08a;
    --ok-soft: #13301f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.5rem;
  padding: 0 24px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 1.3rem; justify-content: center; }
.brand-mark {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: .95rem;
}
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a { color: var(--muted); padding: .4rem .7rem; border-radius: 8px; font-weight: 500; }
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.topbar nav a.active { color: var(--text); background: var(--surface-2); }
.user { margin-left: auto; display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .9rem; }
.user form { margin: 0; }

/* ---------- layout */
.page { max-width: 1180px; margin: 0 auto; padding: 24px; }
.page.wide { max-width: 1480px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.empty { text-align: center; padding: 64px 16px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- forms */
input, select, textarea {
  font: inherit; color: inherit; background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
select:disabled { opacity: .6; }
label { display: block; font-size: .85rem; font-weight: 550; margin-bottom: .3rem; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: .85rem; font-weight: 550; margin-bottom: .3rem; padding: 0; display: flex; gap: .5rem; width: 100%; }
legend .clear { margin-left: auto; font-weight: 400; }
.field { margin-bottom: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 550;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }

.messages { margin-bottom: 16px; display: grid; gap: 8px; }
.msg { padding: .6rem .9rem; border-radius: 8px; background: var(--accent-soft); }
.msg-error { background: var(--danger-soft); color: var(--danger); }
.msg-success { background: var(--ok-soft); color: var(--ok); }
.warn { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: .5rem .7rem; margin: .5rem 0; }
.warn a { color: inherit; text-decoration: underline; }
ul.plain { margin: .4rem 0 0; padding-left: 1.1rem; }

/* ---------- login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); text-align: center;
}
.login-card label { text-align: left; margin-bottom: 14px; }
.login-card label input { margin-top: .3rem; font-weight: 400; }
.login-card p { margin: .25rem 0 1.25rem; }
.login-card .small { margin: 1rem 0 0; }

/* ---------- ads list */
.list-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 24px; align-items: start; }
.filters {
  position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.filters summary { font-weight: 650; cursor: pointer; margin-bottom: 12px; list-style: none; }
.filters summary::-webkit-details-marker { display: none; }
.check-list { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.check-list.short { max-height: 200px; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; margin: 0; padding: .25rem .4rem; border-radius: 6px; cursor: pointer; }
.check:hover { background: var(--surface-2); }
.check input { width: auto; margin: 0; }
.check span:first-of-type { flex: 1; }
.count { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.mini-search { margin-bottom: 6px; padding: .35rem .55rem; font-size: .9rem; }
.range { display: flex; align-items: center; gap: .4rem; }
.filter-actions { display: flex; gap: .5rem; }
.filter-actions .btn { flex: 1; }

.results-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 16px; flex-wrap: wrap; }
.results-head p { margin: 0; }
.results-tools { display: flex; gap: .5rem; }
.results-tools select { width: auto; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; color: var(--text); box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16, 24, 40, .12); }
.card.removed .thumb img { filter: grayscale(1); opacity: .6; }
.thumb { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); overflow: hidden; flex: none; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.no-photo, .gallery-empty { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: .9rem; }
.gallery-empty { height: 200px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.badge { position: absolute; font-size: .75rem; font-weight: 600; padding: .2rem .5rem; border-radius: 6px; }
.badge-photos { right: 8px; bottom: 8px; background: rgba(0, 0, 0, .6); color: #fff; }
.badge-removed { left: 8px; top: 8px; background: var(--danger); color: #fff; }
.card-body { padding: 12px 14px 8px; display: grid; gap: 6px; flex: 1; align-content: start; }
.price-row { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.price { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.price.big { font-size: 1.75rem; }
.facts { display: flex; flex-wrap: wrap; gap: .2rem .6rem; font-size: .9rem; }
.facts span { color: var(--muted); }
.loc { font-size: .9rem; color: var(--muted); }
.loc strong { color: var(--text); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .1rem .55rem; }
.chip.more { color: var(--muted); }
.card .warn { margin: 0; padding: .3rem .5rem; }
.card-foot { display: flex; justify-content: space-between; gap: .5rem; padding: 8px 14px 12px; border-top: 1px solid var(--border); margin-top: 6px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: 24px 0 8px; }

/* ---------- ad detail */
.back { display: inline-block; margin-bottom: 12px; }
.banner { border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 16px; }
.banner-removed { background: var(--danger-soft); color: var(--danger); border: 1px solid currentColor; }
.ad-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; margin-bottom: 16px; flex-wrap: wrap; }
.loc-line { margin: 0; color: var(--muted); font-size: 1.05rem; }
.ad-price { text-align: right; }
.ad-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.ad-main > * + * { margin-top: 16px; }
.ad-side { position: sticky; top: 80px; }

.gallery-main { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; }
.gallery-main img { width: 100%; height: 100%; object-fit: contain; display: block; }
.gallery-main .nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .85); color: #111; font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.gallery-main .prev { left: 10px; }
.gallery-main .next { right: 10px; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 2px; }
.thumbs button { flex: 0 0 88px; height: 66px; padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; background: none; }
.thumbs button.active { border-color: var(--accent); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }

.specs { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 20px; margin: 0; }
.specs dt, .timeline dt { font-size: .8rem; color: var(--muted); }
.specs dd { margin: 0; font-weight: 550; }
.description { white-space: normal; line-height: 1.6; }
.phone { display: block; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ad-side .btn.full { margin-top: .75rem; }
.timeline { margin: 0; display: grid; gap: 8px; }
.timeline div { display: flex; justify-content: space-between; gap: 1rem; }
.timeline dd { margin: 0; text-align: right; font-size: .9rem; }
.timeline .removed-row dt, .timeline .removed-row dd { color: var(--danger); font-weight: 600; }
.chart { width: 100%; height: 80px; margin-bottom: 8px; }
.chart polyline { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart circle { fill: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th.num { text-align: right; }
.history td.up { color: var(--danger); }
.history td.down { color: var(--ok); }

/* ---------- searches */
.search-cards { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; margin: 20px 0 32px; align-items: start; }
.search-cards .panel + .panel { margin-top: 0; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.jobs td.actions form { margin: 0; }
.status { font-size: .78rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.status-running { background: var(--accent-soft); color: var(--accent); }
.status-queued { background: var(--warn-soft); color: var(--warn); }
.status-done { background: var(--ok-soft); color: var(--ok); }
.status-failed { background: var(--danger-soft); color: var(--danger); }

/* ---------- small screens */
@media (max-width: 1000px) {
  .ad-layout { grid-template-columns: minmax(0, 1fr); }
  .ad-side { position: static; }
}
@media (max-width: 860px) {
  .list-layout, .search-cards { grid-template-columns: minmax(0, 1fr); }
  .filters { position: static; max-height: none; }
  .filters summary { margin-bottom: 0; }
  .filters details[open] summary { margin-bottom: 12px; }
}
@media (max-width: 600px) {
  .page { padding: 16px; }
  .topbar { padding: 0 16px; gap: .75rem; }
  .topbar .brand { font-size: 0; gap: 0; }
  .topbar .brand .brand-mark { font-size: .95rem; }
  .user span { display: none; }
  .ad-price { text-align: left; }
  .grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- maps */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a { padding: .45rem .8rem; color: var(--muted); font-weight: 550; }
.seg a + a { border-left: 1px solid var(--border); }
.seg a:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }
.seg a.active { background: var(--accent-soft); color: var(--accent); }
.big-map { height: calc(100vh - 220px); min-height: 420px; border-radius: var(--radius); border: 1px solid var(--border); z-index: 0; }
.map-legend { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: 8px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--accent); margin-left: .6rem; }
.dot:first-child { margin-left: 0; }
.dot.exact { background: var(--accent); }
.dot.approx { border-style: dashed; background: var(--accent-soft); }
.map-pop { display: block; color: #1b1f24; min-width: 180px; line-height: 1.4; }
.map-pop:hover { text-decoration: none; }
.map-pop img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; margin-bottom: 6px; display: block; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.panel-head h2 { margin: 0; }
.pill { font-size: .78rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.map-embed { width: 100%; height: 340px; border: 1px solid var(--border); border-radius: 8px; display: block; }
.map-links { display: flex; gap: 1rem; flex-wrap: wrap; margin: .6rem 0 0; }
.map-links .muted { margin-left: auto; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) {
  .results-tools { flex-wrap: wrap; }
  .big-map { height: 70vh; }
}

/* ---------- deals and video */
.deal-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.deal-tabs a { padding: .5rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.deal-tabs a:hover { color: var(--text); text-decoration: none; }
.deal-tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.deal-tabs .count { font-weight: 500; margin-left: .25rem; }
.price small { font-size: .7em; font-weight: 600; color: var(--muted); }
.pill-sale { background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.pill-rent { background: var(--warn-soft); color: var(--warn); vertical-align: middle; }
h1 .pill { font-size: .8rem; }
.video { position: relative; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: #000; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
