/* =============================================================================
   MAP — 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;

  --danger: #b91c1c;
  --danger-bg: #fde8e8;
  --warn: #92400e;
  --warn-bg: #fef3c7;

  /* Цвета групп — синхронно с COLORS в map.svg.js */
  --c1: #2a78d6;
  --c2: #eb6834;
  --c3: #1baf7a;
  --c4: #eda100;
  --c5: #e87ba4;
  --c6: #008300;
  --c7: #6250d6;
  --minor: #8e96a3;
  --none: #a8a294;
  --rest: #e4dfd3;

  --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);
}

*,
*::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 {
  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;
  justify-content: center;
  background: var(--surface);
}

header.site-header .title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

@media (max-width: 900px) {
  header.site-header {
    grid-column: span 12;
  }
  header.site-header .title {
    font-size: 20px;
  }
}

/* SUBHEAD — информационная строка карты, под заголовком карточки */
.subhead {
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 18px;
}

.info-main {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 18px;
}

.subhead b {
  font-weight: 600;
  color: var(--text);
}

.subhead .delta {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.subhead [hidden] {
  display: none;
}

.note {
  border-radius: var(--radius);
  padding: 2px 10px;
  background: var(--accent-bg);
  color: var(--accent-text);
}

.note a {
  color: inherit;
  font-weight: 600;
  margin-left: 6px;
}

.note--warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.note--err {
  background: var(--danger-bg);
  color: var(--danger);
}

/* КАРТОЧКИ */
.card {
  margin-top: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
}

/* НАСТРОЙКИ */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.seg button,
.btn {
  font: 500 14px/1 var(--sans);
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 0 14px;
  min-height: 36px;
  cursor: pointer;
  transition:
    background 0.12s,
    border-color 0.12s;
}

.seg button:hover,
.btn:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.seg button[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.seg button:focus-visible,
.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Свободное место строки забирает блок окон: на одной строке «Поделиться»
   стоит справа, а при переносе — в начале новой строки, а не у правого края */
#segWindow {
  flex-grow: 1;
}

.btn[aria-expanded='true'] {
  border-color: var(--accent);
  color: var(--accent);
}

.share {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.share[hidden] {
  display: none;
}

.share-title {
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.share-grid:last-child {
  margin-bottom: 0;
}

.share-grid .btn {
  width: 100%;
  padding-block: 6px;
  line-height: 1.2;
}

a.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
}

/* Кнопки соцсетей — в фирменных цветах сетей */
.net {
  gap: 8px;
  color: #fff;
  background: var(--net);
  border-color: var(--net);
}

.net:hover {
  color: #fff;
  background: var(--net);
  border-color: var(--net);
  filter: brightness(0.9);
}

.net svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: currentColor;
}

.net-telegram {
  --net: #26a5e4;
}

.net-x {
  --net: #000000;
}

.net-linkedin {
  --net: #0a66c2;
}

.net-facebook {
  --net: #0866ff;
}

.net-threads {
  --net: #000000;
}

.net-reddit {
  --net: #ff4500;
}

.net-bluesky {
  --net: #1185fe;
}

.share-link {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
  font: 400 14px/1.2 var(--mono);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 6px;
}

.share-link[hidden] {
  display: none;
}

.share-status {
  min-height: 1.2em;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.sw-c1 {
  background: var(--c1);
}
.sw-c2 {
  background: var(--c2);
}
.sw-c3 {
  background: var(--c3);
}
.sw-c4 {
  background: var(--c4);
}
.sw-c5 {
  background: var(--c5);
}
.sw-c6 {
  background: var(--c6);
}
.sw-c7 {
  background: var(--c7);
}
.sw-minor {
  background: var(--minor);
}
.sw-none {
  background: var(--none);
}
.sw-rest {
  background: var(--rest);
}

/* КАРТА */
#stage {
  width: 100%;
  margin-top: 12px;
}

#mapbox {
  position: relative;
}

#mapsvg svg,
#restbar svg {
  display: block;
}

#restbar {
  margin-top: 4px;
}

.tile {
  cursor: pointer;
  outline: none;
}

.tile:hover rect,
.tile:focus-visible rect {
  stroke: var(--text);
  stroke-width: 1.5;
}

.fade .lbl {
  animation: lblin 0.25s ease-out both;
}

@keyframes lblin {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fade .lbl {
    animation: none;
  }
}

