:root {
  --bg: #131722;
  --panel: #1e222d;
  --border: #2a2e39;
  --text: #d1d4dc;
  --muted: #787b86;
  --accent: #2962ff;
  --up: #26a69a;
  --down: #ef5350;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 10px; border-bottom: 1px solid var(--border);
  background: var(--bg); flex-shrink: 0;
}
.brand { font-weight: 700; font-size: 16px; margin-right: 6px; }
.brand span { color: var(--accent); }
.spacer { flex: 1; }

.symbol-btn, .tool-btn, .seg button, .icon-btn {
  background: transparent; border: 0; border-radius: 4px; padding: 6px 9px;
}
.symbol-btn { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; }
.symbol-btn:hover, .tool-btn:hover, .seg button:hover, .icon-btn:hover { background: var(--panel); }
.seg { display: flex; gap: 2px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0 6px; }
.seg button { padding: 6px 7px; color: var(--muted); }
.seg button.active { color: var(--accent); background: rgba(41,98,255,.12); }

.dropdown { position: relative; }
.menu {
  position: absolute; top: 36px; left: 0; z-index: 20; min-width: 270px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 0; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.menu label { display: flex; align-items: center; gap: 8px; padding: 6px 12px; cursor: pointer; }
.menu label:hover { background: var(--border); }
.menu .swatch { width: 10px; height: 10px; border-radius: 2px; margin-left: auto; }

.demo-link { color: #f0b90b; text-decoration: none; border: 1px solid rgba(240,185,11,.4); border-radius: 4px; padding: 4px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.demo-link:hover { background: rgba(240,185,11,.12); }
.conn { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: #f0b90b; }
.conn.ok i { background: var(--up); }
.conn.err i { background: var(--down); }

.layout { flex: 1; display: flex; min-height: 0; }
.chart-wrap { position: relative; flex: 1; min-width: 0; }
.chart { position: absolute; inset: 0; }
.legend {
  position: absolute; top: 8px; left: 10px; z-index: 5; pointer-events: none;
  font-size: 12px; line-height: 1.6;
}
.legend .title { font-size: 15px; font-weight: 600; margin-right: 8px; }
.legend .k { color: var(--muted); margin-left: 6px; }
.legend .up { color: var(--up); } .legend .down { color: var(--down); }
.status {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(19,23,34,.75); z-index: 6; font-size: 14px; text-align: center; padding: 20px;
}

.watchlist {
  width: 280px; border-left: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0;
}
.wl-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; font-weight: 600; }
.icon-btn { font-size: 18px; line-height: 1; padding: 2px 8px; }
.wl-cols, #wlList li {
  display: grid; grid-template-columns: 1fr 96px 62px; gap: 6px; padding: 5px 10px; align-items: center;
}
.wl-cols { color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--border); }
.wl-cols span:not(:first-child), #wlList li span:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
#wlList { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; min-height: 80px; }
.alarms { border-top: 1px solid var(--border); display: flex; flex-direction: column; max-height: 58%; min-height: 0; flex-shrink: 0; overflow-y: auto; }
.alarms > * { flex-shrink: 0; }
.alarms .k { color: var(--muted); }
.snd { font-weight: 400; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; cursor: pointer; }
.al-form { display: grid; grid-template-columns: 1fr 64px auto; gap: 6px; padding: 0 10px; }
.al-form input, .al-form select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 5px 7px; font: inherit; min-width: 0;
}
.al-form input { text-transform: uppercase; }
.al-form input:focus, .al-form select:focus { outline: none; border-color: var(--accent); }
.btn-primary { background: var(--accent); border: 0; border-radius: 4px; padding: 5px 10px; color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.1); }
.al-links { padding: 4px 10px 0; font-size: 11px; color: var(--muted); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: inherit; }
.link:hover { text-decoration: underline; }
.al-msg { padding: 2px 10px; font-size: 11px; color: #f0b90b; min-height: 0; }
.al-msg:empty { display: none; }
.btn-perm { margin: 6px 10px 0; background: rgba(240,185,11,.12); border: 1px solid rgba(240,185,11,.4); color: #f0b90b; border-radius: 4px; padding: 5px; font-size: 12px; }
.btn-perm[hidden] { display: none; }
#alList, #alLog { list-style: none; margin: 6px 0 0; padding: 0; }
#alList li { display: grid; grid-template-columns: 30px 1fr auto 18px; align-items: center; gap: 6px; padding: 5px 10px; cursor: pointer; font-size: 12px; }
#alList li:hover { background: var(--panel); }
#alList li.empty { display: block; cursor: default; font-size: 11px; }
#alList li.hit { animation: hit 1s ease-in-out 4; }
@keyframes hit { 50% { background: rgba(240,185,11,.2); } }
#alList .rm { background: none; border: 0; color: var(--muted); font-size: 15px; padding: 0; }
#alList .rm:hover { color: var(--down); }
.al-name { font-weight: 600; }
.sw { position: relative; width: 28px; height: 16px; cursor: pointer; }
.sw input { opacity: 0; position: absolute; }
.sw i { position: absolute; inset: 0; background: var(--border); border-radius: 8px; transition: .15s; }
.sw i::after { content: ''; position: absolute; left: 2px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); transition: .15s; }
.sw input:checked + i { background: rgba(41,98,255,.5); }
.sw input:checked + i::after { left: 14px; background: #fff; }
.al-sub { display: flex; justify-content: space-between; padding: 8px 10px 0; font-size: 11px; color: var(--muted); border-top: 1px solid var(--border); margin-top: 6px; }
#alLog li { padding: 3px 10px; font-size: 11.5px; }
#alLog b { font-weight: 600; }
.al-note { padding: 8px 10px 10px; font-size: 11px; color: var(--muted); }
#wlList li { cursor: pointer; position: relative; }
#wlList li:hover { background: var(--panel); }
#wlList li.active { background: rgba(41,98,255,.12); }
#wlList li .rm { position: absolute; right: 2px; top: 4px; display: none; background: none; border: 0; color: var(--muted); }
#wlList li:hover .rm { display: block; }
#wlList li:hover span:last-of-type { visibility: hidden; }
.up { color: var(--up); } .down { color: var(--down); }
.flash-up { animation: fu .6s; } .flash-down { animation: fd .6s; }
@keyframes fu { from { background: rgba(38,166,154,.25); } }
@keyframes fd { from { background: rgba(239,83,80,.25); } }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50;
  display: flex; justify-content: center; align-items: flex-start; padding-top: 10vh;
}
.modal[hidden], .menu[hidden], .status[hidden], .sig-panel[hidden] { display: none; }
.sig-panel {
  position: absolute; top: 60px; left: 10px; z-index: 5; pointer-events: none; max-width: min(460px, calc(100% - 90px));
  background: rgba(30,34,45,.85); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
  font-size: 12px; line-height: 1.6;
}
.sig-panel .sp-title { font-weight: 600; }
.sig-panel .k, .sig-opts .k { color: var(--muted); }
.sig-panel b { font-weight: 600; }
.sig-panel .sp-note { color: var(--muted); font-size: 11px; margin-top: 2px; }
.sig-opts { border-top: 1px solid var(--border); margin-top: 4px; padding: 6px 0 2px; }
.sig-opts .k { padding: 2px 12px; font-size: 11px; }
.sig-opts label { justify-content: space-between; cursor: default; }
.sig-opts select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 2px 4px; font: inherit; }
.modal-box {
  width: min(560px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; max-height: 70vh;
}
#searchInput {
  background: transparent; border: 0; border-bottom: 1px solid var(--border); color: var(--text);
  padding: 14px 16px; font-size: 16px; outline: none; text-transform: uppercase;
}
.quote-tabs { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.quote-tabs button { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 2px 10px; font-size: 12px; color: var(--muted); }
.quote-tabs button.active { color: var(--text); border-color: var(--accent); }
#searchResults { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#searchResults li {
  display: grid; grid-template-columns: 1fr 110px 70px; gap: 8px; padding: 8px 16px; cursor: pointer;
}
#searchResults li span:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
#searchResults li .base { font-weight: 600; } #searchResults li .quote { color: var(--muted); }
#searchResults li.sel, #searchResults li:hover { background: var(--border); }
#searchResults .empty { color: var(--muted); display: block; }

@media (max-width: 760px) {
  .watchlist { display: none; }
  .brand { display: none; }
  .topbar { gap: 4px; padding: 0 6px; }
  .seg { overflow-x: auto; min-width: 0; flex-shrink: 1; scrollbar-width: none; }
  .tool-btn, .symbol-btn { white-space: nowrap; padding: 6px; }
  .conn span { display: none; }
}
