/* PineChart Theme & Executor Stylesheet */
:root {
  --pc-bg: #131722;
  --pc-bg-elev: #1e222d;
  --pc-bg-panel: #181c27;
  --pc-border: #2a2e39;
  --pc-text: #d1d4dc;
  --pc-text-dim: #787b86;
  --pc-accent: #2962ff;
  --pc-accent-hover: #1e53e5;
  --pc-green: #089981;
  --pc-red: #f23645;
  --pc-yellow: #ffeb3b;
  --pc-font: -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, Ubuntu, sans-serif;
  --pc-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.pc-app, .pc-app * {
  box-sizing: border-box;
}

.pc-app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 680px;
  background: var(--pc-bg);
  color: var(--pc-text);
  font-family: var(--pc-font);
  font-size: 13px;
  overflow: hidden;
  user-select: none;
}

.pc-app.pc-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  height: 100vh;
}

/* Top Toolbar */
.pc-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  background: var(--pc-bg-elev);
  border-bottom: 1px solid var(--pc-border);
  flex-shrink: 0;
  overflow-x: auto;
}

.pc-topbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pc-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  padding-right: 8px;
  border-right: 1px solid var(--pc-border);
  white-space: nowrap;
}

.pc-select, .pc-btn {
  background: transparent;
  color: var(--pc-text);
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 5px 9px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.pc-select {
  background: #232734;
  border-color: var(--pc-border);
  font-weight: 600;
}

.pc-select:hover, .pc-btn:hover {
  background: #2a2e39;
  color: #fff;
}

.pc-btn.active {
  background: rgba(41, 98, 255, 0.2);
  color: #6b9bff;
  border-color: rgba(41, 98, 255, 0.45);
}

.pc-btn-primary {
  background: var(--pc-accent);
  color: #fff;
  font-weight: 600;
  padding: 6px 13px;
}

.pc-btn-primary:hover {
  background: var(--pc-accent-hover);
  color: #fff;
}

.pc-btn-green {
  background: rgba(8, 153, 129, 0.18);
  color: #26a69a;
  border: 1px solid rgba(8, 153, 129, 0.4);
  font-weight: 600;
}

.pc-btn-green:hover {
  background: rgba(8, 153, 129, 0.32);
}

.pc-tf-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 4px;
  border-left: 1px solid var(--pc-border);
  border-right: 1px solid var(--pc-border);
}

.pc-tf-btn {
  padding: 4px 7px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--pc-text-dim);
  background: transparent;
  border: none;
  cursor: pointer;
}

.pc-tf-btn:hover {
  color: #fff;
  background: #2a2e39;
}

.pc-tf-btn.active {
  color: #6b9bff;
  background: rgba(41, 98, 255, 0.16);
}

