/* TradingView-like studio on Trendbot gold/black */
body.tv-lock { overflow: hidden; }
.tv-shell {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-areas:
    "top top top"
    "left chart right"
    "left bottom right";
  grid-template-rows: auto 1fr 220px;
  grid-template-columns: 52px 1fr 280px;
  background: #050505;
}
.tv-top {
  grid-area: top;
  display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap;
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid rgba(212,175,55,0.14);
  background: #0a0a0a;
}
.tv-main {
  display: none;
  grid-area: main;
  overflow: auto;
  background: #070707;
  padding: 1.25rem 1.5rem 2.5rem;
}
.tv-shell.ws-doc .tv-tf,
.tv-shell.ws-notes .tv-tf,
.tv-shell.ws-pine .tv-tf { display: none; }
.tv-shell.ws-doc,
.tv-shell.ws-notes,
.tv-shell.ws-pine {
  grid-template-areas: "top" "main";
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
}
.tv-shell.ws-doc .tv-left,
.tv-shell.ws-doc .tv-chart,
.tv-shell.ws-doc .tv-right,
.tv-shell.ws-doc .tv-bottom,
.tv-shell.ws-notes .tv-left,
.tv-shell.ws-notes .tv-chart,
.tv-shell.ws-notes .tv-right,
.tv-shell.ws-notes .tv-bottom,
.tv-shell.ws-pine .tv-left,
.tv-shell.ws-pine .tv-chart,
.tv-shell.ws-pine .tv-right,
.tv-shell.ws-pine .tv-bottom { display: none; }
.tv-shell.ws-doc .tv-main,
.tv-shell.ws-notes .tv-main,
.tv-shell.ws-pine .tv-main { display: block; }
.tv-ws {
  display: flex; gap: 0.3rem; flex-wrap: wrap;
  margin-right: 0.4rem;
}
.tv-ws button {
  background: transparent; border: 1px solid rgba(212,175,55,0.18);
  color: var(--muted); border-radius: 8px; padding: 0.32rem 0.75rem;
  font-size: 0.78rem; font-weight: 700; cursor: pointer;
}
.tv-ws button.active { color: #111; background: linear-gradient(135deg,#c9a227,#f0d78c); border-color: #d4af37; }
.lang-box { display: none; }
.lang-bar {
  display: flex; align-items: flex-end; gap: 0.7rem; flex-wrap: wrap;
  background: #111; border: 1px solid rgba(212,175,55,0.28);
  border-radius: 12px; padding: 0.85rem 1rem; margin-top: 0.85rem;
}
.lang-bar label { margin: 0; color: var(--gold-light); font-weight: 800; font-size: 0.78rem; }
.lang-bar select { min-width: 16rem; margin: 0; }
.doc-grid {
  display: grid; grid-template-columns: 1fr; gap: 1.1rem;
  max-width: 980px; margin: 0 auto;
}
.doc-sec { margin-bottom: 0; }
.doc-sec textarea { min-height: 150px; resize: vertical; font-size: 1rem; line-height: 1.6; }
.doc-sec.wide textarea { min-height: 220px; }
#pane-notes textarea, #pine-view { min-height: calc(100vh - 160px); font-size: 0.95rem; }
.doc-head {
  max-width: 980px; margin: 0 auto 1.1rem;
}
.tv-left {
  grid-area: left;
  border-right: 1px solid rgba(212,175,55,0.12);
  display: flex; flex-direction: column; align-items: center; gap: 0.45rem;
  padding: 0.6rem 0.25rem; background: #080808;
}
.tv-left button {
  width: 38px; height: 38px; border-radius: 8px;
  background: transparent; border: 1px solid transparent; color: var(--muted); cursor: pointer;
}
.tv-left button:hover, .tv-left button.active {
  border-color: rgba(212,175,55,0.35); color: var(--gold-light); background: rgba(212,175,55,0.08);
}
.tv-chart {
  grid-area: chart;
  position: relative; min-height: 0; background: #050505;
  overflow: hidden;
  touch-action: none;
}
.tv-chart.dragging, .tv-chart.dragging canvas { cursor: grabbing; }
.tv-shell.ws-chart {
  --tester-h: 280px;
  grid-template-areas:
    "top top"
    "left chart"
    "left tester";
  grid-template-columns: 48px 1fr;
  grid-template-rows: auto 1fr 56px;
}
.tv-shell.ws-chart.tester-open {
  grid-template-rows: auto 1fr var(--tester-h);
}
.tv-shell.ws-chart .tv-main { display: none; }
.tv-shell.ws-chart .tv-pine { display: none; }
.tv-shell.ws-chart.pine-open .tv-pine { display: flex; }
.tv-chart-tools {
  position: absolute; top: 10px; left: 10px; z-index: 4;
  display: flex; gap: 0.3rem;
}
.tv-chart-tools button {
  background: #111; color: var(--gold-light);
  border: 1px solid rgba(212,175,55,0.3);
  border-radius: 6px; min-width: 32px; height: 28px;
  font-weight: 800; cursor: pointer;
}
.tv-chart-hud {
  position: absolute; bottom: 8px; left: 12px; z-index: 2;
  font-size: 0.72rem; color: var(--muted); pointer-events: none;
}
.tv-pine {
  display: none;
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(440px, 42vw);
  flex-direction: column;
  border-left: 1px solid rgba(212,175,55,0.18);
  background: rgba(11,11,11,0.96);
  z-index: 5; min-height: 0;
}
.pine-dock-h {
  padding: 0.65rem 0.8rem 0.4rem;
  border-bottom: 1px solid rgba(212,175,55,0.1);
  display: flex; justify-content: space-between; gap: 0.6rem; align-items: flex-start;
}
.pine-live {
  flex: 1; overflow: auto; font-family: ui-monospace, Consolas, monospace;
  font-size: 0.78rem; line-height: 1.5; color: #d6d0c4;
}
.pine-line { display: flex; gap: 0.55rem; padding: 0 0.5rem; white-space: pre; }
.pine-line .ln { width: 2.2rem; color: #6b6560; text-align: right; flex-shrink: 0; }
.pine-line.hl { background: rgba(212,175,55,0.16); color: #f0d78c; }
.tester-resizer {
  position: absolute; top: 0; left: 0; right: 0; height: 8px;
  background: transparent; border: 0; cursor: ns-resize; z-index: 3;
}
.tester-resizer:hover { background: rgba(212,175,55,0.25); }
.tester-head { display: flex; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; padding: 0.45rem 0.75rem; align-items: center; }
.tv-kpis { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); gap: 0.4rem; flex: 1; min-width: 280px; }
.tv-kpi {
  background: #111; border: 1px solid rgba(212,175,55,0.12);
  border-radius: 8px; padding: 0.35rem 0.5rem;
}
.tv-kpi .lab { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.tv-kpi .v { font-weight: 800; font-size: 0.88rem; }
.tv-kpi .v.pos, td.pos { color: #26a69a; }
.tv-kpi .v.neg, td.neg { color: #ef5350; }
.tv-tabs { display: flex; gap: 0.3rem; padding: 0.25rem 0.75rem; }
.tv-tabs button {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 0.3rem 0.55rem; cursor: pointer; font-weight: 700; font-size: 0.78rem;
}
.tv-tabs button.active { color: var(--gold-light); border-bottom-color: var(--gold); }
.tester-body { display: none; overflow: auto; min-height: 0; flex: 1; }
.tv-shell.tester-open .tester-body { display: flex; flex-direction: column; }
.tester-pane { padding: 0.4rem 0.75rem 0.75rem; overflow: auto; min-height: 0; flex: 1; }
.tester-split { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 0.8rem; }
.mini-pane { width: 100%; height: 140px; display: block; background: #0a0a0a; border-radius: 8px; }
.lab { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 0.3rem; }
.donut-wrap { display: flex; align-items: center; gap: 0.8rem; }
.donut { width: 92px; height: 92px; border-radius: 50%; background: #222; flex-shrink: 0;
  mask: radial-gradient(circle at center, transparent 48%, #000 50%);
  -webkit-mask: radial-gradient(circle at center, transparent 48%, #000 50%);
}
.sig-row { display: grid; grid-template-columns: 140px 1fr auto; gap: 0.5rem; align-items: center; margin: 0.28rem 0; font-size: 0.78rem; }
.sig-bar { display: flex; height: 10px; background: #1a1a1a; border-radius: 6px; overflow: hidden; justify-content: flex-end; }
.sig-bar .win { background: #26a69a; display: block; height: 100%; }
.sig-bar .loss { background: #ef5350; display: block; height: 100%; }
.tv-bottom .table-scroll { max-height: none; height: 100%; overflow: auto; }
.tv-right { grid-area: right; }
.tv-shell.ws-chart .tv-pine { padding: 0; overflow: hidden; }
.tv-chart canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block; cursor: grab;
  touch-action: none;
}
.tv-bottom {
  grid-area: bottom;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-top: 1px solid rgba(212,175,55,0.12);
  background: #080808;
  overflow: hidden;
}
.tv-shell.ws-chart .tv-bottom { grid-area: tester; }
.tv-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; margin: 0.65rem 0 0.85rem; }
.tv-metric {
  background: #111; border: 1px solid rgba(212,175,55,0.12);
  border-radius: 8px; padding: 0.45rem 0.55rem;
}
.tv-metric .lab { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.tv-metric .v { font-weight: 800; color: var(--gold-light); font-size: 0.95rem; }
.tv-tf { display: flex; gap: 0.25rem; margin-left: auto; }
.tv-tf button {
  background: transparent; border: 1px solid rgba(212,175,55,0.18);
  color: var(--muted); border-radius: 6px; padding: 0.2rem 0.45rem;
  font-size: 0.72rem; cursor: pointer;
}
.tv-tf button.active { color: var(--gold-light); border-color: var(--gold); background: rgba(212,175,55,0.12); }
.trade-row { cursor: pointer; }
.trade-row.sel td { background: rgba(212,175,55,0.12); }
.trade-row td { line-height: 1.4; white-space: nowrap; }
.trade-row td b { font-weight: 700; }
.mkt-section { max-width: 1240px; margin: 0 auto 3rem; padding: 0 2rem; }
.tv-symbol {
  font-weight: 800; color: var(--gold-light); letter-spacing: 0.04em;
}
.tv-chip {
  font-size: 0.72rem; padding: 0.2rem 0.5rem; border-radius: 6px;
  border: 1px solid rgba(212,175,55,0.2); color: var(--muted);
}
.mkt-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem;
}
.mkt-card {
  display: block; color: inherit; text-decoration: none;
  background: linear-gradient(165deg, #141414, #0a0a0a);
  border: 1px solid rgba(212,175,55,0.16); border-radius: 14px; padding: 1.1rem;
  cursor: pointer; min-height: 180px;
}
.mkt-card:hover { border-color: rgba(212,175,55,0.4); transform: translateY(-2px); }
.mkt-card .ret { font-size: 1.35rem; font-weight: 800; }
.mkt-card .ret.pos { color: var(--green); }
.mkt-card .ret.neg { color: #fca5a5; }
.hero-tv {
  display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 2rem; align-items: center;
  padding: 2.5rem 0 1.5rem;
}
.mini-chart {
  height: 280px; border-radius: 16px; border: 1px solid rgba(212,175,55,0.16);
  background: #070707; overflow: hidden; position: relative;
}
.mini-chart canvas { width: 100%; height: 100%; }
.clarify { color: #fde68a; font-size: 0.78rem; }
@media (max-width: 960px) {
  .tv-shell:not(.ws-doc):not(.ws-notes):not(.ws-pine),
  .tv-shell.ws-chart {
    grid-template-areas:
      "top"
      "left"
      "chart"
      "tester";
    grid-template-columns: 1fr;
    grid-template-rows: auto 42px 1fr 56px;
  }
  .tv-shell.ws-chart.tester-open {
    grid-template-rows: auto 42px 1fr minmax(180px, 40vh);
  }
  .tv-pine { width: 100%; }
  .tv-left { flex-direction: row; justify-content: flex-start; padding: 0.3rem 0.5rem; overflow-x: auto; }
  .lang-bar select { min-width: 100%; }
  .hero-tv { grid-template-columns: 1fr; }
  .mkt-section { padding-left: 1.25rem; padding-right: 1.25rem; }
  .tv-kpis, .tester-split { grid-template-columns: 1fr 1fr; }
}

/* Strategy Studio v2 — stable TradingView-style workspaces */
body.studio-app {
  min-height: 100vh;
  overflow-y: auto;
  background: #050505;
  color: #e8e4dc;
}
.studio-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  min-height: 62px;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid rgba(212,175,55,0.18);
  background: rgba(8,8,8,0.97);
  backdrop-filter: blur(12px);
}
.studio-brand,
.studio-actions,
.studio-nav,
.studio-status-line,
.chart-toolbar,
.chart-meta,
.chart-footer,
.language-controls,
.trade-filters,
.trades-summary,
.pagination {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.studio-brand .nav-mark { width: 36px; height: 36px; flex: 0 0 36px; }
.studio-brand strong { color: var(--gold-light); font-size: 0.95rem; }
.studio-status-line { margin-top: 0.2rem; gap: 0.35rem; white-space: nowrap; }
.studio-status-line .muted { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.studio-nav { justify-content: center; flex-wrap: wrap; }
.studio-nav button {
  padding: 0.45rem 0.8rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}
.studio-nav button:hover,
.studio-nav button.active {
  color: var(--gold-light);
  border-bottom-color: var(--gold);
}
.studio-actions { justify-content: flex-end; flex-wrap: wrap; }
.data-state {
  padding: 0.15rem 0.45rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 900;
}
.data-state.live { color: #2dd4bf; }
.data-state.historical { color: #60a5fa; }
.data-state.delayed { color: #fbbf24; }
.data-state.unavailable { color: #f87171; }
.studio-content { min-height: calc(100vh - 62px); }
.studio-workspace {
  display: none;
  min-height: calc(100vh - 62px);
  padding: 1.25rem;
}
.studio-workspace.active { display: block; }
#workspace-chart.active {
  display: grid;
  grid-template-rows: auto auto minmax(540px, calc(100vh - 190px)) auto;
  padding: 0;
  min-height: calc(100vh - 62px);
}
.chart-toolbar {
  flex-wrap: wrap;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid rgba(212,175,55,0.12);
  background: #0b0b0b;
}
.chart-toolbar label,
.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
}
.chart-toolbar input[type="date"] {
  width: 145px;
  padding: 0.32rem 0.45rem;
}
.toggle-label input { width: auto; accent-color: var(--gold); }
.tf-group { display: flex; gap: 0.2rem; }
.tf-group button {
  min-width: 38px;
  padding: 0.35rem 0.5rem;
  border: 1px solid rgba(212,175,55,0.2);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tf-group button.active {
  color: #111;
  border-color: var(--gold);
  background: var(--gold);
  font-weight: 900;
}
.chart-meta,
.chart-footer {
  justify-content: space-between;
  padding: 0.35rem 0.9rem;
  background: #070707;
  color: var(--muted);
  font-size: 0.72rem;
  border-bottom: 1px solid rgba(212,175,55,0.08);
}
.chart-meta #chart-symbol { color: var(--gold-light); font-weight: 900; }
.strategy-chart {
  position: relative;
  width: 100%;
  min-height: 540px;
  background: #050505;
}
.chart-loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(5,5,5,0.74);
  color: var(--gold-light);
  font-weight: 900;
}
.chart-footer {
  border-top: 1px solid rgba(212,175,55,0.1);
  border-bottom: 0;
}
.workspace-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  max-width: 1500px;
  margin: 0 auto 1.25rem;
}
.workspace-heading h1,
.workspace-heading h2 { margin: 0.12rem 0; }
.performance-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 0.8rem;
  max-width: 1500px;
  margin: 0 auto 1rem;
}
.performance-kpi,
.studio-card {
  border: 1px solid rgba(212,175,55,0.15);
  border-radius: 12px;
  background: #0c0c0c;
}
.performance-kpi { padding: 0.8rem 1rem; }
.performance-kpi .label,
.card-title {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.performance-kpi .value { margin-top: 0.25rem; font-size: 1.25rem; font-weight: 900; }
.performance-kpi .value.pos { color: #2dd4bf; }
.performance-kpi .value.neg { color: #f87171; }
.performance-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr;
  gap: 1rem;
  max-width: 1500px;
  margin: 0 auto;
}
.studio-card { min-height: 240px; padding: 1rem; }
.studio-card.wide { grid-column: 1 / -1; }
.performance-chart { width: 100%; height: 320px; margin-top: 0.5rem; }
.trade-mix { display: flex; align-items: center; justify-content: center; gap: 1.2rem; min-height: 180px; }
.trade-mix .donut { width: 130px; height: 130px; }
.detail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 0.8rem;
}
.detail-stat { padding: 0.6rem; border-bottom: 1px solid rgba(212,175,55,0.1); }
.detail-stat span { display: block; color: var(--muted); font-size: 0.68rem; }
.detail-stat strong { display: block; margin-top: 0.15rem; }
.signal-breakdown-row {
  display: grid;
  grid-template-columns: minmax(140px, 0.5fr) 2fr 110px;
  gap: 0.7rem;
  align-items: center;
  margin: 0.65rem 0;
}
.signal-breakdown-bar { display: flex; height: 16px; overflow: hidden; border-radius: 5px; background: #181818; }
.signal-breakdown-bar .loss { background: #ef5350; }
.signal-breakdown-bar .win { background: #26a69a; }
.trade-filters { flex-wrap: wrap; }
.trade-filters input { min-width: 240px; }
.trade-filters select { min-width: 130px; }
.trades-summary { max-width: 1500px; margin: 0 auto 0.7rem; color: var(--muted); }
.studio-table-wrap {
  max-width: 1500px;
  margin: 0 auto;
  overflow: auto;
  border: 1px solid rgba(212,175,55,0.14);
  border-radius: 10px;
  background: #090909;
}
.studio-trades-table { width: 100%; border-collapse: collapse; min-width: 1100px; }
.studio-trades-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0.75rem;
  background: #111;
  color: var(--muted);
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
}
.studio-trades-table td {
  padding: 0.8rem 0.75rem;
  border-top: 1px solid rgba(212,175,55,0.08);
  vertical-align: top;
  white-space: nowrap;
  font-size: 0.82rem;
}
.studio-trades-table tbody tr:hover { background: rgba(212,175,55,0.06); }
.trade-time { display: block; color: #e8e4dc; font-weight: 700; }
.trade-price { display: block; color: var(--muted); margin-top: 0.2rem; }
.pagination { justify-content: center; margin: 1rem auto; }
.doc-heading { align-items: center; }
.language-controls { flex-wrap: wrap; }
.language-controls label { margin: 0; }
.language-controls select { width: auto; min-width: 220px; }
.document-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}
.document-section {
  padding: 0.9rem;
  border: 1px solid rgba(212,175,55,0.14);
  border-radius: 10px;
  background: #0b0b0b;
}
.document-section.wide { grid-column: 1 / -1; }
.document-section textarea { min-height: 150px; resize: vertical; line-height: 1.55; }
.document-section.wide textarea { min-height: 210px; }
.notes-card { max-width: 1200px; margin: 1rem auto; }
.notes-card textarea { min-height: 180px; margin: 0.7rem 0; }
.pine-export {
  max-width: 1300px;
  min-height: 70vh;
  max-height: none;
  margin: 0 auto;
  overflow: auto;
  padding: 1.2rem;
  border: 1px solid rgba(212,175,55,0.15);
  border-radius: 10px;
  background: #090909;
  color: #ddd6c8;
  font: 0.85rem/1.55 Consolas, monospace;
  white-space: pre;
}
.history-dialog {
  width: min(1200px, 94vw);
  max-height: 88vh;
  padding: 1rem;
  border: 1px solid rgba(212,175,55,0.28);
  border-radius: 12px;
  background: #090909;
  color: #e8e4dc;
}
.history-dialog::backdrop { background: rgba(0,0,0,0.8); }
.studio-workspace:fullscreen {
  overflow: auto;
  padding: 1.2rem;
  background: #050505;
}

@media (max-width: 1100px) {
  .studio-header { grid-template-columns: 1fr; }
  .studio-nav { justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; }
  .studio-actions { justify-content: flex-start; }
  .performance-kpis { grid-template-columns: 1fr 1fr; }
  .performance-grid { grid-template-columns: 1fr; }
  .studio-card.wide { grid-column: auto; }
}
@media (max-width: 700px) {
  .studio-workspace { padding: 0.8rem; }
  #workspace-chart.active { grid-template-rows: auto auto minmax(430px, 65vh) auto; }
  .strategy-chart { min-height: 430px; }
  .performance-kpis,
  .document-grid,
  .detail-stats { grid-template-columns: 1fr; }
  .document-section.wide { grid-column: auto; }
  .chart-toolbar input[type="date"] { width: 132px; }
}
