/* AutoTG — Telegram-подібний каталог: спокійні поверхні, синій акцент,
   зелена ціна. Теми: світла, темна, системна (перемикач у шапці). */

:root {
  color-scheme: light;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --fg: #16191c;
  --fg-muted: #707579;
  --border: #e6e8eb;
  --border-strong: #d3d6da;
  --muted-bg: #f1f3f5;

  --price: #047857;
  --action: #1a73e8;
  --action-fg: #ffffff;
  --action-soft: #e7f2fd;
  --bubble: #eef6fd;
  --bubble-border: #d8e9f9;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --ok-bg: #d1fae5;
  --ok-fg: #065f46;
  --danger: #991b1b;
  --danger-bg: #fee2e2;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: none;
  --shadow-hover: none;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* Системна тема: темна, доки користувач явно не обрав світлу. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #17191c;
    --surface: #212327;
    --surface-2: #26292e;
    --fg: #e9edef;
    --fg-muted: #8b9398;
    --border: #2b2e33;
    --border-strong: #3a3e44;
    --muted-bg: #26292e;

    --price: #4dcd5e;
    --action: #6ab7ff;
    --action-fg: #0b0e11;
    --action-soft: #1d2b38;
    --bubble: #1e2a35;
    --bubble-border: #2b3b49;
    --warning: #fbbf24;
    --warning-bg: #422c06;
    --ok-bg: #0b3b2a;
    --ok-fg: #6ee7b7;
    --danger: #fca5a5;
    --danger-bg: #450a0a;

    --shadow: none;
    --shadow-hover: none;
  }
}

/* Явний вибір користувача перемагає системну тему в обидва боки. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #17191c;
  --surface: #212327;
  --surface-2: #26292e;
  --fg: #e9edef;
  --fg-muted: #8b9398;
  --border: #2b2e33;
  --border-strong: #3a3e44;
  --muted-bg: #26292e;

  --price: #4dcd5e;
  --action: #6ab7ff;
  --action-fg: #0b0e11;
  --action-soft: #1d2b38;
  --bubble: #1e2a35;
  --bubble-border: #2b3b49;
  --warning: #fbbf24;
  --warning-bg: #422c06;
  --ok-bg: #0b3b2a;
  --ok-fg: #6ee7b7;
  --danger: #fca5a5;
  --danger-bg: #450a0a;

  --shadow: none;
  --shadow-hover: none;
}

* { box-sizing: border-box; }

body { padding-bottom: var(--comparison-space, 0px); }
.catalog-coverage { padding: 12px 16px; margin-bottom: 20px; border-radius: 12px; color: var(--fg-muted); background: var(--surface); border: 1px solid var(--border); font-size: 13px; }
.account-columns { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 24px; }
.account-panel { display: grid; align-content: start; gap: 16px; padding: 24px; margin-bottom: 24px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); min-width: 0; }
.account-panel h2 { font-size: 22px; }
.account-panel form { display: grid; gap: 12px; min-width: 0; }
.account-panel input, .account-panel select, .account-panel textarea { width: 100%; min-width: 0; font-size: 16px; }
.account-panel textarea { padding: 12px; border: 1px solid var(--border-strong); border-radius: 10px; color: var(--fg); background: var(--surface); font: inherit; }
.account-tabs { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 24px; }
.account-tabs a { padding: 10px 14px; min-height: 44px; border: 1px solid var(--border); border-radius: 999px; }
.account-ad { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding-block: 12px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.account-ad > a:first-child { font-weight: 600; }
.like-form { margin: 0; }
.like-button { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px; border: 1px solid var(--border); border-radius: 999px; color: var(--fg-muted); background: var(--surface); font: inherit; cursor: pointer; width: fit-content; }
.like-button svg { width: 22px; height: 22px; fill: none; }
.like-button[aria-pressed="true"] svg { fill: currentColor; }
.like-button[aria-pressed="true"] { color: var(--action); background: var(--muted-bg); }
.seller-contact { margin-bottom: 16px; }
@media (max-width:700px) { .account-columns { grid-template-columns:minmax(0,1fr); } .account-panel { padding:16px; } }
.history-panel { margin-bottom: 20px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.history-panel summary { min-height: 44px; padding-block: 10px; cursor: pointer; font-weight: 600; }
.history-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-block: 12px; }
[data-history-progress] li { padding-block: 10px; border-top: 1px solid var(--border); font-size: 13px; overflow-wrap: anywhere; }
.source-filter summary, .offer-list summary { cursor: pointer; min-height: 44px; padding-block: 10px; font-weight: 600; }
.source-filter-options { max-height: 260px; overflow-y: auto; margin-top: 8px; }
.source-filter-options .check { padding-block: 6px; align-items: flex-start; }
.source-filter-options span { overflow-wrap: anywhere; }
.compare-choice { display: flex; gap: 8px; align-items: center; min-height: 44px; font-size: 13px; cursor: pointer; color: var(--action); }
.compare-choice input { width: 18px; height: 18px; accent-color: var(--action); }
.offer-list { border-top: 1px solid var(--border); font-size: 13px; }
.offer-row { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding-block: 12px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.offer-original { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow-y: auto; padding: 10px; background: var(--muted-bg); border-radius: 8px; }
.compare-tray { position: fixed; inset-inline: 16px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 20; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; max-width: 1300px; margin-inline: auto; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; box-shadow: var(--shadow-hover); }
.compare-tray > p { font-weight: 600; font-size: 13px; }
#compare-selection { display: flex; gap: 8px; flex: 1; overflow-x: auto; }
#compare-selection li { flex: 0 0 auto; }
#compare-selection button { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 44px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--muted-bg); color: var(--fg); cursor: pointer; font: inherit; font-size: 12px; }
.compare-dialog { width: min(1300px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--fg); padding: 20px; }
.compare-dialog::backdrop { background: rgb(0 0 0 / 65%); }
.compare-close { display: flex; justify-content: flex-end; margin-bottom: 16px; position: sticky; top: 0; z-index: 3; background: var(--surface); padding-bottom: 8px; }
.compare-dialog { scroll-padding-top: 70px; }
.comparison-scroll { overflow: auto; max-width: 100%; margin-top: 16px; }
.compare-table { border-collapse: separate; border-spacing: 0; font-size: 14px; width: 100%; }
.compare-table th, .compare-table td { text-align: left; vertical-align: top; min-width: 210px; max-width: 280px; padding: 14px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.compare-table th:first-child { position: sticky; left: 0; z-index: 1; min-width: 140px; max-width: 180px; background: var(--surface); }
.compare-table img { display: block; width: 180px; height: 115px; object-fit: contain; background: var(--muted-bg); border-radius: 10px; margin-bottom: 12px; }
.compare-table tr[data-different="true"] td { background: var(--muted-bg); }
.only-differences tr[data-different="false"] { display: none; }
.compare-differences { margin-top: 12px; }
.comparison-hint { color: var(--fg-muted); font-size: 13px; margin-block: 8px; }
.header-nav { flex-wrap: wrap; }
.comparison-page-head { padding-block: 16px 24px; }
html:root { scroll-padding-top: calc(var(--site-header-height, 100px) + 12px); }
.comparison-page-head h1 { font-size: clamp(24px, 4vw, 36px); margin-bottom: 12px; }
.comparison-form { padding: 20px; margin-bottom: 32px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); display: grid; gap: 16px; }
.comparison-picker-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.comparison-picker-grid .field { min-width: 0; }
.comparison-picker-grid select, .comparison-picker-grid input { width: 100%; min-width: 0; font-size: 16px; }
.comparison-full-page { margin-block: 12px; }
.comparison-analysis { margin-block: 24px; padding: 24px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; }
.comparison-analysis h3 { font-size: 22px; }
.comparison-analysis h4 { margin: 20px 0 10px; }
.analysis-recommendation { padding: 16px; margin-top: 16px; border-left: 4px solid var(--action); border-radius: 8px; background: var(--muted-bg); line-height: 1.7; }
.comparison-analysis ul { list-style: disc; padding-left: 20px; }
.comparison-analysis li { margin-bottom: 8px; }
.analysis-cars { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 16px; margin-block: 24px; }
.analysis-cars section { padding: 16px; border: 1px solid var(--border); border-radius: 12px; overflow-wrap: anywhere; }
.analysis-cars h4 { margin-top: 0; }
.analysis-cars ul { color: var(--fg-muted); margin-block: 12px; font-size: 13px; }
.analysis-export { margin-block: 16px; }
.analysis-export summary, .comparison-record summary { cursor: pointer; padding-block: 12px; min-height: 44px; font-weight: 600; }
.analysis-export textarea { width: 100%; padding: 16px; margin-top: 12px; border: 1px solid var(--border-strong); background: var(--muted-bg); color: var(--fg); border-radius: 12px; font: inherit; resize: vertical; }
.comparison-records { margin-block: 32px; }
.comparison-record { padding: 12px 16px; margin-top: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.comparison-record h4 { margin-block: 16px 8px; }
@media (max-width: 700px) {
  .comparison-picker-grid { grid-template-columns: minmax(0, 1fr); }
  .comparison-form, .comparison-analysis { padding: 16px; }
}
@media (max-width: 480px) {
  .site-header .header-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; gap: 2px; }
  .site-header .header-nav a { padding-inline: 2px; text-align: center; font-size: 11px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
}
@media (max-width: 560px) {
  #compare-selection { flex-basis: 100%; order: -1; }
  .compare-tray { gap: 8px; inset-inline: 8px; padding: 10px; }
  .compare-tray .btn-primary, .compare-tray .btn-secondary { padding-inline: 12px; font-size: 13px; }
  .compare-dialog { padding: 12px; }
  .compare-table th:first-child { min-width: 108px; max-width: 120px; padding: 10px; font-size: 12px; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

a { color: var(--action); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
  border-radius: 4px;
}

.shell {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding-inline: var(--space-4);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mono { font-family: var(--font-mono); font-size: 0.92em; }
.muted { color: var(--fg-muted); }

/* ---------- Header / footer ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding-block: var(--space-3);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--fg);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--action); flex: none; }
.brand-accent { color: var(--action); margin-left: 2px; }

.header-note {
  color: var(--fg-muted);
  font-size: 13px;
  margin-left: auto;
}

.site-footer {
  margin-top: var(--space-7);
  padding-block: var(--space-5);
  border-top: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 13px;
}

/* ---------- Search hero ---------- */

