/* dsl-editor.css — full-viewport DSL editor + Vidura AI
   Uses only app CSS variables. No dark-mode overrides.
   z-index: 9500 (above topbar at 9000, below nothing)              */

/* ── Z-index scale ──────────────────────────────────────────────────── */
:root {
  --z-topbar: 9000;
  --z-dse:    10500;  /* above .ov modal backdrop (10000) */
  --z-vidura: 10600;
}

/* ── DSL Editor Overlay ─────────────────────────────────────────────── */
.dse-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-dse);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  animation: dse-in 0.2s var(--t) both;
}
@keyframes dse-in {
  from { opacity:0; transform:translateY(10px); }
  to   { opacity:1; transform:translateY(0);    }
}

/* ── Editor header ───────────────────────────────────────────────────── */
.dse-topbar-wrap { flex-shrink:0; position:relative; }
.dse-topbar {
  display:flex; align-items:center; gap:14px;
  min-height:58px; padding:8px 12px;
  border-bottom:1px solid var(--bd2);
  background:var(--glass-bg);
  backdrop-filter:blur(12px);
  -webkit-backdrop-filter:blur(12px);
}
.dse-action-btn {
  display:flex; align-items:center; gap:6px;
  padding:7px 10px; border:0; border-radius:var(--r-md);
  background:transparent; color:var(--txt2);
  font-size:12px; font-family:var(--font); font-weight:600;
  cursor:pointer; white-space:nowrap;
}
.dse-action-btn:hover { background:var(--s2); color:var(--txt); }
.dse-action-btn svg { width:15px; height:15px; }
.dse-back-btn { flex-shrink:0; }
.dse-type-area {
  display:flex; align-items:center; gap:12px; min-width:280px;
  padding-right:14px; border-right:1px solid var(--bd2);
}
.dse-type-heading { display:flex; flex-direction:column; gap:2px; min-width:58px; }
.dse-type-kicker { font-size:9px; text-transform:uppercase; letter-spacing:.08em; color:var(--muted); }
.dse-type-heading strong { font-size:12px; color:var(--txt); }
.dse-type-fields { display:flex; align-items:center; gap:10px; min-width:0; }
.dse-field { display:flex; align-items:center; gap:6px; }
.dse-field > span, .dse-field-label { font-size:10px; color:var(--muted); white-space:nowrap; }
.dse-type-input {
  box-sizing:border-box; min-width:130px; height:30px;
  padding:5px 9px; border:1px solid var(--bd2); border-radius:var(--r-md);
  background:var(--s2); color:var(--txt);
  font:12px var(--mono,monospace); outline:none;
}
.dse-type-input:focus { border-color:var(--acc); }
.dse-params-field { display:flex; align-items:center; gap:6px; min-width:0; }
.dse-params-list { display:flex; gap:5px; max-width:360px; overflow-x:auto; }
.dse-param-row { display:flex; align-items:center; gap:2px; flex-shrink:0; }
.dse-param-row .dse-type-input { min-width:90px; width:90px; }
.dse-param-remove, .dse-param-add {
  border:0; cursor:pointer; background:transparent; color:var(--muted);
  display:flex; align-items:center; justify-content:center;
}
.dse-param-remove svg, .dse-param-add svg { width:13px; height:13px; }
.dse-param-remove:hover { color:var(--red); }
.dse-param-add { gap:3px; padding:4px 6px; color:var(--acc); font-size:10px; white-space:nowrap; }
.dse-condition-heading {
  display:flex; align-items:center; gap:7px; color:var(--txt);
  font-size:12px; min-width:120px;
}
.dse-condition-heading svg { width:15px; height:15px; color:var(--acc); }
.dse-actions { margin-left:auto; display:flex; align-items:center; gap:4px; flex-shrink:0; }
.dse-apply-btn { background:var(--acc-d); color:var(--acc); }
.dse-apply-btn:hover { background:var(--acc); color:#fff; }
.dse-vidura-btn.active { background:var(--acc-d); color:var(--acc); }
@media (max-width:850px) {
  .dse-topbar { flex-wrap:wrap; gap:8px; }
  .dse-type-area { min-width:0; flex:1; border-right:0; padding-right:0; }
  .dse-condition-heading { display:none; }
}
@media (max-width:560px) {
  .dse-type-heading { display:none; }
  .dse-type-area { width:100%; order:2; }
  .dse-actions { order:1; }
  .dse-back-btn { order:0; }
}

/* ── Metrics dropdown ────────────────────────────────────────────────── */
.dse-metrics-panel {
  position: absolute;
  top: 100%; left: 0; right: 0; z-index: 10;
  background: var(--s1);
  border-bottom: 1px solid var(--bd2);
  padding: 10px 12px 12px;
  box-shadow: var(--nm-out);
}
.dse-metrics-search {
  width: 100%; box-sizing: border-box;
  padding: 7px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--bd2);
  background: var(--s2);
  color: var(--txt); font-size: 13px; font-family: var(--font);
  outline: none; margin-bottom: 10px;
}
.dse-metrics-search:focus { border-color: var(--acc); }
.dse-metrics-grid {
  display: flex; flex-wrap: wrap; gap: 5px;
  max-height: 180px; overflow-y: auto;
}
.dse-metric-chip {
  padding: 4px 11px; border-radius: var(--r-pill); border: 1px solid var(--bd2);
  background: var(--s2); color: var(--txt);
  font-size: 12px; font-family: var(--font);
  cursor: pointer;
  transition: background var(--t), color var(--t);
}
.dse-metric-chip:hover { background: var(--acc-d); color: var(--acc); border-color: var(--acc); }
.dse-metric-chip.is-fn { color: var(--acc); }

