/* Mobile interaction layer, shared by every dashboard page. */
.trader-mobile-only, .trader-trade-cards { display: none; }
@media (max-width: 991.98px) {
  html { scroll-padding-block: 5rem; }
  body { --trader-viewport-height: 100dvh; }
  body .layout-page, body .content-wrapper, body .container-p-y { min-width: 0; }
  body .container-p-y { padding-inline: max(.75rem, env(safe-area-inset-left), env(safe-area-inset-right)) !important; }
  body .card-body, body .trade-detail-box { min-width: 0; }
  body .card-body > .d-flex, body .rank-head > .d-flex { flex-wrap: wrap; gap: .65rem; }
  body .card-body > .d-flex > *, body .row > * { min-width: 0; }
  body .btn, body .btn-sm, body .btn-icon, body summary, body .menu-link { min-height: 44px; }
  body .btn { white-space: normal; overflow-wrap: anywhere; }
  body .btn-icon { min-width: 44px; }
  body .btn-close { flex: 0 0 44px; width: 44px; height: 44px; padding: 0; margin: 0 !important; background-size: 14px; }
  body .form-control, body .form-select, body .select2-selection { font-size: 16px !important; min-height: 44px; max-width: 100%; }
  body .form-switch .form-check-input { width: 2.75rem; min-width: 2.75rem; height: 1.5rem; }
  body .form-check, body .switch { min-height: 44px; align-content: center; }
  body .switch-label { white-space: normal; }
  body .input-group { flex-wrap: wrap; }
  body .input-group > .form-control { min-width: 4rem; }
  body .btn-group { flex-wrap: wrap; gap: .25rem; }
  body .btn-group > .btn { border-radius: .375rem !important; margin: 0; }
  body .exchange-switch { display: flex; flex-wrap: wrap; width: 100%; }
  body .exchange-switch form { flex: 1 1 45%; }
  body .exchange-switch .btn { min-width: 0; width: 100%; }
  body .exchange-card-meta { flex-wrap: wrap; gap: .5rem; }
  body .exchange-key-hint { overflow-wrap: anywhere; }
  body .scanner-model-bar, body .scanner-filter-groups { grid-template-columns: minmax(0, 1fr); }
  body .scanner-model-actions { flex-wrap: wrap; }
  body .scanner-model-actions .form-select { min-width: 0; flex: 1 1 12rem; }
  body .scanner-scenario-filter { flex-wrap: wrap; }
  body .filter-chip-grid { grid-template-columns: minmax(0, 1fr) !important; }
  body .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)) !important; }
  body .stat-value, body .badge { overflow-wrap: anywhere; white-space: normal; }
  body .table-responsive, body .operations-table-wrap, body .rank-table {
    width: 100%; max-width: 100%; margin-inline: 0; padding-inline: 0;
    overflow-x: auto; overscroll-behavior-x: contain; touch-action: pan-x pan-y;
  }
  .trader-scroll-hint { color: var(--bs-secondary-color); font-size: .8rem; margin: .5rem 0; }
  body .modal, body #scannerPairChartModal, body #scannerInvestmentSimulatorModal { padding: 0 !important; }
  body .modal .modal-dialog, body #scannerPairChartModal .modal-dialog, body #scannerInvestmentSimulatorModal .modal-dialog {
    width: 100% !important; max-width: 100% !important; margin: 0 !important;
    height: var(--trader-viewport-height, 100dvh) !important; min-height: 0 !important;
  }
  body .modal .modal-content, body #scannerPairChartModal .modal-content, body #scannerInvestmentSimulatorModal .modal-content {
    display: flex; flex-direction: column; height: 100% !important; min-height: 0 !important;
    max-height: 100% !important; border-radius: 0 !important; overflow: hidden;
  }
  body .modal-header { flex: 0 0 auto; padding: max(.75rem,env(safe-area-inset-top)) .75rem .5rem !important; gap: .5rem; }
  body .modal-header > div { min-width: 0; }
  body .modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto !important; padding: .75rem !important; overscroll-behavior-y: contain; }
  body .modal-footer { flex: 0 0 auto; position: static; padding: .5rem .75rem max(.5rem,env(safe-area-inset-bottom)) !important; gap: .5rem; }
  body .modal-footer, body .modal-footer > .d-flex { display: flex !important; flex-wrap: wrap !important; }
  body .modal-footer > *, body .modal-footer > .d-flex > * { flex: 1 1 auto; width: auto !important; margin: 0 !important; }
  body .modal-footer > .d-flex { width: 100% !important; }
  body #scannerPairChartModal .modal-header { padding-right: 3.5rem !important; flex-wrap: wrap; }
  body #scannerPairChartModal .modal-header > .btn-close { right: .5rem; top: .5rem; transform: none; }
  body .chart-indicator-panel, body .chart-ema-hover-panel { max-width: calc(100vw - 2rem); max-height: calc(var(--trader-viewport-height,100dvh) - 6rem); overflow: auto; }
  body .chart-indicator-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  body .chart-indicator-panel .btn { white-space: normal; min-height: 44px; }
  body .trade-replay-bar, body .scanner-replay-bar { display: flex; flex-wrap: wrap; padding: .5rem; }
  body .trade-replay-progress, body .scanner-replay-progress { flex: 1 0 100%; min-height: 32px; }
  body .trade-replay-bar .trade-replay-date, body .scanner-replay-bar .scanner-replay-date { min-width: 0; flex: 1 1 9rem; }
  body .trade-replay-strategy-grid { grid-template-columns: minmax(0,1fr); }
  body .trade-replay-simulator:not(.is-minimized) {
    position: fixed !important; inset: 0 !important; width: 100% !important;
    height: var(--trader-viewport-height,100dvh) !important; max-height: var(--trader-viewport-height,100dvh) !important;
    border-radius: 0; z-index: 21000;
  }
  body .trade-replay-simulator:not(.is-minimized) > .p-3 {
    height: 100%; max-height: 100% !important; overflow-y: auto !important;
    padding: max(.75rem,env(safe-area-inset-top)) .75rem max(1rem,env(safe-area-inset-bottom)) !important;
  }
  body .trade-replay-simulator .trade-replay-simulator-handle { touch-action: pan-y; cursor: default; flex-wrap: wrap; gap: .5rem; top: -.75rem; }
  body #tradeReplayStrategyExpander[open], body .trade-replay-simulator [data-scanner-strategy-settings][open] { max-height: none; overflow: visible; }
  body .trade-replay-simulator.is-minimized { position: fixed !important; top: auto !important; left: auto !important; right: .75rem !important; bottom: max(.75rem,env(safe-area-inset-bottom)) !important; z-index: 21000; }
  body .trade-replay-capital-dialog, body .scanner-replay-capital-dialog {
    height: var(--trader-viewport-height,100dvh) !important; align-items: center; padding: .75rem;
  }
  body .trade-replay-capital-card, body .scanner-replay-capital-card { width: 100%; max-height: calc(var(--trader-viewport-height,100dvh) - 1.5rem); overflow-y: auto; }
  body .scanner-investment-results { max-width: calc(100vw - 2rem); left: 1rem !important; right: auto !important; }
  body .swal2-popup { max-width: calc(100vw - 1.5rem); max-height: calc(var(--trader-viewport-height,100dvh) - 1.5rem); overflow-y: auto; }
  body .swal2-input { font-size: 16px; min-width: 0; max-width: 100%; }
  body .trader-mobile-only { display: flex; }
  .trader-trade-cards { gap: .75rem; }
  body .trader-trade-cards.is-active { display: grid; }
  body .operations-table-wrap.mobile-list-active { display: none; }
  .trader-trade-card { display: block; width: 100%; text-align: left; border: 1px solid var(--bs-border-color); border-radius: .75rem; padding: 1rem; background: var(--bs-paper-bg); color: var(--bs-body-color); }
  .trader-trade-card:focus-visible { outline: 3px solid var(--bs-primary); outline-offset: 2px; }
  .trader-trade-card header { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
  .trader-trade-card dl { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: 0; }
  .trader-trade-card dt { color: var(--bs-secondary-color); font-size: .75rem; font-weight: 400; }
  .trader-trade-card dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
  .trader-trade-card footer { color: var(--bs-primary); margin-top: .75rem; font-size: .8rem; }
  body .column-option { flex-wrap: wrap; padding: .65rem !important; }
  .column-move-actions { margin-left: auto; display: flex; gap: .25rem; }
  body #columnsConfigModal .modal-body > .d-flex { flex-wrap: wrap; gap: .5rem; }
}
@media (max-width: 359.98px) {
  body .kpi-grid, body .stats-grid { grid-template-columns: minmax(0,1fr) !important; }
}
@media (max-width: 991.98px) and (max-height: 500px) {
  body .modal-header small { font-size: .75rem; }
  body .modal-footer .btn { padding-block: .35rem; }
  body .modal-header h5 { margin: 0; }
}
@media (max-width: 991.98px) {
  body .chart-ema-hover-menu .chart-ema-hover-panel {
    position: fixed; left: .75rem; right: .75rem; top: var(--mobile-menu-top,5rem);
    width: auto; max-width: none; transform: none !important;
    max-height: calc(var(--trader-viewport-height,100dvh) - var(--mobile-menu-top,5rem) - .75rem);
    opacity: 0 !important; visibility: hidden !important; pointer-events: none;
  }
  body .chart-ema-hover-menu.is-mobile-open .chart-ema-hover-panel { opacity: 1 !important; visibility: visible !important; pointer-events: auto; }
}
@media (max-width: 991.98px) {
  body .trader-chart-toolbar { display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)); width: 100%; align-items: stretch !important; }
  body .trader-chart-toolbar > *, body .trader-chart-toolbar > .chart-ema-hover-menu > .btn { width: 100%; min-width: 0; margin: 0 !important; }
  body .trader-chart-toolbar .btn { overflow-wrap: normal; }
  body #tradeDetailModal .modal-header { display: grid; grid-template-columns: minmax(0,1fr) 44px; align-items: start !important; }
  body #tradeDetailModal .modal-header > div { grid-column: 1; }
  body #tradeDetailModal .modal-header > .btn-close { grid-column: 2; grid-row: 1; }
  body #tradeInvestmentBadge { grid-column: 1 / -1; margin: 0 !important; justify-self: start; }
  body #tradeModalFullscreen, body #scannerModalFullscreen { display: none !important; }
  body #scannerPairChartModal .modal-header { min-height: 0; }
  body .chart-ema-hover-menu.is-mobile-open { z-index: 500; }
  body .chart-ema-hover-menu .chart-ema-hover-panel { background: var(--bs-paper-bg,#192c42); transition: none; }
}
@media (max-width: 991.98px) {
  body input, body textarea, body select { scroll-margin-block: 6rem; }
  body .trade-replay-simulator-handle [data-replay-simulator-minimize] { width: auto !important; min-width: 7.5rem; height: 44px !important; flex-shrink: 0; gap: .35rem; border: 1px solid var(--bs-border-color); color: var(--bs-body-color); }
  body .trade-replay-simulator-handle [data-replay-simulator-reset] { display: none; }
  body .trade-replay-simulator-handle > .d-flex { flex-wrap: wrap; }
}
@media (max-width: 575.98px) {
  body .trade-replay-simulator [data-scanner-strategy-settings] .row > .col-4 { width: 100%; }
}
@media (max-width: 991.98px) {
  body .btn { overflow-wrap: normal; }
  body form.d-flex { flex-wrap: wrap; }
  body form.d-flex > .btn { flex-shrink: 0; }
  body .rank-table th:first-child, body .rank-table td:first-child {
    width: 10rem; min-width: 9rem; max-width: 10rem;
    white-space: normal !important; overflow-wrap: anywhere;
  }
  body .modal-header { position: relative; }
  body .modal-header > .btn-close { position: static; transform: none; }
  body .trade-replay-simulator-handle [data-replay-simulator-minimize] { font-size: .875rem; }
}
@media (max-width: 991.98px) {
  body #tradeChartModule:fullscreen, body #scannerPairChartModule:fullscreen { overflow-y: auto; min-height: 0; }
}

/* Compact trade details: keep the chart ahead of oversized controls. */
@media(max-width:767.98px){
 body #tradeDetailModal .modal-dialog{margin:0;width:100%;max-width:none;height:100dvh}
 body #tradeDetailModal .modal-content{min-height:100%;border-radius:0}
 body #tradeDetailModal .modal-header{padding:10px 12px;gap:6px;border-bottom:1px solid var(--bs-border-color)}
 body #tradeDetailModal .modal-title{font-size:15px;line-height:1.35;flex:1 0 100%}
 body #tradeDetailModal .trade-heading>.d-flex{gap:5px!important}
 body #tradeDetailModal #tradeAuditToggle,body #tradeDetailModal #tradeSummaryToggle{min-height:32px;padding:5px 8px;font-size:11px;box-shadow:none;border-color:transparent;background:rgba(var(--bs-primary-rgb),.07);color:var(--bs-body-color)}
 body #tradeDetailModal #tradeModalPeriod{font-size:10px;line-height:1.4}
 body #tradeDetailModal .modal-body{padding:8px 10px}
 body #tradeDetailModal .trader-chart-toolbar{grid-template-columns:repeat(3,minmax(0,1fr));gap:4px!important;margin:0 0 6px}
 body #tradeDetailModal .trader-chart-toolbar>.btn,body #tradeDetailModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn{min-height:38px;padding:5px 3px;font-size:10px;letter-spacing:-.02em;white-space:nowrap;border-color:transparent;background:rgba(var(--bs-primary-rgb),.06);box-shadow:none;border-radius:7px}
 body #tradeDetailModal .trader-chart-toolbar>.btn .icon-base,body #tradeDetailModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn .icon-base{font-size:14px;margin-right:3px!important}
 body #tradeDetailModal #chartDailyHistory{min-height:32px;font-size:12px;padding-block:4px}
 body #tradeDetailModal label[for="chartDailyHistory"],body #tradeDetailModal #tradeTechnicalChartTitle{font-size:10px}
 body #tradeDetailModal #tradeChartModule>.d-flex{gap:6px!important}
}

@media(max-width:767.98px){
 body #tradeDetailModal .modal-header{padding:7px 10px;gap:3px}
 body #tradeDetailModal .modal-title{font-size:13px}
 body #tradeDetailModal #tradeAuditToggle,body #tradeDetailModal #tradeSummaryToggle{min-height:28px;padding:3px 6px;font-size:10px;background:transparent}
 body #tradeDetailModal #tradeAuditToggle .icon-base,body #tradeDetailModal #tradeSummaryToggle .icon-base{font-size:15px}
 body #tradeDetailModal #tradeModalPeriod{font-size:9px;margin-top:2px!important}
 body #tradeDetailModal .modal-body{padding:5px 8px}
 body #tradeDetailModal .trader-chart-toolbar{display:flex!important;flex-wrap:nowrap!important;overflow-x:auto;overscroll-behavior-x:contain;scrollbar-width:thin;gap:4px!important;padding-bottom:4px;margin-bottom:2px}
 body #tradeDetailModal .trader-chart-toolbar>*{width:auto!important;flex:0 0 auto}
 body #tradeDetailModal .trader-chart-toolbar>.btn,body #tradeDetailModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn{width:auto!important;min-height:34px;padding:4px 7px;font-size:10px;border-radius:5px}
 body #tradeDetailModal #chartDailyHistory{height:28px;min-height:28px!important;font-size:11px!important;padding:2px 25px 2px 8px}
 body #tradeDetailModal label[for="chartDailyHistory"]{display:none}
 body #tradeDetailModal #tradeChartModule>.d-flex{gap:4px!important}
}

/* Keep every mobile tool visible, without horizontal scrolling. */
@media(max-width:767.98px){
 body #tradeDetailModal .modal-header{position:relative;display:block;padding:7px 42px 7px 10px}
 body #tradeDetailModal .modal-header>.btn-close{position:absolute;right:10px;top:10px;margin:0}
 body #tradeDetailModal .trade-heading>.d-flex{display:grid!important;grid-template-columns:auto minmax(0,1fr);gap:2px 8px!important;align-items:center}
 body #tradeDetailModal .modal-title{grid-column:1/-1;font-size:13px;line-height:1.3}
 body #tradeDetailModal #tradeAuditToggle,body #tradeDetailModal #tradeSummaryToggle{justify-self:start;min-height:26px;padding:2px 0;font-size:10px}
 body #tradeDetailModal #tradeModalPeriod{font-size:9px;line-height:1.25;margin-top:1px!important}
 body #tradeDetailModal .trader-chart-toolbar{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr));overflow:visible;gap:3px!important;padding:0;margin-bottom:3px}
 body #tradeDetailModal .trader-chart-toolbar>*,body #tradeDetailModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn{width:100%!important;min-width:0}
 body #tradeDetailModal .trader-chart-toolbar>.btn,body #tradeDetailModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn{min-height:32px;padding:3px 2px;font-size:10px}
 body #tradeDetailModal #chartDailyHistory{padding-right:28px;min-width:76px}
}

/* Persistent selection mirrors the menu/tool state, not keyboard focus. */
@media(max-width:767.98px){
 body #tradeDetailModal .trader-chart-toolbar>.btn[aria-pressed="true"],
 body #tradeDetailModal .trader-chart-toolbar>.btn.active,
 body #tradeDetailModal .trader-chart-toolbar>.chart-ema-hover-menu.is-mobile-open>.btn,
 body #tradeDetailModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn[aria-expanded="true"]{
  background:var(--bs-primary);color:var(--bs-white,#fff);border-color:var(--bs-primary);box-shadow:inset 0 -2px 0 rgba(0,0,0,.14)
 }
 body #tradeDetailModal .trader-chart-toolbar .chart-ema-hover-panel .btn[aria-pressed="true"],
 body #tradeDetailModal .trader-chart-toolbar .chart-ema-hover-panel .btn.active{
  background:var(--bs-primary);color:var(--bs-white,#fff);border-color:var(--bs-primary)
 }
 body #tradeDetailModal:has(#tradeAuditDialog[open]) #tradeAuditToggle,
 body #tradeDetailModal:has(#tradeSummaryDialog[open]) #tradeSummaryToggle{
  background:rgba(var(--bs-primary-rgb),.18);color:var(--bs-primary);border-color:var(--bs-primary)
 }
}

