:root {
  --bg0: #0d0f12;
  --bg1: #141720;
  --bg2: #1c2030;
  --bg3: #242840;
  --border: #2a2e45;
  --border2: #3a3f5c;
  --text0: #e8eaf0;
  --text1: #9aa0bc;
  --text2: #5a6080;
  --accent: #4a90d9;
  --font: 'Courier New', monospace;
  /* configurable via settings */
  --ma-label-size: 9px;
  --ma-sym-size: 12px;
  --ma-price-size: 10px;
  --tfb-size: 8.5px;
  --tfb-on-border: #4a90d9;
  --tfb-height: 18px;
  --tfb-gap: 2px;
  --tfb-pad: 3px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  background: var(--bg0); color: var(--text0);
  font-family: var(--font); font-size: 11px;
  width: 100%; height: 100%; overflow: hidden;
  display: flex; flex-direction: column;
}

/* ── TOOLBAR ── */
#toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap; min-height: 32px;
}
.tb-label { font-size: 13px; font-weight: bold; color: var(--accent); letter-spacing: 3px; margin-right: 6px; }
.tb-sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; flex-shrink: 0; }
.gbtn {
  padding: 3px 8px; border: 1px solid var(--border2);
  border-radius: 3px; cursor: pointer; font-size: 10px;
  background: var(--bg2); color: var(--text1);
  font-family: var(--font); transition: all 0.1s; white-space: nowrap;
}
.gbtn:hover { background: var(--bg3); color: var(--text0); border-color: var(--accent); }
.gbtn.active { background: rgba(74,144,217,0.18); color: var(--accent); border-color: var(--accent); }
.gbtn.star { background: rgba(217,174,74,0.12); color: #d9ae4a; border-color: #d9ae4a55; }
.gbtn.add { border-style: dashed; color: var(--text2); }
.gbtn.danger { color: #d06060; border-color: #d0606044; }
.gbtn.danger:hover { background: rgba(208,96,96,0.12); }

/* ── WORKSPACE ── */
#workspace {
  flex: 1; overflow: hidden;
  display: flex; flex-direction: column;
  padding: 5px; gap: 0;
}

/* ── ROW ── */
.row-wrap {
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg1); overflow: hidden;
  display: flex; flex-direction: column;
  flex: 1; min-height: 150px;
}
.row-header {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px; background: var(--bg2);
  border-bottom: 1px solid var(--border);
  font-size: 10px; color: var(--text2); flex-shrink: 0;
}
.row-label { color: var(--text0); font-size: 11px; font-weight: bold; }
.row-body { display: flex; flex-direction: row; overflow: hidden; flex: 1; }

/* ── ROW RESIZE HANDLE ── */
.row-resize {
  height: 5px; background: var(--border); cursor: row-resize;
  flex-shrink: 0; transition: background 0.15s; margin: 2px 0;
}
.row-resize:hover, .row-resize.dragging { background: var(--accent); }

