:root {
  --bg: #0b0e14; --bg2: #11151d; --bg3: #171c26; --border: #232a37; --border2: #2f3848;
  --text: #d7dce5; --muted: #7d8797; --accent: #4f8cff;
  --up: #26a69a; --down: #ef5350; --flat: #f0b429;
  --up-bg: rgba(38,166,154,.14); --down-bg: rgba(239,83,80,.14); --flat-bg: rgba(240,180,41,.12);
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.45 var(--sans); }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h3 { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 11px; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--flat); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; }
.pin-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 320px; text-align: center; }
.pin-card h1 { font-size: 22px; margin-bottom: 4px; }
#pin-input { width: 100%; margin: 16px 0; padding: 12px; text-align: center; font-size: 28px; letter-spacing: .4em; background: var(--bg); border: 1px solid var(--border2); border-radius: 8px; font-family: var(--mono); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { padding: 14px; font-size: 18px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.keypad button:hover { border-color: var(--accent); }
.keypad .ok { background: var(--accent); color: #fff; border-color: var(--accent); }
.pin-msg { min-height: 20px; margin: 14px 0 0; color: var(--down); }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr 380px; grid-template-rows: 52px 1fr; grid-template-areas: "top top top" "side main chat"; min-height: 100vh; }
.app.chat-collapsed { grid-template-columns: 220px 1fr 0; }
.app.chat-collapsed .chat { display: none; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 16px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--bg2); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; } .brand span { color: var(--accent); }
.search { position: relative; flex: 0 1 380px; }
.search input { width: 100%; padding: 7px 10px; background: var(--bg); border: 1px solid var(--border2); border-radius: 6px; }
.dropdown { position: absolute; top: 100%; left: 0; right: 0; margin: 4px 0 0; padding: 4px 0; list-style: none; background: var(--bg3); border: 1px solid var(--border2); border-radius: 6px; max-height: 320px; overflow: auto; z-index: 30; }
.dropdown li { padding: 7px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.dropdown li:hover, .dropdown li.active { background: var(--bg2); }
.dropdown .sym { font-family: var(--mono); font-weight: 600; min-width: 80px; }
.dropdown .exch { margin-left: auto; color: var(--muted); font-size: 11px; }
.quote { display: flex; gap: 10px; align-items: baseline; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; }
.quote .sym { font-family: var(--mono); font-weight: 700; font-size: 16px; }
.quote .name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.quote .px { font-family: var(--mono); font-size: 16px; }
.actions { display: flex; gap: 8px; align-items: center; }
.icon { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 5px 9px; cursor: pointer; }
.icon:hover { border-color: var(--accent); } .icon.on { color: var(--flat); border-color: var(--flat); }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; } .link:hover { color: var(--text); }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 7px 12px; cursor: pointer; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 5px 9px; font-size: 12px; background: var(--bg3); border: 1px solid var(--border); color: var(--text); }
.toggle { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); cursor: pointer; }