@media(max-width:767.98px){
 body #tradeDetailModal .trade-mobile-chart-meta{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:5px;margin-right:-18px}
 body #tradeDetailModal .trade-mobile-chart-meta #chartDailyHistory{height:26px;min-height:26px!important;font-size:11px!important;padding-block:2px}
 body #tradeDetailModal .trade-mobile-chart-meta #tradeTechnicalChartTitle{font-size:10px}
}

@media(max-width:991.98px){
 body #tradeDetailModal{inset:0!important;width:100%!important;height:100dvh!important;padding:0!important}
 body #tradeDetailModal.show{align-items:stretch!important;justify-content:stretch!important}
 body #tradeDetailModal .trade-detail-dialog{width:100vw!important;max-width:100vw!important;height:var(--trader-viewport-height,100dvh)!important;margin:0!important;flex:1}
 body #tradeDetailModal .trade-detail-dialog .modal-content{width:100%!important;height:100%!important;max-height:100%!important;border:0!important;border-radius:0!important}
 body #tradeDetailModal .modal-body{padding:6px max(10px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left))!important}
}

@media(max-width:991.98px){
 body #tradeDetailModal{position:fixed!important;left:0!important;right:0!important;width:100vw!important;max-width:none!important;margin:0!important;overflow-x:hidden!important}
 body #tradeDetailModal .trade-detail-dialog{min-width:100%!important;padding:0!important;transform:none!important}
 body #tradeDetailModal .trade-detail-dialog .modal-content{margin:0!important;box-shadow:none!important}
}

