/* Trading Monitor / Market Practice PWA — dark MT5-like theme */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: #0d1117;
  color: #e6edf3;
  font-family: -apple-system, "SF Pro Text", Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
input, button { font-family: inherit; }
.hidden { display: none !important; }

#app { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ── Gate ── */
.gate {
  align-items: center; justify-content: center; gap: 18px;
  padding: 24px calc(16px + env(safe-area-inset-right)) 24px calc(16px + env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 20%, #16202e 0%, #0d1117 65%);
}
.gate-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.gate-logo { padding: 10px; }
.gate h1 { font-size: 26px; font-weight: 800; letter-spacing: .3px; }
.gate-sub { color: #8b949e; text-align: center; line-height: 1.45; }
#gateCode {
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid #30363d;
  background: #161b22; color: #e6edf3; font-size: 17px; text-align: center; letter-spacing: 1px;
  -webkit-user-select: text; user-select: text;
}
#gateCode:focus { outline: none; border-color: #2f81f7; }
.btn-primary {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: #2f81f7; color: #fff; font-size: 17px; font-weight: 700;
}
.btn-primary:active { background: #1f6feb; }
.gate-status { min-height: 20px; color: #f0883e; text-align: center; font-size: 13px; }
.gate-status.ok { color: #3fb950; }
.gate-mode-row { margin-top: 6px; }
.link-btn { background: none; border: none; color: #58a6ff; font-size: 13px; text-decoration: underline; }
.gate-hint {
  position: absolute; bottom: calc(14px + env(safe-area-inset-bottom));
  color: #6e7681; font-size: 12px; text-align: center; padding: 0 24px; line-height: 1.5;
}

/* ── Top bar ── */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px 12px;
  background: #161b22; border-bottom: 1px solid #21262d;
  flex: none;
}
.topbar-left { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 10px; color: #8b949e; font-size: 12px; }
.topbar-right button {
  background: #21262d; color: #c9d1d9; border: 1px solid #30363d; border-radius: 8px;
  width: 32px; height: 28px; font-size: 15px;
}
.topbar-right button.on { color: #f0c040; border-color: #f0c040; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #f85149; display: inline-block; }
.conn-dot.ok { background: #3fb950; }
.conn-dot.wait { background: #f0883e; }
.remote-status {
  display: inline-flex; align-items: center; gap: 5px; margin-left: 8px;
  padding: 3px 8px; border: 1px solid #30363d; border-radius: 999px;
  color: #8b949e; font-size: 10.5px; font-weight: 600;
}
.remote-dot { width: 7px; height: 7px; border-radius: 50%; background: #6e7681; }
.remote-status.on { color: #79c0ff; border-color: #1f6feb; }
.remote-status.on .remote-dot { background: #3fb950; box-shadow: 0 0 7px rgba(63,185,80,.75); }

.banner {
  flex: none; background: #1f2d3d; color: #9fc4ef; padding: 6px 12px; font-size: 12px;
  border-bottom: 1px solid #21262d; text-align: center;
}
.banner.err { background: #3d1f1f; color: #f2a5a0; }

/* ── Tabs area ── */
.tab { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; }
#tab-charts, #tab-replay { overflow-y: auto; }

/* ── Bottom nav ── */
#bottomNav {
  flex: none; display: flex; background: #161b22; border-top: 1px solid #21262d;
  padding-bottom: env(safe-area-inset-bottom);
}
#bottomNav button {
  flex: 1; background: none; border: none; color: #8b949e; padding: 7px 0 6px;
  font-size: 10.5px; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
#bottomNav button.on { color: #58a6ff; }
#bottomNav .nav-ico { font-size: 18px; line-height: 1; }

/* ── Cards / rows ── */
.card {
  background: #161b22; border: 1px solid #21262d; border-radius: 12px;
  margin: 8px 10px; padding: 12px;
}
.card h3 { font-size: 13px; color: #8b949e; font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .5px; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.row .lbl { color: #8b949e; }
.big-num { font-size: 24px; font-weight: 800; }
.pos-num { color: #3fb950; } .neg-num { color: #f85149; } .mut { color: #8b949e; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.stat-cell { background: #0d1117; border: 1px solid #21262d; border-radius: 10px; padding: 8px; text-align: center; }
.stat-cell .v { font-size: 17px; font-weight: 800; }
.stat-cell .k { font-size: 10.5px; color: #8b949e; margin-top: 2px; }

/* quotes */
.quote-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; margin: 6px 10px; background: #161b22; border: 1px solid #21262d; border-radius: 12px;
}
.quote-row .sym { font-weight: 800; font-size: 16px; }
.quote-row .src { color: #6e7681; font-size: 11px; }
.quote-ba { display: flex; gap: 14px; text-align: right; }
.quote-ba .p { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.quote-ba .t { font-size: 10px; color: #8b949e; }

/* ── Chart panes ── */
.chart-toolbar {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; gap: 8px;
}
.chart-toolbar-right { display: flex; align-items: center; gap: 8px; }
.mini-tag { font-size: 9.5px; color: #6e7681; }
.seg { display: inline-flex; background: #161b22; border: 1px solid #30363d; border-radius: 9px; overflow: hidden; }
.seg button {
  background: none; border: none; color: #8b949e; padding: 6px 12px; font-size: 12.5px; font-weight: 600;
  white-space: nowrap;
}
.seg button.on { background: #2f81f7; color: #fff; }
.seg-scroll { overflow-x: auto; max-width: 60vw; -webkit-overflow-scrolling: touch; }
.overlay-seg button { padding-left: 8px; padding-right: 8px; font-size: 10.5px; }
.chart-zoom {
  display: inline-flex; align-items: center; height: 30px; overflow: hidden;
  border: 1px solid #30363d; border-radius: 9px; background: #161b22;
}
.chart-zoom button { width: 28px; height: 28px; border: 0; background: none; color: #c9d1d9; font-size: 16px; }
.chart-zoom span { min-width: 38px; text-align: center; color: #00e0ed; font: 700 10px ui-monospace, monospace; }
.seg-full { display: flex; margin: 6px 10px; }
.seg-full button { flex: 1; }
.btn-mini {
  background: #21262d; color: #c9d1d9; border: 1px solid #30363d; border-radius: 8px;
  padding: 6px 12px; font-size: 12.5px; font-weight: 600;
}
#chartPanes { flex: none; display: flex; flex-direction: column; gap: 2px; padding: 0 4px; }
.pane { position: relative; background: #0b0e13; border: 1px solid #1c2128; border-radius: 8px; overflow: hidden; }
.pane canvas { display: block; width: 100%; height: 27vh; touch-action: none; }
.pane-tall canvas { height: 38vh; }
.pane-head {
  position: absolute; top: 4px; left: 8px; z-index: 2; font-size: 11px; color: #8b949e;
  display: flex; gap: 8px; align-items: center; pointer-events: none;
  text-shadow: 0 1px 2px #000;
}
.pane-head b { color: #c9d1d9; }
.pane-head .cd { color: #f0c040; font-variant-numeric: tabular-nums; }

/* ── Trade panels ── */
.trade-panel { flex: none; padding: 4px 10px 10px; }
.tp-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.btn-sell, .btn-buy {
  flex: 1; padding: 13px 0; border: none; border-radius: 10px; font-size: 15px; font-weight: 800; color: #fff;
}
.btn-sell { background: #d64545; } .btn-sell:active { background: #b73535; }
.btn-buy { background: #1d8a6b; } .btn-buy:active { background: #14705a; }
.btn-sell:disabled, .btn-buy:disabled { opacity: .4; }
.qty-step { display: flex; align-items: center; background: #161b22; border: 1px solid #30363d; border-radius: 10px; }
.qty-step button { width: 40px; height: 44px; background: none; border: none; color: #c9d1d9; font-size: 20px; }
.qty-step .q { min-width: 34px; text-align: center; font-weight: 800; font-size: 16px; }
.sltp-row { display: flex; gap: 8px; margin-top: 8px; }
.sltp-box { flex: 1; background: #161b22; border: 1px solid #30363d; border-radius: 10px; padding: 6px 8px; }
.sltp-box .h { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: #8b949e; }
.sltp-box .val { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.sltp-box .val button { width: 34px; height: 32px; background: #21262d; border: 1px solid #30363d; border-radius: 8px; color: #c9d1d9; font-size: 16px; }
.sltp-box .pv { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13.5px; }
.sltp-box.off { opacity: .45; }
.switch { width: 34px; height: 20px; border-radius: 10px; background: #30363d; border: none; position: relative; }
.switch.on { background: #2f81f7; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on::after { left: 16px; }
.rr-chip { font-size: 11.5px; color: #f0c040; font-weight: 700; }

/* Depth of Market */
#tab-dom { overflow: hidden; background: radial-gradient(circle at 45% 15%, #111c29 0, #090d13 58%); }
.dom-toolbar { border-bottom: 1px solid #21262d; background: rgba(13,17,23,.92); }
.dom-stats { display: flex; align-items: center; gap: 18px; }
.dom-stats > span { display: flex; align-items: baseline; gap: 6px; }
.dom-stats small { color: #6e7681; font-size: 8px; letter-spacing: .8px; }
.dom-stats b { color: #e6edf3; font: 700 11px ui-monospace, monospace; }
.dom-feed { padding: 4px 8px; border: 1px solid #5a4020; border-radius: 999px; color: #f0a030; font-size: 8px; letter-spacing: .65px; }
.dom-feed.live { border-color: #176f50; color: #3fb950; box-shadow: 0 0 10px rgba(63,185,80,.12); }
.dom-workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(500px, 1fr) 350px; gap: 8px; padding: 8px; }
.dom-ladder-card, .dom-ticket-card { min-height: 0; background: rgba(13,17,23,.94); border: 1px solid #25303b; border-radius: 12px; overflow: hidden; box-shadow: 0 18px 60px rgba(0,0,0,.22); }
.dom-ladder-card { display: flex; flex-direction: column; }
.dom-title-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid #21262d; }
.dom-title-row > div:first-child { display: flex; align-items: baseline; gap: 10px; }
.dom-title-row strong { font-size: 18px; color: #fff; }
.dom-title-row span, .dom-hint { color: #6e7681; font-size: 10px; }
.dom-columns, .dom-row { display: grid; grid-template-columns: 70px minmax(100px, 1fr) 130px 95px; align-items: center; }
.dom-columns { padding: 5px 14px; color: #58616d; font-size: 8px; letter-spacing: 1px; border-bottom: 1px solid #1c2128; }
.dom-columns span:nth-child(n+2), .dom-row span:nth-child(n+2) { text-align: right; }
.dom-ladder { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 0; }
.dom-row { position: relative; min-height: 25px; padding: 2px 14px; border: 0; border-bottom: 1px solid rgba(48,54,61,.34); width: 100%; color: #c9d1d9; background: transparent; font: 600 11px ui-monospace, SFMono-Regular, Consolas, monospace; }
.dom-row::before { content: ""; position: absolute; top: 2px; bottom: 2px; right: 0; width: var(--bar, 0%); opacity: .16; pointer-events: none; }
.dom-row.ask::before { background: linear-gradient(90deg, transparent, #ff4c42); }
.dom-row.bid::before { background: linear-gradient(90deg, transparent, #13da72); }
.dom-row:hover { background: rgba(88,166,255,.09); }
.dom-row .side { text-align: left; font-size: 9px; letter-spacing: .8px; }
.dom-row.ask .side, .dom-row.ask .price { color: #ff6b62; }
.dom-row.bid .side, .dom-row.bid .price { color: #38e688; }
.dom-row .price { font-size: 12.5px; font-weight: 800; }
.dom-row .cum { color: #7d8590; }
.dom-mid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; padding: 8px 14px; color: #f0c040; font: 800 12px ui-monospace, monospace; border-top: 1px solid #30363d; border-bottom: 1px solid #30363d; background: linear-gradient(90deg, rgba(19,218,114,.06), rgba(47,129,247,.08), rgba(255,76,66,.06)); }
.dom-mid::before, .dom-mid::after { content: ""; height: 1px; background: #30363d; }
.dom-empty { padding: 48px 20px; text-align: center; color: #6e7681; line-height: 1.55; }
.dom-ticket-card { overflow-y: auto; }
.dom-ticket-head { display: flex; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid #21262d; color: #7d8590; font-size: 9px; letter-spacing: .8px; }
.dom-ticket-head b { color: #58a6ff; font: 800 13px ui-monospace, monospace; letter-spacing: 0; }
#domTradePanel { padding: 6px 14px 14px; }

/* positions list */
.pos-card { background: #161b22; border: 1px solid #21262d; border-radius: 12px; margin: 6px 10px; padding: 10px 12px; }
.pos-head { display: flex; justify-content: space-between; align-items: center; }
.pos-head .s { font-weight: 800; }
.side-buy { color: #3fb950; } .side-sell { color: #f85149; }
.pos-sub { display: flex; justify-content: space-between; color: #8b949e; font-size: 12px; margin-top: 4px; }
.pos-actions { display: flex; gap: 8px; margin-top: 8px; }
.pos-actions button { flex: 1; padding: 8px 0; border-radius: 8px; border: 1px solid #30363d; background: #21262d; color: #c9d1d9; font-size: 12.5px; font-weight: 600; }
.pos-actions .danger { color: #f2a5a0; border-color: #5a2b2b; }

/* replay transport */
#repTransport { flex: none; padding: 2px 12px 4px; }
#repSeek { width: 100%; }
input[type=range] { -webkit-appearance: none; height: 26px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: #30363d; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: #2f81f7; margin-top: -9px; border: 2px solid #0d1117;
}
.transport-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.btn-tr { width: 44px; height: 38px; border-radius: 9px; border: 1px solid #30363d; background: #161b22; color: #c9d1d9; font-size: 14px; }
.btn-play { background: #2f81f7; border-color: #2f81f7; color: #fff; width: 54px; }
.speed-wrap { flex: 1; display: flex; align-items: center; gap: 6px; }
.speed-wrap input { flex: 1; }
#repSpeedLabel { font-size: 11.5px; color: #f0c040; min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }

/* results */
.trade-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #1c2128; font-size: 12.5px; }
.trade-line .r { font-variant-numeric: tabular-nums; font-weight: 700; }

.empty-note { color: #6e7681; text-align: center; padding: 26px 20px; line-height: 1.5; }

/* ── Windows workstation ─────────────────────────────────────────────────── */
@media (min-width: 900px) {
  body { font-size: 13px; }
  .main {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 0;
  }
  #topbar { grid-column: 1 / -1; grid-row: 1; padding: 8px 14px; }
  .banner { grid-column: 1 / -1; grid-row: 2; }
  .tab { grid-column: 2; grid-row: 3; min-width: 0; min-height: 0; }
  #bottomNav {
    grid-column: 1; grid-row: 3; min-height: 0;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    border-top: 0; border-right: 1px solid #21262d; padding: 8px 6px;
  }
  #bottomNav button {
    flex: none; min-height: 64px; border-radius: 9px; padding: 8px 3px;
    font-size: 11px; gap: 5px;
  }
  #bottomNav button:hover { background: #1c222b; color: #c9d1d9; }
  #bottomNav button.on { background: #172439; }
  #bottomNav .nav-ico { font-size: 20px; }
  button { cursor: pointer; }
  button:hover { filter: brightness(1.12); }

  #homeBody, #quotesBody, #positionsBody {
    width: 100%; max-width: 1500px; margin: 0 auto; padding: 8px;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    align-content: start; gap: 2px;
  }
  .card, .quote-row, .pos-card { margin: 6px; }

  #tab-charts {
    display: grid; grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr); overflow: hidden;
  }
  #tab-charts:has(#chartTradePanel:not(.hidden)) {
    grid-template-columns: minmax(0, 1fr) 350px;
  }
  #tab-charts > .chart-toolbar { grid-column: 1 / -1; grid-row: 1; }
  #chartPanes {
    grid-column: 1; grid-row: 2; min-height: 0; height: 100%;
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr) minmax(0, 1.45fr);
    gap: 4px; padding: 0 6px 6px;
  }
  #chartPanes .pane { min-width: 0; min-height: 0; height: 100%; }
  #chartPanes .pane:nth-child(1) { grid-column: 1 / -1; grid-row: 2; }
  #chartPanes .pane:nth-child(2) { grid-column: 1; grid-row: 1; }
  #chartPanes .pane:nth-child(3) { grid-column: 2; grid-row: 1; }
  #chartPanes .pane canvas { width: 100%; height: 100%; min-height: 0; }
  #chartTradePanel {
    grid-column: 2; grid-row: 2; min-height: 0; overflow-y: auto;
    border-left: 1px solid #21262d; background: #0f141b; padding: 10px 14px 14px;
  }
  .overlay-seg { max-width: none; }

  #tab-dom { display: flex; }

  #tab-replay {
    display: grid; grid-template-columns: minmax(0, 1fr) 350px;
    grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden;
  }
  #replayTop { grid-column: 1; grid-row: 1; }
  #tab-replay > .pane-tall { grid-column: 1; grid-row: 2; min-height: 0; margin: 0 6px; }
  #tab-replay > .pane-tall canvas { width: 100%; height: 100%; min-height: 420px; }
  #repTransport { grid-column: 1; grid-row: 3; }
  #repPanelSwitch { grid-column: 2; grid-row: 1; align-self: center; }
  #repTradePanel, #repResults {
    grid-column: 2; grid-row: 2 / 4; min-height: 0; overflow-y: auto;
    border-left: 1px solid #21262d; padding: 4px 10px 12px;
  }

  .gate-hint { display: none; }
}

@media (min-width: 1500px) {
  #tab-charts:has(#chartTradePanel:not(.hidden)), #tab-replay {
    grid-template-columns: minmax(0, 1fr) 390px;
  }
}

@media (max-width: 1100px) {
  .dom-workspace { grid-template-columns: minmax(420px, 1fr) 310px; }
  .dom-columns, .dom-row { grid-template-columns: 54px minmax(80px, 1fr) 105px 75px; }
  .dom-hint { display: none; }
}
