:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-soft: #f0f3ec;
  --text: #1d2420;
  --muted: #66706b;
  --line: #dce2d8;
  --accent: #256f57;
  --accent-strong: #154c3b;
  --accent-soft: #e5f2ec;
  --warning: #a36318;
  --shadow: 0 16px 36px rgb(40 55 45 / 10%);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgb(37 111 87 / 12%), transparent 34rem),
    var(--bg);
  color: var(--text);
}

button,
input,
select,
a.secondary-button {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 620px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 14px;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
}

.brand {
  min-width: 0;
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow,
h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin-top: 3px;
  font-size: 23px;
  line-height: 1.08;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 255 255 / 82%);
  color: var(--accent-strong);
  font-size: 20px;
  font-weight: 800;
}

.language-button {
  min-width: 46px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #111827;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.language-button.is-ru {
  background: linear-gradient(#fff 0 33%, #1f5fbf 33% 66%, #d62626 66% 100%);
  color: #fff;
  text-shadow: 0 1px 2px rgb(0 0 0 / 55%);
}

.language-button.is-en {
  background:
    linear-gradient(90deg, transparent 0 42%, #d31f2f 42% 58%, transparent 58% 100%),
    linear-gradient(transparent 0 42%, #d31f2f 42% 58%, transparent 58% 100%),
    #17468f;
  color: #fff;
}

.search-panel,
.metrics,
.empty-state,
.market-card,
.ad-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 10px 24px rgb(45 60 50 / 6%);
}

.search-panel {
  padding: 15px;
}

.section-heading {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

#search-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.field-grid,
.range-row,
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field,
.number-field {
  display: grid;
  gap: 7px;
}

.field span,
.number-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

select,
input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

select {
  padding: 0 12px;
}

input {
  padding: 0 11px;
}

select:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(37 111 87 / 12%);
}

.range-row,
.segmented,
.toggle-grid {
  margin-top: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segment {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.segment.is-active {
  background: #fff;
  color: var(--accent-strong);
  box-shadow: 0 6px 16px rgb(35 55 45 / 10%);
}

.toggle {
  display: flex;
  min-height: 44px;
  gap: 9px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin: 12px -2px 0;
  padding: 6px 2px;
  background: rgb(245 246 242 / 92%);
  backdrop-filter: blur(12px);
}

.tab {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.tab.is-active {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 8px;
  overflow: hidden;
}

.metrics div {
  min-width: 0;
  padding: 12px 10px;
  text-align: center;
}

.metrics div + div {
  border-left: 1px solid var(--line);
}

.metrics strong,
.metrics span {
  display: block;
}

.metrics strong {
  font-size: 18px;
  line-height: 1.1;
}

.metrics span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.view-title {
  margin: 16px 2px 8px;
  font-size: 17px;
  font-weight: 900;
}

.content {
  display: grid;
  gap: 10px;
}

.ad-card {
  overflow: hidden;
  border-left: 4px solid var(--accent);
}

.ad-photo-button {
  position: relative;
  display: block;
  width: 100%;
  height: 176px;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--surface-soft);
  padding: 0;
}

.ad-photo-button img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.ad-photo-button span {
  position: absolute;
  right: 10px;
  bottom: 10px;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgb(29 36 32 / 82%);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.ad-body {
  padding: 14px 13px 13px;
}

.ad-topline,
.ad-actions,
.market-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.ad-source {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.fresh {
  color: var(--warning);
  font-size: 12px;
  font-weight: 900;
}

.ad-card h3 {
  margin: 7px 0 0;
  font-size: 17px;
  line-height: 1.22;
}

.ad-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  min-height: 28px;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.ad-description {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.ad-details {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.detail-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.detail-row strong {
  min-width: 0;
  color: var(--text);
  text-align: right;
}

.photo-gallery {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(178px, 74%);
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  padding-bottom: 2px;
  scroll-snap-type: inline mandatory;
}

.gallery-item {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-soft);
  scroll-snap-align: start;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.photo-missing {
  margin-top: 12px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.ad-actions {
  flex-wrap: wrap;
  margin-top: 12px;
}

.secondary-button,
.favorite-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 146px;
  padding: 0 12px;
  text-align: center;
  text-decoration: none;
}

.call-button {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.favorite-button {
  width: 44px;
  flex: 0 0 auto;
  color: var(--accent);
}

.favorite-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.market-card,
.empty-state {
  padding: 15px;
}

.market-card h3,
.empty-state h3 {
  margin: 0;
  font-size: 16px;
}

.market-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.market-row {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.market-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.market-row strong {
  color: var(--text);
}

.empty-state p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.bottom-action {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 76%, rgb(245 246 242 / 0));
}

.primary-button {
  display: flex;
  width: min(100%, 592px);
  min-height: 52px;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.primary-button:active,
.secondary-button:active,
.favorite-button:active,
.icon-button:active {
  transform: translateY(1px);
}

@media (max-width: 390px) {
  .app-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  h1 {
    font-size: 20px;
  }

  .field-grid,
  .range-row {
    grid-template-columns: 1fr;
  }

  .tab {
    font-size: 12px;
  }
}