.search-hero { padding: 48px 0 32px; }

.search-hero h1 {
  font-size: clamp(28px, 3.4vw, 46px);
  margin-bottom: var(--space-4);
  max-width: 34ch;
}

.search-box {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.search-box input {
  flex: 1 1 320px;
  min-width: 0;
  padding: 11px var(--space-4);
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
.search-box input::placeholder { color: var(--fg-muted); }

.search-hint {
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--fg-muted);
}

/* ---------- Buttons ---------- */

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--space-5);
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}

.btn-primary {
  background: var(--action);
  color: var(--action-fg);
}
.btn-primary:hover { background: color-mix(in srgb, var(--action) 85%, #000); text-decoration: none; }

.btn-secondary {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--muted-bg); text-decoration: none; }

.btn-block { display: flex; width: 100%; }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.sidebar {
  min-width: 0;
}

/* ---------- Filters ---------- */

.filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}

.filters-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}
.filters-head h2 { font-size: 15px; }
.filters-reset { font-size: 13px; }

.field { display: flex; flex-direction: column; gap: var(--space-1); }

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field select, .field input, .field-group select, .field-pair input {
  min-height: 44px;
  padding: 0 var(--space-3);
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
}

.field-inline {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}
.field-inline .field-label { white-space: nowrap; }

/* ---------- Results ---------- */

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.results-count { font-size: 14px; color: var(--fg-muted); }
.results-count strong { color: var(--fg); font-size: 16px; }

.sort-form { display: flex; align-items: center; gap: var(--space-2); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4);
}

.empty {
  padding: var(--space-6);
  text-align: center;
  color: var(--fg-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* ---------- Card ---------- */

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 180ms ease, border-color 180ms ease;
}

.card-media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 10;
  background:
    linear-gradient(135deg, var(--muted-bg) 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
}
.card-media:hover { text-decoration: none; }

.card-media-label {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
  opacity: 0.55;
}

.card-status { position: absolute; top: var(--space-2); left: var(--space-2); }

.card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  flex: 1;
}