/* ── COLUMN ── */
.col-wrap { display: flex; flex-direction: column; overflow: hidden; min-width: 100px; flex: 1; }
.col-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 3px 6px; background: var(--bg2);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.col-title { font-size: 10px; color: var(--text1); }
.col-body { flex: 1; display: flex; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
.col-body:has(.mapanel:only-child) .mapanel { flex: 1; }

/* ── COL RESIZE HANDLE ── */
.col-resize {
  width: 5px; background: var(--border2); cursor: col-resize;
  flex-shrink: 0; transition: background 0.15s; position: relative;
}
.col-resize:hover, .col-resize.dragging { background: var(--accent); }

/* ── MA PANEL ── */
.mapanel {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  flex: 1; min-width: 110px; overflow: hidden;
  transition: flex 0.2s, min-width 0.2s;
}
.mapanel:last-child { border-right: none; }
.mapanel.collapsed { flex: 0 0 22px; min-width: 22px; max-width: 22px; cursor: pointer; }
.mp-head {
  display: flex; align-items: baseline;
  padding: 4px 6px 3px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.mp-head:hover { background: var(--bg3); }
.mp-collapsed-bar {
  display: none; flex-direction: column; align-items: center;
  justify-content: center; flex: 1; cursor: pointer;
  background: var(--bg2); border-right: 1px solid var(--border);
  overflow: hidden;
}
.mapanel.collapsed .mp-collapsed-bar { display: flex; }
.mapanel.collapsed .mp-head,
.mapanel.collapsed .mp-svg-wrap,
.mapanel.collapsed .mp-tfs { display: none; }
.mp-collapsed-label {
  writing-mode: vertical-rl; text-orientation: mixed;
  transform: rotate(180deg);
  font-size: 11px; font-weight: bold; letter-spacing: 1px;
  color: var(--text0); white-space: nowrap; font-family: var(--font);
}
.mp-sym { font-size: var(--ma-sym-size); font-weight: bold; letter-spacing: 0.5px; color: var(--text0); }
.mp-price { font-size: var(--ma-price-size); color: var(--text1); font-family: var(--font); }
.mp-svg-wrap { flex: 1; overflow: hidden; position: relative; min-height: 60px; }
.mp-svg-wrap svg { display: block; }

/* ── TF BUTTONS 3×4 ── */
.mp-tfs {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: var(--tfb-gap); padding: var(--tfb-pad); flex-shrink: 0;
  border-top: 1px solid var(--border);
}
.tfb {
  font-size: var(--tfb-size); padding: 0 2px;
  height: var(--tfb-height);
  border-radius: 2px; border: none; outline: none;
  cursor: pointer; font-family: var(--font);
  text-align: center; white-space: nowrap;
  color: #111; font-weight: bold;
  transition: box-shadow 0.1s;
  overflow: hidden; text-overflow: ellipsis;
}
.tfb.on  { box-shadow: inset 0 0 0 3px var(--tfb-on-border); }
.tfb.off { box-shadow: none; }
.tfb:hover { box-shadow: inset 0 0 0 2px #e8eaf0 !important; }

/* ── DRAG HANDLES ── */
.drag-handle {
  cursor: grab; color: var(--text2); font-size: 12px;
  padding: 0 4px; flex-shrink: 0; user-select: none;
  display: flex; align-items: center; line-height: 1;
}
.drag-handle:hover { color: var(--text0); }
.drag-handle:active { cursor: grabbing; }

/* ── DROP INDICATORS ── */
.drop-indicator-v {
  position: absolute; top: 0; bottom: 0; width: 3px;
  background: var(--accent); z-index: 50; pointer-events: none;
  border-radius: 2px; box-shadow: 0 0 6px var(--accent);
}
.drop-indicator-h {
  position: absolute; left: 0; right: 0; height: 3px;
  background: var(--accent); z-index: 50; pointer-events: none;
  border-radius: 2px; box-shadow: 0 0 6px var(--accent);
}

/* ── DRAG GHOST ── */
#drag-ghost {
  position: fixed; pointer-events: none; z-index: 999;
  opacity: 0.85; border: 1px solid var(--accent);
  border-radius: 4px; background: var(--bg2);
  font-size: 11px; font-weight: bold; color: var(--text0);
  padding: 4px 10px; white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6); font-family: var(--font);
}

/* ── DROP ZONE OVERLAYS ── */
.drop-zone {
  position: fixed; z-index: 900; display: none;
  align-items: center; justify-content: center;
  font-size: 11px; font-weight: bold; pointer-events: none;
}
.drop-zone.active { display: flex; }
#dz-top {
  top: 0; left: 0; right: 0; height: 48px;
  background: rgba(74,144,217,0.25);
  border-bottom: 2px solid var(--accent);
  color: var(--accent); letter-spacing: 2px;
}
#dz-sides {
  top: 48px; bottom: 0; right: 0; width: 48px;
  background: rgba(74,144,217,0.18);
  border-left: 2px solid var(--accent);
  color: var(--accent); writing-mode: vertical-rl;
}
.dragging-source { opacity: 0.3; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── SETTINGS PANEL ── */
.cfg-section { margin-bottom: 12px; }
.cfg-title { font-size: 9px; color: var(--text2); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; border-bottom: 1px solid var(--border); padding-bottom: 3px; }
.cfg-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.cfg-label { font-size: 10px; color: var(--text1); flex: 1; white-space: nowrap; }
.cfg-range { width: 90px; accent-color: var(--accent); cursor: pointer; }
.cfg-val { font-size: 10px; color: var(--text0); width: 38px; text-align: right; font-family: var(--font); }
.cfg-color { width: 32px; height: 22px; border: 1px solid var(--border2); border-radius: 3px; cursor: pointer; padding: 1px; background: var(--bg2); }

/* ── SYM PICKER ── */
#sym-picker {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.7); z-index: 100;
  align-items: center; justify-content: center;
}
#sym-picker.open { display: flex; }
.picker-box {
  background: var(--bg1); border: 1px solid var(--border2);
  border-radius: 6px; padding: 16px; width: 420px; max-height: 80vh;
  display: flex; flex-direction: column; gap: 10px;
}
.picker-title { font-size: 12px; color: var(--text0); font-weight: bold; }
.picker-presets { display: flex; flex-wrap: wrap; gap: 4px; }
.picker-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; overflow-y: auto; }
.picker-sym {
  padding: 4px 2px; border: 1px solid var(--border);
  border-radius: 3px; cursor: pointer; font-size: 16px;
  text-align: center; background: var(--bg2); color: var(--text1); transition: all 0.1s;
}
.picker-sym.sel { background: rgba(74,144,217,0.2); color: var(--accent); border-color: var(--accent); }
.picker-presets .gbtn { font-size: 16px; }
.picker-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* ── CURRENCY STRENGTH (cs module) ── */
.cs-col { display: flex; flex-direction: column; padding: 8px 10px; overflow-y: auto; }
.cs-title { font-size: 9px; color: var(--text2); margin-bottom: 8px; letter-spacing: 1px; text-transform: uppercase; }
.cs-row { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.cs-cur { width: 28px; font-size: 10px; color: var(--text1); }
.cs-track { flex: 1; height: 8px; background: var(--bg3); border-radius: 2px; overflow: hidden; }
.cs-fill { height: 100%; border-radius: 2px; }
.cs-num { width: 36px; text-align: right; font-size: 10px; }

/* ── EI CALENDAR MODULE ── */
.ei-wrap {
  display: flex; flex-direction: column;
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg1);
}
.ei-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 3px 8px; background: var(--bg2);
  border-bottom: 1px solid var(--border); flex-shrink: 0; gap: 6px;
}
.ei-title { font-size: 10px; font-weight: bold; color: var(--text0); letter-spacing: 1px; }
.ei-scale-label { font-size: 9px; color: var(--text2); }
.ei-scale-val { font-size: 9px; color: var(--text1); min-width: 52px; text-align: center; }
.ei-now-btn { font-size: 9px; padding: 1px 6px; background: rgba(74,144,217,0.15); color: var(--accent); border-color: var(--accent); }