.sidebar { grid-area: side; border-right: 1px solid var(--border); padding: 14px 12px; overflow: auto; background: var(--bg2); position: sticky; top: 52px; height: calc(100vh - 52px); align-self: start; }
.sidebar h3 { margin: 8px 0 8px; }
.list { list-style: none; margin: 0 0 16px; padding: 0; }
.list li { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.list li:hover, .list li.active { background: var(--bg3); }
.list .sym { font-family: var(--mono); font-weight: 600; }
.list .name { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.list .x { color: var(--muted); background: none; border: 0; cursor: pointer; padding: 0 4px; } .list .x:hover { color: var(--down); }
.list .empty { color: var(--muted); cursor: default; font-size: 12px; }
.macro-quick li { cursor: default; justify-content: space-between; font-size: 12px; }

.main { grid-area: main; padding: 14px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.progress { padding: 10px 14px; background: var(--bg3); border: 1px solid var(--border2); border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { padding: 10px 14px; background: var(--down-bg); border: 1px solid var(--down); border-radius: 8px; }

.verdicts { display: grid; grid-template-columns: 1fr 1fr 220px; gap: 14px; }
.verdict { display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center; }
.verdict h4 { align-self: flex-start; font-size: 11px; letter-spacing: .08em; color: var(--muted); }
.gauge { width: 200px; height: 110px; }
.small-verdict .gauge { width: 140px; height: 80px; }
.verdict .label { font-size: 18px; font-weight: 700; }
.small-verdict .label { font-size: 15px; }
.verdict .score { font-family: var(--mono); font-size: 14px; }
.verdict .summary { color: var(--muted); font-size: 11px; }

.tf-grid { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 6px; }
.tf { min-width: 0; border: 1px solid var(--border); border-radius: 8px; padding: 8px 4px; cursor: pointer; text-align: center; background: var(--bg3); transition: border-color .15s; }
.tf:hover { border-color: var(--border2); } .tf.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tf .tfname { font-family: var(--mono); font-weight: 700; font-size: 13px; }
.tf .tflabel { font-size: 10px; margin: 4px 0; padding: 2px 4px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tf .tfscore { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.tf .tfvotes, .tf .tfclose { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.tf.err { opacity: .5; cursor: default; } .tf.err .tflabel { color: var(--muted); }
.bg-up { background: var(--up-bg); color: var(--up); } .bg-down { background: var(--down-bg); color: var(--down); } .bg-flat { background: var(--flat-bg); color: var(--flat); }

.chart-card { padding-bottom: 8px; }
.chart { height: 420px; width: 100%; }
.legend { display: flex; gap: 12px; font-family: var(--mono); font-size: 11px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 3px; margin-right: 4px; vertical-align: middle; }

.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th.num, .tbl td.num { text-align: right; font-family: var(--mono); }
.tbl .note { color: var(--muted); }
.tbl .grp { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg3); color: var(--muted); }
.sig { font-weight: 600; white-space: nowrap; }
.pill { font-family: var(--mono); padding: 2px 8px; border-radius: 12px; font-size: 12px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.news { list-style: none; margin: 0; padding: 0; }
.news li { padding: 7px 0; border-bottom: 1px solid var(--border); }
.news .meta { color: var(--muted); font-size: 11px; }
.regime { display: flex; gap: 12px; align-items: baseline; padding: 10px 12px; border-radius: 8px; background: var(--bg3); margin-bottom: 12px; }
.regime .label { font-weight: 700; font-size: 15px; }
.macro-groups { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.macro-groups h4 { font-size: 11px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px; }
.macro-groups .tbl td { padding: 4px 6px; }

/* chat */
.chat { grid-area: chat; border-left: 1px solid var(--border); background: var(--bg2); display: flex; flex-direction: column; height: calc(100vh - 52px); position: sticky; top: 52px; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
#chat-close { display: none; }
@media (max-width: 1200px) { #chat-close { display: inline-block; } }
.chat-head select { flex: 1; min-width: 0; max-width: 220px; background: var(--bg); border: 1px solid var(--border2); border-radius: 6px; padding: 4px 6px; font-size: 12px; }
.chat-convs { padding: 10px 12px; border-bottom: 1px solid var(--border); max-height: 180px; overflow: auto; }
.chat-convs .list { margin: 8px 0 0; }
.chat-convs .list li { font-size: 12px; }
.chat-convs .date { color: var(--muted); font-size: 10px; margin-left: auto; white-space: nowrap; }
.messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 8px 11px; border-radius: 10px; font-size: 13px; line-height: 1.5; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: #1d3a6b; }
.msg.assistant { align-self: flex-start; background: var(--bg3); border: 1px solid var(--border); }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin: 0; }
.msg ul, .msg ol { margin: 0 0 8px; padding-left: 18px; }
.msg h1, .msg h2, .msg h3 { font-size: 13px; margin: 6px 0 4px; color: var(--text); text-transform: none; letter-spacing: 0; }
.msg code { font-family: var(--mono); background: var(--bg); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.msg.streaming::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg.error { border-color: var(--down); color: var(--down); }
.chat-form { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.chat-input { display: flex; gap: 8px; }
.chat-input textarea { flex: 1; resize: none; background: var(--bg); border: 1px solid var(--border2); border-radius: 6px; padding: 8px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--bg3); border: 1px solid var(--down); color: var(--text); padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.toast.info { border-color: var(--accent); }

@media (max-width: 1200px) {
  .app { grid-template-columns: 200px 1fr; grid-template-areas: "top top" "side main"; }
  .chat { position: fixed; right: 0; top: 52px; width: min(420px, 100vw); z-index: 25; box-shadow: -8px 0 32px rgba(0,0,0,.5); }
  .app.chat-collapsed .chat { display: none; }
  .tf-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .macro-groups { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .sidebar { display: none; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px; }
  .search { flex-basis: 100%; }
  .quote .name { display: none; }
  .verdicts, .two-col { grid-template-columns: 1fr; }
  .tf-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .chart { height: 300px; }
  .chat { width: 100vw; }
  .card { overflow-x: auto; }
  .main { padding: 8px; gap: 8px; }
}