@media(max-width:767.98px){
 body #tradesQuickFilters .trades-quick-period .input-group-text{display:flex;align-items:center;justify-content:center;padding-inline:7px;flex:0 0 30px}
 body #tradesQuickFilters .trades-quick-period .input-group-text .icon-base{font-size:18px}
 body #tradesQuickFilters .trades-quick-period .input-group{flex-wrap:nowrap}
 body #tradesQuickFilters .trades-quick-period .form-control{min-width:0;padding-inline:7px}
}

@media(max-width:767.98px){
 body #tradesQuickFilters .trades-quick-period{position:relative;width:auto!important;max-width:none;flex:0 0 auto;gap:4px}
 body #tradesQuickFilters .trades-quick-period .input-group-text{width:44px;height:44px;flex:0 0 44px;border-radius:8px!important;padding:0;pointer-events:none}
 body #tradesQuickFilters .trades-quick-period #trades_quick_date_range{position:absolute;inset:0 auto auto 0;width:44px!important;height:44px;min-height:44px;padding:0;opacity:0;z-index:2;cursor:pointer}
 body #tradesQuickFilters .trades-quick-period:focus-within .input-group-text{outline:2px solid var(--bs-primary);outline-offset:2px}
 body #tradesQuickFilters #trades_clear_date_range{border:0;min-width:32px;padding:4px}
}