/* ── Body layout ─────────────────────────────────────────────────────── */
.dse-body { flex:1; display:flex; overflow:hidden; position:relative; }

.dse-editor-pane {
  flex: 1; display:flex; flex-direction:column;
  min-width: 0; overflow: hidden; position: relative;
}
.dse-editor-meta {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 4px;
  font-size: 11px; color: var(--muted); flex-shrink: 0;
}
.dse-mode-label { font-weight: 700; color: var(--txt); }
.dse-char-count { margin-left: auto; }
.dse-validity { font-size:11px; }
.dse-validity.ok  { color: var(--green); }
.dse-validity.err { color: var(--red);   }

/* CodeMirror fills the pane */
.dse-cm-wrap { flex:1; overflow:hidden; position:relative; }
.dse-cm-wrap .CodeMirror {
  height: 100% !important;
  font-family: 'Source Code Pro', 'JetBrains Mono', monospace !important;
  font-size: 14px !important;
  line-height: 1.7 !important;
  background: var(--s1) !important;
  color: var(--txt) !important;
  padding: 10px 0;
}
.dse-cm-wrap .CodeMirror-scroll { padding: 0 16px; box-sizing: border-box; }
.dse-cm-wrap .CodeMirror-cursor { border-left: 2px solid var(--acc) !important; }
/* DSL syntax highlight */
.cm-klines-keyword { color: var(--acc);  font-weight:600; }
.cm-klines-fn      { color: var(--acc2); }
.cm-klines-field   { color: var(--green); }
.cm-klines-number  { color: var(--red);  }
.cm-klines-op      { color: var(--muted); }
.cm-klines-var     { color: var(--txt2); font-style:italic; }

/* Token tooltip */
.dse-token-tip {
  position: absolute; z-index: 20;
  background: var(--s1);
  border: 1px solid var(--bd2);
  border-radius: var(--r-lg); padding: 8px 12px;
  font-size: 12px; max-width: 280px;
  box-shadow: var(--nm-out); pointer-events: none;
}
.dse-token-tip-name { font-weight:700; color:var(--txt); margin-bottom:3px; }
.dse-token-tip-sig  { font-family:monospace; color:var(--acc); font-size:11px; }
.dse-token-tip-desc { color:var(--muted); margin-top:4px; line-height:1.4; }

