:root {
  --bg: #0b0f17;
  --panel: #111827;
  --panel-2: #161f30;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --amber: #f59e0b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.full-w { width: 100%; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* TOPBAR */
.topbar {
  height: 54px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border);
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #22c55e, #3b82f6);
  display: grid; place-items: center; font-weight: 800; color: #051014;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.account-strip { display: flex; gap: 16px; align-items: center; }
.metric { display: flex; flex-direction: column; }
.metric-sep { width: 1px; height: 28px; background: var(--border); }
.mode-select {
  background: var(--panel-2); color: var(--amber); border: 1px solid rgba(245,158,11,0.45);
  border-radius: 6px; padding: 5px 8px; font-weight: 700; font-size: 12px; cursor: pointer;
}
.m-label { font-size: 10px; text-transform: uppercase; color: var(--muted); }
.m-val { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }

.top-actions { display: flex; align-items: center; gap: 8px; }
.pill {
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.pill.ok { color: var(--green); border-color: rgba(34,197,94,0.4); }
.pill.warn { color: var(--amber); border-color: rgba(245,158,11,0.4); }

/* BUTTONS */
.btn {
  border: 1px solid transparent; border-radius: 6px; padding: 6px 11px;
  font-size: 12px; font-weight: 600; cursor: pointer; color: var(--text);
  background: var(--panel-2); transition: 0.15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-buy { background: var(--green); color: #04130a; }
.btn-sell { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger-ghost { background: transparent; border-color: rgba(239,68,68,0.4); color: var(--red); }
.btn-warn { background: rgba(245,158,11,0.18); border-color: rgba(245,158,11,0.45); color: var(--amber); }

/* WORKSPACE */
.workspace {
  display: grid; grid-template-columns: 240px 1fr 270px;
  height: calc(100vh - 54px); overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; padding: 10px; gap: 10px;
}
.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; padding: 2px 4px;
}
.symbol-list { display: flex; flex-direction: column; gap: 6px; }
.sym-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 10px; cursor: pointer; transition: 0.12s ease;
}
.sym-card:hover { border-color: #374151; }
.sym-card.active { border-color: var(--blue); background: rgba(59,130,246,0.1); }
.sym-row { display: flex; justify-content: space-between; align-items: center; }
.sym-name { font-weight: 700; font-size: 13px; }
.sym-ltp { font-weight: 700; font-variant-numeric: tabular-nums; }
.sym-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; }

.sig-badge {
  padding: 2px 7px; border-radius: 4px; font-size: 11px; font-weight: 700;
  background: #1f2937; color: var(--muted);
}
.sig-badge.BUY { background: rgba(34,197,94,0.18); color: var(--green); }
.sig-badge.SELL { background: rgba(239,68,68,0.18); color: var(--red); }
.sig-badge.FLAT { background: rgba(245,158,11,0.15); color: var(--amber); }

.strategy-box {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; display: flex; flex-direction: column; gap: 9px;
}
.box-title { font-weight: 700; font-size: 12px; color: #cbd5e1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-grid label, .modal-fields label {
  display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted);
}
input, select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 5px 7px; font-size: 12px;
}
.toggles-row { display: flex; flex-direction: column; gap: 5px; }
.switch-row { display: flex; align-items: center; gap: 7px; font-size: 12px; cursor: pointer; }
.highlight-auto { color: var(--amber); font-weight: 600; }

/* MAIN COLUMN */
.main-col { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.chart-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 8px;
}
.chart-title-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ct-sym { font-weight: 800; font-size: 15px; }
.ct-ltp { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.ct-reason { font-size: 12px; }

.chart-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chk-inline { display: flex; align-items: center; gap: 4px; font-size: 12px; cursor: pointer; }
.trade-quick { display: flex; align-items: center; gap: 5px; }
.trade-quick input { width: 52px; text-align: center; }

.tf-pills {
  display: inline-flex; border: 1px solid var(--border); border-radius: 5px; overflow: hidden;
  background: var(--bg);
}
.tf-btn {
  background: transparent; color: var(--muted); border: none; padding: 4px 8px;
  font-size: 11px; font-weight: 700; cursor: pointer;
}
.tf-btn:hover { color: var(--text); }
.tf-btn.active { background: var(--blue); color: #fff; }
.tb-select { padding: 4px 6px; font-size: 11px; font-weight: 600; }

/* TTchart + LEFT DRAWING TOOLBAR + FLOATING HUD */
.chart-area-row {
  display: flex; flex: 1 1 auto; min-height: 120px; background: #090d14; overflow: hidden;
}
.draw-bar {
  width: 38px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 6px 4px; gap: 4px;
  flex-shrink: 0;
}
.draw-btn {
  width: 28px; height: 28px; border: 1px solid transparent; border-radius: 5px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 14px;
  display: grid; place-items: center; padding: 0;
}
.draw-btn:hover { background: var(--panel-2); color: var(--text); }
.draw-btn.active { background: rgba(59,130,246,0.22); border-color: var(--blue); color: #fff; }
.draw-sep { width: 20px; height: 1px; background: var(--border); margin: 2px 0; }

.chart-stack { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; height: 100%; }
.chart-wrap { position: relative; flex: 1 1 auto; min-height: 160px; background: #090d14; }
.ttchart { width: 100%; height: 100%; }
.draw-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 10;
  pointer-events: none;
}
.draw-canvas.drawing { pointer-events: auto; cursor: crosshair; }
.draw-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 15;
  background: rgba(17,24,39,0.92); border: 1px solid var(--blue); border-radius: 6px;
  padding: 4px 10px; font-size: 11px; color: var(--text); pointer-events: none;
}
.rsi-wrap {
  height: 110px; border-top: 1px solid var(--border); background: #090d14;
  position: relative; flex-shrink: 0;
}
.rsi-chart { width: 100%; height: 100%; }
.rsi-label {
  position: absolute; top: 4px; left: 8px; z-index: 5; font-size: 10px; font-weight: 700;
  color: var(--muted); pointer-events: none;
}
.pal-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 6px 8px; margin-bottom: 6px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px;
}

.panel-resizer {
  height: 14px; background: var(--panel-2); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: ns-resize; display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--muted); user-select: none; flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.panel-resizer:hover { background: var(--blue); color: #fff; }

/* RIGHT SIDEBAR */
.right-panel {
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; padding: 8px; gap: 10px;
}
.rp-section {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px; display: flex; flex-direction: column; gap: 7px;
}
.rp-head {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 12px; color: #e2e8f0;
}
.rp-strategy-list, .rp-msg-list, .rp-alert-list {
  display: flex; flex-direction: column; gap: 6px;
}
.rp-strat-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 8px; display: flex; flex-direction: column; gap: 4px;
}
.rp-strat-card.blink-hit {
  animation: blinkSignal 1s infinite;
  border-color: var(--green);
}
@keyframes blinkSignal {
  0%, 100% { box-shadow: 0 0 0 1px rgba(34,197,94,0.4); background: rgba(34,197,94,0.12); }
  50% { box-shadow: 0 0 12px 2px rgba(245,158,11,0.65); background: rgba(245,158,11,0.18); }
}
.rp-strat-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-weight: 700; font-size: 11px; }
.rp-strat-desc { font-size: 10px; color: var(--muted); line-height: 1.3; }
.rp-script {
  background: #06090f; border: 1px solid var(--border); border-radius: 4px;
  padding: 5px 6px; font-family: Consolas, monospace; font-size: 10px; color: #93c5fd;
  white-space: pre-wrap; margin: 0;
}
.rp-msg-card {
  background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.35); border-radius: 6px;
  padding: 6px 8px; font-size: 11px; display: flex; flex-direction: column; gap: 3px;
}
.rp-msg-card.SELL { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.35); }
.rp-msg-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.rp-alarm-form { display: flex; flex-direction: column; gap: 5px; }
.rp-alarm-row { display: flex; gap: 5px; }
.rp-alarm-row > * { flex: 1; min-width: 0; }
.rp-alert-item {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 7px; font-size: 11px; display: flex; justify-content: space-between; align-items: center; gap: 6px;
}