/* One balanced mobile toolbar: title, then a compact action group. */
@media(max-width:767.98px){
 body .trades-toolbar-card .card-body{grid-template-columns:minmax(0,1fr) auto auto;gap:4px;padding:10px 12px!important}
 body .trades-toolbar-card{border-radius:14px}
 body .trades-toolbar-card .trades-mobile-header h4{font-size:17px;gap:8px;line-height:1.25}
 body .trades-toolbar-card .trades-mobile-header h4>.icon-base{font-size:20px}
 body .trades-toolbar-card #tradesQuickFilters{justify-self:end;margin:0;padding:0;gap:0}
 body .trades-toolbar-card .trades-mobile-actions{display:flex;align-items:center;gap:4px;flex-wrap:nowrap}
 body .trades-toolbar-card .trades-mobile-actions>.btn{display:inline-flex;align-items:center;justify-content:center;width:40px;min-width:40px;min-height:44px;padding:0;border:0;border-radius:9px;box-shadow:none;background:transparent}
 body .trades-toolbar-card .trades-mobile-actions>.trades-mobile-filter{background:rgba(var(--bs-primary-rgb),.08);color:var(--bs-primary)}
 body .trades-toolbar-card .trades-mobile-actions>.btn .icon-base{font-size:21px;margin:0!important}
 body .trades-toolbar-card #tradesQuickFilters .trades-quick-period .input-group-text{border-color:transparent;background:rgba(var(--bs-secondary-rgb),.07);border-radius:9px!important}
 body .trades-toolbar-card #tradesQuickFilters .trades-quick-period .input-group-text .icon-base{font-size:21px}
}