.card-title { font-size: 17px; }
.card-title a { color: var(--fg); }

.card-price { display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }

.price {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 18px;
  color: var(--price);
}
.price-lg { font-size: 26px; }

.price-was {
  font-size: 13px;
  color: var(--fg-muted);
  text-decoration: line-through;
}

.card-specs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  font-size: 13px;
  color: var(--fg-muted);
}
.card-specs li { position: relative; }
.card-specs li + li::before {
  content: "";
  position: absolute;
  left: calc(var(--space-3) / -2);
  top: 50%;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: var(--border-strong);
}

.card-location { font-size: 13px; color: var(--fg-muted); }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-muted);
}

.source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
  color: var(--fg);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-check { color: var(--price); flex: none; }

.card-updated { white-space: nowrap; }
.card-origin-link { display: inline-flex; align-items: center; min-height: 40px; font-size: 13px; }

/* ---------- Status badges ---------- */

.status {
  display: inline-block;
  padding: 3px var(--space-2);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.status-available { background: var(--ok-bg); color: var(--ok-fg); }
.status-reserved { background: var(--warning-bg); color: var(--warning); }
.status-sold { background: var(--muted-bg); color: var(--fg-muted); }
.status-unknown { background: var(--muted-bg); color: var(--fg-muted); }

/* ---------- Detail page ---------- */

.breadcrumb { padding-block: var(--space-5) var(--space-3); font-size: 14px; }

.detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: var(--space-5);
  align-items: start;
  padding-bottom: var(--space-6);
}

.detail-main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}

.detail-media {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 7;
  max-width: 100%;
  background: linear-gradient(135deg, var(--muted-bg) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: var(--space-5);
}
.detail-media .card-media-label { font-size: 28px; }

.detail-head h1 { font-size: clamp(20px, 2.6vw, 26px); }

.detail-price {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  margin-top: var(--space-5);
  margin-bottom: var(--space-3);
}

.specs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--space-3);
  margin: 0;
}
.specs div {
  padding: var(--space-3);
  background: var(--muted-bg);
  border-radius: 8px;
}
.specs dt { font-size: 12px; color: var(--fg-muted); margin-bottom: 2px; }
.specs dd { margin: 0; font-weight: 500; }

.tags { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.tag {
  padding: 4px var(--space-3);
  background: var(--muted-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--fg-muted);
}

.raw-text {
  margin: 0;
  padding: var(--space-4);
  background: var(--muted-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: auto;
}

.dupes { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-2); }

/* ---------- Source card ---------- */

.detail-side { position: sticky; top: 76px; }

.source-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}
.source-card .section-title { margin-top: 0; }

.source-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 16px;
}

.source-handle { color: var(--fg-muted); margin-top: 2px; margin-bottom: var(--space-4); }

.source-card .btn-primary, .source-card .btn-secondary { margin-bottom: var(--space-2); }

.source-updated { font-size: 13px; color: var(--fg-muted); margin-top: var(--space-3); }

.source-disclaimer {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-muted);
}

/* ---------- Recognised query chips ---------- */

.query-result {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.query-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  margin-bottom: var(--space-3);
}

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-2); }

.chip {
  padding: 5px var(--space-3);
  background: var(--muted-bg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Filter extras ---------- */

.field-group {
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  border: 0;
}
.field-group legend { padding: 0; margin-bottom: var(--space-1); }

.field-pair { display: flex; gap: var(--space-2); }
.field-group select { min-width: 0; width: 100%; }
.field-pair input { flex: 1 1 0; min-width: 0; }

.field-hint { font-size: 11px; color: var(--fg-muted); line-height: 1.4; }

.checks { display: flex; flex-direction: column; gap: var(--space-2); }

.check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 14px;
  cursor: pointer;
  min-height: 36px;
}
.check input { width: 16px; height: 16px; accent-color: var(--action); flex: none; margin: 0; }

/* ---------- Channels we know of but do not ingest ---------- */

.more-sources {
  margin-top: var(--space-6);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.more-sources .section-title { margin-top: 0; }

.source-links {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-size: 14px;
}
.source-links li { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: baseline; }

/* ---------- Pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-5);
}

.page-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}
.page-link:hover { background: var(--muted-bg); text-decoration: none; }
.page-link.is-disabled { color: var(--fg-muted); border-color: var(--border); opacity: 0.6; cursor: default; }
.page-link.is-disabled:hover { background: var(--surface); }

.page-status { font-size: 14px; color: var(--fg-muted); }

/* Keep the grid readable while HTMX swaps it. */
.results.htmx-request { opacity: 0.55; transition: opacity 120ms ease; }

/* ---------- Pills, history, damage ---------- */

.pill {
  display: inline-block;
  padding: 3px var(--space-2);
  background: var(--muted-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  white-space: nowrap;
}
.pill-in_transit { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.pill-damage { background: var(--danger-bg); color: var(--danger); border-color: transparent; }

.tag-ok { background: var(--ok-bg); color: var(--ok-fg); border-color: transparent; }
.tag-alert { background: var(--danger-bg); color: var(--danger); border-color: transparent; }

.card-meta-row { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.card-meta-row:empty { display: none; }

.damage-note {
  margin-top: var(--space-3);
  padding: var(--space-3);
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  font-size: 14px;
}

.history { display: flex; flex-direction: column; gap: var(--space-2); }
.history li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3);
  background: var(--muted-bg);
  border-radius: 8px;
  font-size: 14px;
}

/* ---------- Sources table ---------- */

.page-title { font-size: clamp(20px, 3vw, 26px); margin-bottom: var(--space-2); }
.page-subtitle { font-size: 14px; margin-bottom: var(--space-5); max-width: 70ch; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: var(--space-6);
}

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; vertical-align: top; }
.table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody tr + tr td { border-top: 1px solid var(--border); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.source-handle-link { font-size: 12px; color: var(--fg-muted); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); }
.dot-on { background: var(--price); }

/* ---------- Admin forms / notices ---------- */

.notice, .error {
  padding: var(--space-3) var(--space-4);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: var(--space-4);
}
.notice { background: var(--ok-bg); color: var(--ok-fg); border: 1px solid transparent; }
.error { background: var(--danger-bg); color: var(--danger); border: 1px solid transparent; }

.add-source-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: var(--space-5);
}
.field-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  flex-wrap: wrap;
}
.row-actions { white-space: nowrap; }
.row-actions form { display: inline-block; }
.row-actions .btn-sm { margin-right: var(--space-2); }