/* Main Workspace */
.pc-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* Left Drawing Bar */
.pc-drawbar {
  width: 42px;
  background: var(--pc-bg-elev);
  border-right: 1px solid var(--pc-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 4px;
  flex-shrink: 0;
}

.pc-tool-btn {
  width: 30px;
  height: 30px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--pc-text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.pc-tool-btn:hover {
  background: #2a2e39;
  color: #fff;
}

.pc-tool-btn.active {
  background: rgba(41, 98, 255, 0.22);
  color: #6b9bff;
}

.pc-tool-sep {
  width: 24px;
  height: 1px;
  background: var(--pc-border);
  margin: 4px 0;
}

/* Chart Column */
.pc-chart-col {
  flex: 1;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  background: #0b0e14;
  position: relative;
  overflow: hidden;
}

.pc-main-chart-wrap {
  position: relative;
  flex: 1;
  min-height: 200px;
  width: 100%;
}

.pc-pane-chart-wrap {
  position: relative;
  height: 190px;
  min-height: 120px;
  border-top: 2px solid var(--pc-border);
  width: 100%;
  display: none;
}

.pc-pane-chart-wrap.visible {
  display: block;
}

.pc-chart-mount {
  position: absolute;
  inset: 0;
}

.pc-overlay-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.pc-overlay-canvas.drawing-active {
  pointer-events: auto;
  cursor: crosshair;
}

/* Chart HUD Overlay */
.pc-hud {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 6;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: calc(100% - 90px);
}

.pc-hud-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: auto;
}

.pc-symbol-title {
  font-weight: 700;
  font-size: 13px;
  color: #e6e9f0;
  background: rgba(19, 23, 34, 0.72);
  padding: 2px 7px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pc-ohlc {
  font-family: var(--pc-mono);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(19, 23, 34, 0.72);
  padding: 2px 7px;
  border-radius: 4px;
}

.pc-ohlc span b {
  color: var(--pc-text-dim);
  font-weight: 500;
  margin-right: 2px;
}

.pc-up { color: #089981; }
.pc-dn { color: #f23645; }

/* Buy / Sell quick buttons matching screenshot */
.pc-trade-strip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  pointer-events: auto;
}

.pc-order-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid;
  font-family: var(--pc-mono);
  transition: transform 0.08s;
}

.pc-order-box:active { transform: scale(0.97); }

.pc-order-sell {
  background: rgba(242, 54, 69, 0.14);
  border-color: rgba(242, 54, 69, 0.7);
  color: #ff6b78;
}

.pc-order-buy {
  background: rgba(41, 98, 255, 0.16);
  border-color: rgba(41, 98, 255, 0.8);
  color: #6b9bff;
}

.pc-order-px { font-size: 11px; font-weight: 700; }
.pc-order-lbl { font-size: 9px; letter-spacing: 0.5px; opacity: 0.9; }

.pc-spread {
  font-size: 10px;
  color: var(--pc-text-dim);
  padding: 0 3px;
  font-family: var(--pc-mono);
}

.pc-indicator-legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(19, 23, 34, 0.78);
  border: 1px solid rgba(42, 46, 57, 0.7);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  pointer-events: auto;
}

.pc-legend-actions {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
}

.pc-icon-mini {
  background: transparent;
  border: none;
  color: var(--pc-text-dim);
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

.pc-icon-mini:hover {
  background: #2a2e39;
  color: #fff;
}

.pc-pane-legend {
  position: absolute;
  top: 6px;
  left: 10px;
  z-index: 6;
  background: rgba(19, 23, 34, 0.78);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--pc-text);
  pointer-events: none;
}

/* Resizable Splitter */
.pc-splitter {
  width: 5px;
  background: var(--pc-border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
}

.pc-splitter:hover, .pc-splitter.dragging {
  background: var(--pc-accent);
}

/* Right Pine Editor Column */
.pc-editor-col {
  width: 46%;
  min-width: 320px;
  max-width: 78%;
  display: flex;
  flex-direction: column;
  background: var(--pc-bg-panel);
  border-left: 1px solid var(--pc-border);
}

.pc-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 10px;
  background: var(--pc-bg-elev);
  border-bottom: 1px solid var(--pc-border);
  flex-wrap: wrap;
}

.pc-editor-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: #fff;
}

.pc-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(41, 98, 255, 0.2);
  color: #7aa7ff;
  font-weight: 600;
}

/* Code Editor Container */
.pc-code-wrap {
  flex: 1;
  min-height: 180px;
  display: flex;
  position: relative;
  overflow: hidden;
  background: #131722;
}

.pc-line-nums {
  width: 44px;
  padding: 12px 6px;
  background: #161a25;
  border-right: 1px solid #222633;
  color: #565c6e;
  font-family: var(--pc-mono);
  font-size: 12.5px;
  line-height: 1.55;
  text-align: right;
  overflow: hidden;
  flex-shrink: 0;
  user-select: none;
}

.pc-code-scroll {
  position: relative;
  flex: 1;
  overflow: auto;
}

.pc-code-highlight, .pc-code-input {
  margin: 0;
  padding: 12px 14px;
  font-family: var(--pc-mono);
  font-size: 12.5px;
  line-height: 1.55;
  tab-size: 4;
  white-space: pre;
  word-wrap: normal;
  border: none;
  outline: none;
  min-width: 100%;
  min-height: 100%;
}