/* Datas empilhadas à esquerda do calendário no mobile. */
.trades-selected-period { display: none; }
@media (max-width: 767.98px) {
  body .trades-toolbar-card .trades-mobile-header > div:first-child { min-width: 0; }
  body .trades-toolbar-card .trades-selected-period:not([hidden]) {
    display: block;
    margin: 0;
    flex: 0 0 auto;
    text-align: right;
    white-space: nowrap;
    font-size: 10px;
    line-height: 1.35;
    font-weight: 400;
    color: var(--bs-secondary-color);
  }
  body .trades-toolbar-card .trades-selected-period > span { display: block; }
  body .trades-toolbar-card #tradesQuickFilters .trades-period-controls { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
}

@media (max-width: 767.98px) {
  body .trades-toolbar-card #tradesQuickFilters .trades-quick-period { order: 0; }
  body .trades-toolbar-card #tradesSelectedPeriod { order: -1; }
}

/* Scanner uses the same compact mobile chart controls as trade details. */
@media(max-width:767.98px){
 body #scannerPairChartModal .modal-content>.modal-header{position:relative;display:block;padding:7px 54px 7px 10px!important}
 body #scannerPairChartModal .modal-header>.btn-close{position:absolute;right:6px;top:5px;margin:0!important}
 body #scannerPairChartModal .scanner-chart-title-row{display:flex;flex-direction:column;align-items:flex-start;gap:2px}
 body #scannerPairChartModal .modal-title{font-size:13px;line-height:1.3}
 body #scannerPairChartModal #scannerAuditToggle{min-height:26px;padding:2px 0;font-size:10px;gap:5px;border-color:transparent;background:transparent;box-shadow:none}
 body #scannerPairChartModal #scannerAuditToggle .icon-base{font-size:15px}
 body #scannerPairChartModal .scanner-chart-subtitle{font-size:9px;line-height:1.25;margin-top:1px}
 body #scannerPairChartModal .scanner-chart-subtitle span{padding:0;border:0}
 body #scannerPairChartModal .modal-body{padding:6px max(10px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left))!important;gap:4px}
 body #scannerPairChartModal .scanner-chart-command-bar{gap:4px;padding-bottom:3px}
 body #scannerPairChartModal .scanner-chart-caption{display:flex;font-size:10px;font-weight:400}
 body #scannerPairChartModal .scanner-chart-command-bar>.d-inline-flex{margin-left:auto}
 body #scannerPairChartModal label[for="chartDailyHistory"]{display:none}
 body #scannerPairChartModal #chartDailyHistory{height:26px;min-height:26px!important;min-width:76px;font-size:11px!important;padding:2px 28px 2px 8px}
 body #scannerPairChartModal .trader-chart-toolbar{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr));width:100%;overflow:visible;gap:3px!important;padding:0;margin:0 0 3px}
 body #scannerPairChartModal .trader-chart-toolbar>*,body #scannerPairChartModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn{width:100%!important;min-width:0}
 body #scannerPairChartModal .trader-chart-toolbar>.btn,body #scannerPairChartModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn{min-height:32px;padding:3px 2px;font-size:10px;letter-spacing:-.02em;white-space:nowrap;border-color:transparent;background:rgba(var(--bs-primary-rgb),.06);box-shadow:none;border-radius:7px}
 body #scannerPairChartModal .trader-chart-toolbar>.btn .icon-base,body #scannerPairChartModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn .icon-base{font-size:14px;margin-right:3px!important}
 body #scannerPairChartModal .trader-chart-toolbar>.btn[aria-pressed="true"],body #scannerPairChartModal .trader-chart-toolbar>.btn.active,body #scannerPairChartModal .trader-chart-toolbar>.chart-ema-hover-menu.is-mobile-open>.btn,body #scannerPairChartModal .trader-chart-toolbar>.chart-ema-hover-menu>.btn[aria-expanded="true"]{background:var(--bs-primary);color:var(--bs-white,#fff);border-color:var(--bs-primary)}
 body #scannerPairChartModal:has(#scannerAuditDialog[open]) #scannerAuditToggle{background:rgba(var(--bs-primary-rgb),.18);color:var(--bs-primary)}
}