.ei-body {
  display: flex; flex-direction: row;
  flex: 1; overflow-y: scroll; overflow-x: hidden;
  position: relative;
}
.ei-body::-webkit-scrollbar { width: 4px; }

/* Time axis */
.ei-time-axis {
  width: 52px; flex-shrink: 0;
  position: relative; background: var(--bg2);
  border-right: 1px solid var(--border);
}
.ei-date-line {
  position: absolute; left: 0; right: 0; height: 1px;
  background: var(--border2);
}
.ei-date-label {
  position: absolute; left: 2px;
  font-size: 8px; color: var(--accent); white-space: nowrap;
  font-weight: bold; letter-spacing: 0.3px;
}
.ei-tick {
  position: absolute; right: 0; width: 4px; height: 1px;
  background: var(--border2);
}
.ei-tick-hour {
  width: 8px; background: var(--border);
}
.ei-tick-label {
  position: absolute; right: 6px;
  font-size: 8px; color: var(--text2);
  font-family: var(--font); white-space: nowrap;
}
.ei-now-line {
  position: absolute; left: 0; right: 0; height: 1px;
  background: #e84040; z-index: 10; pointer-events: none;
}
.ei-now-label {
  position: absolute; left: 2px;
  font-size: 8px; color: #e84040; font-weight: bold;
  z-index: 11;
}

