/* Pine Editor (pine-editor.js, code-editor.js). Token colours are TradingView's editor theme
   (script-form bundle, 2026-11-26): dark = vs-dark rules, light = vs rules, with TradingView's palette. */
:root,
[data-theme="dark"] {
  --pe-comment: #808080;
  --pe-text: #ffffff;
  --pe-string: #388e3c;
  --pe-const: #f77c80;
  --pe-func: #5b9cf6;
  --pe-type: #42bda8;
  --pe-kw: #42bda8;
  --pe-var: #dbdbdb;
  --pe-num: #f57f17;
  --pe-call: #ba68c8;
  --pe-ln: #808080;
  --pe-ln-cur: #b8b8b8;
  --pe-curline: #132042;
  --pe-sel: #142e61;
  --pe-bracket: #303030;
  --pe-widget: #131313;
  --pe-match: rgba(255, 152, 0, 0.28);
  --pe-match-cur: rgba(255, 152, 0, 0.55);
}
[data-theme="light"] {
  --pe-comment: #9c9c9c;
  --pe-text: #000000;
  --pe-string: #388e3c;
  --pe-const: #cc2929;
  --pe-func: #2962ff;
  --pe-type: #22ab94;
  --pe-kw: #22ab94;
  --pe-var: #222222;
  --pe-num: #f57f17;
  --pe-call: #8e24aa;
  --pe-ln: #9c9c9c;
  --pe-ln-cur: #464646;
  --pe-curline: #e3effd;
  --pe-sel: #bbd9fb;
  --pe-bracket: #ebebeb;
  --pe-widget: #ffffff;
  --pe-match: #ffe0b2;
  --pe-match-cur: rgba(255, 152, 0, 0.45);
}

