:root {
  /* Тёмная тема — фон строго равен фону страницы сайта (layout-shell #0d1421),
     чтобы виджет не читался как отдельный «тёмный контейнер». */
  --bg: #0d1421;
  --panel: #161c2a;
  --panel-2: #1e2636;
  --border: #2a3346;
  --divider: rgba(255,255,255,.06);
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.22);
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --up: #16c784;
  --down: #ea3943;
  --accent: #5b8cff;
  --accent-tint: rgba(91,140,255,.16);
  --up-tint: rgba(22,199,132,.10);
  --down-tint: rgba(234,57,67,.10);
  --warn: #f7931a;
}
html.light, body.light {
  --bg: #ffffff;
  --panel: #f4f7fb;
  --panel-2: #e9eff6;
  --border: #dbe3ee;
  --divider: rgba(15,23,42,.07);
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 12px 30px rgba(15,23,42,.07);
  --text: #0f1115;
  --muted: #5b6472;
  --up: #0aa05f;
  --down: #d12c39;
  --accent: #2f6bff;
  --accent-tint: rgba(47,107,255,.12);
  --up-tint: rgba(10,160,95,.09);
  --down-tint: rgba(209,44,57,.09);
  --warn: #e07b00;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
body.embedded { background: var(--bg); min-height: 100vh; }

.wrap {
  display: flex; flex-direction: column; gap: 14px;
  padding: 10px 18px 22px; max-width: 980px; margin: 0 auto;
}

/* ───── Панель управления ───── */
.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.tabs { display: flex; gap: 6px; }
.tabs button {
  background: var(--panel-2); color: var(--muted); border: 0;
  border-radius: 10px; padding: 8px 14px; cursor: pointer; font-size: 13px;
  font-weight: 700; transition: background .15s, color .15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); background: var(--accent-tint); }

.periods { display: flex; gap: 5px; margin-left: auto; }
.periods button {
  background: var(--panel-2); color: var(--muted); border: 0;
  border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 12px;
  font-weight: 600; transition: background .15s, color .15s; font-variant-numeric: tabular-nums;
}
.periods button:hover { color: var(--text); }
.periods button.active { color: var(--accent); background: var(--accent-tint); }

.meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.stale-badge {
  background: var(--warn); color: #fff; border-radius: 6px; padding: 2px 7px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
html.light .stale-badge, body.light .stale-badge { color: #fff; }

/* ───── Фильтры ───── */
.filters { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 0 2px; }
.chk { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.chk:hover { color: var(--text); }
#fNetwork {
  background: var(--panel-2); color: var(--text); border: 0; border-radius: 8px;
  padding: 6px 10px; font-size: 12.5px; cursor: pointer; font-family: inherit;
}
/* Переключатель количества строк (50/100/250) — справа в ряду фильтров. */
.limits { margin-left: auto; display: flex; align-items: center; gap: 5px; }
.limits-label { color: var(--muted); font-size: 12px; margin-right: 2px; }
.limits button {
  background: var(--panel-2); color: var(--muted); border: 0;
  border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 12px;
  font-weight: 600; transition: background .15s, color .15s; font-variant-numeric: tabular-nums;
}
.limits button:hover { color: var(--text); }
.limits button.active { color: var(--accent); background: var(--accent-tint); }

/* Вкладко-зависимая видимость фильтров. */
.dex-only { display: none; }
body.market-dex .cex-only { display: none; }
body.market-dex .dex-only { display: inline-flex; }
body.market-dex #fNetwork { display: inline-block; }

/* ───── Две колонки ───── */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { background: var(--panel); border: 0; border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); }
.col-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.col-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.col-count { margin-left: auto; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.up { background: var(--up); }
.dot.down { background: var(--down); }

/* Каждая колонка скроллится внутри себя — в iframe фикс. высоты видно все 50 строк. */
.rows { display: flex; flex-direction: column; max-height: 68vh; overflow-y: auto; padding-right: 4px; }
.row {
  display: grid; grid-template-columns: 22px 1fr auto auto; align-items: center;
  gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--divider);
  border-radius: 8px; transition: background .12s;
}
.row:hover { background: var(--panel-2); }
.row:last-child { border-bottom: 0; }
.r-rank { color: var(--muted); font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }
.r-name { display: flex; flex-direction: column; min-width: 0; }
.r-name b { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-name i { font-style: normal; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-net { font-style: normal; color: var(--accent); font-size: 10px; font-weight: 600; }
.r-risk { font-style: normal; color: var(--warn); font-size: 11px; margin-left: 4px; }
.r-sub { color: var(--muted); font-size: 11.5px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.r-chg { text-align: right; font-weight: 700; font-size: 13.5px; font-variant-numeric: tabular-nums; min-width: 66px; }
.row.up .r-chg { color: var(--up); }
.row.down .r-chg { color: var(--down); }
.muted-row { color: var(--muted); font-size: 13px; padding: 18px 6px; text-align: center; }

.rows::-webkit-scrollbar { width: 7px; }
.rows::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 4px; }

.disclaimer { color: var(--muted); font-size: 11px; margin: 2px 0 0; line-height: 1.5; }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .periods { margin-left: 0; }
  .toolbar { gap: 8px; }
}

/* ───── Карточка главной (?layout=card): 1 ячейка грида ~340×160 ───── */
html:has(body.card-layout), body.card-layout { height: 100%; }
/* Фон = цвет грид-ячейки (darkBackground:'panel'): тёмная rgb(34,37,49), светлая #fff. */
body.card-layout { overflow: hidden; min-height: 0; background: #222531; }
html.light body.card-layout, body.card-layout.light { background: #ffffff; }
body.card-layout .wrap { display: block; padding: 0; margin: 0; max-width: none; height: 100%; }

.mcard { display: flex; flex-direction: column; height: 100%; padding: 10px 13px; box-sizing: border-box; gap: 3px; }
.mcard-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: 0 0 auto; }
.mcard-title { font-size: 12.5px; font-weight: 800; color: var(--text); white-space: nowrap; letter-spacing: -0.01em; }
/* Группа контролов справа: микро CEX/DEX + стрелки ‹ › + «Страница». */
.mcard-ctrls { display: flex; flex-shrink: 0; align-items: center; gap: 6px; }
/* Микро-кнопки рынка CEX/DEX — компактный сегментный тумблер. */
.mcard-market { display: flex; flex-shrink: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; overflow: hidden; }
.mcard-mbtn {
  padding: 2px 6px; font-size: 9.5px; font-weight: 700; font-family: inherit; cursor: pointer;
  border: 0; background: transparent; color: var(--muted); line-height: 1.4; letter-spacing: 0.02em;
  user-select: none; transition: background .15s, color .15s;
}
.mcard-mbtn:hover { color: var(--text); }
.mcard-mbtn.active { background: var(--accent); color: #fff; }
/* Стрелки ‹ › — круглые 22×22, значения 1:1 как у .volatility-arrow-button. */
.mcard-arrow {
  display: flex; flex-shrink: 0; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0; cursor: pointer; color: #ffffff;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50%; transition: all 0.2s;
}
.mcard-arrow:hover { background: rgba(255,255,255,0.1); }
html.light .mcard-arrow, body.light .mcard-arrow { color: #000000; background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.1); }
html.light .mcard-arrow:hover, body.light .mcard-arrow:hover { background: rgba(0,0,0,0.08); }
/* Кнопка «Страница» — значения 1:1 из .widget-page-button / .tlap-page-btn. */
.mcard-page {
  display: inline-flex; align-items: center; justify-content: center; height: 26px; padding: 0 11px;
  color: #94a3b8; font-family: inherit; font-size: 11px; font-weight: 600; line-height: 1;
  text-decoration: none; white-space: nowrap; background: rgba(255,255,255,0.08);
  border: 1px solid transparent; border-radius: 7px; transition: background .2s, color .2s;
}
.mcard-page:hover { color: #f1f5f9; background: rgba(255,255,255,0.16); }
html.light .mcard-page, body.light .mcard-page { color: #000000; background: rgba(0,0,0,0.06); }
html.light .mcard-page:hover, body.light .mcard-page:hover { color: #000000; background: rgba(0,0,0,0.1); }
.mcard-rows { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.mcard-row {
  display: grid; grid-template-columns: 13px auto minmax(0, 1fr) auto; align-items: center;
  gap: 7px; flex: 1 1 0; min-height: 0; border-bottom: 1px solid var(--divider); font-size: 12px;
}
.mcard-row:last-child { border-bottom: 0; }
.mcard-rank { color: var(--muted); font-size: 10px; text-align: right; font-variant-numeric: tabular-nums; }
.mcard-sym { font-weight: 800; }
.mcard-name { color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcard-chg { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.mcard-row.up .mcard-chg { color: var(--up); }
.mcard-row.down .mcard-chg { color: var(--down); }
.mcard-empty { color: var(--muted); font-size: 12px; padding: 14px 2px; text-align: center; }