.chart-pos-hud {
  position: absolute; top: 12px; left: 12px; z-index: 20;
  background: rgba(17, 24, 39, 0.92); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  display: flex; flex-direction: column; gap: 6px;
}
.hud-top { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 12px; }
.hud-side { padding: 2px 6px; border-radius: 4px; }
.hud-side.BUY { background: rgba(34,197,94,0.2); color: var(--green); }
.hud-side.SELL { background: rgba(239,68,68,0.2); color: var(--red); }
.hud-pnl { margin-left: auto; font-variant-numeric: tabular-nums; }
.hud-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hud-controls label { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.hud-controls input[type="number"] { width: 78px; padding: 3px 5px; font-size: 12px; }
.hud-hint { font-size: 10px; color: var(--muted); }

/* BOTTOM PANEL */
.bottom-panel {
  flex: 0 0 260px; min-height: 140px; max-height: 78vh;
  display: flex; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--border);
}
.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 10px; gap: 4px; }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 8px 12px; cursor: pointer; font-weight: 600; font-size: 12px;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--blue); }
.tab-body { display: none; overflow: auto; flex: 1; padding: 6px 8px 8px; }
.tab-body.active { display: block; }

.split-books {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; height: 100%;
}
.book-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
.book-head {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px;
  padding: 6px 10px; background: var(--panel-2); border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 700;
}
.book-head-left { display: flex; align-items: center; gap: 8px; }
.seg-toggle {
  display: inline-flex; border: 1px solid var(--border); border-radius: 5px; overflow: hidden;
  background: var(--bg);
}
.seg-btn {
  background: transparent; color: var(--muted); border: none; padding: 2px 8px;
  font-size: 11px; font-weight: 700; cursor: pointer;
}
.seg-btn.active { background: var(--blue); color: #fff; }
.seg-btn.active.auto-on { background: var(--amber); color: #111827; }
.book-stats { font-variant-numeric: tabular-nums; font-size: 11px; }
.book-scroll { overflow: auto; flex: 1; }
.subsec-lbl {
  padding: 4px 8px; font-size: 10px; font-weight: 700; text-transform: uppercase;
  color: var(--muted); background: rgba(255,255,255,0.02); border-bottom: 1px solid var(--border);
}

/* WATCHLIST */
.watchlist-box {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.wl-search-wrap { position: relative; }
.wl-search-wrap input { width: 100%; }
.wl-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 40;
  background: var(--panel); border: 1px solid var(--blue); border-radius: 6px;
  max-height: 200px; overflow-y: auto; box-shadow: 0 10px 24px rgba(0,0,0,0.6);
}
.wl-res-item {
  padding: 6px 8px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; font-size: 11px;
}
.wl-res-item:hover { background: rgba(59,130,246,0.15); }
.wl-items { display: flex; flex-direction: column; gap: 6px; }
.wl-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 8px; display: flex; flex-direction: column; gap: 4px;
}
.wl-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 12px; }
.wl-ohlcv {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 6px;
  font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.wl-alert-row { display: flex; align-items: center; gap: 5px; font-size: 10px; margin-top: 2px; }
.wl-alert-row input { width: 78px; padding: 2px 5px; font-size: 11px; }
.toast.PROX { border-color: var(--amber); }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }

