:root {
  --bg: #131722;
  --pane: #131722;
  --elev: #1e222d;
  --hover: #2a2e39;
  --border: #2a2e39;
  --text: #d1d4dc;
  --muted: #787b86;
  --green: #089981;
  --red: #f23645;
  --blue: #2962ff;
  --ma: #f5d76e;
  --font: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}
button, input, a { font: inherit; color: inherit; }
button { border: 0; background: transparent; cursor: pointer; }
.hidden { display: none !important; }

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========== TOP TOOLBAR ========== */
.topbar {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

.logo {
  width: 36px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  text-decoration: none;
}
.logo:hover { background: rgba(41,98,255,.12); }

.icon-btn {
  width: 32px;
  height: 30px;
  border-radius: 4px;
  color: var(--muted);
  display: grid;
  place-items: center;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--elev); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; font-size: 12px; }

.symbol-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 14px;
}
.symbol-btn:hover { background: var(--elev); }
.symbol-btn .caret { width: 12px; height: 12px; color: var(--muted); }

.vsep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 6px;
}

.intervals { display: flex; }
.tbtn {
  padding: 5px 8px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.tbtn:hover { background: var(--elev); color: var(--text); }
.tbtn.active { color: var(--blue); }
.tbtn.with-icon svg { width: 18px; height: 18px; }
.tbtn.label { color: var(--text); }
.tbtn.save { color: var(--blue); }

.topbar-spacer { flex: 1; }

/* ========== BODY ========== */
.body-row {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 52px 1fr auto;
}

/* LEFT BAR */
.leftbar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0;
  gap: 1px;
  background: var(--bg);
}
.tool {
  width: 42px;
  height: 38px;
  border-radius: 6px;
  color: var(--muted);
  display: grid;
  place-items: center;
}
.tool svg { width: 22px; height: 22px; }
.tool:hover { background: var(--elev); color: var(--text); }
.tool.active { background: rgba(41,98,255,.16); color: var(--blue); }
.lsep { width: 26px; height: 1px; background: var(--border); margin: 5px 0; }
.lspacer { flex: 1; }

/* CENTER */
.center {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--pane);
}

.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}
.chart { width: 100%; height: 100%; }

.legend {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 6;
  pointer-events: none;
  text-shadow: 0 1px 2px #131722, 0 0 8px #131722;
}
.legend-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 2px;
}
.legend-head strong { font-weight: 700; }
.legend-head span { color: var(--muted); font-size: 12px; font-weight: 600; }
.market-open { color: var(--green) !important; }

.legend-ohlc {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
}
.legend-ohlc span span,
#legO, #legH, #legL, #legC {
  margin-left: 4px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.up { color: var(--green) !important; }
.down { color: var(--red) !important; }

.legend-ind {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}
.legend-ind .ind b { margin-left: 4px; font-weight: 600; }
.legend-ind .ma b { color: var(--ma); }
.legend-ind .vol b { color: var(--blue); }

.watermark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 1;
  color: rgba(209,212,220,.055);
  font-size: clamp(40px, 8vw, 84px);
  font-weight: 800;
  letter-spacing: .02em;
  user-select: none;
}

/* Bottom range bar */
.bottombar {
  height: 30px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  flex-shrink: 0;
  background: var(--bg);
}
.ranges { display: flex; gap: 1px; }
.rbtn {
  padding: 4px 8px;
  border-radius: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.rbtn:hover { background: var(--elev); color: var(--text); }
.rbtn.active { color: var(--blue); }
.bottom-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.muted { color: var(--muted); font-weight: 500; }

/* RIGHT STACK */
.rightstack {
  display: flex;
  border-left: 1px solid var(--border);
  background: var(--bg);
  min-height: 0;
}

.widget-panel {
  width: 300px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.widget-panel.closed { display: none; }

.wp-head {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 0 4px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.wp-tabs { display: flex; gap: 2px; }
.wp-tab {
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.wp-tab:hover { color: var(--text); }
.wp-tab.active { color: var(--text); background: var(--elev); }

.wp-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.wl-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px;
  padding: 0 10px;
  height: 32px;
  background: var(--elev);
  border-radius: 4px;
  color: var(--muted);
  border: 1px solid transparent;
}
.wl-search:focus-within { border-color: var(--blue); color: var(--text); }
.wl-search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.wl-head {
  display: grid;
  grid-template-columns: 1.2fr .9fr .7fr;
  gap: 6px;
  padding: 4px 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.wl-list { flex: 1; overflow: auto; }

.watch-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1.2fr .9fr .7fr;
  gap: 6px;
  align-items: center;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(42,46,57,.55);
}
.watch-row:hover { background: var(--elev); }
.watch-row.active { background: rgba(41,98,255,.13); }
.watch-row .sym { font-weight: 700; font-size: 13px; }
.watch-row .px {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.watch-row .ch {
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.detail-title {
  padding: 14px 14px 8px;
  font-size: 16px;
  font-weight: 700;
}
.detail-grid {
  display: grid;
  gap: 10px;
  padding: 8px 14px 14px;
}
.detail-grid div {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}
.detail-grid span { color: var(--muted); }
.detail-grid b { font-weight: 600; font-variant-numeric: tabular-nums; }

.pill {
  margin: 0 14px 14px;
  width: fit-content;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 3px;
  background: rgba(242,54,69,.18);
  color: #ff8a80;
}

.widgetbar {
  width: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  gap: 2px;
}
.wbtn {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  color: var(--muted);
  display: grid;
  place-items: center;
  text-decoration: none;
}
.wbtn svg { width: 22px; height: 22px; }
.wbtn:hover { background: var(--elev); color: var(--text); }
.wbtn.active { color: var(--blue); background: rgba(41,98,255,.14); }
.wspacer { flex: 1; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 80;
  display: none;
  place-items: start center;
  padding-top: 8vh;
}
.modal-backdrop.is-open {
  display: grid;
}
.modal {
  width: min(560px, calc(100vw - 24px));
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
  overflow: hidden;
  pointer-events: auto;
}
.modal-search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.modal-search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}
.modal-search button {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 4px;
  background: var(--hover);
}
.modal-search button:hover { color: var(--text); }
.modal-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.modal-tabs button {
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.modal-tabs button.active { background: var(--hover); color: var(--text); }
.modal-list {
  max-height: 420px;
  min-height: 180px;
  overflow: auto;
}
.modal-list .empty {
  padding: 28px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.modal-list button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid rgba(42,46,57,.55);
  color: var(--text);
  background: transparent;
  cursor: pointer;
}
.modal-list button:hover { background: var(--hover); }
.modal-list .m-sym { font-weight: 700; }
.modal-list .m-pair { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; }
.modal-list .m-px { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(14px);
  background: var(--elev);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 6px;
  opacity: 0;
  transition: .2s ease;
  z-index: 90;
  font-weight: 700;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.good { border-color: rgba(8,153,129,.55); }
.toast.bad { border-color: rgba(242,54,69,.55); }

@media (max-width: 1000px) {
  .widget-panel { width: 260px; }
  .tbtn.label { display: none; }
}
@media (max-width: 760px) {
  .body-row { grid-template-columns: 1fr auto; }
  .leftbar { display: none; }
  .widget-panel { display: none !important; }
}
