/**
 * Тёмная тема в духе 3x-ui (токены из VPN3 custom.min.css), без Vue/Ant.
 */
:root {
  --color-primary-100: #008771;
  --color-primary-hover: #009980;
  --dark-color-background: #0a1222;
  --dark-color-surface-100: #151f31;
  --dark-color-surface-200: #222d42;
  --dark-color-surface-300: #2c3950;
  --dark-color-surface-400: rgba(65, 85, 119, 0.5);
  --dark-color-text-primary: rgba(255, 255, 255, 0.75);
  --dark-color-text-secondary: rgba(255, 255, 255, 0.45);
  --dark-color-stroke: #2c3950;
  --dark-color-table-hover: rgba(44, 57, 80, 0.35);
  --dark-color-scrollbar: #313f5a;
  --dark-color-scrollbar-thumb: #7484a0;
  --dark-color-scrollbar-thumb-hover: #90a4c7;
  --tag-blue: #529fff;
  --tag-green: #3ad3ba;
  --tag-orange: #ffa031;
  --tag-purple: #d988cd;
  --tag-gold: #e8c07d;
  --radius-card: 1.5rem;
  --radius-inner: 0.75rem;
  --radius-btn: 0.5rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html.dark {
  color-scheme: dark;
}

html.dark,
html.dark body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--dark-color-text-primary);
  background-color: var(--dark-color-background);
  -webkit-font-smoothing: antialiased;
}

html.dark ::selection {
  color: #fff;
  background-color: var(--color-primary-100);
}

/* Scrollbar (как в 3x-ui dark) */
html.dark * {
  scrollbar-color: var(--dark-color-scrollbar) transparent;
  scrollbar-width: thin;
}

html.dark ::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  background: transparent;
}

html.dark ::-webkit-scrollbar-thumb {
  border-radius: 9999px;
  background-color: var(--dark-color-scrollbar-thumb);
  border: 2px solid transparent;
  background-clip: content-box;
}

html.dark ::-webkit-scrollbar-thumb:hover {
  background-color: var(--dark-color-scrollbar-thumb-hover);
}

