/* 23HP Trading Analyst — тёмная мобильная оболочка. Шрифты только системные. */

:root {
  --bg: #0b0f14;
  --panel: #111827;
  --up: #22c55e;
  --down: #ef4444;
  --ema20: #22d3ee;
  --ema50: #f59e0b;
  --support: #10b981;
  --resistance: #f43f5e;
  --fib: #eab308;
  --text: #e5e7eb;
  --grid: #263244;
  /* Состояния выбора. Значения по умолчанию = то, что controls.js считает для этой темы (сверяет тест);
     в Telegram они пересчитываются из themeParams с проверкой контраста (текст >= 4.5:1, границы/заливка >= 3:1). */
  --muted: #a5a9b0;
  --ctl-border: #6d7075;
  --accent: #22d3ee;
  --on-accent: #000000;
  --sel-edge: #22d3ee;
  --focus: #e5e7eb;
  --ease: 150ms ease;
  --nav-h: 64px;
  --radius: 16px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overflow-x: hidden;
  max-width: 100%;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

#app {
  min-height: 100dvh;
}

.app {
  width: min(430px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  overflow-x: hidden;
}

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 16px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.brand-mark {
  font-size: 15px;
  letter-spacing: 0.14em;
  font-weight: 700;
  color: var(--accent);
}

.brand-sub,
.header-note {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--ctl-border);
  flex: 0 0 auto;
  min-width: 44px;
  transition: background var(--ease), color var(--ease), box-shadow var(--ease), transform var(--ease);
}

/* Нажатая шестерёнка: заливка + вдавленность (не только цвет). */
.icon-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--sel-edge);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.35);
  transform: translateY(1px);
}

.icon {
  width: 22px;
  height: 22px;
  display: block;
}

.main {
  flex: 1;
  padding: 4px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 180ms ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 650;
}

h2 {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}

.search {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--grid);
  background: var(--panel);
  padding: 0 14px;
}

.seg {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--ctl-border);
  border-radius: 14px;
}

.seg button {
  position: relative;
  flex: 1;
  min-height: 44px;
  min-width: 44px;
  border-radius: 10px;
  color: var(--muted);
  padding: 0 8px;
  transition: background var(--ease), color var(--ease), box-shadow var(--ease), transform var(--ease);
}

/* Выбрано: заливка + вдавленность (inset) + подчёркивание. Видно и без цвета; без галочки (узкие кнопки). */
.seg button.is-on {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--sel-edge);
  transform: translateY(1px);
}

.seg button.is-on::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 5px;
  height: 3px;
  border-radius: 2px;
  background: var(--on-accent);
}

.pair-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pair-card {
  text-align: left;
  min-height: 84px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--ctl-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  transition: box-shadow var(--ease), border-color var(--ease);
}

/* Текущая пара: толстая рамка, боковая полоса и inset (не только цвет). */
.pair-card.is-current {
  border-color: var(--sel-edge);
  box-shadow: inset 0 0 0 1px var(--sel-edge), inset 0 3px 6px rgba(0, 0, 0, 0.3);
}

.pair-card.is-current::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 4px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.pair-card.is-current .pair-title {
  font-weight: 800;
}

.pair-title {
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
}