/* Grid */
.ei-grid {
  flex: 1; position: relative; overflow: hidden;
  display: flex; flex-direction: column;
}
.ei-col-header-row {
  display: flex; flex-direction: row;
  position: sticky; top: 0; z-index: 20;
  background: var(--bg2); border-bottom: 1px solid var(--border2);
  flex-shrink: 0;
}
.ei-col-header {
  flex-shrink: 0; text-align: center;
  font-size: 9px; font-weight: bold; color: var(--text0);
  padding: 3px 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.ei-col-countdown {
  font-size: 8px; color: var(--text2); font-weight: normal;
}
.ei-lanes {
  display: flex; flex-direction: row; position: relative;
}
.ei-lane {
  flex-shrink: 0; position: relative;
  border-right: 1px solid var(--border);
}

/* Event dots */
.ei-dot {
  position: absolute; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px; cursor: pointer;
  line-height: 1; user-select: none;
  display: flex; align-items: center; gap: 1px;
  transition: transform 0.1s;
}
.ei-dot:hover { transform: translate(-50%, -50%) scale(1.4); }
.ei-dot-h   { color: #e05050; }
.ei-dot-m   { color: #3ab070; }
.ei-dot-hol { color: var(--text2); font-size: 10px; }
.ei-dot-count {
  font-size: 7px; color: var(--text1);
  background: var(--bg3); border-radius: 2px; padding: 0 2px;
  position: absolute; top: -4px; right: -6px;
}

/* Tooltip */
.ei-tooltip {
  position: fixed; z-index: 1000;
  background: var(--bg1); border: 1px solid var(--border2);
  border-radius: 4px; padding: 8px 10px;
  min-width: 200px; max-width: 280px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
  font-family: var(--font); pointer-events: none;
}
.ei-tt-time { font-size: 10px; color: var(--accent); margin-bottom: 3px; font-weight: bold; }
.ei-tt-rel  { font-size: 9px; margin-bottom: 5px; }
.ei-tt-rel.future { color: #3ab070; }
.ei-tt-rel.past   { color: var(--text2); }
.ei-tt-event { font-size: 9px; color: var(--text1); margin-bottom: 2px; }
.ei-tt-cur   { color: var(--text0); font-weight: bold; }
.ei-tt-name  { color: var(--text0); }
.ei-tt-fore  { color: var(--text2); }
.ei-tt-act   { color: #3ab070; font-weight: bold; }

/* ── TF BUTTON BLINK ── */
@keyframes tfb-blink {
  0%,100% { opacity:1; }
  50%      { opacity:0.25; }
}
.tfb.blink-buy  { animation: tfb-blink 2.0s ease-in-out infinite; }
.tfb.blink-sell { animation: tfb-blink 2.0s ease-in-out infinite; }
.tfb.on.blink-buy  { box-shadow: inset 0 0 0 3px var(--tfb-on-border), inset 0 0 0 5px #4ab870 !important; }
.tfb.on.blink-sell { box-shadow: inset 0 0 0 3px var(--tfb-on-border), inset 0 0 0 5px #e84040 !important; }
.tfb.off.blink-buy  { box-shadow: none !important; }
.tfb.off.blink-sell { box-shadow: none !important; }
