:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --panel: #ffffff;
  --ink: #142033;
  --muted: #667386;
  --line: #d9e2ea;
  --accent: #ff5f37;
  --accent-soft: #fff0eb;
  --blue: #2563eb;
  --blue-soft: #e8efff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 20px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: clamp(25px, 4vw, 34px);
  line-height: 1.15;
  letter-spacing: -0.04em;
}

.feed-heading {
  display: grid;
  gap: 7px;
}

.feed-heading p {
  margin: 8px 0 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.feed-brand {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.feed-brand-mark {
  position: relative;
  width: 21px;
  height: 21px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.feed-brand-mark::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  top: 5px;
  left: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 95, 55, 0.14);
}

.topbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.feed-heading .feed-intro {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.territory-breadcrumb {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.territory-breadcrumb a,
.territory-directory a { color: var(--blue); }

.filters-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.filters-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  min-height: 44px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
}

.filters-summary::-webkit-details-marker { display: none; }
.filters-summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.filters-panel[open] .filters-summary { border-bottom: 1px solid var(--line); }
.filters-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.filters-action { color: var(--blue); font-size: 12px; font-weight: 600; }
.filters-chevron { width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); }
.filters-panel[open] .filters-chevron { transform: rotate(225deg); }

.filterbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: flex-end;
  gap: 10px;
  padding: 14px 14px 2px;
}

.filterbar select {
  min-width: 0;
}

.filterbar .rooms-filter { grid-column: span 3; }
.rooms-filter { display: flex; flex-wrap: wrap; gap: 8px 14px; min-width: 0; margin: 0; padding: 5px 10px 8px; border: 1px solid var(--line); border-radius: 9px; }
.rooms-filter legend { color: var(--muted); font-size: 12px; }
.rooms-filter label { white-space: nowrap; font-size: 13px; }
.rooms-filter input { accent-color: var(--accent); }
.numeric-filter input { width: 100%; min-width: 0; min-height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); font: inherit; font-size: 14px; }
.numeric-filter input[aria-invalid="true"] { border-color: #ad341d; }
.filter-error { grid-column: 1 / -1; color: #ad341d; font-size: 13px; }
.filter-error[hidden] { display: none; }
.filter-note { margin: 5px 14px 14px; color: var(--muted); font-size: 12px; }

.secondary-button {
  background: transparent;
}

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

select,
button {
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 9px;
  font-size: 14px;
}

select {
  min-width: 220px;
  padding: 0 10px;
}

button {
  padding: 0 12px;
  cursor: pointer;
}

.change-location {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

button:disabled {
  cursor: default;
  opacity: 0.7;
}

.notify-button[hidden] {
  display: none;
}

.sound-toggle-button[hidden] {
  display: none;
}

.test-notify-button[hidden] {
  display: none;
}

.notification-status {
  max-width: 210px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.live-hint {
  margin: 12px 0 14px;
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 18px;
  flex-wrap: wrap;
}

.live-status-message {
  display: inline-flex;
  align-items: center;
}

.telegram-feed-link {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid #b8cbff;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
  text-decoration: none;
}

.telegram-feed-link:hover {
  border-color: var(--blue);
  background: #dce8ff;
}

.telegram-feed-link:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.live-dot {
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  display: inline-block;
  background: #27c48f;
  box-shadow: 0 0 0 5px rgba(39, 196, 143, 0.12);
}

.live-hint.has-alert {
  color: var(--ink);
  font-weight: 700;
}

.live-hint.has-alert .live-dot {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(255, 95, 55, 0.14);
}

.feed-list {
  display: grid;
  gap: 10px;
}

.feed-card {
  display: grid;
  gap: 7px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 7px 24px rgba(25, 43, 67, 0.04);
}

.feed-card.is-new {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
  animation: incomingPulse 1.1s ease;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.card-head-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.source-badge {
  min-width: 44px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  text-align: center;
}

.source-badge.source-cian {
  background: #e8efff;
  color: #1d4ed8;
}

.source-badge.source-avito {
  background: #e7f6df;
  color: #3f7f16;
}

.created-at {
  padding: 3px 8px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  background: #f3f8f6;
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.morning-recovery-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: #f2eefb;
  color: #60438e;
  font-weight: 700;
  line-height: 1.2;
}

.morning-recovery-badge[hidden] {
  display: none;
}

.lead-date {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.price {
  font-size: 20px;
  font-weight: 700;
}

.listing-title,
.params,
.address {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.listing-title {
  color: var(--ink);
  font-size: 16px;
  font-weight: 750;
}

.params {
  color: var(--ink);
}

.empty-state {
  margin: 20px 0;
  color: var(--muted);
}

.open-link {
  width: fit-content;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid #1d4ed8;
  border-radius: 6px;
  background: var(--blue);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}

.open-link:hover {
  background: #1d4ed8;
}

.open-link:visited {
  color: #ffffff;
}

.open-link.is-opened {
  border-color: #b7c2d7;
  background: var(--blue-soft);
  color: #42526b;
}

.open-link.is-opened:hover {
  background: #dbe6ff;
}

@keyframes incomingPulse {
  0% {
    background: var(--accent-soft);
  }
  100% {
    background: var(--panel);
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0 12px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    justify-content: stretch;
    gap: 8px;
  }

  .topbar-actions .field {
    min-width: 0;
  }

  .topbar-actions select {
    min-width: 0;
    width: 100%;
  }

  .change-location {
    justify-content: center;
    white-space: nowrap;
  }

  .notify-button,
  .sound-toggle-button,
  .test-notify-button,
  .notification-status {
    grid-column: 1 / -1;
  }

  .notification-status {
    max-width: none;
  }

  .filterbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .filterbar .rooms-filter { grid-column: 1 / -1; }

  .filterbar .field:first-child,
  .filterbar .secondary-button {
    grid-column: 1 / -1;
  }

  .filterbar select {
    min-width: 0;
  }

  .card-head {
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
  }

  select,
  button,
  .open-link {
    width: 100%;
  }

}
:root .access-info { margin: 0 0 18px; padding: 12px 16px; border: 1px solid #dbe6f1; border-radius: 12px; background: #f7fafc; font-size: 14px; }
:root .access-info[hidden], :root .access-info details[hidden] { display: none; }
:root .access-info summary { cursor: pointer; color: #185bb2; margin-top: 8px; }
:root .access-info p { max-width: 65ch; line-height: 1.5; }
:root .access-notice { padding: 12px 16px; background: #fff6dc; border-radius: 12px; }
