/* =============================================================================
   SCANNER — LIGHT THEME
   ============================================================================= */

:root {
  --bg:          #f5f0e6;
  --surface:     #ffffff;
  --surface-2:   #eef0f4;
  --border:      #dde1e8;
  --border-2:    #c4c8d1;

  --text:        #0c1222;
  --text-2:      #1f2937;
  --text-muted:  #475569;
  --text-dim:    #6b7a8d;

  --accent:      #1e40af;
  --accent-bg:   #e6ecfa;
  --accent-text: #1a3699;

  --yes:         #0f766e;
  --yes-bg:      #e0f7f3;
  --no:          #1e40af;
  --no-bg:       #e6ecfa;

  --danger:      #b91c1c;
  --danger-bg:   #fde8e8;

  --mono: 'IBM Plex Mono', monospace;
  --sans: 'IBM Plex Sans', sans-serif;

  --radius:    4px;
  --radius-lg: 10px;
  --shadow:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

/* =============================================================================
   RESET
   ============================================================================= */

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

html { font-size: 14px; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* =============================================================================
   PAGE CONTAINER — единая ширина для всего содержимого
   ============================================================================= */

.page-container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px;
}

/* =============================================================================
   TOP GRID — логотип + шапка (как в мониторе)
   ============================================================================= */

.top-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 5px;
}

header.site-header {
  grid-column: span 11;
  padding: 16px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface);
}

header.site-header .hcontent {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

header.site-header .hrow {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
}

header.site-header .title {
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: center;
  color: var(--text);
  text-align: center;
}

header.site-header .meta {
  justify-self: end;
  color: var(--text-muted);
  font-size: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Переключатель между половинами сканера: /scanner ↔ /scanner/uselection */
.scope-switch {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.scope-switch:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.scope-switch:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.loading-status {
  color: var(--text-muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-label { color: var(--text-muted); }
.meta-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
}

@media (max-width: 900px) {
  header.site-header { grid-column: span 12; }
  header.site-header { flex-direction: column; text-align: center; }
  header.site-header .hrow { grid-template-columns: 1fr; justify-items: center; gap: 6px; }
  header.site-header .meta { justify-self: center; }
  .scope-switch { justify-self: center; }
}

/* =============================================================================
   SUBHEAD — информационная строка (статус загрузки, сообщения фильтров)
   ============================================================================= */

.subhead {
  margin-top: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: flex-start;
}

.subhead .loading-status {
  max-width: none;
  white-space: normal;
  color: var(--text);
}

/* =============================================================================
   REFRESH BUTTON
   ============================================================================= */

.refresh-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
}

.refresh-btn:hover:not(:disabled) {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.refresh-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.refresh-btn.loading {
  color: transparent;
  position: relative;
}

.refresh-btn.loading::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================================================
   TAGS PANEL
   ============================================================================= */

/* JS sets display:grid on .filters-grid when tags are loaded */
.filters-grid {
  margin-top: 5px;
}

/* Override JS-set grid to 3/4 + 1/4 layout */
.filters-grid[style*="display: grid"],
.filters-grid[style*="display:grid"] {
  display: grid !important;
  grid-template-columns: 3fr 1fr;
  gap: 8px;
  align-items: stretch;
}

.tags-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px 10px;
  box-shadow: var(--shadow);
}

/* Services sidebar — promo banners */
.services-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.promo-banner {
  background: linear-gradient(160deg, #0f172a 0%, #1e3a5f 100%);
  border: 1px solid #334155;
  border-radius: var(--radius-lg);
  overflow: hidden;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
}

/* Нижнее объявление растягивается до нижнего края панели с тегами:
   services-panel тянется на высоту тегов (align-items: stretch у грида),
   а последняя карточка забирает остаток высоты колонки. */
.promo-banner:last-child {
  flex: 1;
}

.promo-label {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #f0c040;
  margin-bottom: 12px;
}

.promo-subtitle {
  font-size: 16px;
  font-weight: 600;
  color: #e2e8f0;
  line-height: 1.45;
  margin-bottom: 14px;
}

.promo-text {
  font-size: 15px;
  color: #cbd5e1;
  line-height: 1.55;
  flex: 1;
}

.promo-link {
  display: inline-block;
  margin-top: 16px;
  padding: 9px 16px;
  background: #f0c040;
  color: #0f172a;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius);
  transition: background 0.15s;
  align-self: flex-start;
}

.promo-link:hover {
  background: #fcd34d;
}

/* Tag logic toggle */
.tag-logic-group {
  padding-bottom: 8px !important;
}

.tag-logic-btn {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface-2);
  cursor: pointer;
  transition: all 0.12s;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  user-select: none;
}

.tag-logic-btn:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.tag-logic-btn.active {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent-text);
}

/* Tag groups */
#tagsStatsContent {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.tag-group {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.tag-group:last-child  { border-bottom: none; padding-bottom: 2px; }
.tag-group:first-child { padding-top: 2px; }

.tag-group-title {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: pre-line;
  min-width: 90px;
  flex-shrink: 0;
}

.tag-group-title.clickable {
  cursor: pointer;
  transition: color 0.12s;
}

.tag-group-title.clickable:hover {
  color: var(--accent);
}

.tag-group-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Tag chip */
.tag-stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface-2);
  cursor: pointer;
  transition: all 0.12s;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: nowrap;
  user-select: none;
}