/* ── Reference panel ─────────────────────────────────────────────────── */
.dse-ref-panel {
  width: 280px; flex-shrink:0;
  display:flex; flex-direction:column;
  border-left: 1px solid var(--bd2);
  background: var(--s1);
  overflow: hidden;
}
@media (max-width:640px) {
  .dse-ref-panel {
    position:absolute; inset:0; width:100%; z-index:5; border-left:none;
  }
}
.dse-ref-header {
  display:flex; align-items:center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bd2); flex-shrink:0;
}
.dse-ref-title { flex:1; font-size:13px; font-weight:600; color:var(--txt); }
.dse-ref-close {
  display:grid; place-items:center;
  width:28px; height:28px; border-radius:var(--r-pill); border:none;
  background:transparent; color:var(--muted); cursor:pointer;
}
.dse-ref-close:hover { background:var(--s2); }
.dse-ref-close svg { width:14px; height:14px; }
.dse-ref-tabs { display:flex; gap:2px; padding:6px 8px; flex-shrink:0; }
.dse-ref-tab {
  flex:1; padding:5px 6px; border-radius:var(--r-pill); border:none;
  background:transparent; color:var(--muted);
  font-size:11px; font-family:var(--font); font-weight:500; cursor:pointer;
  transition:background var(--t), color var(--t);
}
.dse-ref-tab.active { background:var(--acc-d); color:var(--acc); }
.dse-ref-body { flex:1; overflow-y:auto; padding:8px; font-size:12px; }
.dse-ref-section { margin-bottom:14px; }
.dse-ref-section-title {
  font-size:10px; font-weight:700; letter-spacing:.08em;
  text-transform:uppercase; color:var(--muted); margin-bottom:6px; padding:0 4px;
}
.dse-ref-item {
  display:flex; flex-direction:column; gap:1px;
  padding:5px 8px; border-radius:var(--r-lg); cursor:pointer; margin-bottom:2px;
  transition:background var(--t);
}
.dse-ref-item:hover { background:var(--s2); }
.dse-ref-item-name { font-family:monospace; color:var(--acc); font-size:12px; }
.dse-ref-item-desc { font-size:11px; color:var(--muted); line-height:1.35; }

/* ── Autocomplete dropdown ───────────────────────────────────────────── */
.dse-ac {
  position: fixed; z-index: calc(var(--z-dse) + 5);
  background: var(--s1);
  border: 1px solid var(--bd2);
  border-radius: var(--r-lg);
  box-shadow: var(--nm-out);
  min-width: 200px; max-width: 320px;
  max-height: 220px; overflow-y: auto;
  font-size: 13px;
}
.dse-ac-item {
  display:flex; align-items:baseline; gap:8px;
  padding:7px 12px; cursor:pointer;
  transition:background var(--t);
}
.dse-ac-item:hover, .dse-ac-item.selected { background:var(--acc-d); }
.dse-ac-name { font-family:monospace; font-weight:600; color:var(--txt); flex-shrink:0; }
.dse-ac-name mark { background:transparent; color:var(--acc); font-weight:800; }
.dse-ac-sig  { font-family:monospace; font-size:11px; color:var(--muted); }
.dse-ac-type { font-size:10px; color:var(--acc2); margin-left:auto; flex-shrink:0; }

/* ═══════════════════════════════════════════════════════════════════════
   VIDURA AI PANEL
   ═══════════════════════════════════════════════════════════════════════ */
.vidura-panel {
  position: fixed;
  bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
  right: 16px;
  width: 360px;
  max-height: calc(100vh - 120px);
  z-index: var(--z-vidura);
  background: var(--s1);
  border: 1px solid var(--bd2);
  border-radius: var(--r-xl);
  box-shadow: var(--nm-deep);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: vidura-in 0.2s var(--t) both;
}
@keyframes vidura-in {
  from { opacity:0; transform:scale(0.96) translateY(8px); }
  to   { opacity:1; transform:scale(1)    translateY(0);   }
}
@media (max-width:480px) {
  .vidura-panel {
    bottom:0; right:0; left:0; width:100%;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height:70vh;
  }
}

.vidura-header {
  display:flex; align-items:center; gap:8px;
  padding:12px 14px;
  border-bottom: 1px solid var(--bd2); flex-shrink:0;
  background: var(--s2);
}
.vidura-glyph { font-size:18px; color:var(--acc); font-weight:700; flex-shrink:0; }
.vidura-title { font-size:14px; font-weight:700; color:var(--txt); font-family:var(--font); }
.vidura-sub   { font-size:11px; color:var(--muted); }
.vidura-close {
  margin-left:auto;
  display:grid; place-items:center;
  width:28px; height:28px; border-radius:var(--r-pill);
  border:none; background:transparent; color:var(--muted); cursor:pointer;
}
.vidura-close:hover { background:var(--s3); }
.vidura-close svg { width:14px; height:14px; }

.vidura-chat {
  flex:1; overflow-y:auto; padding:12px;
  display:flex; flex-direction:column; gap:8px;
}
.vidura-bubble { padding:9px 12px; border-radius:var(--r-lg); font-size:13px; line-height:1.5; max-width:92%; }
.vidura-bot  { background:var(--s2); color:var(--txt); align-self:flex-start; border-bottom-left-radius:4px; }
.vidura-user { background:var(--acc-d); color:var(--txt); align-self:flex-end; border-bottom-right-radius:4px; }
.vidura-result {
  background: var(--s2);
  border: 1px solid var(--acc);
  color: var(--acc);
  font-family: monospace; font-size:12px;
  align-self:flex-start; border-bottom-left-radius:4px;
  word-break:break-all;
}
.vidura-bubble em { color:var(--muted); font-style:normal; font-size:12px; }

