:root {
  --bg: #131722;
  --panel: #1e222d;
  --panel-2: #171a23;
  --border: #2a2e39;
  --text: #d1d4dc;
  --muted: #787b86;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #2962ff;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

#topbar {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  position: relative;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.toolbar-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  display: flex; align-items: center; gap: 10px;
}
.toolbar-right {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 14px;
}

.brand { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.muted { color: var(--muted); font-weight: 400; }

.count-label {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 12px;
}
.count-label input {
  width: 46px; padding: 3px 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-size: 13px;
}

#layout {
  display: flex;
  height: 100%;
}

/* ── ticker panel ── */
#ticker-panel {
  width: 260px; min-width: 200px;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  position: relative;
}

.search { position: relative; display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--border); }
.search input {
  flex: 1; min-width: 0; padding: 6px 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 5px; color: var(--text); font-size: 13px;
}
.search input:focus { outline: none; border-color: var(--accent); }
.search button {
  width: 30px; border: 1px solid var(--border); border-radius: 5px;
  background: var(--panel-2); color: var(--text); font-size: 16px; cursor: pointer;
}
.search button:hover { border-color: var(--accent); }

#ticker-list { flex: 1; overflow-y: auto; }

.ticker-header {
  height: 48px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px; border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: 11px; font-weight: 600;
  background: var(--panel-2); user-select: none;
}
.ticker-header .sym { flex: 1; }
.ticker-header .vol { min-width: 48px; text-align: center; cursor: pointer; }
.ticker-header .pct { min-width: 60px; text-align: center; cursor: pointer; }
.ticker-header .flags { display: flex; align-items: center; justify-content: flex-start; min-width: 28px; }
.ticker-header .vol:hover, .ticker-header .pct:hover { color: var(--text); }
.clear-all {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 50%;
  background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; line-height: 1; font-weight: 700;
}
.clear-all:hover { color: var(--down); border-color: var(--down); }

.ticker {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.ticker:hover { background: var(--panel-2); }
.ticker.selected { background: rgba(41, 98, 255, .14); }
.ticker .sym {
  font-weight: 600; font-size: 13px;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer;
}
.ticker .sym:hover { color: var(--accent); }
.ticker .sym.copied { color: var(--up); }
.ticker .vol { color: var(--muted); font-size: 12px; min-width: 48px; text-align: right; }
.ticker .pct { font-size: 13px; font-weight: 600; min-width: 60px; text-align: right; }
.ticker .flags { display: flex; gap: 3px; min-width: 28px; justify-content: flex-start; }

.flag-btn {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1px dashed var(--muted); background: transparent; cursor: pointer;
  position: relative; flex: none;
}
.flag-btn:hover { border-style: solid; border-color: var(--text); }
.flag-btn.has-flag { border: none; }
.flag-btn.has-flag:hover { border: none; opacity: .85; }

.flag-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,.4);
}

/* flag picker popover */
.flag-picker {
  position: absolute; z-index: 20;
  display: flex; gap: 4px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.flag-picker .swatch {
  width: 16px; height: 16px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
}
.flag-picker .swatch.on { border-color: var(--text); }
.flag-picker .swatch-clear {
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted); font-weight: 700;
  border: 1px solid var(--border); font-size: 12px; line-height: 1;
}
.flag-picker .swatch-clear:hover { color: var(--down); border-color: var(--down); }

/* ── charts area ── */
#charts-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.toolbar-group { display: flex; gap: 4px; align-items: center; }
.sep { width: 1px; height: 22px; background: var(--border); }
#selected-hint { font-size: 12px; }

.tf-btn, .group-btn {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--panel-2); color: var(--muted); font-size: 12px; cursor: pointer;
}
.tf-btn:hover, .group-btn:hover { color: var(--text); border-color: var(--muted); }
.tf-btn.active { color: #fff; border-color: var(--accent); background: rgba(41,98,255,.15); }

.group-btn {
  display: flex; align-items: center; gap: 5px;
}
.group-btn .dot { width: 10px; height: 10px; border-radius: 50%; }
.group-btn .x { color: var(--muted); font-weight: 700; line-height: 1; }
.group-btn .x:hover { color: var(--down); }
.group-btn.active { color: #fff; border-color: var(--muted); }
.group-btn.clear { color: var(--muted); }

#charts-grid {
  flex: 1; min-height: 0;
  overflow: hidden;
  display: grid;
  gap: 8px; padding: 10px;
}

.cell {
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel-2); overflow: hidden;
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
}
.cell.selected { border-color: var(--accent); }