.btn-sm {
  min-height: 40px;
  padding: 4px var(--space-3);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}
.btn-sm:hover { background: var(--muted-bg); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-danger:hover { background: var(--danger-bg); }
.pill-error { background: var(--danger-bg); color: var(--danger); border-color: transparent; }

/* ---------- Responsive ---------- */

[hidden] { display: none !important; }
html { scroll-padding-top: 100px; }
.skip-link { position: fixed; top: -80px; left: 16px; z-index: 100; padding: 12px; background: var(--surface); }
.skip-link:focus { top: 12px; }
.header-nav { display: flex; margin-left: auto; gap: 8px; }
.header-nav a { color: var(--fg-muted); padding: 10px 14px; border-radius: 10px; font-weight: 500; }
.header-nav a[aria-current] { color: var(--action); background: var(--muted-bg); }
.eyebrow { color: var(--action); font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 16px; }
.search-hero h1 span { color: var(--fg-muted); font-weight: 400; }
.hero-description { max-width: 65ch; margin-bottom: 24px; color: var(--fg-muted); font-size: 16px; }
.search-box { max-width: 880px; }
.search-box input { min-height: 54px; box-shadow: var(--shadow); }
.search-box .btn-primary { gap: 20px; }
.quick-searches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.quick-searches a { display: inline-flex; gap: 16px; align-items: center; min-height: 40px; padding: 8px 14px; border: 1px solid var(--border-strong); border-radius: 999px; color: var(--fg); background: var(--surface); font-size: 13px; }
.quick-searches a:hover { background: var(--muted-bg); text-decoration: none; }
.filter-panel > summary { display: none; }
.active-filters { margin-bottom: 20px; }
.chip { display: inline-block; overflow-wrap: anywhere; }
.chip-reset { color: var(--action); background: transparent; }
.empty h2 { color: var(--fg); font-size: 22px; }
.empty p { margin: 12px 0 24px; }
.htmx-indicator { display: none; padding: 10px 0; color: var(--action); }
.htmx-indicator.htmx-request { display: block; }
.results { min-width: 0; }
.media-placeholder { display: flex; flex-direction: column; align-items: center; color: var(--fg-muted); gap: 6px; }
.media-placeholder > span { font-weight: 600; }
.media-placeholder small { font-size: 11px; }
.listing-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--muted-bg); }
.detail-media .listing-photo { object-fit: contain; background: var(--muted-bg); }
.card-status { z-index: 1; }
.price { font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.freshness-note { margin-top: 20px; padding: 16px; background: var(--warning-bg); color: var(--warning); border-radius: 12px; }
.specs dd { overflow-wrap: anywhere; }
.admin-disclosure { margin: 24px 0; }
.admin-disclosure > summary { cursor: pointer; padding: 16px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); font-weight: 600; }
.admin-disclosure .add-source-form { margin-top: 12px; }
.source-search { max-width: 440px; margin-bottom: 12px; }
.table-wrap { margin-top: 16px; }
.table tbody tr:hover:not(:has(img:hover, video:hover, .detail-media:hover)) { background: var(--muted-bg); }
button:disabled { opacity: .55; cursor: not-allowed; }
.field-row > .field { min-width: 150px; }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }

@media (max-width: 900px) {
  .layout, .detail { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .detail-side { position: static; }
  .header-note { display: none; }
  .filter-panel > summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; padding: 16px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; font-weight: 600; }
  .filter-panel > summary span { font-size: 12px; font-weight: 400; }
  .filter-panel[open] > summary { margin-bottom: 8px; }
  .search-hero { padding-top: 28px; }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .detail-main { padding: var(--space-4); }
  .results-head { align-items: flex-start; flex-direction: column; }
  .search-box .btn-primary { width: 100%; }
  .header-inner { gap: 8px; }
  .brand { font-size: 16px; }
  .brand-mark { width: 22px; }
  .header-nav { gap: 0; }
  .header-nav a { padding: 10px 8px; font-size: 12px; }
  .field-row { flex-direction: column; align-items: stretch; }
  .field-row > .field { width: 100%; }
  .search-hero h1 { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ── Перемикач теми ──────────────────────────────────────────────────────
   Три стани: світла, темна, системна. Показується лише коли є JS, бо без
   нього вибір нікуди не зберігається — системна тема працює й так. */

.theme-switch {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--muted-bg);
}

.theme-switch button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--fg-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.theme-switch button:hover { color: var(--fg); }

.theme-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--action);
  box-shadow: var(--shadow);
}

.theme-switch svg { width: 18px; height: 18px; }

/* ── Аватар джерела ──────────────────────────────────────────────────────
   Кружечок з ініціалом, як у списку чатів Telegram. Колір визначається
   номером джерела, тому один канал завжди має той самий вигляд. */

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--avatar-bg, var(--action));
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

