:root {
  --bg: #ffffff;
  --bg-rail: #ffffff;
  --border: #e6e8eb;
  --text: #1f2328;
  --muted: #8b949e;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #2962ff;
  --hover: #f5f6f8;
}

body.theme-dark {
  --bg: #131722;
  --bg-rail: #131722;
  --border: #2a2e39;
  --text: #d1d4dc;
  --muted: #787b86;
  --hover: #1e222d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.5; }

/* ---------- вход ---------- */
.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 50;
}
.login-card {
  width: 300px; display: flex; flex-direction: column; gap: 10px; align-items: stretch;
  padding: 28px 24px; border: 1px solid var(--border); border-radius: 12px;
}
.login-logo {
  width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px;
}
.login-card h1 { margin: 0; font-size: 18px; }
.login-card p { margin: 0; }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text); font-size: 14px;
}
.login-card button {
  padding: 10px 12px; border: none; border-radius: 8px; background: var(--accent);
  color: #fff; font-size: 14px; cursor: pointer;
}
.login-error { color: var(--down); font-size: 12px; min-height: 16px; }

/* ---------- каркас ---------- */
.app { display: flex; height: 100vh; }

.rail {
  width: 48px; flex: 0 0 48px; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 4px;
  background: var(--bg-rail);
}
.rail-logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; margin-bottom: 8px;
}
.rail-btn {
  width: 34px; height: 34px; border: none; border-radius: 8px; background: transparent;
  color: var(--muted); display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.rail-btn:hover { background: var(--hover); color: var(--text); }
.rail-btn.active { color: var(--accent); }
.rail-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.rail-spacer { flex: 1; }

.rail-btn { position: relative; }
.badge {
  position: absolute; top: 2px; right: 2px; min-width: 14px; height: 14px;
  padding: 0 3px; border-radius: 7px; background: #ef5350; color: #fff;
  font-size: 9px; line-height: 14px; text-align: center; font-weight: 600;
}

/* уведомления */
.notes {
  position: fixed; left: 56px; top: 56px; width: 360px; max-height: 62vh;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0,0,0,.16); z-index: 40; display: flex; flex-direction: column;
}
.notes-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 11px; text-transform: none; letter-spacing: 0; }
.notes-list { overflow: auto; padding: 6px; }
.note { padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.45; }
.note + .note { border-top: 1px solid var(--border); border-radius: 0; }
.note.unread { background: var(--hover); }
.note-time { color: var(--muted); font-size: 11px; margin-top: 4px; }
.tv-badge {
  width: 26px; height: 26px; border-radius: 6px; background: #e9edf2; color: #56606b;
  font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  text-decoration: none;
}
body.theme-dark .tv-badge { background: #2a2e39; color: #b2b5be; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---------- шапка ---------- */
.topbar {
  height: 48px; flex: 0 0 48px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  position: relative; z-index: 20;
}
.topbar-spacer { flex: 1; min-width: 0; }

.search-wrap { position: relative; flex: 0 1 280px; min-width: 120px; }
#search {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text); font-size: 13px;
}
.search-results {
  position: absolute; top: 38px; left: 0; width: 360px; max-height: 320px; overflow: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 20;
}
.search-item {
  padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--hover); }
.search-item .sym { font-weight: 600; }
.search-item .meta { color: var(--muted); font-size: 12px; }

.tf-select {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text); font-size: 13px;
}
.tab-btn {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: transparent;
  color: var(--text); font-size: 13px; cursor: pointer;
}
.tab-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.tab-btn:hover { background: var(--hover); }

/* панель индикаторов */
.ind-wrap { position: relative; }
.popover {
  position: absolute; top: 40px; left: 0; z-index: 30;
  min-width: 230px; padding: 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 26px rgba(0,0,0,.14);
}
.popover-head {
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.ind-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 6px;
  cursor: pointer; font-size: 13px;
}
.ind-row:hover { background: var(--hover); }
.ind-row input { accent-color: var(--accent); }
.ind-row em { margin-left: auto; font-style: normal; font-size: 11px; color: var(--muted); }
.ind-row.disabled { color: var(--muted); cursor: default; }
.ind-row.disabled:hover { background: transparent; }

.pill {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px;
  border-radius: 999px; background: var(--hover); color: var(--muted); font-size: 12px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #b0b6bd; display: inline-block; }
.dot.green { background: #26a65b; }
.dot.yellow { background: #f0a500; }
.dot.red { background: #ef5350; }

.star { background: transparent; border: none; cursor: pointer; color: var(--muted); flex: 0 0 auto; }
.star svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.star.on { color: #f5a623; }
.star.on svg { fill: #f5a623; stroke: #f5a623; }

@media (max-width: 900px) {
  #pill-stream-text { display: none; }
}
@media (max-width: 700px) {
  .tab-btn span { display: none; }
  .tab-btn { padding: 6px 8px; }
}

/* ---------- график ---------- */
.chart-area { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.legend {
  padding: 8px 12px 4px; display: flex; flex-direction: column; gap: 2px; z-index: 5;
}
.legend-symbol { font-weight: 700; }
.legend-name { color: var(--muted); margin-left: 8px; font-size: 12px; }
.legend-values { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); }
.legend-values b { color: var(--muted); font-weight: 600; }
.legend-values .val-up { color: var(--up); }
.legend-values .val-down { color: var(--down); }
.chart { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.attribution {
  position: absolute; right: 10px; bottom: 4px; font-size: 10px; color: var(--muted);
}
.attribution a { color: var(--muted); }

/* ---------- модальное окно ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(10, 12, 16, .35);
  display: flex; align-items: center; justify-content: center; z-index: 60;
}
.modal-card {
  width: 560px; max-height: 88vh; overflow: auto; padding: 18px 20px 24px;
  background: var(--bg); border-radius: 12px; border: 1px solid var(--border);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-card h3 {
  margin: 18px 0 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.icon-btn { background: transparent; border: none; font-size: 14px; color: var(--muted); cursor: pointer; }
.field input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text); font-size: 13px;
}
.row { display: flex; gap: 8px; margin-top: 8px; }
.row button, .theme-btn {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text); font-size: 13px; cursor: pointer;
}
.row button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.theme-btn.active { border-color: var(--accent); color: var(--accent); }
.status-line {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  padding: 8px 10px; border-radius: 8px; background: var(--hover); font-size: 12px; color: var(--muted);
}