.nedvigi-wrap {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

.nedvigi-header {
  text-align: center;
  margin-bottom: 8px;
}

.nedvigi-wordmark-link {
  display: inline-block;
  margin: 0 0 14px;
  text-decoration: none;
  color: inherit;
}

.nedvigi-wordmark-link:focus-visible {
  outline: 2px solid var(--color-primary-100);
  outline-offset: 6px;
  border-radius: 10px;
}

/* Надпись THE BASE — жирная, в палитре темы (бирюза + светлый текст) */
.nedvigi-wordmark {
  margin: 0 0 20px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(1.9rem, 5.2vw, 2.85rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: center;
}

.nedvigi-wordmark-the {
  color: rgba(255, 255, 255, 0.92);
  margin-right: 0.28em;
}

.nedvigi-wordmark-base {
  color: var(--color-primary-hover);
  text-shadow: 0 0 28px rgba(0, 153, 128, 0.35);
}

.nedvigi-title {
  margin: 0 0 22px;
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  letter-spacing: 0.06em;
  text-transform: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Верхняя панель (аналог ant-card) */
.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  margin-bottom: 20px;
  background: var(--dark-color-surface-100);
  border: 1px solid var(--dark-color-surface-400);
  border-radius: var(--radius-card);
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  flex: 1 1 auto;
  min-width: min(100%, 280px);
}

.stats-total {
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.95rem;
  white-space: nowrap;
}

.stats-total b {
  color: #fff;
  font-weight: 600;
}

.stats-source-btns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.stats-source-btn {
  padding: 7px 14px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  color: var(--dark-color-text-primary);
  background: rgba(10, 117, 87, 0.22);
  border: 1px solid var(--dark-color-surface-300);
  border-radius: var(--radius-btn);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.stats-source-btn:hover:not(.disabled) {
  color: #fff;
  background: rgba(10, 117, 87, 0.38);
  border-color: var(--color-primary-100);
}

.stats-source-btn.active {
  color: #fff;
  background: var(--color-primary-100);
  border-color: var(--color-primary-100);
  box-shadow: 0 0 0 1px rgba(0, 135, 113, 0.35);
}

.stats-source-btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.stats-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.stats-admin-link {
  margin-right: 8px;
}

.stats-admin-link a {
  color: var(--tag-blue);
  text-decoration: none;
  font-size: 0.85rem;
}

.stats-admin-link a:hover {
  text-decoration: underline;
}

.view-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.view-toggle button {
  padding: 8px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--dark-color-text-primary);
  background: rgba(10, 117, 87, 0.28);
  border: 1px solid var(--color-primary-100);
  border-radius: var(--radius-btn);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.view-toggle button:hover {
  color: #fff;
  background: rgba(10, 117, 87, 0.45);
  border-color: var(--color-primary-hover);
}

.view-toggle button.active {
  color: #fff;
  background: var(--color-primary-100);
  border-color: var(--color-primary-100);
  box-shadow: 0 0 0 1px rgba(0, 135, 113, 0.35);
}

.view-toggle button[data-view="telegram"].active {
  background: #201425;
  border-color: #5a2969;
  color: var(--tag-purple);
  box-shadow: 0 0 0 1px rgba(90, 41, 105, 0.4);
}

/* Контент-зона */
.list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.loading {
  text-align: center;
  padding: 48px 20px;
  color: var(--dark-color-text-secondary);
  background: var(--dark-color-surface-100);
  border: 1px solid var(--dark-color-surface-400);
  border-radius: var(--radius-card);
}

/* Блоки продавцов */
.seller-block {
  margin-bottom: 14px;
  border-radius: var(--radius-inner);
  overflow: hidden;
  background: var(--dark-color-surface-100);
  border: 1px solid var(--dark-color-surface-400);
}

.seller-block:nth-of-type(4n + 1),
.seller-block:nth-of-type(4n + 2),
.seller-block:nth-of-type(4n + 3),
.seller-block:nth-of-type(4n + 4) {
  background: var(--dark-color-surface-100);
}

.seller-block--facebook {
  border-color: rgba(82, 159, 255, 0.35);
  box-shadow: inset 3px 0 0 rgba(82, 159, 255, 0.55);
}

.seller-block--livuma {
  border-color: rgba(0, 188, 164, 0.35);
  box-shadow: inset 3px 0 0 rgba(0, 188, 164, 0.55);
}

.seller-block--telegram {
  border-color: rgba(217, 136, 205, 0.35);
  box-shadow: inset 3px 0 0 rgba(217, 136, 205, 0.5);
}

.seller-block-header {
  padding: 12px 18px;
  font-weight: 600;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid var(--dark-color-surface-400);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.seller-block--collapsible .seller-block-header {
  cursor: pointer;
  user-select: none;
}

.seller-block--collapsible .seller-block-header:hover {
  background: var(--dark-color-table-hover);
}

.seller-block-toggle {
  font-size: 0.7rem;
  color: var(--dark-color-text-secondary);
  transition: transform 0.2s;
}

.seller-block-body {
  overflow: hidden;
  transition: max-height 0.35s ease-out;
}

.seller-block-body--collapsed {
  max-height: 0;
  border-bottom: none;
}

.seller-block-body:not(.seller-block-body--collapsed) {
  max-height: 3000px;
}

.row-thumb img {
  border-radius: 8px;
  border: 1px solid var(--dark-color-surface-300);
}

.row {
  display: flex;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--dark-color-surface-400);
  gap: 18px;
  flex-wrap: wrap;
}

.row:last-child {
  border-bottom: none;
}

.row:hover {
  background: var(--dark-color-table-hover);
}

.row-title {
  flex: 1 1 300px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.88);
}

.row-price {
  font-weight: 600;
  color: var(--tag-green);
  white-space: nowrap;
}

.row-meta {
  font-size: 0.85rem;
  color: var(--dark-color-text-secondary);
  flex: 0 0 200px;
}

.row-date {
  font-size: 0.85rem;
  color: var(--dark-color-text-secondary);
  flex: 0 0 100px;
}

.row a {
  color: var(--tag-blue);
  text-decoration: none;
  white-space: nowrap;
}

.row a:hover {
  color: #7eb8ff;
  text-decoration: underline;
}

/* Карточки объявлений */
#cards {
  margin-top: 8px;
}

.cards-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--dark-color-surface-400);
}

