* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #ffffff; color: #131722; display: flex; flex-direction: column; height: 100vh;
}

.toolbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 14px;
  background: #f8f9fd; border-bottom: 1px solid #e0e3eb; flex-wrap: wrap;
}
.brand { font-weight: 600; font-size: 14px; }
.sym-label { font-size: 12px; color: #5d606b; display: flex; align-items: center; gap: 6px; }
.sym-label select {
  background: #fff; color: #131722; border: 1px solid #d1d4dc; border-radius: 4px;
  padding: 4px 8px; font-size: 13px;
}

.tf-group.hidden-layout { display: none; } /* global TF group only applies to layout 1 */
.tf-group { display: flex; gap: 2px; }
.tf-group button {
  background: transparent; color: #5d606b; border: 1px solid transparent; border-radius: 4px;
  padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.tf-group button:hover { background: #eef0f4; color: #131722; }
.tf-group button.active { background: #2962ff; color: #fff; }

/* Layout picker (1 / 2 / 4 chart windows) — grid icons (SVG), same visual language as .tf-group. */
.layout-group { display: flex; gap: 2px; border-left: 1px solid #e0e3eb; padding-left: 12px; }
.layout-group button {
  background: transparent; color: #5d606b; border: 1px solid transparent; border-radius: 4px;
  padding: 5px 7px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.layout-group button svg { width: 15px; height: 15px; display: block; }
.layout-group button svg rect { fill: none; stroke: currentColor; stroke-width: 1.4; }
.layout-group button:hover { background: #eef0f4; color: #131722; }
.layout-group button.active { background: #2962ff; color: #fff; }

.replay-group { display: flex; align-items: center; gap: 6px; }
.replay-group button {
  background: #fff; color: #131722; border: 1px solid #d1d4dc; border-radius: 4px;
  padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.replay-group button:hover { background: #eef0f4; }
.replay-group button.active { background: #ef5350; color: #fff; border-color: #ef5350; }
.replay-group select { background: #fff; color: #131722; border: 1px solid #d1d4dc; border-radius: 4px; padding: 4px 6px; font-size: 12px; }
.replay-clock { font-size: 12px; color: #131722; font-weight: 600; }
.replay-group button.buy { background: #26a69a; color: #fff; border-color: #26a69a; }
.replay-group button.sell { background: #ef5350; color: #fff; border-color: #ef5350; }

/* Trade calculator panel + stats panel (float over the chart). */
.trade-panel {
  position: absolute; top: 10px; right: 70px; z-index: 6; min-width: 250px;
  background: #fff; border: 1px solid #d1d4dc; border-radius: 6px; padding: 8px 10px;
  font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.tp-title { font-weight: 700; margin-bottom: 6px; }
.tp-row { display: flex; gap: 10px; margin-bottom: 6px; }
.tp-row label { display: flex; flex-direction: column; gap: 2px; color: #5d606b; font-size: 11px; flex: 1; }
.tp-row input { border: 1px solid #d1d4dc; border-radius: 4px; padding: 3px 6px; font-size: 12px; }
.tp-metrics { line-height: 1.7; margin-bottom: 8px; }
.tp-actions { display: flex; gap: 6px; }
.tp-actions button { flex: 1; border: 1px solid #d1d4dc; border-radius: 4px; padding: 5px; font-size: 12px; font-weight: 600; cursor: pointer; }
#btnConfirm { background: #2962ff; color: #fff; border-color: #2962ff; }
/* MT5-style bottom terminal */
#terminal { flex-shrink: 0; height: 200px; display: flex; flex-direction: column; background: #f8f9fd; border-top: 1px solid #d1d4dc; font-size: 12px; }
#terminal[hidden] { display: none; }              /* [hidden] must beat the display:flex above */
#terminal.collapsed { height: auto; }              /* collapsed = just the header row */
#terminal.collapsed .term-body { display: none; }
.term-collapse { background: transparent; border: 0; color: #5d606b; cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 6px; }
.term-collapse:hover { color: #131722; }
.term-head { display: flex; align-items: center; gap: 14px; padding: 4px 10px; border-bottom: 1px solid #e0e3eb; }
.term-tabs { display: flex; gap: 2px; }
.term-tab { background: transparent; border: 1px solid transparent; border-radius: 4px 4px 0 0; padding: 4px 12px; font-size: 12px; font-weight: 600; color: #5d606b; cursor: pointer; }
.term-tab.active { background: #fff; color: #131722; border: 1px solid #e0e3eb; border-bottom-color: #fff; }
.term-summary { margin-left: auto; color: #131722; font-weight: 600; }
.term-body { flex: 1; overflow: auto; }
.term-table { width: 100%; border-collapse: collapse; }
.term-table th { text-align: right; padding: 4px 10px; color: #5d606b; font-weight: 600; position: sticky; top: 0; background: #f8f9fd; border-bottom: 1px solid #e0e3eb; }
.term-table th:first-child, .term-table td:first-child { text-align: left; }
.term-table td { text-align: right; padding: 4px 10px; border-bottom: 1px solid #eef0f4; white-space: nowrap; }
.term-empty { padding: 16px; color: #9598a1; text-align: center; }
.term-close { background: #ef5350; color: #fff; border: 0; border-radius: 3px; padding: 2px 7px; cursor: pointer; font-size: 11px; }
.pnl-pos { color: #26a69a; } .pnl-neg { color: #ef5350; }
.type-buy { color: #26a69a; font-weight: 600; } .type-sell { color: #ef5350; font-weight: 600; }

.status { margin-left: auto; font-size: 12px; color: #5d606b; }
.status.err { color: #ef5350; }

/* Multi-tab sync (Phase 06): join-project picker, session indicator, max-loss warning, modal. */
.join-project { position: relative; }
.join-project[hidden] { display: none; }
#btnProjects { background: #fff; color: #131722; border: 1px solid #d1d4dc; border-radius: 4px; padding: 5px 11px; font-size: 12px; font-weight: 600; cursor: pointer; }
#btnProjects:hover { background: #eef0f4; }
.proj-menu { position: absolute; top: 32px; left: 0; z-index: 20; min-width: 220px; background: #fff; border: 1px solid #d1d4dc; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.14); padding: 4px; }
.proj-menu[hidden] { display: none; }
.proj-menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 12px; font-size: 13px; color: #131722; cursor: pointer; border-radius: 4px; }
.proj-menu button:hover { background: #eef0f4; }
.proj-menu .proj-empty { padding: 10px 12px; font-size: 12px; color: #9598a1; }
.session-info { display: flex; align-items: center; gap: 8px; }
.session-info[hidden] { display: none; }
.session-dot { font-size: 12px; font-weight: 600; color: #26a69a; }
.session-dot.disconnected { color: #f0a020; }
.ml-warn { background: #ef5350; color: #fff; font-weight: 700; font-size: 11px; padding: 2px 8px; border-radius: 4px; margin-left: 12px; }
.ml-warn[hidden] { display: none; }

.modal { position: fixed; inset: 0; z-index: 30; background: rgba(19,23,34,.45); display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 10px; padding: 20px 22px; width: 320px; box-shadow: 0 14px 44px rgba(20,30,50,.3); }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.modal-sub { font-size: 12px; color: #5d606b; margin-bottom: 14px; }
.modal-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #5d606b; margin-bottom: 12px; }
.modal-field input { border: 1px solid #d1d4dc; border-radius: 5px; padding: 7px 9px; font-size: 14px; color: #131722; }
.modal-actions { display: flex; gap: 8px; margin-top: 4px; }
.modal-actions button { flex: 1; border: 1px solid #d1d4dc; border-radius: 5px; padding: 8px; font-size: 13px; font-weight: 600; cursor: pointer; background: #fff; color: #131722; }
.modal-actions .pm-ok { background: #2962ff; color: #fff; border-color: #2962ff; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chart-area { flex: 1; position: relative; min-height: 0; }
/* #chart is the grid container; it holds 1/2/4 .chart-panel children (chart-panel.js
   renders lightweight-charts into each). Layout is driven by the .layout-1/2/4 class
   app.js toggles on it — grid-template-columns/rows do the rest, no JS math needed. */
#chart { position: absolute; inset: 0; background: #ffffff; display: grid; gap: 1px; }
#chart.layout-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
#chart.layout-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
#chart.layout-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.chart-panel { position: relative; min-width: 0; min-height: 0; background: #ffffff; overflow: hidden; }
.chart-panel + .chart-panel { border-left: 1px solid #e0e3eb; }
#chart.layout-4 .chart-panel:nth-child(3), #chart.layout-4 .chart-panel:nth-child(4) { border-top: 1px solid #e0e3eb; }

/* Per-panel mini TF selector (Stage 2: live mode, each panel picks its own timeframe). */
.panel-tf {
  position: absolute; top: 8px; right: 10px; z-index: 6;
  background: #fff; color: #131722; border: 1px solid #d1d4dc; border-radius: 4px;
  padding: 2px 5px; font-size: 11px; font-weight: 600; cursor: pointer;
}

.legend {
  position: absolute; top: 10px; left: 12px; z-index: 5;
  font-size: 12px; line-height: 1.6; pointer-events: none;
  display: flex; flex-direction: column; gap: 2px;
  text-shadow: 0 1px 2px rgba(255,255,255,.85);
}
.legend b { font-weight: 600; }
.lg-row { white-space: nowrap; }
.lg-ttl { font-weight: 700; font-size: 13px; color: #131722; }
.lg-dt { color: #5d606b; font-size: 11px; }
.lbl { color: #5d606b; font-size: 11px; }
.lg-vals b { margin-right: 6px; }
/* Indicator rows: clickable, eye appears on hover (TradingView-style). */
.lg-ind { pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 5px; color: #5d606b; }
.lg-ind:hover { color: #131722; }
.lg-ind .eye { display: inline-flex; opacity: 0; transition: opacity .1s; }
.lg-ind:hover .eye { opacity: 1; }
.lg-ind.off { opacity: .4; }
.lg-ind.off .eye { opacity: 1; }
.lg-name { font-size: 12px; }

.ctx-menu {
  position: fixed; z-index: 20; min-width: 180px;
  background: #fff; border: 1px solid #d1d4dc; border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,.14); padding: 4px;
}
.ctx-menu[hidden] { display: none; }
.ctx-menu button {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  padding: 8px 12px; font-size: 13px; color: #131722; cursor: pointer; border-radius: 4px;
}
.ctx-menu button:hover { background: #eef0f4; }