.tag-stat:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.tag-stat.active {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.tag-stat-name {
  color: var(--text-2);
  font-weight: 500;
}

.tag-stat.active .tag-stat-name {
  color: var(--accent-text);
}

.tag-stat-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

.tag-stat.active .tag-stat-count {
  color: var(--accent-text);
  opacity: 0.8;
}

/* =============================================================================
   ACTIVE FILTERS BAR
   ============================================================================= */

.active-filters-bar {
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  box-shadow: var(--shadow);
}

.active-filters-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  white-space: nowrap;
}

.active-filters-text {
  font-size: 13px;
  color: var(--text-2);
  flex: 1;
}

.active-filters-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-left: 12px;
}

.chip-btn {
  padding: 2px 10px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  border: 1px solid;
  background: transparent;
  font-family: var(--sans);
}

.chip-btn--clear {
  border-color: var(--border-2);
  color: var(--text-muted);
}

.chip-btn--clear:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
}

.chip-btn--reset {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
}

.chip-btn--reset:hover {
  background: #fee2e2;
}

/* =============================================================================
   TABLE
   ============================================================================= */

#marketsContainer {
  margin-top: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead { background: var(--surface-2); }

th {
  padding: 10px 14px;
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  user-select: none;
  white-space: nowrap;
}

th.col-price { text-align: center; }
th.col-num   { text-align: center; }

th.sortable {
  cursor: pointer;
  position: relative;
  padding-right: 22px;
  transition: color 0.12s;
}

th.sortable:hover { color: var(--accent); }

th.sortable::after {
  content: '⇅';
  position: absolute;
  right: 6px;
  opacity: 0.35;
  font-size: 10px;
}

th.sort-asc::after  { content: '↑'; opacity: 1; color: var(--accent); }
th.sort-desc::after { content: '↓'; opacity: 1; color: var(--accent); }

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13.5px;
  color: var(--text);
}

tbody tr:last-child td { border-bottom: none; }

tbody tr { transition: background 0.1s; }

tbody tr:hover td { background: var(--surface-2); }

/* Market cell */
.market-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.market-image {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
}

.market-text { flex: 1; min-width: 0; }

.market-title {
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 3px;
}

.market-link {
  color: var(--text);
  text-decoration: none;
  transition: color 0.12s;
}

.market-link:hover { color: var(--accent); }

.market-question {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Inline tags */
.tag {
  display: inline-block;
  padding: 1px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 3px;
  font-size: 11px;
  margin-right: 3px;
  margin-bottom: 1px;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.tag:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-bg);
}

