:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #0e1621);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #7d8b99);
  --link: var(--tg-theme-link-color, #62bcf9);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --btn: var(--tg-theme-button-color, #5288c1);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --danger: var(--tg-theme-destructive-text-color, #ec3942);
  --sep: var(--tg-theme-section-separator-color, rgba(127,127,127,.18));
  --c-in: #3987e5; --c-out: #d95926;          /* проверенная пара: синий/оранжевый */
  --mine: #f5b82e; --mine-bg: rgba(245,184,46,.10);
  --lcd-bg: #9fb38a; --lcd-ink: #1d2a12; --lcd-dim: rgba(29,42,18,.5);
  --r: 14px;
}
html[data-scheme="light"] { --c-in: #2a78d6; --c-out: #eb6834; --mine: #c98a00; --mine-bg: rgba(245,184,46,.16); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
html[lang="fa"] body { font-family: Vazirmatn, Tahoma, -apple-system, "Segoe UI", sans-serif; }
body { padding: 10px 12px calc(28px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--sep);
  border-radius: 10px; padding: 9px 11px; width: 100%; outline: none; min-width: 0; }
input:focus, select:focus { border-color: var(--btn); }
a { color: var(--link); text-decoration: none; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.mono { font: 12.5px ui-monospace, Menlo, monospace; color: var(--hint); word-break: break-all; direction: ltr;
  unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ---------- пейджер + языки ---------- */
.pager { background: #22262b; border-radius: 22px; padding: 10px 12px 12px; margin-bottom: 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 6px 20px rgba(0,0,0,.25); }
.pager-top { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 8px; gap: 8px; direction: ltr; }
.brand { color: #8a9199; font: 700 11px/1 ui-monospace, Menlo, monospace; letter-spacing: .14em; white-space: nowrap; }
.led { width: 8px; height: 8px; border-radius: 50%; background: #3b4148; display: inline-block; margin-right: 6px; vertical-align: middle; }
.led.on { background: #7dff6a; box-shadow: 0 0 8px #7dff6a; animation: blink 1.6s infinite; }
.led.off { background: #ff9d3b; }
@keyframes blink { 50% { opacity: .35; } }
.langs { display: flex; gap: 4px; background: #15181c; border-radius: 14px; padding: 3px; }
.lang { font-size: 13px; font-weight: 700; color: #9aa3ad; padding: 4px 9px; border-radius: 11px; white-space: nowrap; }
.lang .flag { font-size: 17px; vertical-align: -2px; margin-inline-end: 4px; }
.lang.active { background: #f5f5f5; color: #15181c; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
.lcd { background: var(--lcd-bg); color: var(--lcd-ink); border-radius: 8px; padding: 9px 12px; min-height: 70px;
  font: 500 14px/1.35 ui-monospace, "SF Mono", Menlo, Consolas, monospace; position: relative; overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.35); }
html[lang="fa"] .lcd { font-family: Vazirmatn, Tahoma, sans-serif; }
.lcd::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.05) 0 1px, transparent 1px 3px); }
.lcd-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--lcd-dim);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px; }
.lcd-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }

/* ---------- вкладки ---------- */
.tabs { display: flex; gap: 4px; background: var(--section); padding: 4px; border-radius: 12px; margin-bottom: 10px;
  position: sticky; top: 6px; z-index: 20; box-shadow: 0 2px 10px rgba(0,0,0,.14); }
.tab { flex: 1; padding: 8px 2px; border-radius: 9px; color: var(--hint); font-size: 13px; font-weight: 650;
  white-space: nowrap; position: relative; }
.tab.active { background: var(--btn); color: var(--btn-text); }
.badge { background: var(--danger); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; margin-inline-start: 3px; }

/* ---------- поиск и фильтры ---------- */
.searchbar { display: flex; gap: 8px; margin-bottom: 8px; }
.searchbar input { background: var(--section); border-color: transparent; }
.fbtn { background: var(--section); border-radius: 10px; padding: 0 12px; font-weight: 650; white-space: nowrap;
  color: var(--link); display: flex; align-items: center; gap: 6px; }
.fbtn .count { background: var(--btn); color: var(--btn-text); border-radius: 9px; font-size: 12px; padding: 0 6px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
/* компьютер: колесо и перетаскивание мышью (app.js), полоса прокрутки видна */
@media (hover: hover) and (pointer: fine) {
  .chips:not(.wrap) { scrollbar-width: thin; cursor: grab; }
  .chips:not(.wrap)::-webkit-scrollbar { display: block; height: 4px; }
  .chips:not(.wrap)::-webkit-scrollbar-thumb { background: var(--hint); border-radius: 2px; }
  .chips.dragging { cursor: grabbing; user-select: none; }
}
.chip { flex: none; padding: 6px 11px; border-radius: 16px; background: var(--section); color: var(--hint);
  font-size: 13px; font-weight: 600; border: 1px solid transparent; }
.chip.active { color: var(--btn-text); background: var(--btn); }
.chip .n { opacity: .65; margin-inline-start: 4px; font-weight: 500; }
.chip.preset { border-color: var(--sep); }
.fsec .chip, .panel .chip { background: var(--bg2); }
.fsec .chip.active, .panel .chip.active { background: var(--btn); }
.chip.user-preset { border-style: dashed; border-color: var(--btn); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.pill { background: color-mix(in srgb, var(--btn) 18%, transparent); color: var(--text); border-radius: 14px;
  padding: 4px 6px 4px 10px; font-size: 12.5px; display: flex; gap: 6px; align-items: center; }
.pill button { width: 20px; height: 20px; border-radius: 50%; background: rgba(127,127,127,.25); font-size: 12px; line-height: 20px; }
.resultbar { display: flex; justify-content: space-between; align-items: center; color: var(--hint); font-size: 13px;
  margin: 2px 4px 8px; gap: 8px; }
.resultbar select { width: auto; padding: 4px 8px; background: var(--section); border-color: transparent; font-size: 13px; }

/* ---------- нижний лист фильтров ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 88vh; z-index: 51; background: var(--bg2);
  border-radius: 18px 18px 0 0; display: flex; flex-direction: column; box-shadow: 0 -8px 30px rgba(0,0,0,.35);
  animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-head { padding: 12px 16px 8px; display: flex; justify-content: space-between; align-items: center; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 0 14px 12px; }
.sheet-foot { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 8px;
  border-top: 1px solid var(--sep); background: var(--bg2); }
.fsec { background: var(--section); border-radius: var(--r); padding: 10px 12px; margin-bottom: 8px; }
.fsec h4 { margin: 0 0 8px; font-size: 13px; color: var(--hint); font-weight: 650; text-transform: uppercase; letter-spacing: .03em; }
.seg { display: flex; gap: 3px; background: var(--bg2); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; padding: 6px 4px; border-radius: 8px; color: var(--hint); font-size: 13px; font-weight: 600; white-space: nowrap; }
.seg button.active { background: var(--section); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.fsec .seg { background: var(--bg2); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.switch { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; gap: 10px; }
.switch + .switch { border-top: 1px solid var(--sep); }
.toggle { width: 44px; height: 26px; border-radius: 13px; background: rgba(127,127,127,.35); position: relative; flex: none; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: inset-inline-start .15s; }
.toggle.on { background: var(--btn); }
.toggle.on::after { inset-inline-start: 21px; }

/* ---------- карточки событий ---------- */
.card { background: var(--section); border-radius: var(--r); padding: 11px 13px; margin-bottom: 9px; position: relative; }
.card.mine { background: linear-gradient(var(--mine-bg), var(--mine-bg)), var(--section);
  box-shadow: inset 3px 0 0 var(--mine); }
html[dir="rtl"] .card.mine { box-shadow: inset -3px 0 0 var(--mine); }
.card.reply { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
.card.mine.reply { box-shadow: inset 3px 0 0 var(--mine), inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
html[dir="rtl"] .card.mine.reply { box-shadow: inset -3px 0 0 var(--mine), inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
.card.hid { opacity: .55; }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-title { font-weight: 650; }
.amt { font-weight: 650; white-space: nowrap; }
.amt.in { color: var(--c-in); } .amt.out { color: var(--c-out); }
.mine-badge { background: var(--mine); color: #1b1300; font-size: 11px; font-weight: 700; border-radius: 6px; padding: 1px 6px;
  margin-inline-start: 6px; vertical-align: 1px; }
.quote { border-inline-start: 3px solid var(--accent); padding: 2px 0; padding-inline-start: 10px; margin: 7px 0 4px;
  white-space: pre-wrap; word-break: break-word; }
.tr { color: var(--hint); font-style: italic; margin: 3px 0 4px; white-space: pre-wrap; word-break: break-word; }
.trbtn { color: var(--link); font-size: 13px; margin: 2px 0 4px; }
.meta { color: var(--hint); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 6px; align-items: center; }
.meta .who { color: var(--link); }
.tags { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.tag { color: var(--link); font-size: 12.5px; }
.reacts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.react { background: var(--bg2); border-radius: 14px; padding: 3px 9px; font-size: 13px; border: 1px solid transparent; }
.react.on { border-color: var(--btn); background: color-mix(in srgb, var(--btn) 18%, transparent); }
.react .c { margin-inline-start: 3px; font-variant-numeric: tabular-nums; color: var(--hint); }
.empty { text-align: center; color: var(--hint); padding: 34px 12px; }
.more { width: 100%; padding: 10px; color: var(--link); font-weight: 600; }
.btn { background: var(--btn); color: var(--btn-text); border-radius: 10px; padding: 10px 14px; font-weight: 650; }
.btn.ghost { background: transparent; color: var(--link); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; }
.err { color: var(--danger); font-size: 13px; margin-top: 6px; }

/* ---------- статистика ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.kpi { background: var(--section); border-radius: var(--r); padding: 10px 12px; }
.kpi b { display: block; font-size: 21px; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; text-align: start; }
.kpi span { color: var(--hint); font-size: 12.5px; }
.kpi.wide { grid-column: 1 / -1; }
.kpi .in { color: var(--c-in); } .kpi .out { color: var(--c-out); }
.panel { background: var(--section); border-radius: var(--r); padding: 11px 12px; margin-bottom: 8px; }
.panel h4 { margin: 0 0 8px; font-size: 13px; color: var(--hint); font-weight: 650; text-transform: uppercase; letter-spacing: .03em;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel h4 .seg { text-transform: none; letter-spacing: 0; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--hint); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }
.chart { width: 100%; display: block; direction: ltr; touch-action: pan-y; }
.chart text { fill: var(--hint); font-size: 10px; font-family: inherit; }
.chart .grid { stroke: var(--sep); stroke-width: 1; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; margin-bottom: 7px; }
.hbar .lbl { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .val { font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.hbar .track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--bg2); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 3px; background: var(--c-in); }
.hbar .fill.out { background: var(--c-out); }
.toprow { display: flex; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--sep); }
.toprow:last-child { border-bottom: 0; }
.toprow .rank { width: 20px; color: var(--hint); font-variant-numeric: tabular-nums; text-align: center; }
.tip { position: fixed; z-index: 60; pointer-events: none; background: rgba(20,22,26,.94); color: #f0efec; font-size: 12.5px;
  padding: 6px 9px; border-radius: 8px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.3); direction: ltr; }
.tip b { font-weight: 650; }
.note { font-size: 12.5px; color: var(--hint); margin: 4px 4px 10px; }

/* ---------- настройки ---------- */
.biglangs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.biglang { background: var(--bg2); border-radius: 12px; padding: 10px 4px; text-align: center; font-weight: 650; border: 2px solid transparent; }
.biglang .flag { font-size: 30px; display: block; line-height: 1.2; }
.biglang.active { border-color: var(--btn); background: color-mix(in srgb, var(--btn) 15%, transparent); }
.wl { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--sep); }
.wl:last-child { border-bottom: 0; }
.section-h { color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; margin: 16px 4px 7px; font-weight: 650; }
button.link { color: var(--link, var(--accent)); padding: 0; font: inherit; text-decoration: underline; text-underline-offset: 2px; }