.cards-section--telegram {
  border-top-color: rgba(217, 136, 205, 0.35);
}

.cards-title {
  font-size: 1.15rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  margin: 0 0 16px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.cards-grid--telegram {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.cards-grid--singles {
  margin-bottom: 20px;
}

.card {
  background: var(--dark-color-surface-100);
  border: 1px solid var(--dark-color-surface-400);
  border-radius: var(--radius-inner);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  border-left: 4px solid transparent;
}

.card:hover {
  border-color: rgba(0, 135, 113, 0.45);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.card--olx {
  background: linear-gradient(135deg, rgba(255, 160, 49, 0.08) 0%, var(--dark-color-surface-100) 45%);
  border-left-color: var(--tag-orange);
}

.card--rumah123 {
  background: linear-gradient(135deg, rgba(58, 211, 186, 0.1) 0%, var(--dark-color-surface-100) 45%);
  border-left-color: var(--tag-green);
}

.card--facebook {
  background: linear-gradient(135deg, rgba(82, 159, 255, 0.1) 0%, var(--dark-color-surface-100) 45%);
  border-left-color: var(--tag-blue);
}

.card--telegram {
  background: linear-gradient(135deg, rgba(217, 136, 205, 0.12) 0%, var(--dark-color-surface-100) 45%);
  border-left-color: var(--tag-purple);
}

.card--livuma {
  background: linear-gradient(135deg, rgba(0, 188, 164, 0.1) 0%, var(--dark-color-surface-100) 45%);
  border-left-color: #00bca4;
}

.card--unknown {
  border-left-color: var(--dark-color-text-secondary);
}

.card-image {
  height: 140px;
  background-color: var(--dark-color-surface-200);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.card-body {
  padding: 14px;
}

.card-title {
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.88);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-price {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--tag-green);
}

.card-specs {
  font-size: 0.78rem;
  color: var(--dark-color-text-secondary);
  margin-top: 6px;
  line-height: 1.35;
}

.card-seller {
  font-size: 0.8rem;
  color: var(--dark-color-text-secondary);
  margin-top: 6px;
}

.card-date {
  font-size: 0.75rem;
  color: var(--dark-color-text-secondary);
  margin-top: 4px;
}

.card-source {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.card--olx .card-source {
  color: var(--tag-orange);
}

.card--rumah123 .card-source {
  color: var(--tag-green);
}

.card--facebook .card-source {
  color: var(--tag-blue);
}

.card--telegram .card-source {
  color: var(--tag-purple);
}

.card--livuma .card-source {
  color: #5eead4;
}

/* Агентские карточки */
.agent-cards-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.agent-card {
  background: var(--dark-color-surface-100);
  border: 1px solid var(--dark-color-surface-400);
  border-radius: var(--radius-inner);
  overflow: hidden;
}

.agent-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.agent-card-header:hover {
  background: var(--dark-color-table-hover);
}

.agent-card-preview {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  flex-shrink: 0;
  background-color: var(--dark-color-surface-200);
  background-position: center;
  background-size: cover;
  border: 1px solid var(--dark-color-surface-300);
}

.agent-card-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.agent-card-name {
  font-weight: 600;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.88);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-card-count {
  font-size: 0.85rem;
  color: var(--dark-color-text-secondary);
  flex-shrink: 0;
}

.agent-card-toggle {
  font-size: 0.75rem;
  color: var(--dark-color-text-secondary);
  transition: transform 0.2s;
}

.agent-card-body {
  overflow: hidden;
  transition: max-height 0.35s ease-out;
}

.agent-card-body--collapsed {
  max-height: 0;
}

.agent-card-body:not(.agent-card-body--collapsed) .cards-grid {
  padding: 12px 16px 18px;
  border-top: 1px solid var(--dark-color-surface-400);
}

/* Ошибки / таймаут в #stats (inline style от JS) — чуть мягче на тёмном фоне */
.stats span[style*="c62828"],
.list p[style*="c62828"] {
  color: #ff6b6b !important;
}

body.property-modal-open {
  overflow: hidden;
}

/* Карточка Telegram как кнопка (модалка вместо прямой ссылки) */
button.card {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  font: inherit;
  text-align: left;
  color: inherit;
  cursor: pointer;
  background: transparent;
  border-radius: var(--radius-card);
}

button.card:focus-visible {
  outline: 2px solid var(--color-primary-100);
  outline-offset: 2px;
}

.row-open-modal {
  padding: 6px 12px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-btn);
  border: 1px solid var(--color-primary-100);
  background: rgba(10, 117, 87, 0.25);
  color: var(--dark-color-text-primary);
}

.row-open-modal:hover {
  background: rgba(10, 117, 87, 0.4);
  color: #fff;
}

.row-tg-link {
  margin-left: 8px;
  font-size: 0.8rem;
  color: var(--tag-blue);
}

/* Модалка объявления */
.property-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 48px;
  overflow-y: auto;
  box-sizing: border-box;
}

.property-modal[hidden] {
  display: none !important;
}

.property-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, 0.72);
  backdrop-filter: blur(4px);
}