.avatar-sm { width: 26px; height: 26px; font-size: 12px; }
.avatar-1 { --avatar-bg: #e17076; }
.avatar-2 { --avatar-bg: #eda86c; }
.avatar-3 { --avatar-bg: #a695e7; }
.avatar-4 { --avatar-bg: #7bc862; }
.avatar-5 { --avatar-bg: #65aadd; }
.avatar-6 { --avatar-bg: #ee7aae; }
.avatar-7 { --avatar-bg: #6ec9cb; }

.source-row { display: flex; align-items: center; gap: var(--space-3); }
.source-row .source-title { font-weight: 600; }
.source-row .source-handle { color: var(--fg-muted); font-size: 13px; }

/* ── Оригінальний пост у вигляді повідомлення ────────────────────────────
   Текст зберігається як опублікований: переноси, пробіли, емодзі. */

.message {
  max-width: 640px;
  border: 1px solid var(--bubble-border);
  border-radius: var(--radius);
  border-bottom-left-radius: var(--space-1);
  background: var(--bubble);
  overflow: hidden;
}

.message-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--bubble-border);
}

.message-head .source-title { font-size: 14px; }

.message-body {
  margin: 0;
  padding: var(--space-4);
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--fg);
}

.message-body.is-clamped {
  display: -webkit-box;
  -webkit-line-clamp: 12;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.message-more {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-4) var(--space-3);
  border: 0;
  background: none;
  color: var(--action);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.message-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: 0 var(--space-4) var(--space-3);
  color: var(--fg-muted);
  font-size: 12px;
}

.message-foot .edited { font-style: italic; }

/* ── Дії копіювання ──────────────────────────────────────────────────── */

.copy-btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg-muted);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.copy-btn:hover { color: var(--action); border-color: var(--action); }
.copy-btn[data-copied="true"] { color: var(--ok-fg); border-color: var(--ok-fg); }
.copy-btn svg { width: 13px; height: 13px; }

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.tg-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--action);
  color: var(--action-fg);
  font-size: 13px;
  font-weight: 500;
}

.tg-link:hover { text-decoration: none; filter: brightness(1.05); }
.tg-link svg { width: 15px; height: 15px; }

/* ── Форма оголошення ────────────────────────────────────────────────────
   Поле вводу поводиться як у месенджері: одне повідомлення, форматування
   під рукою, живий попередній перегляд тим самим компонентом, що й пост. */

.compose-page { max-width: 720px; margin: 0 auto; padding-block: var(--space-5); }
.compose-intro h1 { font-size: 26px; margin-bottom: var(--space-2); }
.compose-intro p { color: var(--fg-muted); max-width: 60ch; }
.compose-form { margin-top: var(--space-5); }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.compose-fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.compose-fields .field { flex: 1 1 180px; margin: 0; }
.compose-fields .field-narrow { flex: 0 1 116px; }
.compose-fields label { display: block; margin-bottom: 4px; font-size: 12px; color: var(--fg-muted); }
.compose-fields .req { color: var(--action); }

.compose-fields input,
.compose-fields select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}

.compose-fields input:focus-visible,
.compose-fields select:focus-visible { border-color: var(--action); }

.composer {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.composer:focus-within { border-color: var(--action); }

.composer-toolbar {
  display: flex;
  gap: 2px;
  padding: var(--space-2) var(--space-2) 0 var(--space-3);
}

.composer-toolbar button {
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--fg-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.composer-toolbar button:hover { background: var(--muted-bg); color: var(--fg); }
.composer-toolbar code { font-family: var(--font-mono); font-size: 12px; }

.composer textarea {
  display: block;
  width: 100%;
  min-height: 150px;
  padding: var(--space-2) var(--space-4) var(--space-3);
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  line-height: 1.55;
  resize: vertical;
}

.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--fg-muted); }

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0 var(--space-3) var(--space-3) var(--space-4);
}