/* Ink vanish/appear */
.vidura-ink-wrap.ink-vanish {
  -webkit-mask-image: linear-gradient(to right, transparent 45%, black 50%, black 55%);
          mask-image: linear-gradient(to right, transparent 45%, black 50%, black 55%);
  -webkit-mask-size:300% 100%; mask-size:300% 100%;
  animation: diary-vanish 1.6s ease-in-out forwards;
}
.vidura-ink-wrap.ink-appear {
  -webkit-mask-image: linear-gradient(to right, black 45%, transparent 50%, transparent 55%);
          mask-image: linear-gradient(to right, black 45%, transparent 50%, transparent 55%);
  -webkit-mask-size:300% 100%; mask-size:300% 100%;
  animation: diary-appear 1.6s ease-in-out forwards;
}
@keyframes diary-vanish {
  0%   { -webkit-mask-position:100% 0; mask-position:100% 0; }
  100% { -webkit-mask-position:0%   0; mask-position:0%   0; }
}
@keyframes diary-appear {
  0%   { -webkit-mask-position:100% 0; mask-position:100% 0; }
  100% { -webkit-mask-position:0%   0; mask-position:0%   0; }
}

.vidura-loading { padding:12px 14px; flex-shrink:0; display:flex; align-items:center; gap:8px; }
.vidura-thinking { font-size:12px; color:var(--muted); }
.vidura-dots { display:inline-flex; gap:4px; }
.vidura-dots span {
  width:5px; height:5px; border-radius:50%;
  background:var(--acc); animation:dot-bounce 1.2s infinite;
}
.vidura-dots span:nth-child(2) { animation-delay:.2s; }
.vidura-dots span:nth-child(3) { animation-delay:.4s; }
@keyframes dot-bounce {
  0%,80%,100% { transform:scale(1);   opacity:.5; }
  40%          { transform:scale(1.4); opacity:1;  }
}