/* ---------- panel */
.pe [hidden], .pe-menu [hidden] { display: none !important; }
.pe { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--bg); color: var(--text); }
.pe-head { display: flex; align-items: center; gap: 4px; height: 38px; padding: 0 8px; border-bottom: 1px solid var(--sep-line); flex: none; }
.pe-head .spacer, .pe-status .spacer, .pe-chead .spacer { flex: 1; }
.pe-lang { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; padding: 2px; gap: 2px; margin-right: 6px; flex: none; }
.pe-lang button { border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; padding: 3px 8px; border-radius: 4px; cursor: default; }
.pe-lang button.on { background: var(--btn-on); color: var(--text); }
.pe-lang button:hover:not(.on) { background: var(--btn-hover); color: var(--text); }
.tester .left > .row-flex:first-child .pe-lang { margin-right: 0; }
.pe-name { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 6px 0 8px; border: 0; border-radius: 4px; background: none; color: var(--text); font: inherit; font-size: 14px; font-weight: 600; cursor: default; max-width: 40%; min-width: 0; }
.pe-name:hover { background: var(--btn-hover); }
.pe-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pe-name svg, .pe-btn svg, .pe-icon svg, .pe-sbtn svg, .pe-mi svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.3; flex: none; }
.pe-icon svg circle { fill: currentColor; stroke: none; }
.pe-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); flex: none; }
.pe-btn { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 10px 0 6px; border: 0; border-radius: 4px; background: none; color: var(--text); font: inherit; font-size: 13px; cursor: default; white-space: nowrap; }
.pe-btn:hover, .pe-icon:hover, .pe-sbtn:hover { background: var(--btn-hover); }
.pe-icon, .pe-sbtn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border: 0; border-radius: 4px; background: none; color: var(--text); cursor: default; }
.pe-sbtn { width: 24px; height: 22px; }
.pe-hist { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; font-size: 12px; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; }
.pe-hist .pe-btn { color: var(--accent); }
.pe-main { flex: 1; min-height: 60px; position: relative; display: flex; }
.pe-code { flex: 1; min-width: 0; position: relative; display: flex; }
.pe-console { flex: none; height: 30%; min-height: 70px; max-height: 50%; display: flex; flex-direction: column; border-top: 1px solid var(--sep-line); }
.pe-console[hidden] { display: none; }
.pe-chead { display: flex; align-items: center; height: 26px; padding: 0 4px 0 10px; font-size: 12px; color: var(--muted); flex: none; }
.pe-chead .pe-icon { width: 24px; height: 22px; }
.pe-log { flex: 1; overflow: auto; padding: 0 10px 6px; font: 12px/18px Menlo, Monaco, Consolas, "Courier New", monospace; }
.pe-msg { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-word; }
.pe-time { color: var(--muted); flex: none; }
.pe-msg.error .pe-text { color: var(--down); }
.pe-msg.warning .pe-text { color: #ff9800; }
.pe-msg a { color: inherit; text-decoration: underline; }
.pe-status { display: flex; align-items: center; gap: 8px; height: 24px; padding: 0 8px 0 4px; border-top: 1px solid var(--sep-line); font-size: 11px; color: var(--muted); flex: none; }
.pe-errs .e { color: var(--down); margin-right: 8px; }
.pe-errs .w { color: #ff9800; }

/* menus and windows */
.pe-menu { position: fixed; z-index: 1000; min-width: 180px; padding: 6px 0; background: var(--panel); border-radius: 6px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.35); color: var(--text); font-size: 14px; }
.pe-mi { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 34px; padding: 0 12px 0 16px; cursor: default; white-space: nowrap; }
.pe-mi:hover { background: var(--hover); }
.pe-mi.off { color: var(--muted); cursor: default; }
.pe-mi.off:hover { background: none; }
.pe-msep { height: 1px; margin: 6px 0; background: var(--sep-line); }
.pe-submenu { display: none; position: absolute; left: 100%; top: -6px; }
.pe-sub:hover > .pe-submenu { display: block; }
.pe-open { display: flex; flex-direction: column; gap: 8px; min-height: 240px; }
.pe-search { width: 100%; }
.pe-olist { max-height: 52vh; overflow: auto; }
.pe-orow { display: flex; align-items: center; gap: 12px; height: 38px; padding: 0 6px 0 10px; border-radius: 4px; cursor: default; }
.pe-orow:hover { background: var(--hover); }
.pe-orow.cur { background: var(--accent-soft); }
.pe-oname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pe-okind, .pe-odate { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pe-orow .pe-icon { opacity: 0; width: 26px; height: 26px; }
.pe-orow:hover .pe-icon { opacity: 1; }
.pe-field { display: flex; flex-direction: column; gap: 6px; min-width: min(380px, 80vw); }
.pe-field .in { width: 100%; }

/* ---------- code box */
.ce { --ce-gw: 50px; position: relative; flex: 1; display: flex; min-width: 0; min-height: 0; overflow: hidden; font: 13px/20px Menlo, Monaco, Consolas, "Courier New", monospace; color: var(--pe-var); tab-size: 4; -moz-tab-size: 4; }
.ce-measure { position: absolute; visibility: hidden; white-space: pre; font: inherit; }
.ce-gutter { position: relative; width: var(--ce-gw); flex: none; overflow: hidden; }
.ce-gin { position: absolute; inset: 0; }
.ce-ln { position: absolute; right: 14px; height: 20px; color: var(--pe-ln); font-variant-numeric: tabular-nums; user-select: none; }
.ce-ln.cur { color: var(--pe-ln-cur); }
.ce-ln.err::before, .ce-ln.warn::before { content: ""; position: absolute; left: -12px; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--down); }
.ce-ln.warn::before { background: #ff9800; }
.ce-scroll { position: relative; flex: 1; min-width: 0; overflow: auto; scrollbar-color: var(--scroll) transparent; }
.ce-layer { position: absolute; left: 0; top: 0; pointer-events: none; }
.ce-l { position: absolute; left: 6px; height: 20px; white-space: pre; }
.ce-ta { position: absolute; left: 0; top: 0; margin: 0; padding: 4px 6px; border: 0; outline: 0; resize: none; overflow: hidden; background: transparent; color: transparent; caret-color: var(--pe-text); font: inherit; line-height: 20px; white-space: pre; tab-size: 4; -moz-tab-size: 4; word-wrap: normal; overflow-wrap: normal; z-index: 1; }
.ce-ta::selection { background: var(--pe-sel); color: transparent; }
.ce.ro .ce-ta { caret-color: transparent; }
.ce-curline { position: absolute; left: 0; right: 0; height: 20px; background: var(--pe-curline); }
.ce-bracket { position: absolute; height: 20px; background: var(--pe-bracket); outline: 1px solid var(--pe-ln); outline-offset: -1px; }
.ce-match { position: absolute; height: 20px; background: var(--pe-match); }
.ce-match.cur { background: var(--pe-match-cur); outline: 1px solid #ff9800; outline-offset: -1px; }
.ce-squiggle { position: absolute; height: 4px; background: repeating-linear-gradient(135deg, transparent 0 1.5px, var(--down) 1.5px 3px, transparent 3px 4px); background-size: 4px 4px; opacity: 0.95; }
.ce-squiggle.warn { background-image: repeating-linear-gradient(135deg, transparent 0 1.5px, #ff9800 1.5px 3px, transparent 3px 4px); }
.tk-c { color: var(--pe-comment); }
.tk-a { color: var(--pe-comment); font-weight: 700; }
.tk-s { color: var(--pe-string); }
.tk-n { color: var(--pe-num); }
.tk-k { color: var(--pe-kw); }
.tk-t { color: var(--pe-type); font-weight: 700; }
.tk-f { color: var(--pe-func); }
.tk-m { color: var(--pe-call); }
.tk-v { color: var(--pe-const); }
.tk-i { color: var(--pe-var); }
.tk-p { color: var(--pe-text); }

/* find / replace (Monaco's widget, top right) */
.ce-find { position: absolute; top: 0; right: 18px; z-index: 5; display: flex; gap: 2px; padding: 4px 4px 4px 2px; background: var(--pe-widget); box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.36); border-radius: 0 0 4px 4px; font: 13px -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, sans-serif; color: var(--text); }
.ce-find[hidden] { display: none; }
.ce-frows { display: flex; flex-direction: column; gap: 4px; }
.ce-frow { display: flex; align-items: center; gap: 2px; }
.ce-frow[hidden] { display: none; }
.ce-fin { display: flex; align-items: center; width: 240px; height: 26px; padding-right: 2px; background: var(--input); border: 1px solid var(--border); border-radius: 3px; }
.ce-find.bad .ce-frow:first-child .ce-fin { border-color: var(--down); }
.ce-fin input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; padding: 0 6px; }
.ce-fo { width: 22px; height: 20px; border: 1px solid transparent; border-radius: 3px; background: none; color: var(--muted); font: 12px Menlo, monospace; cursor: default; padding: 0; }
.ce-fo.on { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.ce-fcount { min-width: 64px; padding: 0 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.ce-fcount.none { color: var(--down); }
.ce-fx { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 3px; background: none; color: var(--text); cursor: default; padding: 0; }
.ce-fx:hover, .ce-fo:hover { background: var(--btn-hover); }
.ce-fx svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.3; }
.ce-ftog { height: auto; align-self: stretch; }
.ce-find.rep .ce-ftog svg { transform: rotate(90deg); }

/* suggestions and hover help */
.ce-pop { position: absolute; z-index: 6; display: flex; flex-direction: column; width: 440px; max-width: calc(100% - 8px); background: var(--pe-widget); border: 1px solid var(--border); border-radius: 4px; box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.36); }
.ce-pop[hidden] { display: none; }
.ce-plist { max-height: 192px; overflow: auto; }
.ce-pi { display: flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px 0 4px; cursor: default; white-space: nowrap; }
.ce-pi.on { background: var(--pe-curline); }
.ce-pi b { color: var(--accent); font-weight: 700; }
.ce-pk { width: 16px; text-align: center; font-size: 12px; color: var(--muted); flex: none; }
.ce-pk.k-function { color: var(--pe-func); }
.ce-pk.k-variable, .ce-pk.k-constant { color: var(--pe-const); }
.ce-pk.k-keyword, .ce-pk.k-type { color: var(--pe-kw); }
.ce-pn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--pe-var); }
.ce-pt { color: var(--muted); font-size: 11px; font-family: -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, sans-serif; }
.ce-pdoc { border-top: 1px solid var(--border); padding: 6px 10px; font: 12px/1.45 -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, sans-serif; color: var(--text); white-space: normal; }
.ce-sig { font: 12px/1.45 Menlo, Monaco, Consolas, monospace; color: var(--pe-func); margin-bottom: 2px; word-break: break-word; }
.ce-tip { position: absolute; z-index: 7; max-width: min(520px, 90%); padding: 6px 10px; background: var(--pe-widget); border: 1px solid var(--border); border-radius: 4px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); font: 12px/1.45 -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, sans-serif; color: var(--text); white-space: normal; }
.ce-tip[hidden] { display: none; }
.ce-tmsg { margin-bottom: 4px; }
.ce-tmsg.err { color: var(--down); }
.ce-tmsg.warn { color: #ff9800; }
.ce-ttext { margin-bottom: 4px; }
.ce-tref { color: var(--accent); text-decoration: none; font-size: 11px; }
.ce-tref:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .pe-btn span { display: none; }
  .pe-btn { padding: 0 6px; }
  .pe-name { max-width: none; flex: 1 1 auto; min-width: 70px; font-size: 13px; }
  .pe-head .spacer { flex: 0 0 0; }
  .pe-lang { margin-right: 2px; }
  .pe-lang button { padding: 3px 5px; }
  .ce-fin { width: 150px; }
}