/* Date column */
td.date {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Price columns */
td.price {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

td.num {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  color: var(--text-2);
}

.price-yes { color: var(--yes); }
.price-no  { color: var(--no);  }

.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 13px;
}

/* =============================================================================
   PAGINATION
   ============================================================================= */

.pagination-container {
  border: 1px solid var(--border);
  border-top: none;
  background: var(--surface);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  padding: 10px 16px;
  display: flex;
  justify-content: center;
  box-shadow: var(--shadow);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pagination button {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

.pagination button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#pageInfo {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  min-width: 100px;
  text-align: center;
}

/* =============================================================================
   RANGE FILTERS BAR
   ============================================================================= */

.range-filters-bar {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.range-filter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.range-filter-title {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.range-filter-inputs {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.range-filter-inputs input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  transition: border-color 0.12s;
}

.range-filter-inputs input[type="number"] {
  text-align: right;
  -moz-appearance: textfield;
}

.range-filter-inputs input[type="number"]::-webkit-outer-spin-button,
.range-filter-inputs input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.range-filter-inputs input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

.range-filter-inputs input::placeholder {
  color: var(--text-dim);
}

.range-filter-inputs button {
  margin-top: 4px;
  width: 100%;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  font-family: var(--sans);
}

.range-filter-inputs button:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-bg);
}

/* Search bar (full width, above main layout) */
.search-bar {
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

.search-bar .search-row input {
  font-size: 13.5px;
}

.search-bar .search-row button {
  width: auto;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-text);
}

/* Search */
.search-row {
  display: flex;
  gap: 6px;
}

.search-row input {
  flex: 1;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.12s;
  min-width: 0;
  font-family: var(--sans);
}

.search-row input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

.search-row input::placeholder {
  color: var(--text-dim);
  font-size: 12px;
}

.search-row button {
  width: 32px;
  flex-shrink: 0;
  padding: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.12s;
}

.search-row button:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
}

/* =============================================================================
   SCANNER — RESPONSIVE (TABLETS & MOBILE)
   ============================================================================= */

/* =============================================================================
   TABLET  (≤ 1024px)
   ============================================================================= */

@media (max-width: 1024px) {

  .page-container {
    padding: 18px;
  }

  /* Filters grid: одна колонка, убираем services sidebar */
  .filters-grid[style*="display: grid"],
  .filters-grid[style*="display:grid"] {
    grid-template-columns: 1fr !important;
  }

  .services-panel {
    display: none;
  }

  /* Tag group titles — уже min-width */
  .tag-group-title {
    min-width: 70px;
    font-size: 10px;
  }

  /* Range filters: 3 колонки */
  .range-filters-bar {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Таблица: уменьшаем отступы */
  th { padding: 8px 10px; }
  td { padding: 9px 10px; }

  .market-image {
    width: 32px;
    height: 32px;
  }

  .market-content {
    gap: 8px;
  }

  /* Active filters: вертикальнее */
  .active-filters-actions {
    margin-left: 0;
    width: 100%;
  }
}

/* =============================================================================
   MOBILE  (≤ 640px)
   ============================================================================= */

@media (max-width: 640px) {

  .page-container {
    padding: 8px;
  }

  /* Tag groups: вертикально, заголовок сверху */
  .tag-group {
    flex-direction: column;
    gap: 6px;
    padding: 8px 0;
  }

  .tag-group-title {
    min-width: auto;
  }

  .tag-stat {
    font-size: 12px;
    padding: 4px 8px;
  }

  .tags-panel {
    padding: 10px 12px 8px;
  }

  /* Range filters: 2 колонки */
  .range-filters-bar {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .range-filter {
    padding: 10px 10px;
  }

  /* Search bar */
  .search-bar {
    padding: 8px 10px;
  }

  /* Active filters: вертикальный поток */
  .active-filters-bar {
    flex-direction: column;
    align-items: flex-start;
    padding: 8px 10px;
    gap: 6px;
  }

  /* =========================================================================
     ТАБЛИЦА → КАРТОЧКИ
     ========================================================================= */

  #marketsContainer {
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  #marketsTable {
    display: block;
  }

  #marketsTable thead {
    display: none;
  }

  #marketsTable tbody {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  #marketsTable tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 12px;
    transition: none;
  }

  #marketsTable tbody tr:hover td {
    background: transparent;
  }

  /* Ячейка рынка — на всю ширину, первый ряд */
  #marketsTable tbody tr td:nth-child(1) {
    grid-column: 1 / -1;
    grid-row: 1;
    padding: 0 0 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
  }

  /* Дата — под рынком слева */
  #marketsTable tbody tr td:nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 8px 0 6px 0;
    border-bottom: none;
    text-align: left;
  }

  #marketsTable tbody tr td:nth-child(2)::before {
    content: 'Окончание: ';
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-dim);
  }

  /* Числовые ячейки — сетка 2×2 + 1 */
  #marketsTable tbody tr td:nth-child(3),
  #marketsTable tbody tr td:nth-child(4),
  #marketsTable tbody tr td:nth-child(5),
  #marketsTable tbody tr td:nth-child(6),
  #marketsTable tbody tr td:nth-child(7) {
    padding: 6px 0 0 0;
    border-bottom: none;
    text-align: left;
    font-size: 13px;
  }

  /* Цены: ДА и НЕТ в одном ряду */
  #marketsTable tbody tr td:nth-child(3) {
    grid-column: 1;
    grid-row: 3;
  }

  #marketsTable tbody tr td:nth-child(4) {
    grid-column: 2;
    grid-row: 3;
  }

  /* Спред и объём — второй ряд */
  #marketsTable tbody tr td:nth-child(5) {
    grid-column: 1;
    grid-row: 4;
  }

  #marketsTable tbody tr td:nth-child(6) {
    grid-column: 2;
    grid-row: 4;
  }

  /* Ликвидность — третий ряд */
  #marketsTable tbody tr td:nth-child(7) {
    grid-column: 1;
    grid-row: 5;
  }

  /* Общие свойства лейблов перед значениями */
  #marketsTable tbody tr td:nth-child(3)::before,
  #marketsTable tbody tr td:nth-child(4)::before,
  #marketsTable tbody tr td:nth-child(5)::before,
  #marketsTable tbody tr td:nth-child(6)::before,
  #marketsTable tbody tr td:nth-child(7)::before {
    font-size: 10px;
    font-family: var(--mono);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }

  /* Индивидуальные лейблы */
  #marketsTable tbody tr td:nth-child(3)::before { content: 'ДА '; color: var(--yes); }
  #marketsTable tbody tr td:nth-child(4)::before { content: 'НЕТ '; color: var(--no); }
  #marketsTable tbody tr td:nth-child(5)::before { content: 'Спред: '; color: var(--text-dim); }
  #marketsTable tbody tr td:nth-child(6)::before { content: 'Объём: '; color: var(--text-dim); }
  #marketsTable tbody tr td:nth-child(7)::before { content: 'Ликв.: '; color: var(--text-dim); }

  /* Market content в карточке */
  .market-content {
    gap: 10px;
  }

  .market-image {
    width: 34px;
    height: 34px;
  }

  .market-title {
    font-size: 13px;
    line-height: 1.35;
  }

  .market-question {
    white-space: normal;
  }

  /* Pagination */
  .pagination-container {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-top: 6px;
  }
}