/* Uniform touch targets for the shared chart toolbar. */
@media(max-width:767.98px){
 body :is(#scannerPairChartModal,#tradeDetailModal) .trader-chart-toolbar{gap:6px!important;align-items:stretch!important;}
 body :is(#scannerPairChartModal,#tradeDetailModal) .trader-chart-toolbar>.btn,
 body :is(#scannerPairChartModal,#tradeDetailModal) .trader-chart-toolbar>.chart-ema-hover-menu>.btn{display:flex;align-items:center;justify-content:center;gap:4px;height:44px!important;min-height:44px!important;padding:6px 3px!important;font-size:11px!important;line-height:1.2; border-width:1px!important;border-radius:7px;}
 body :is(#scannerPairChartModal,#tradeDetailModal) .trader-chart-toolbar>.btn .icon-base,
 body :is(#scannerPairChartModal,#tradeDetailModal) .trader-chart-toolbar>.chart-ema-hover-menu>.btn .icon-base{font-size:16px!important;width:16px;height:16px;flex-shrink:0;margin:0!important;}
 body #scannerPairChartModal .scanner-chart-title-row{gap:6px;}
 body #scannerPairChartModal #scannerAuditToggle{display:inline-flex;align-items:center;justify-content:center;min-height:36px;padding:6px 10px;font-size:11px;line-height:1.2;gap:5px;}
 body #scannerPairChartModal #scannerAuditToggle .icon-base{font-size:16px;width:16px;height:16px;}
 body #scannerPairChartModal .scanner-chart-subtitle{margin-top:5px;}
}

/* Match the Trades-to-equity gap to the mobile content top inset. */
@media (max-width: 991.98px) {
  body .trades-toolbar-card { margin-bottom: 0 !important; }
  body .bi-shell > #portfolioOverview { margin-top: 12px !important; padding-top: 0; }
}

/* Open positions use the scanner's compact mobile presentation. */
@media(max-width:767.98px){
 body #tradeDetailModal.open-position-chart #tradeModalPeriod,
 body #tradeDetailModal.open-position-chart #tradeTechnicalChartTitle{display:none!important}
 body #tradeDetailModal.open-position-chart .modal-header{padding:12px 10px;align-items:center!important}
 body #tradeDetailModal.open-position-chart .modal-title{font-size:16px;line-height:1.3;margin-bottom:4px!important}
 body #tradeDetailModal.open-position-chart #tradeAuditToggle,
 body #tradeDetailModal.open-position-chart #tradeSummaryToggle{min-height:24px;padding:2px 5px;font-size:10px}
 body #tradeDetailModal.open-position-chart .modal-body{padding:6px 10px!important}
 body #tradeDetailModal.open-position-chart #tradeChartModule>.d-flex{gap:0!important}
 body #tradeDetailModal.open-position-chart #tradeChartModule>.trader-chart-viewport{min-height:300px}
}

/* Position tools stay available without taking space from the scanner layout. */
#tradePositionOptions{width:min(420px,calc(100vw - 24px));max-height:85dvh;overflow:auto;border:1px solid var(--bs-border-color);border-radius:12px;padding:18px;background:var(--bs-body-bg);color:var(--bs-body-color)}
#tradePositionOptions::backdrop{background:rgba(0,0,0,.5)}
#tradePositionOptions .position-options-actions{display:grid;grid-template-columns:1fr;gap:10px}
#tradePositionOptions .position-options-actions>.btn{min-height:44px;justify-content:center}
@media(max-width:767.98px){
 body #tradeDetailModal.open-position-chart .modal-header{min-height:58px;flex-shrink:0;gap:10px;padding:12px 10px!important}
 body #tradeDetailModal.open-position-chart .modal-title{margin:0!important}
 body #tradeDetailModal.open-position-chart .trade-heading{flex:1;min-width:0}
 body #tradeDetailModal.open-position-chart .modal-header .btn-close{position:static!important;margin:0!important;flex-shrink:0}
 body #tradeDetailModal.open-position-chart .trader-chart-toolbar{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr));width:100%;margin:0 0 3px;padding:0}
 body #tradeDetailModal.open-position-chart .trader-chart-toolbar>.btn{border-color:transparent;background:rgba(var(--bs-primary-rgb),.06);box-shadow:none}
}

@media(max-width:767.98px){
 body #tradeDetailModal.open-position-chart .modal-header{display:flex!important;flex-direction:row!important;flex-wrap:nowrap!important}
 body #tradeDetailModal.open-position-chart .modal-header .btn-close{width:24px!important;height:24px!important;min-width:24px!important;min-height:24px!important;padding:0!important;transform:none!important}
}

/* Mobile replay keeps only the timeline; desktop retains playback controls. */
@media (max-width: 991.98px) {
  body .trade-replay-bar > :not(.trade-replay-progress),
  body .scanner-replay-bar > :not(.scanner-replay-progress) {
    display: none !important;
  }
  body .trade-replay-bar, body .scanner-replay-bar {
    flex-wrap: nowrap; gap: 0; padding: 0 .5rem; min-height: 44px;
  }
  body .trade-replay-bar > .trade-replay-progress,
  body .scanner-replay-bar > .scanner-replay-progress {
    flex: 1 1 auto; width: 100%; min-width: 0; min-height: 44px; margin: 0;
  }
}

/* Keep indicator plots and axis values visible without floating text legends. */
:is(#scannerPairChartModule, #tradeChartModule) :is(.tv-volume-legend, .tv-stochastic-legend, .tv-adx-legend) {
  display: none !important;
}

/* The Replay toggle remains the way to leave replay; omit the redundant live button. */
:is(#scannerPairChartModule, #tradeChartModule) #tradeReplayLive { display: none !important; }
/* Anchor the first toolbar menu to its left edge rather than centering it offscreen. */
body :is(#scannerPairChartModule, #tradeChartModule) #tradeChartTimeframe > .chart-ema-hover-panel {
  left: 0 !important; right: auto !important; top: 100%;
  transform: none !important; max-width: calc(100vw - 2rem);
}

/* Share the top row with the timeline when desktop space is available. */
@media (min-width: 992px) {
  #scannerPairChartModule .scanner-chart-command-bar {
    display: flex; align-items: center; flex-wrap: wrap; gap: .5rem;
  }
  :is(#scannerPairChartModule, #tradeChartModule) .trader-chart-toolbar { flex: 0 0 auto; }
  :is(#scannerPairChartModule, #tradeChartModule) #tradeReplayBar {
    flex: 1 1 330px; min-width: 0; width: auto; margin: 0;
    padding: .25rem .4rem; gap: .35rem; flex-wrap: nowrap;
  }
  :is(#scannerPairChartModule, #tradeChartModule) #tradeReplayProgress {
    flex: 1 1 100px; min-width: 60px; width: 100px;
  }
  :is(#scannerPairChartModule, #tradeChartModule) #tradeReplayDate {
    flex: 0 0 auto; min-width: 0; font-size: .65rem; white-space: nowrap;
  }
  :is(#scannerPairChartModule, #tradeChartModule) #tradeReplayBar > .btn {
    padding: .25rem .4rem; flex-shrink: 0;
  }
  :is(#scannerPairChartModule, #tradeChartModule) #tradeReplaySpeed {
    padding: .25rem 1.5rem .25rem .4rem; font-size: .7rem;
  }
}