/* TOAST ALERTS */
.toast-container {
  position: fixed; bottom: 16px; right: 16px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px; max-width: 360px;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--blue); border-radius: 8px;
  padding: 10px 12px; box-shadow: 0 10px 28px rgba(0,0,0,0.55);
}
.toast.BUY { border-color: var(--green); }
.toast.SELL { border-color: var(--red); }
.toast-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 4px; }
.toast-levels { font-size: 12px; margin: 5px 0; font-variant-numeric: tabular-nums; }
.toast-actions { display: flex; gap: 6px; margin-top: 6px; }

/* NATIVE DIALOG MODAL */
dialog.modal {
  border: 1px solid var(--border); border-radius: 10px; padding: 0;
  background: var(--panel); color: var(--text); width: 460px; max-width: 94vw;
}
dialog.modal::backdrop { background: rgba(0,0,0,0.65); }
.modal-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-fields { display: flex; flex-direction: column; gap: 10px; }
.sec-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; }

.chart-bt-overlay {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 25;
  background: rgba(11, 17, 29, 0.88);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
  color: #e5e7eb;
  max-width: 520px;
  pointer-events: auto;
}
.bt-ov-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bt-ov-toggle { display: flex; align-items: center; gap: 5px; cursor: pointer; font-weight: 600; color: #93c5fd; }
.bt-ov-body { margin-top: 6px; display: flex; flex-direction: column; gap: 5px; }
.bt-ov-body.hidden { display: none; }
.bt-ov-filters { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.bt-ov-filters label { display: flex; align-items: center; gap: 3px; font-size: 10px; color: #9ca3af; }
.bt-ov-filters input { background: #0f172a; border: 1px solid #334155; color: #e5e7eb; border-radius: 4px; padding: 2px 4px; font-size: 10px; }
.bt-ov-table { width: 100%; border-collapse: collapse; text-align: center; font-size: 11px; }
.bt-ov-table th { color: #94a3b8; font-weight: 500; padding: 2px 5px; border-bottom: 1px solid #1e293b; font-size: 10px; }
.bt-ov-table td { padding: 3px 5px; font-weight: 600; }