.pc-code-highlight {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  color: #d1d4dc;
}

.pc-code-input {
  position: relative;
  width: 100%;
  height: 100%;
  background: transparent;
  color: transparent;
  caret-color: #ffffff;
  resize: none;
  user-select: text;
  overflow: auto;
}

/* Syntax tokens */
.tok-comm { color: #6a737d; font-style: italic; }
.tok-str  { color: #98c379; }
.tok-num  { color: #d19a66; }
.tok-kw   { color: #c678dd; font-weight: 600; }
.tok-ns   { color: #56b6c2; }
.tok-fn   { color: #61afef; }
.tok-var  { color: #e5c07b; }

/* Bottom Drawer (Console / Strategy / Inputs) */
.pc-drawer {
  height: 215px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--pc-border);
  background: var(--pc-bg-elev);
}

.pc-drawer-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  border-bottom: 1px solid var(--pc-border);
  height: 34px;
  flex-shrink: 0;
}

.pc-tab-list {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pc-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--pc-text-dim);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.pc-tab-btn.active {
  color: #fff;
  border-bottom-color: var(--pc-accent);
}

.pc-drawer-body {
  flex: 1;
  overflow: auto;
  padding: 10px 12px;
  font-size: 12px;
  user-select: text;
}

.pc-log-ok { color: #26a69a; font-family: var(--pc-mono); margin-bottom: 6px; }
.pc-log-err {
  color: #ff6b78;
  background: rgba(242, 54, 69, 0.12);
  border: 1px solid rgba(242, 54, 69, 0.35);
  padding: 8px 10px;
  border-radius: 5px;
  font-family: var(--pc-mono);
}
.pc-log-meta { color: var(--pc-text-dim); font-family: var(--pc-mono); line-height: 1.6; }

/* Strategy Tester Grid & Table */
.pc-strat-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.pc-kpi-card {
  background: #131722;
  border: 1px solid var(--pc-border);
  border-radius: 6px;
  padding: 7px 9px;
}

.pc-kpi-lbl { font-size: 10px; color: var(--pc-text-dim); text-transform: uppercase; }
.pc-kpi-val { font-size: 14px; font-weight: 700; font-family: var(--pc-mono); margin-top: 2px; }

.pc-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--pc-mono);
  font-size: 11px;
}

.pc-table th, .pc-table td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid #242834;
}

.pc-table th {
  color: var(--pc-text-dim);
  font-weight: 600;
}

/* Inputs Panel & Settings Modal */
.pc-inputs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}

.pc-input-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #131722;
  border: 1px solid var(--pc-border);
  padding: 7px 9px;
  border-radius: 5px;
}

.pc-input-item label {
  font-size: 11px;
  color: var(--pc-text-dim);
  display: flex;
  justify-content: space-between;
}

.pc-input-item input, .pc-input-item select {
  background: #1e222d;
  border: 1px solid var(--pc-border);
  color: #fff;
  border-radius: 4px;
  padding: 4px 7px;
  font-size: 12px;
  font-family: var(--pc-mono);
}

/* Modal */
.pc-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.pc-modal-backdrop.open {
  display: flex;
}

.pc-modal {
  width: min(560px, 92vw);
  max-height: 82vh;
  background: var(--pc-bg-elev);
  border: 1px solid var(--pc-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.pc-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--pc-border);
  font-weight: 700;
  font-size: 14px;
}

.pc-modal-body {
  padding: 14px 16px;
  overflow: auto;
  flex: 1;
}

.pc-modal-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--pc-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.pc-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6b9bff;
  margin: 12px 0 6px;
}

.pc-group-title:first-child { margin-top: 0; }

/* Responsive layout for smaller viewports */
@media (max-width: 960px) {
  .pc-workspace {
    flex-direction: column;
  }
  .pc-drawbar {
    display: none;
  }
  .pc-splitter {
    display: none;
  }
  .pc-editor-col {
    width: 100% !important;
    max-width: 100%;
    height: 46%;
    border-left: none;
    border-top: 1px solid var(--pc-border);
  }
}

.pc-hidden {
  display: none !important;
}