.vidura-input-row {
  display:flex; gap:6px; padding:10px 12px;
  border-top: 1px solid var(--bd2); flex-shrink:0;
}
.vidura-textarea {
  flex:1; resize:none;
  background:var(--s2); border:1px solid var(--bd2);
  border-radius:var(--r-lg); padding:8px 10px;
  color:var(--txt); font-size:13px; font-family:var(--font);
  outline:none; line-height:1.5;
}
.vidura-textarea:focus { border-color:var(--acc); }
.vidura-send {
  display:grid; place-items:center;
  width:38px; height:38px; border-radius:var(--r-pill); border:none;
  background:var(--acc-d); color:var(--acc); cursor:pointer;
  flex-shrink:0; align-self:flex-end;
  transition:background var(--t), color var(--t);
}
.vidura-send:hover { background:var(--acc); color:#fff; }
.vidura-send svg { width:15px; height:15px; }
.vidura-footer {
  padding:4px 14px 10px;
  font-size:10px; color:var(--muted); text-align:center; flex-shrink:0;
}

/* ── Live section (inside existing page layout) ──────────────────────── */
.live-status-bar {
  display:flex; align-items:center; flex-wrap:wrap;
  gap:10px; padding:10px 14px; margin-bottom:14px;
  background:var(--s1);
  border:1px solid var(--bd2);
  border-radius:var(--r-lg);
  box-shadow:var(--nm-btn);
}
.live-dot { width:8px; height:8px; border-radius:50%; background:var(--s4); flex-shrink:0; transition:background var(--t); }
.live-dot-connecting { background:var(--red); animation:live-pulse 1s infinite; }
.live-dot-connected  { background:var(--green); }
.live-dot-disconnected { background:var(--s4); }
.live-dot-error      { background:var(--red); }
.live-status-text { font-size:13px; font-weight:600; color:var(--txt); min-width:90px; }
.live-stat { font-size:12px; color:var(--muted); }
.live-stat-sep { opacity:.4; }

.live-layout {
  display:grid; grid-template-columns:300px 1fr; gap:14px; align-items:start;
}
@media (max-width:900px) { .live-layout { grid-template-columns:1fr; } }
.live-col-config, .live-col-results { display:flex; flex-direction:column; gap:14px; }

.live-panel { border-radius:var(--r-lg); box-shadow:var(--nm-out); }
.live-label { font-size:12px; color:var(--muted); flex-shrink:0; }

.live-condition-preview {
  font-family:monospace; font-size:12px;
  background:var(--s2); border-radius:var(--r-lg);
  padding:10px 12px; margin-top:10px;
  white-space:pre-wrap; word-break:break-all; color:var(--txt);
  min-height:36px; border:1px solid var(--bd2);
}
.live-textarea {
  width:100%; box-sizing:border-box; resize:vertical;
  font-family:monospace; font-size:12px;
  border:1px solid var(--bd2); border-radius:var(--r-lg);
  background:var(--s2); color:var(--txt); padding:8px 10px;
}
.live-condition-direct { margin-top:10px; }
.live-tf-row { display:flex; align-items:center; gap:8px; margin-top:10px; flex-wrap:wrap; }
.live-tf-select { max-width:120px; }
.live-signal-row { display:flex; align-items:center; gap:8px; }
.live-signal-input { flex:1; }
.live-icon-buy { color:var(--green); }
.live-icon-fav { color:#f5a623; }

.live-col-row { display:flex; align-items:center; gap:6px; margin-bottom:6px; }
.live-col-label { width:80px; flex-shrink:0; }
.live-col-expr  { flex:1; }
.live-col-empty { font-size:12px; color:var(--muted); padding:8px 0; }

.live-results-toolbar { border-radius:var(--r-lg); box-shadow:var(--nm-out); }
.live-results-grid {
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(min(260px,100%), 1fr));
  gap:8px;
}
.live-result-card {
  padding:12px 14px; border-radius:var(--r-lg);
  border:1px solid var(--bd2); background:var(--s1);
  box-shadow:var(--nm-btn);
  transition:border-color var(--t);
}
.live-result-card.is-buy { border-color:var(--green); }
.live-result-card.is-fav { border-color:#f5a623; }
.lrc-header { display:flex; align-items:center; gap:6px; margin-bottom:6px; }
.lrc-sym { font-weight:700; font-size:14px; color:var(--txt); flex:1; }
.lrc-change { font-size:12px; font-weight:600; }
.lrc-ohlc { display:flex; gap:10px; font-size:11px; color:var(--muted); font-family:monospace; flex-wrap:wrap; }
.lrc-ohlc strong { color:var(--txt); }
.lrc-cols { display:flex; flex-wrap:wrap; gap:6px; margin-top:6px; font-size:11px; }
.lrc-col-item em { color:var(--muted); font-style:normal; margin-right:2px; }

.live-results-table-wrap { overflow-x:auto; border-radius:var(--r-lg); box-shadow:var(--nm-out); }
.live-results-table { width:100%; border-collapse:collapse; font-size:12px; font-family:monospace; }
.live-results-table th { text-align:left; padding:8px 10px; background:var(--s2); color:var(--muted); font-weight:600; border-bottom:1px solid var(--bd2); white-space:nowrap; }
.live-results-table td { padding:7px 10px; border-bottom:1px solid var(--bd2); color:var(--txt); vertical-align:middle; }
.live-results-table tr:last-child td { border-bottom:none; }
.live-results-table tr:hover td { background:var(--s2); }
.lrc-sym-td { font-weight:700; }

.live-pos { color:var(--green); }
.live-neg { color:var(--red);   }

.live-signals-surface { border-radius:var(--r-lg); box-shadow:var(--nm-out); }
.live-chip-row { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.live-chip { padding:3px 12px; border-radius:var(--r-pill); font-size:12px; font-weight:600; }
.chip-buy { background:rgba(26,168,111,.10); color:var(--green); }
.chip-fav { background:rgba(245,166,35,.10);  color:#f5a623;     }

.live-badge { display:inline-flex; align-items:center; padding:1px 8px; border-radius:var(--r-pill); font-size:11px; font-weight:600; background:var(--s2); color:var(--muted); }
.live-badge-primary { background:var(--acc-d); color:var(--acc); }
.live-badge-green   { background:rgba(26,168,111,.10); color:var(--green); }
.live-badge-amber   { background:rgba(245,166,35,.10); color:#f5a623;    }

.live-empty { display:flex; flex-direction:column; align-items:center; gap:10px; padding:40px 20px; color:var(--muted); font-size:13px; text-align:center; }

/* Builder Live button + timeframe */
.card-live-btn { display:inline-flex; align-items:center; padding:4px 6px; border-radius:var(--r-pill); border:1px solid var(--bd2); background:var(--acc-d); color:var(--acc); cursor:pointer; transition:background var(--t); }
.card-live-btn:hover { background:var(--acc); color:#fff; }

/* Remove old insert-number button */
#insert-num-btn, .btn-insert-num { display:none !important; }