/* Вспышка рамки графика при алерте: уровень — жёлтый, всплеск — зелёный */
@keyframes flash-surge {
  0%   { box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.9), 0 0 14px 2px rgba(46, 204, 113, 0.5); }
  100% { box-shadow: 0 0 0 2px rgba(46, 204, 113, 0), 0 0 14px 2px rgba(46, 204, 113, 0); }
}
.cell.flash-surge { animation: flash-surge 3.5s ease-out; }

@keyframes flash-level {
  0%   { box-shadow: 0 0 0 2px rgba(232, 200, 74, 0.9), 0 0 14px 2px rgba(232, 200, 74, 0.5); }
  100% { box-shadow: 0 0 0 2px rgba(232, 200, 74, 0), 0 0 14px 2px rgba(232, 200, 74, 0); }
}
.cell.flash-level { animation: flash-level 3.5s ease-out; }

@keyframes flash-down {
  0%   { box-shadow: 0 0 0 2px rgba(239, 83, 80, 0.9), 0 0 14px 2px rgba(239, 83, 80, 0.5); }
  100% { box-shadow: 0 0 0 2px rgba(239, 83, 80, 0), 0 0 14px 2px rgba(239, 83, 80, 0); }
}
.cell.flash-down { animation: flash-down 3.5s ease-out; }

/* Внутренняя заливка области графика — вспышка не только по периметру */
.cell-body::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 6; /* выше канвасов (рисование z-index:5) */
}
@keyframes fill-fade {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}
.cell.flash-surge .cell-body::after { background: rgba(46, 204, 113, 0.35); animation: fill-fade 3.5s ease-out; }
.cell.flash-level .cell-body::after { background: rgba(232, 200, 74, 0.35); animation: fill-fade 3.5s ease-out; }
.cell.flash-down .cell-body::after { background: rgba(239, 83, 80, 0.35); animation: fill-fade 3.5s ease-out; }

.cell-head {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; font-size: 12px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none;
}
.cell-head .sym { font-weight: 700; cursor: pointer; }
.cell-head .sym:hover { color: var(--accent); }
.cell-head .sym.copied { color: var(--up); }
.cell-head .tf { color: var(--muted); }
.cell-head .pct { margin-left: auto; font-weight: 600; }
.focus-btn {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 4px;
  background: transparent; color: var(--muted);
  cursor: pointer; font-size: 12px; line-height: 1;
}
.focus-btn:hover { color: var(--text); border-color: var(--muted); }
.cell-head .flags { display: flex; align-items: center; gap: 3px; }
.cell-head .fdot { width: 8px; height: 8px; border-radius: 50%; cursor: pointer; }
.cell-head .fdot:hover { transform: scale(1.35); }
.cell-head .fdot.dashed {
  width: 10px; height: 10px;
  background: transparent;
  border: 1px dashed var(--muted);
  box-sizing: border-box;
}
.cell-head .fdot.dashed:hover { border-style: solid; border-color: var(--text); }

.cell-body { flex: 1; min-height: 0; position: relative; }

.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ── выпадающий список групп ── */
#flag-filter { position: relative; }

.dropdown-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  min-width: 120px; padding: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 4px; cursor: pointer;
  font-size: 13px;
}
.dropdown-item:hover { background: var(--panel-2); }
.dropdown-item .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.dropdown-item .dot.all { background: transparent; border: 1.5px solid var(--muted); }
.dropdown-item .x { margin-left: auto; color: var(--muted); font-weight: 700; padding: 0 2px; }
.dropdown-item .x:hover { color: var(--down); }
.group-btn .dot.all { background: transparent; border: 1.5px solid var(--muted); }
.group-clear {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--panel-2); color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1; font-weight: 700;
}
.group-clear:hover { color: var(--down); border-color: var(--down); }