.pair-price {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.pair-meta {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.up {
  color: var(--up);
}

.down {
  color: var(--down);
}

.flat {
  color: var(--muted);
}

.hero {
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 20px;
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 3px solid var(--grid);
}

.hero.status-BULLISH {
  border-top-color: var(--up);
}

.hero.status-BEARISH {
  border-top-color: var(--down);
}

.hero.status-NEUTRAL {
  border-top-color: var(--muted);
}

.hero.status-WAIT {
  border-top-color: var(--muted);
}

.hero.status-CONFLICT {
  border-top-color: var(--ema50);
}

.status-word {
  font-size: 13px;
  letter-spacing: 0.16em;
  font-weight: 750;
}

.status-BULLISH .status-word {
  color: var(--up);
}

.status-BEARISH .status-word {
  color: var(--down);
}

.status-NEUTRAL .status-word {
  color: var(--muted);
}

.status-WAIT .status-word {
  color: var(--muted);
}

.status-CONFLICT .status-word {
  color: var(--ema50);
}

.price-xl {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--grid);
  font-size: 12px;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  display: block;
}

.pill-LIVE {
  color: var(--up);
}

.pill-DELAYED {
  color: var(--ema50);
}

.pill-STALE {
  color: var(--down);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tf-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.tf-cell {
  min-height: 64px;
  border-radius: 12px;
  border: 1px solid var(--grid);
  background: var(--bg);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.tf-cell b {
  font-size: 12px;
  font-weight: 700;
}

.tf-cell span {
  font-size: 11px;
  text-align: center;
  line-height: 1.2;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  align-items: baseline;
}

.kv span {
  color: var(--muted);
}

.kv b {
  font-weight: 650;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.level-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.level-col {
  border-radius: 12px;
  padding: 10px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 72px;
}

.level-col strong {
  font-size: 12px;
  font-weight: 700;
}

.level-col.support strong {
  color: var(--support);
}

.level-col.resistance strong {
  color: var(--resistance);
}

.level-col b {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Тумблер слоя: дорожка с ползунком; включено = заливка + ползунок справа с ✓; выключено = пустая дорожка. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 8px 0 12px;
  border-radius: 12px;
  border: 1px solid var(--ctl-border);
  background: var(--panel);
  color: var(--muted);
  transition: background var(--ease), color var(--ease), box-shadow var(--ease), border-color var(--ease);
}

.switch.is-on {
  color: var(--text);
  font-weight: 650;
  border-color: var(--sel-edge);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
}

.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  border: 2px solid var(--ctl-border);
  background: transparent;
  transition: background var(--ease), border-color var(--ease);
}

.switch.is-on .switch-track {
  background: var(--accent);
  border-color: var(--sel-edge);
}

.switch-knob {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  transition: transform var(--ease), background var(--ease);
}

.switch.is-on .switch-knob {
  transform: translateX(18px);
  background: var(--on-accent);
}

.chart-main {
  height: 300px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  border-radius: 12px;
  background: var(--bg);
}

.chart-rsi {
  height: 112px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  color: var(--muted);
  font-size: 12px;
}

.legend b {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text);
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.wall {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  align-items: center;
  border-top: 1px solid var(--grid);
  padding-top: 8px;
}

.wall:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.wall b,
.liq-row b {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.liq-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  align-items: center;
  border-top: 1px solid var(--grid);
  padding-top: 8px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prose {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prose p {
  font-size: 15px;
  line-height: 1.5;
}

.disclaimer {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.banner {
  border-left: 3px solid var(--fib);
  padding: 4px 0 4px 10px;
}

.empty {
  padding: 8px 0 4px;
  color: var(--text);
}

.primary {
  min-height: 48px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--sel-edge);
  min-width: 44px;
  padding: 0 14px;
  font-weight: 650;
}

.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(430px, 100%);
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--ctl-border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}

.nav button {
  position: relative;
  flex: 1;
  min-height: var(--nav-h);
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.1;
  padding: 6px 1px 8px;
}

/* Активная вкладка: заливка-«пилюля» + вдавленность + ✓ в углу + полоса сверху (видно и без цвета). */
.nav button {
  margin: 4px 2px;
  min-height: calc(var(--nav-h) - 8px);
  border-radius: 14px;
  transition: background var(--ease), color var(--ease), box-shadow var(--ease), transform var(--ease);
}

.nav button.is-active {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--sel-edge);
  transform: translateY(1px);
}

.nav button.is-active::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 28%;
  right: 28%;
  height: 3px;
  border-radius: 2px;
  background: var(--on-accent);
}

.tab-tick {
  position: absolute;
  top: 3px;
  right: 6px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.nav button span {
  max-width: 100%;
  text-align: center;
  white-space: nowrap;
  letter-spacing: -0.03em;
}

.conf {
  display: inline-flex;
  gap: 3px;
  align-items: flex-end;
  height: 14px;
}

.conf i {
  width: 4px;
  border-radius: 2px;
  background: var(--grid);
  display: block;
}

.conf i:nth-child(1) {
  height: 7px;
}

.conf i:nth-child(2) {
  height: 12px;
}

.conf-low i:nth-child(1),
.conf-medium i {
  background: var(--ema50);
}

.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

/* Без анимации, если пользователь отключил её в системе. */
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}

/* Режим высокого контраста ОС: выбранное обводится системным цветом выделения. */
@media (forced-colors: active) {
  .seg button.is-on,
  .nav button.is-active,
  .switch.is-on,
  .pair-card.is-current,
  .icon-btn[aria-pressed="true"] {
    outline: 3px solid Highlight;
    outline-offset: -3px;
  }
}