.property-modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 720px;
  margin-top: 4vh;
  background: var(--dark-color-surface-100);
  border: 1px solid var(--dark-color-surface-400);
  border-radius: var(--radius-card);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  max-height: min(88vh, 900px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.property-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-btn);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: var(--dark-color-text-primary);
  background: var(--dark-color-surface-200);
}

.property-modal-close:hover {
  background: var(--dark-color-surface-300);
  color: #fff;
}

.property-modal-content {
  padding: 20px 48px 24px 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.property-modal-title {
  margin: 0 0 10px;
  font-size: 1.15rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  padding-right: 28px;
}

.property-modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.property-modal-source {
  color: var(--tag-green);
}

.property-modal-price {
  color: var(--tag-orange);
  font-weight: 600;
}

.property-modal-specs {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--dark-color-text-secondary);
  line-height: 1.45;
}

.property-modal-label {
  color: var(--dark-color-text-secondary);
  font-weight: 600;
  margin-right: 4px;
}

.property-modal-facilities,
.property-modal-seller,
.property-modal-pubdate {
  margin: 0 0 10px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--dark-color-text-primary);
}

.property-modal-desc-hint {
  margin: 0 0 14px;
  font-size: 0.85rem;
  color: var(--dark-color-text-secondary);
  font-style: italic;
  line-height: 1.45;
}

.property-modal-phone {
  margin: 0 0 12px;
  font-size: 0.9rem;
}

.property-modal-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.property-modal-thumb {
  display: block;
  border-radius: var(--radius-inner);
  overflow: hidden;
  border: 1px solid var(--dark-color-surface-400);
  aspect-ratio: 4 / 3;
  background: var(--dark-color-surface-200);
}

.property-modal-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  vertical-align: middle;
}

.property-modal-desc {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--dark-color-text-primary);
  margin-bottom: 14px;
}

.property-modal-external {
  margin: 0;
  font-size: 0.85rem;
}

.property-modal-external a {
  color: var(--tag-blue);
}

.property-modal-loading,
.property-modal-err {
  margin: 24px 0;
  color: var(--dark-color-text-secondary);
}