/* ПОДСКАЗКА */
.tip {
  position: absolute;
  z-index: 5;
  width: 270px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 6px 20px rgba(12, 18, 34, 0.18);
  font-size: 13px;
  pointer-events: none;
}

.tip.touch {
  pointer-events: auto;
}

.tip[hidden] {
  display: none;
}

.tip-g {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.tip-g b {
  font: 500 12px var(--mono);
  color: var(--text-2);
}

.tip-ru {
  font-weight: 600;
  line-height: 1.3;
}

.tip-en {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 8px;
  line-height: 1.3;
}

.tip dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  margin: 0;
}

.tip dt {
  color: var(--text-muted);
}

.tip dd {
  margin: 0;
  font: 500 13px var(--mono);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tip a.open {
  display: block;
  margin-top: 10px;
  text-align: center;
  background: var(--accent);
  color: #ffffff;
  border-radius: 6px;
  padding: 10px;
  text-decoration: none;
  font-weight: 500;
}

/* ТАБЛИЦА */
.tbl-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.tbl-more {
  display: block;
  margin: 12px auto 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 720px;
  font-size: 13.5px;
}

th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tr:last-child td {
  border-bottom: 0;
}

td.n,
th.n {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.n {
  color: var(--text-2);
}

td .en {
  display: block;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

td .grp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Группа внутри «События» — только на узком экране, вместо своей колонки */
td.ev .grp {
  display: none;
}

@media (max-width: 799px) {
  table {
    min-width: 0;
  }
  th,
  td {
    padding-inline: 6px;
  }
  td.n,
  th.n {
    font-size: 12px;
  }
  td.ev {
    overflow-wrap: anywhere;
    hyphens: auto;
  }
  .grp-col {
    display: none;
  }
  td.ev .grp {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-2);
  }
  td.ev .grp .sw {
    margin-right: 6px;
    vertical-align: -1px;
  }
}

td.ev .mk {
  display: none;
}

/* Телефон: пять колонок не помещаются — число рынков уходит в строку группы */
@media (max-width: 479px) {
  .mk-col {
    display: none;
  }
  td.n,
  th.n {
    font-family: var(--sans);
  }
  td.ev .mk {
    display: inline;
    white-space: nowrap;
  }
}

td.ev a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

td.ev a:hover {
  color: var(--accent);
  text-decoration: underline;
}

tr.rest td {
  background: var(--bg);
}

/* КАРТОЧКИ КАРТЫ И ГРАФИКОВ: заголовок и строка о текущем виде, кнопки, строка
   об ошибке, плитки, график, пояснения (графики — map.charts.js) */
.chart-card {
  padding: 16px 20px 14px;
}

.chart-head {
  margin-bottom: 14px;
}

.chart-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.chart-sub {
  margin-top: 2px;
  color: var(--text-muted);
}

.chart-note {
  display: inline-block;
  margin-top: 10px;
}

.chart-note[hidden] {
  display: none;
}

/* Кнопки показателя есть только у тепловой карты: hidden сильнее display: flex */
.seg[hidden] {
  display: none;
}

.seg-label {
  align-self: center;
  margin-right: 4px;
  color: var(--text-muted);
}

/* Выбор темы — обычный select в стиле кнопок */
.chart-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.chart-select[hidden] {
  display: none;
}

.chart-select select {
  font: 500 14px/1 var(--sans);
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 10px;
}

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

/* ИТОГИ — плитки над графиком */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stat {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.stat dt {
  font-size: 12px;
  color: var(--text-muted);
}

.stat dd {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.stat .stat-sub {
  display: block;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-dim);
}

/* ГРАФИК — высота по окну: на мониторе и планшете график целиком в экране */
.chart {
  margin-top: 10px;
  height: clamp(460px, 100dvh - 400px, 720px);
  transition: opacity 0.15s;
}

.chart.is-loading {
  opacity: 0.5;
}

.chart-how {
  margin-top: 6px;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

.chart-how li + li {
  margin-top: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .chart {
    transition: none;
  }
}

/* КАК СЧИТАЕТСЯ */
.how {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.how .card-title {
  font-size: 13px;
  margin-bottom: 6px;
}

.how ul {
  padding-left: 20px;
  max-width: 760px;
}

.how li {
  margin-bottom: 4px;
}

@media (max-width: 599px) {
  .page-container {
    padding: 10px;
  }
}