/* ── переключатель списков ── */
#list-switcher { position: relative; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.list-btn { width: 100%; justify-content: space-between; font-size: 13px; }
.list-btn .caret { color: var(--muted); font-size: 11px; }
.menu-divider { height: 1px; background: var(--border); margin: 4px 0; }
.dropdown-item .item-name { flex: 1; }
.dropdown-item.active { color: #fff; }

/* ── фильтры тикеров ── */
#ticker-filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.filter-select, .filter-input {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-size: 12px; padding: 3px 6px;
}
.filter-field { display: flex; align-items: center; gap: 3px; color: var(--muted); font-size: 11px; }
.filter-field .filter-input { width: 44px; }
.filter-field .unit { color: var(--muted); font-size: 11px; }

/* ── флажки в строке + исключение ── */
.flag-more { font-size: 10px; color: var(--muted); font-weight: 600; }
.exclude-btn {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1;
  padding: 0 2px; opacity: 0; transition: opacity .1s;
}
.ticker:hover .exclude-btn { opacity: 1; }
.exclude-btn:hover { color: var(--down); }

/* ── автокомплит поиска ── */
.suggestions {
  position: absolute; top: calc(100% - 2px); left: 10px; right: 10px; z-index: 40;
  max-height: 280px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.55);
}
.suggestion {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 13px;
}
.suggestion:hover, .suggestion.active { background: var(--panel-2); }
.suggestion .sym { font-weight: 600; }
.suggestion .sub { color: var(--muted); font-size: 12px; font-weight: 600; }

/* ── палитра групп (только цветные точки) ── */
#flag-filter .dropdown-menu.palette {
  grid-template-columns: repeat(5, auto);
  gap: 8px;
  padding: 10px;
  width: max-content;
  min-width: 0;
}
.swatch-item {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer;
  font-size: 11px; font-weight: 700; color: #fff;
  text-shadow: 0 0 3px rgba(0,0,0,.8);
}
.swatch-item:hover { opacity: .85; }
.swatch-item.active { outline: 2px solid var(--text); outline-offset: 1px; }

/* ── поиск инструмента ── */
.search-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.search-box {
  width: 560px; max-width: 92vw;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
  transform: translateY(-6vh);
}
.search-input {
  width: 100%; padding: 16px 18px; font-size: 20px;
  background: var(--panel-2); border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text); outline: none;
}
.search-input::placeholder { color: var(--muted); }
.search-results { max-height: 50vh; overflow-y: auto; }
.search-results .ticker:last-child { border-bottom: none; }
/* поиск покрупнее: строки результатов и флажок крупнее, чем в списке тикеров */
.search-results .ticker { padding: 11px 16px; gap: 12px; }
.search-results .ticker .sym { font-size: 16px; }
.search-results .ticker .vol { font-size: 14px; min-width: 56px; }
.search-results .ticker .pct { font-size: 15px; min-width: 70px; }
.search-results .ticker .flag-btn { width: 18px; height: 18px; }

/* ── кнопка-шестерёнка (настройки) ── */
#settings-btn {
  margin-left: 3px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); cursor: pointer;
}
#settings-btn:hover { color: var(--text); border-color: var(--muted); }
#settings-btn svg { display: block; }
#tg-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  margin-left: auto;
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}
#tg-btn:hover { color: #26a5e4; border-color: #26a5e4; }
#tg-btn svg { display: block; }

/* ── оверлей настроек ── */
.settings-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.settings-box {
  width: 420px; max-width: 92vw;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.settings-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-size: 15px; font-weight: 700;
}
.settings-close {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); font-size: 15px; cursor: pointer;
}
.settings-close:hover { color: var(--down); border-color: var(--down); }
.settings-body { padding: 4px 18px 14px; max-height: 72vh; overflow-y: auto; }
.settings-section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 14px 0 6px;
}
.settings-section:first-child .settings-section-head { margin-top: 8px; }
.settings-section-head h3 {
  margin: 0;
  font-size: 11px; font-weight: 600; letter-spacing: .6px;
  color: var(--muted); text-transform: uppercase;
}
.settings-section.group-off .settings-row { opacity: .45; pointer-events: none; }