.composer-counter { color: var(--fg-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.composer-counter.is-near { color: var(--warning); }

.composer-send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--action);
  color: var(--action-fg);
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.composer-send:hover { filter: brightness(1.06); transform: translateY(-1px); }
.composer-send svg { width: 20px; height: 20px; }

.compose-hint { margin-top: var(--space-3); color: var(--fg-muted); font-size: 13px; }
.compose-hint code { font-family: var(--font-mono); font-size: 12px; }
.compose-preview { margin-top: var(--space-3); }
.compose-preview .message-body { min-height: 3em; }
.compose-preview b, .compose-preview strong { font-weight: 600; }
.compose-preview .spoiler {
  border-radius: 4px;
  background: var(--fg-muted);
  color: transparent;
  cursor: pointer;
}
.compose-preview .spoiler.is-open { background: none; color: inherit; }

/* Telegram-like browsing controls use the same tokens in both themes. */
.view-switch { display: inline-flex; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 999px; background: var(--muted-bg); }
.view-switch button { display: inline-flex; gap: 7px; align-items: center; justify-content: center; min-height: 44px; padding: 8px 12px; border: 0; border-radius: 999px; background: transparent; color: var(--fg-muted); font: inherit; font-size: 13px; cursor: pointer; }
.view-switch button[aria-pressed="true"] { background: var(--surface); color: var(--action); box-shadow: var(--shadow); }
.view-switch svg { width: 18px; height: 18px; }
:root[data-catalog-view="stream"] .results .grid { grid-template-columns: minmax(0, 1fr); }
:root[data-catalog-view="stream"] .card { display: grid; grid-template-columns: 210px minmax(0, 1fr); }
:root[data-catalog-view="stream"] .card-media { align-self: start; aspect-ratio: 1; margin: 12px 0 12px 12px; border-radius: 12px; overflow: hidden; border-bottom: 0; }
:root[data-catalog-view="stream"] .card-body { min-width: 0; }
:root[data-catalog-view="stream"] .card-foot { flex-wrap: wrap; }
.ui-feedback { position: fixed; z-index: 100; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); width: max-content; padding: 12px 20px; border-radius: 16px; background: var(--fg); color: var(--bg); box-shadow: var(--shadow-hover); pointer-events: none; opacity: 0; transition: opacity 150ms ease; }
.ui-feedback.is-visible { opacity: 1; }
.photo-expand { position: absolute; bottom: 12px; right: 12px; z-index: 1; min-height: 44px; border: 1px solid var(--border); border-radius: 999px; padding: 8px 16px; background: var(--surface); color: var(--action); font: inherit; cursor: pointer; box-shadow: var(--shadow); }
.detail-gallery { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0; }
.detail-gallery a { flex: 0 0 auto; border-radius: 10px; overflow: hidden; }
.detail-gallery img { width: 112px; height: 84px; object-fit: cover; display: block; }
html:has(.photo-viewer[open]) { overflow: hidden; }
.photo-viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: #101216; color: #fff; overflow: hidden; overscroll-behavior: contain; }
.photo-viewer[open] { display: flex; flex-direction: column; }
.photo-viewer::backdrop { background: #101216; }
.photo-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 12px 8px; flex-shrink: 0; z-index: 2; background: #181b20; }
[data-photo-counter] { font-variant-numeric: tabular-nums; white-space: nowrap; }
.photo-tools { display: flex; gap: 4px; }
.photo-viewer button { min-width: 44px; min-height: 44px; border: 0; border-radius: 8px; background: transparent; color: #fff; cursor: pointer; font-size: 24px; }
.photo-viewer :is(.photo-tools button, .photo-nav, .photo-error button):hover { background: #ffffff24; }
.photo-viewer button:focus-visible { outline: 2px solid #6ab7ff; outline-offset: -2px; }
.photo-viewer button:disabled { opacity: .3; cursor: default; }
.photo-viewer [data-photo-zoom="reset"] { font-size: 14px; min-width: 60px; font-variant-numeric: tabular-nums; }
.photo-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; user-select: none; display: flex; align-items: center; justify-content: center; }
.photo-full { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; flex-shrink: 0; transform-origin: center; cursor: zoom-in; }
.photo-stage.is-zoomed .photo-full { cursor: grab; }
.photo-stage.is-dragging .photo-full { cursor: grabbing; }
.photo-stage .photo-error, .photo-loading { position: absolute; padding: 24px; text-align: center; color: #fff; pointer-events: none; }
.photo-viewer [hidden] { display: none !important; }
.photo-nav { position: absolute; top: 50%; z-index: 2; background: #181b20bb !important; font-size: 36px !important; }
.photo-prev { left: 12px; }
.photo-next { right: 12px; }
.photo-footer { flex-shrink: 0; padding: 8px 12px max(8px, env(safe-area-inset-bottom)); background: #181b20; }
.photo-thumbs { display: flex; gap: 8px; overflow-x: auto; max-width: 100%; width: max-content; margin: auto; padding: 3px; }
.photo-thumbs button { padding: 0; flex: 0 0 56px; overflow: hidden; opacity: .55; }
.photo-thumbs button[aria-current="true"] { opacity: 1; outline: 2px solid #6ab7ff; outline-offset: 1px; }
.photo-thumbs img { display: block; width: 56px; height: 48px; object-fit: cover; }
.photo-help { text-align: center; font-size: 12px; color: #b7bdc7; margin: 8px 0 0; }
@media (max-width: 600px), (max-height: 500px) {
  .photo-help { display: none; }
  .photo-prev { left: 4px; }
  .photo-next { right: 4px; }
}
.photo-error { padding: 24px; }
@media (max-width: 560px) {
  :root[data-catalog-view="stream"] .card { grid-template-columns: 112px minmax(0, 1fr); }
  :root[data-catalog-view="stream"] .card-body { padding: 12px; }
  :root[data-catalog-view="stream"] .card-title { font-size: 15px; }
  :root[data-catalog-view="stream"] .card-status { position: static; margin: 4px; white-space: normal; }
  :root[data-catalog-view="stream"] .card-media { flex-direction: column; aspect-ratio: auto; min-height: 144px; }
}
.compose-privacy { margin-top: var(--space-4); color: var(--fg-muted); font-size: 13px; }

.notice-ok { border-left: 3px solid var(--price); }
.notice-error { border-left: 3px solid var(--danger); }
.notice-error ul { margin-top: var(--space-2); padding-left: var(--space-4); list-style: disc; }

/* ── Модерація оголошень ─────────────────────────────────────────────── */

.admin-tabs { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-block: var(--space-4); }
.admin-tabs a { padding: 8px 14px; border-radius: 999px; background: var(--muted-bg); color: var(--fg-muted); }
.admin-tabs a[aria-current] { background: var(--action-soft); color: var(--action); }

.submission-list { display: grid; gap: var(--space-4); }

.submission {
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.submission-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); }
.submission-meta { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); margin-block: var(--space-3); }
.submission-meta dt { color: var(--fg-muted); font-size: 12px; }
.submission-text {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  max-height: 260px;
  overflow: auto;
}
.submission-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.submission-actions input { flex: 1 1 220px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--fg); font: inherit; font-size: 14px; }
.submission-verdict { margin-top: var(--space-3); }

/* Уривок оригінального поста в картці — як прев'ю повідомлення у списку чатів.
   Символи й емодзі лишаються ті самі, що написав продавець. */
.card-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: var(--space-2);
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

/* ── Телефон ─────────────────────────────────────────────────────────────
   Шапка тепер має бренд, три посилання й перемикач теми. На вузькому екрані
   вони стають двома рядками: бренд із перемикачем зверху, навігація нижче. */

@media (max-width: 560px) {
  .header-inner { row-gap: 6px; }
  .brand-text { font-size: 15px; }
  .header-nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
    border-top: 1px solid var(--border);
    padding-top: 4px;
  }
  .header-nav a { padding: 8px 10px; font-size: 13px; }
  .theme-switch { margin-left: auto; }

  .compose-page { padding-block: var(--space-4); }
  .compose-fields { gap: var(--space-2); }
  .compose-fields .field { flex: 1 1 140px; }
  .compose-fields .field-narrow { flex: 1 1 96px; }
  .composer textarea { min-height: 180px; font-size: 16px; }
  .composer-toolbar { flex-wrap: wrap; }

  /* 16px не дає iOS зумити сторінку під час фокуса в полі. */
  .compose-fields input,
  .compose-fields select,
  .search-box input,
  .submission-actions input { font-size: 16px; }

  .message { border-radius: 14px; }
  .message-body { padding: var(--space-3); }
  .card-preview { -webkit-line-clamp: 3; }
  .submission-meta { gap: var(--space-2) var(--space-4); }
}

/* Позначка Telegram на посиланнях, що ведуть саме в Telegram. */
.tg-mark { width: 14px; height: 14px; flex: none; }
.card-origin-link { display: inline-flex; align-items: center; gap: 6px; }
.tg-link .tg-mark { width: 15px; height: 15px; }

/* ── Кнопка «написати» на картці й вікно листа ───────────────────────── */

.listing-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0; margin: 8px 0; max-width: 640px; border-top: 1px solid var(--border); }
.listing-actions .listing-action { position: static; display: flex; justify-content: center; align-items: center; gap: 8px; flex: 1 1 135px; min-width: 0; min-height: 46px; margin: 0; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--muted-bg); color: var(--fg); font-size: 14px; font-weight: 600; line-height: 1.4; text-align: center; text-decoration: none; cursor: pointer; }
.listing-actions .listing-action svg { width: 20px; height: 20px; flex: none; }
.listing-actions .write-btn { background: var(--hover-tint); color: var(--action); border-color: var(--hover-ring); }
.listing-actions .listing-action:hover { border-color: var(--action); background: var(--hover-tint); color: var(--action); }
.listing-actions .compare-choice { position: relative; }
.listing-actions .compare-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.listing-actions .compare-choice:has(input:checked) { background: var(--hover-tint); border-color: var(--action); color: var(--action); }
.listing-actions .compare-choice:has(input:focus-visible) { outline: 2px solid var(--action); outline-offset: 3px; }
.listing-actions .contact-unavailable { color: var(--fg-muted); cursor: default; font-weight: 400; }
.compare-table .listing-actions { min-width: 190px; font-weight: 400; }
.card .listing-actions { padding: 4px 0 0; margin: auto 0 0; border-top: 0; gap: 4px; }
.card .listing-actions .listing-action { flex: 0 0 32px; min-height: 32px; padding: 6px; border: 1px solid transparent; background: transparent; border-radius: 8px; color: var(--action); }
.card .listing-actions .listing-action svg { width: 18px; height: 18px; }
.card .listing-actions :is(.write-btn, .compare-choice, .card-origin-link) > span { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.card .listing-actions .listing-action:hover { background: var(--action-soft); border-color: var(--action); }
.card .listing-actions .compare-choice:has(input:checked)::after { content: ''; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--action); }
.card .listing-actions :is(.contact-original, .contact-unavailable) { flex: 0 1 auto; font-size: 12px; padding-inline: 10px; }
@media (pointer: coarse) {
  .card .listing-actions .listing-action { flex-basis: 44px; min-height: 44px; }
  .card .listing-actions :is(.contact-original, .contact-unavailable) { flex-basis: auto; }
}
.card { position: relative; }

.write-dialog {
  width: min(540px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: none;
}

.write-dialog::backdrop { background: rgb(0 0 0 / 45%); }

.write-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.write-who { display: grid; min-width: 0; }
.write-who .source-title { font-weight: 600; }
.write-who .source-handle { font-size: 13px; }
.write-who .source-handle { margin: 4px 0 0; }
.write-recipient { padding: 12px 20px 0; margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.write-text-label { display: block; padding: 16px 20px 8px; font-size: 14px; font-weight: 600; }
html:has(.write-dialog[open]), html:has(.compare-dialog[open]) { overflow: hidden; }
.write-head form { margin-left: auto; }

.write-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--muted-bg);
  color: var(--fg-muted);
  font-size: 15px;
  cursor: pointer;
}

.write-text {
  display: block;
  width: 100%;
  min-height: 132px;
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--bubble);
  color: var(--fg);
  font: inherit;
  line-height: 1.5;
  resize: vertical;
}

.write-dialog .write-text { width: calc(100% - 40px); margin: 0 20px; font-size: 16px; }
.write-text:focus { outline: 2px solid var(--action); outline-offset: 1px; }

.write-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4) 0;
}