/* =============================================================================
   SMALL MOBILE  (≤ 400px)
   ============================================================================= */

@media (max-width: 400px) {

  .page-container {
    padding: 6px;
  }

  /* Range filters: 1 колонка */
  .range-filters-bar {
    grid-template-columns: 1fr;
  }

  /* Inputs в ряд внутри range filter */
  .range-filter-inputs {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .range-filter-inputs input {
    flex: 1;
    min-width: 0;
  }

  .range-filter-inputs button {
    margin-top: 0;
    flex: 0 0 auto;
    width: auto;
    padding: 5px 14px;
  }

  header.site-header .meta .meta-label {
    display: none;
  }

  .tag-stat {
    font-size: 11.5px;
    padding: 3px 6px;
  }
}

/* =============================================================================
   EVENTS MODE — режим «События»
   ============================================================================= */

/* Фильтры диапазонов недоступны в режиме «События» */
body.mode-events .range-filters-bar {
  display: none;
}

/* Сортировка по столбцам отключена */
body.mode-events th.sortable {
  cursor: default;
  padding-right: 14px;
}

body.mode-events th.sortable:hover {
  color: var(--text-muted);
}

body.mode-events th.sortable::after {
  content: none;
}

/* Строка события — кликабельная, с выделенным фоном */
tr.event-row {
  cursor: pointer;
}

tr.event-row td {
  background: var(--surface-2);
}

tr.event-row:hover td {
  background: var(--accent-bg);
}

/* Кнопка-стрелка разворота */
.event-toggle {
  width: 22px;
  height: 22px;
  padding: 0;
  flex-shrink: 0;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.12s, border-color 0.12s;
}

.event-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

tr.event-row.expanded .event-toggle {
  transform: rotate(90deg);
}

/* Строки рынков внутри события — с отступом под стрелку */
tr.market-subrow td:first-child {
  padding-left: 44px;
}

@media (max-width: 640px) {
  /* Карточная вёрстка задаёт display:grid строкам — гарантируем скрытие
     свёрнутых рынков (атрибут hidden) */
  #marketsTable tbody tr[hidden] {
    display: none !important;
  }

  /* Пустые ячейки строки события в карточке не показываем */
  #marketsTable tbody tr.event-row td:empty {
    display: none;
  }
}

/* =============================================================================
   FOOTER — стили вынесены в /elements/elements.css
   ============================================================================= */