/* toggle-слайдер группы */
.switch {
  position: relative; display: inline-block;
  width: 36px; height: 20px; flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 20px;
  transition: background .2s; cursor: pointer;
}
.slider::before {
  content: '';
  position: absolute; width: 16px; height: 16px;
  left: 2px; top: 2px; background: #fff; border-radius: 50%;
  transition: transform .2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* радио-группа «Разгон / Всплеск» */
.radio-group { display: flex; gap: 16px; flex: 0 0 auto; }
.radio { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.radio input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 9px 0; cursor: pointer;
}
.settings-row + .settings-row { border-top: 1px solid var(--border); }
.s-text { display: flex; flex-direction: column; gap: 1px; }
.s-name { font-size: 14px; }
.s-hint { font-size: 11px; color: var(--muted); }
.settings-row input[type="checkbox"] {
  width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex: 0 0 auto;
}

/* ── приветственный оверлей (первый визит) ── */
.welcome-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, .65);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.welcome-box {
  width: 380px; max-width: 92vw;
  max-height: 85vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px 22px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.welcome-box h2 {
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .2px;
  margin: 0 0 14px;
}
.welcome-box p { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 4px; }
.welcome-sub {
  font-size: 11px; font-weight: 600; letter-spacing: .5px;
  color: var(--muted); text-transform: uppercase; margin-top: 12px; margin-bottom: 4px;
}
.welcome-list { list-style: none; margin: 0; padding: 0; font-size: 12px; line-height: 1.6; }
.welcome-list b { color: var(--text); font-weight: 600; }
.welcome-ok {
  display: block; width: 100%; padding: 9px 0; margin-top: 16px;
  background: var(--accent); border: none; border-radius: 6px;
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
}
.welcome-ok:hover { filter: brightness(1.12); }
.welcome-tg {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 8px 0; margin-top: 8px;
  background: rgba(38, 165, 228, .12);
  border: 1px solid rgba(38, 165, 228, .35);
  border-radius: 6px;
  color: #26a5e4; font-size: 13px; font-weight: 600;
  text-decoration: none; cursor: pointer;
  box-sizing: border-box;
}
.welcome-tg:hover { background: rgba(38, 165, 228, .2); }
.welcome-tg svg { flex: 0 0 auto; }

/* ── вертикальная лента уведомлений: пересечение уровня + всплеск ── */
.notifications {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px;
  pointer-events: none;
  z-index: 20;
}
.notification {
  display: flex; align-items: center; gap: 8px;
  position: relative;
  pointer-events: auto; cursor: pointer;
  user-select: none;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid #e8c84a;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .45);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .3s ease-out, transform .3s ease-out;
}
.notification.show { opacity: 1; transform: translateY(0); }
.notification .n-sym { font-weight: 700; pointer-events: auto; cursor: pointer; }
.notification .n-sym .n-base { color: var(--text); }
.notification .n-sym .n-quote { color: var(--muted); }
.notification .n-sym.copied .n-base,
.notification .n-sym.copied .n-quote { color: var(--up); }
.notification .n-event { color: var(--muted); }
.notification .n-pct {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.notification .n-time {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* время самого актуального (верхнего) уведомления — красным */
.notification:first-child .n-time { color: var(--down); }
/* маркер карточки: рост — зелёный, падение — красный, уровень — жёлтый (по умолчанию) */
.notification.n-surge { border-left-color: #2ecc71; }
.notification.n-down { border-left-color: var(--down); }

/* вспышка ленты в момент срабатывания — та же, что на графике (по типу) */
.notification::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  z-index: 1;
}
.notification.flash-surge { animation: flash-surge 3.5s ease-out; }
.notification.flash-level { animation: flash-level 3.5s ease-out; }
.notification.flash-surge::after { background: rgba(46, 204, 113, 0.35); animation: fill-fade 3.5s ease-out; }
.notification.flash-level::after { background: rgba(232, 200, 74, 0.35); animation: fill-fade 3.5s ease-out; }
.notification.flash-down { animation: flash-down 3.5s ease-out; }
.notification.flash-down::after { background: rgba(239, 83, 80, 0.35); animation: fill-fade 3.5s ease-out; }