.write-dialog .field-hint { padding: var(--space-2) var(--space-4) var(--space-4); margin: 0; }

@media (max-width: 560px) {
  .write-text { font-size: 16px; min-height: 150px; }
  .write-foot .tg-link { justify-content: center; min-height: 46px; flex: 1 1 190px; }
}

/* ── Цитата оголошення у вікні листа ─────────────────────────────────── */

.write-quote {
  display: grid;
  gap: 2px;
  margin: var(--space-3) var(--space-4) 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--action);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
  font-size: 13px;
}

.write-quote-car { font-weight: 600; color: var(--fg); }
.write-quote-price { color: var(--price); font-weight: 600; }

.write-quote-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--fg-muted);
  overflow-wrap: anywhere;
}

/* Media stays in the message; the dialog is an explicit enlarged view. */
.listing-media { min-width: 0; margin-bottom: 24px; border-radius: 14px; }
/* Absolutely positioned photos cannot give a shrink-to-fit flex item its width. */
.card-media-block { width: 100%; min-width: 0; align-self: start; }
.card-media-block .listing-media { position: relative; margin: 0; border-radius: 0; }
.card-media-block .detail-media { aspect-ratio: 16 / 10; max-height: none; border: 0; border-radius: 0; }
.card-media-block .detail-gallery, .card-media-block .inline-media-actions p, .card-media-block [data-open-photo] span { display: none; }
.card-media-block .inline-media-actions { position: absolute; right: 8px; top: 8px; margin: 0; }
.card-media-block [data-open-photo] { min-width: 32px; min-height: 32px; padding: 6px; background: #121a28bb; color: white; border-color: #ffffff55; }
.card-media-block .inline-media-nav { width: 36px; height: 40px; top: calc(50% - 20px); font-size: 28px; }
.compare-table .listing-media .listing-photo { width: 100%; height: 100%; margin: 0; }
.card .inline-media-counter { top: 8px; left: 8px; }
.card .listing-photo { cursor: pointer; }
.media-status { padding: 10px 14px; margin: 0; color: var(--fg-muted); font-size: 12px; line-height: 1.5; }
.inline-media-actions [data-open-photo] { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.listing-media .detail-media { width: 100%; aspect-ratio: 4 / 3; max-height: 65vh; margin: 0; background: var(--muted-bg); border-radius: 14px; }
.inline-photo-link { position: absolute; inset: 0; display: block; touch-action: pan-y pinch-zoom; }
.photo-stage .photo-error { pointer-events: auto; max-width: 480px; background: #181b20; border-radius: 12px; }
.photo-error a { color: #6ab7ff; }
.photo-error button { font-size: 16px; border: 1px solid #526077; margin: 12px; }
.inline-video { width: 100%; height: 100%; object-fit: contain; }
.inline-media-nav { position: absolute; z-index: 2; top: calc(50% - 24px); width: 48px; height: 48px; border: 1px solid #ffffff55; border-radius: 50%; background: #121a28bb; color: white; font-size: 32px; cursor: pointer; }
.inline-prev { left: 12px; }
.inline-next { right: 12px; }
.inline-media-nav:disabled { opacity: .25; }
.inline-media-counter { position: absolute; left: 12px; top: 12px; padding: 5px 10px; border-radius: 20px; background: #121a28bb; color: white; font-size: 12px; pointer-events: none; }
@media (hover: hover) and (pointer: fine) {
  .card:hover { transform: translateY(-3px) scale(1.01); z-index: 1; border-color: var(--action); }
  .card :is(.inline-media-nav, .inline-media-counter, .inline-media-actions) {
    opacity: 0;
    visibility: hidden;
    transition: opacity 140ms ease, visibility 140ms ease;
  }
  .card:is(:hover, :has(:focus-visible)) :is(.inline-media-nav, .inline-media-counter, .inline-media-actions) {
    opacity: 1;
    visibility: visible;
  }
  .card:is(:hover, :has(:focus-visible)) .inline-media-nav:disabled { opacity: .25; }
}
@media (prefers-reduced-motion: reduce) {
  .card:hover { transform: none; }
}
.inline-media-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 2px; }
.inline-media-actions p { color: var(--fg-muted); font-size: 13px; margin: 0; }
.inline-media-actions button { flex-shrink: 0; }
.inline-media-error { position: absolute; inset: 35% 60px auto; padding: 12px; background: var(--surface); border-radius: 10px; text-align: center; pointer-events: none; }
.detail-gallery { gap: 10px; padding: 8px 3px; }
.detail-gallery a { border: 2px solid transparent; opacity: .7; }
.detail-gallery a[aria-current="true"] { border-color: var(--action); opacity: 1; }
.detail-gallery img { width: 84px; height: 64px; }
.video-thumb { display: flex; flex-direction: column; justify-content: center; align-items: center; width: 84px; height: 64px; background: var(--muted-bg); color: var(--action); font-size: 25px; }
.video-thumb small { font-size: 11px; }
.viewer-video { display: block; max-width: calc(100% - 112px); width: 100%; max-height: 100%; }
.photo-stage.is-video { touch-action: auto; }
.media-download { display: grid; place-items: center; min-width: 44px; min-height: 44px; color: white; font-size: 24px; border-radius: 8px; }
.media-download:hover { color: white; background: #ffffff24; text-decoration: none; }
.photo-tools select { width: 68px; min-height: 44px; padding: 4px; background: #252a33; color: white; border-color: #526077; }
.source-avatar { position: relative; overflow: hidden; vertical-align: middle; flex-shrink: 0; }
.source-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--surface); }
.feed-post > header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.source-card .source-avatar { width: 44px; height: 44px; }

/* Readable source fields: equipment gets the entire row, with one item per line. */
.detail-main { min-width: 0; }
.detail-main .section-title { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--fg); margin-top: 28px; }
.detail-main .field-hint { font-size: 13px; line-height: 1.6; }
.detail-main .specs { grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 12px; }
.detail-main .specs > div { padding: 14px 16px; border: 1px solid var(--border); }
.detail-main .specs dt { font-size: 13px; margin-bottom: 6px; }
.detail-main .specs dd { font-size: 16px; line-height: 1.5; }
.attribute-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.attribute-item { min-width: 0; padding: 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--muted-bg); }
.attribute-item dt { color: var(--fg-muted); font-size: 14px; margin-bottom: 10px; }
.attribute-item dd { margin: 0; line-height: 1.7; overflow-wrap: anywhere; white-space: pre-line; }
.attribute-wide { grid-column: 1 / -1; }
.equipment-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; white-space: normal; }
.equipment-list li { position: relative; padding: 10px 0 10px 20px; border-bottom: 1px solid var(--border); font-size: 15px; line-height: 1.6; }
.equipment-list li::before { content: '✓'; color: var(--action); position: absolute; left: 0; }
.original-post { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--font-sans, system-ui); font-size: 16px; line-height: 1.8; padding: 20px; }
.original-post a, .feed-original a { text-decoration: underline; text-underline-offset: 3px; }

/* The accent follows the active theme; hover and keyboard focus share feedback. */
:root { --hover-tint: color-mix(in srgb, var(--action) 9%, var(--surface)); --hover-ring: color-mix(in srgb, var(--action) 60%, transparent); }
:where(.card, .feed-post, .source-card, .message, .attribute-item, .specs > div, .filters, .query-result, .add-source-form, .table-wrap, .offer-row, .history li, .account-panel, .comparison-form, .comparison-analysis, input, select, textarea, button, summary, .btn-primary, .btn-secondary) {
  transition: background-color .16s ease, border-color .16s ease;
}
@media (hover: hover) {
  /* Recolour the existing rounded border only; wrappers and labels have no hover layer. */
  :is(.card, .feed-post, .source-card, .message, .attribute-item, .specs > div, .filters, .query-result, .add-source-form, .table-wrap, .offer-row, .history li, .account-panel, .comparison-form, .comparison-analysis):hover:not(:has(img:hover, video:hover, .detail-media:hover, .detail-gallery:hover, .photo-thumbs:hover)) {
    border-color: var(--action);
  }
  :is(input, select, textarea, button, .btn-primary, .btn-secondary):not(:disabled):not(:has(img)):hover { border-color: var(--action); }
  summary:hover { border-color: var(--action); }
  :is(.header-nav a, .quick-searches a, .pagination a, .source-links a):hover { background: var(--hover-tint); color: var(--action); }
  a:not(.card-media, .inline-photo-link):hover { text-decoration-color: var(--action); }
}
:is(.filters, .add-source-form, .comparison-form):has(:focus-visible) { border-color: var(--action); }
:is(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 2px solid var(--action); outline-offset: 3px; }
@media (max-width: 600px) {
  :root[data-catalog-view="stream"] .card:has([data-media-gallery]) { grid-template-columns: minmax(0, 1fr); }
  .detail-main .specs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-main .specs > div:only-child { grid-column: 1 / -1; }
  .detail-main .specs > div { padding: 12px; }
  .equipment-list, .attribute-list { grid-template-columns: minmax(0, 1fr); }
  .attribute-item { padding: 14px; }
  .original-post { padding: 14px; }
  .photo-toolbar { flex-wrap: wrap; }
  .photo-tools { margin-left: auto; }
  .viewer-video { max-width: 100%; }
  .photo-stage.is-video { padding-bottom: 52px; }
  .photo-viewer:has(.is-video) .photo-nav { top: auto; bottom: 84px; }
  .inline-media-actions { align-items: flex-start; }
}
