/* ==========================================================================
   OPIFY Trend Analyzer – native-app mobile UI (phones + portrait tablets)
   Loaded only by trend-analyzer.html. Everything is inside the < 1050px query,
   so the desktop layout is untouched. UI only: no element is removed or moved,
   the original selects / buttons stay the source of truth.
   Phase 1: app shell, chart screen, contract sheet, landscape full screen.
   ========================================================================== */

/* desktop: the mobile-only elements (created on a phone, kept if the window is widened) stay hidden */
.tam-head, .tam-sheet, .tam-sheet-bg, .tam-fs-exit, .tam-ind-hd, .tam-replay-fab, .tam-replay-hint,
.tam-rp-speed, .tam-rp-more, .tam-pop { display: none; }

@media (max-width: 1049.98px) {
  .tam-sheet-bg { display: block; }
  :root {
    --tam-top: 44px;            /* bottom of the OPIFY top bar (set by mobile.js) */
    --tam-nav: 64px;            /* height of the bottom tab bar (set by mobile.js) */
    --tam-head: 50px;           /* contract chip row */
    --tam-tool: 48px;           /* chart toolbar row */
    --tam-strip: 48px;          /* bar-replay / SR control strip under the toolbar (one compact row) */
    --tam-trade: 62px;          /* virtual Buy / Sell bar docked under the chart */
    --tam-bg: #07142a;
    --tam-surface: #0d1c32;
    --tam-line: rgba(148, 163, 184, .14);
    --tam-text: #e6eef6;
    --tam-muted: #94a3b8;
    --tam-accent: #8ad8e5;
    --tam-nav-accent: #70d174;
    --tam-ce: #22c55e;
    --tam-pe: #f87171;
  }

  /* the chart screen never scrolls the page behind it */
  html:has(.chart-panel.active) body { overflow: hidden !important; overscroll-behavior: none; }

  /* closed "report an issue" modal is taller than a landscape phone: its invisible
     part must not swallow taps on the chart screen */
  html .css-jefkefn:not(.show) { pointer-events: none; }

  /* ---------------------------------------------------------------- shell */
  html .workspace.active { padding: 0; margin: 0; gap: 0; }

  html .workspace > .chart-panel {
    position: fixed;
    left: 0; right: 0;
    top: var(--tam-top);
    bottom: var(--tam-nav);
    z-index: 5;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: none !important;
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: var(--tam-bg);
    opacity: 0;
    pointer-events: none;
    transform: translateX(100%);
    transition: transform .24s cubic-bezier(.2, .8, .2, 1), opacity .2s ease;
  }
  html .workspace > .chart-panel.exit { transform: translateX(-30%); }
  html .workspace > .chart-panel.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);   /* keeps the panel the containing block of its overlays */
  }

  /* contract row replaces the 4 dropdowns (they stay in the page, hidden) */
  html.tam .chart-panel .css-tddthjfyfhfsfk { display: none !important; }
  html .chart-panel .chart-header { display: none !important; }

  .tam-head {
    flex: 0 0 var(--tam-head);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--tam-head);
    padding: 0 12px;
    background: var(--tam-bg);
    border-bottom: 1px solid var(--tam-line);
  }
  .tam-contract {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    height: 38px;
    padding: 0 12px 0 14px;
    border: 1px solid rgba(138, 216, 229, .28);
    border-radius: 19px;
    background: rgba(88, 133, 173, .12);
    color: var(--tam-text);
    font: 600 15px/1 Inter, system-ui, Arial;
    letter-spacing: .3px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform .12s ease, background .15s ease;
  }
  .tam-contract:active { transform: scale(.97); background: rgba(88, 133, 173, .2); }
  .tam-c-sym { color: var(--tam-accent); }
  .tam-c-typ {
    padding: 3px 6px;
    border-radius: 6px;
    font-size: 12px;
    letter-spacing: .6px;
  }
  .tam-c-typ.ce { color: var(--tam-ce); background: rgba(34, 197, 94, .14); }
  .tam-c-typ.pe { color: var(--tam-pe); background: rgba(248, 113, 113, .14); }
  .tam-c-exp {
    color: var(--tam-muted);
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tam-c-chev { color: var(--tam-muted); font-size: 12px; margin-left: 2px; }

  /* full-screen button: right end of the contract row */
  .tam-fs-btn,
  .tam-fs-exit {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 40px;
    height: 38px;
    margin-left: auto;
    padding: 0;
    border: 1px solid rgba(148, 163, 184, .24);
    border-radius: 12px;
    background: rgba(255, 255, 255, .04);
    color: #cfd8e3;
    font-size: 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform .12s ease, background .15s ease;
  }
  .tam-fs-btn:active, .tam-fs-exit:active { transform: scale(.92); background: rgba(255, 255, 255, .1); }
  .tam-fs-exit { display: none; }

  /* ---------------------------------------------------------------- full-screen chart (portrait) */
  html.tam-fs .topbar,
  html.tam-fs .css-lfpfoRTYU { display: none !important; }
  html.tam-fs:not(.tam-land) .tam-head { display: none; }
  html.tam-fs .workspace > .chart-panel {
    top: 0;
    bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }
  html.tam-fs:not(.tam-land) .tam-fs-exit {
    display: grid;
    position: absolute;
    top: calc((var(--tam-tool) - 36px) / 2);
    right: 8px;
    z-index: 46;
    width: 40px;
    height: 36px;
    margin: 0;
    background: #0d1c32;
    box-shadow: -14px 0 12px -4px var(--tam-bg);
  }
  html.tam-fs:not(.tam-land) .chart-panel .css-ffjkTHUI > .css-fdrGTeTHUI { padding-right: 56px; }
  html.tam-fs .workspace > #right_side_widow { display: none !important; }

  /* ---------------------------------------------------------------- chart area */
  html .chart-panel .chart-canvas {
    position: relative;
    flex: 1 1 auto;
    display: block;
    min-height: 0;
    margin: 0;
    padding: 0 !important;
    border-radius: 0;
    overflow: hidden;
    overflow: clip;          /* never scrolled by focus / scroll-into-view (keeps the layout put) */
    background: var(--tam-bg) !important;
  }
  /* --tam-ctop = where the chart starts inside the chart area: below the toolbar row and,
     while bar replay / SR detection runs, below its control strip (nothing covers the candles) */
  html .chart-panel .chart-canvas { --tam-ctop: 0px; }
  html .chart-panel .chart-canvas:has(> .css-ffjkTHUI.active) { --tam-ctop: var(--tam-tool); }
  html .chart-panel .chart-canvas:has(> .css-ffjkTHUI.active):has(> .css-lfpfpRTDF .css-lfpfpRTWE.active, > .css-lfpfpRTDFW .css-lfpfpRTWEW.active) {
    --tam-ctop: calc(var(--tam-tool) + var(--tam-strip));
  }
  /* --tam-cbot = space under the chart: the virtual Buy / Sell bar while it is shown */
  html .chart-panel .chart-canvas { --tam-cbot: 0px; }
  html .chart-panel .chart-canvas:has(> .vp-trade.active) { --tam-cbot: var(--tam-trade); }
  html .chart-panel .chart-canvas #chart {
    position: absolute;
    left: 0; right: 0;
    top: var(--tam-ctop);
    bottom: var(--tam-cbot);
    margin: 0 !important;
  }

  /* toolbar: one swipeable row of chips */
  html .chart-panel .chart-canvas > .css-ffjkTHUI {
    position: absolute !important;
    top: 0; left: 0; right: 0;
    width: auto;
    height: var(--tam-tool);
    box-sizing: border-box;
    padding: 0;
    z-index: 40;
    overflow: hidden;
    background: var(--tam-bg);
    border: none;
    border-bottom: 1px solid var(--tam-line);
    box-shadow: none;
  }
  html .chart-panel .css-ffjkTHUI > .css-fdrGTeTHUI {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    height: var(--tam-tool);
    max-width: none;
    padding: 0 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
            mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  }
  html .chart-panel .css-ffjkTHUI > .css-fdrGTeTHUI::-webkit-scrollbar { display: none; }
  html .chart-panel .css-ffjkTHUI .css-flGTfTHUI {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 !important;
    padding-right: 24px;
  }
  html .chart-panel .css-ffjkTHUI .css-lfofpRTYEE button { display: none; }
  /* historical chart: the contract chip replaces the live-ticker select */
  html body:has(.css-tddthjfyfhfsfk.active) .chart-panel .css-ffjkTHUI .css-lfofpRTYEE { display: none; }
  html .chart-panel .css-ffjkTHUI .css-kfleuiOPK { display: flex; gap: 8px; margin: 0; }
  html .chart-panel .css-ffjkTHUI .css-flekeTHUI { display: none; }
  html .chart-panel .css-ffjkTHUI .css-fufifkoF { display: none !important; }

  /* selects + buttons look like chips */
  html .chart-panel .css-ffjkTHUI select.css-flGTeTHUI,
  html .chart-panel .css-ffjkTHUI select.css-jekfioYU {
    -webkit-appearance: none;
            appearance: none;
    height: 34px;
    min-height: 34px;
    padding: 0 28px 0 13px;
    border: 1px solid rgba(148, 163, 184, .28);
    border-radius: 17px;
    background: rgba(255, 255, 255, .04) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2394a3b8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 11px center;
    color: var(--tam-text);
    font: 500 14px Inter, system-ui, Arial;
    outline: none;
  }
  html .chart-panel .css-ffjkTHUI select option { background: var(--tam-surface); color: var(--tam-text); }
  html .chart-panel .css-ffjkTHUI .css-jfklIUJW {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-sizing: border-box;
    height: 34px;
    min-height: 34px;
    min-width: 0;
    padding: 0 14px;
    border-radius: 17px;
    font-size: 13.5px;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
  }
  html .chart-panel .css-ffjkTHUI .css-jfklIUJW[style*="display:none"],
  html .chart-panel .css-ffjkTHUI .css-jfklIUJW[style*="display: none"] { display: none; }
  html .chart-panel .css-ffjkTHUI .css-jfklIUJW:active { transform: scale(.96); }

  /* chart overlays: keep them inside the chart area (the toolbar is on top) */
  /* OHLC legend, then the indicator legend below it with a clear gap
     (--tam-lgh = measured OHLC legend height, set by mobile.js) */
  html .chart-panel .chart-canvas > .css-fjfhwnyuW {
    position: absolute;
    top: calc(var(--tam-ctop) + 8px);
    left: 10px;
    width: auto;
    max-width: calc(100% - 80px);
    row-gap: 4px;
  }
  html .chart-panel .chart-canvas > .css-lfkfouHJt {
    position: absolute;
    top: calc(var(--tam-ctop) + 8px + var(--tam-lgh, 44px) + 12px);
    left: 10px;
    max-width: calc(100% - 80px);
  }
  html .chart-panel .chart-canvas > .css-lfkfouHJt .tooltip_container { gap: 8px; }

  /* bar-replay / SR detection controls: a strip docked under the toolbar */
  html .chart-panel .chart-canvas > .css-lfpfpRTDF,
  html .chart-panel .chart-canvas > .css-lfpfpRTDFW {
    position: absolute;
    top: var(--tam-tool);
    left: 0; right: 0;
    bottom: auto;
    height: var(--tam-strip);
    z-index: 42;
    transform: none;
    pointer-events: none;
    overflow: hidden;
  }
  html .chart-panel .chart-canvas > .css-lfpfpRTDF > .css-lfpfpRTWE,
  html .chart-panel .chart-canvas > .css-lfpfpRTDFW > .css-lfpfpRTWEW {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 100%;
    padding: 0 12px;
    border-radius: 0;
    border-bottom: 1px solid var(--tam-line);
    background: #0b1a30;
    box-shadow: none;
    overflow-x: auto;
    scrollbar-width: none;
    opacity: 0;
    transform: translateY(-100%);
    transition: transform .2s ease, opacity .2s ease;
  }
  html .chart-panel .chart-canvas > .css-lfpfpRTDF > .css-lfpfpRTWE.active,
  html .chart-panel .chart-canvas > .css-lfpfpRTDFW > .css-lfpfpRTWEW.active {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }
  html .chart-panel .css-lfpfpRTWE .css-lfofpkkRTT {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    box-sizing: border-box;
    width: 44px;
    height: 38px;
    padding: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, .03);
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
  }
  html .chart-panel .css-lfpfpRTWE .css-lfofpkkRTT:active { transform: scale(.94); }
  html .chart-panel .css-lfpfpRTWE .css-lfpfpRTWER {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    min-width: 90px;
    padding: 0 4px 0 6px;
  }
  html .chart-panel .css-lfpfpRTWE .css-lfpfpRTWW { width: 100%; max-width: none; height: 28px; }

  /* ---- compact replay row:  ◀◀  ▶/❚❚  ▶▶  ……  [Normal]  ⋮
     The ✕ (exit) moves into the ⋮ menu and the speed slider becomes the speed pill;
     both originals stay in the page, hidden (mobile.js drives them). */
  html.tam .chart-panel .css-lfpfpRTWE { gap: 6px; padding: 0 10px; overflow: hidden; }
  html.tam .chart-panel .css-lfpfpRTWE:has(.tam-rp-speed) > .css-lfofpkIYU,
  html.tam .chart-panel .css-lfpfpRTWE:has(.tam-rp-speed) > .css-lfpfpRTWER { display: none; }
  html.tam .chart-panel .css-lfpfpRTWE > .css-lfofpfkioRR { width: 48px; }
  .tam-rp-speed {
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-sizing: border-box;
    min-width: 72px;
    height: 36px;
    margin-left: auto;
    padding: 0 12px 0 14px;
    border: 1px solid rgba(128, 155, 235, .5);
    border-radius: 18px;
    background: rgba(128, 155, 235, .12);
    color: #c9d4fb;
    font: 600 13.5px Inter, system-ui, Arial;
    letter-spacing: .2px;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tam-rp-speed i { font-size: 10px; opacity: .75; }
  .tam-rp-speed[aria-expanded="true"] { background: rgba(128, 155, 235, .22); border-color: #809beb; }
  .tam-rp-more {
    flex: 0 0 auto;
    place-items: center;
    box-sizing: border-box;
    width: 40px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(148, 163, 184, .24);
    border-radius: 10px;
    background: rgba(255, 255, 255, .03);
    color: #cfd8e3;
    font-size: 15px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tam-rp-speed:active, .tam-rp-more:active { transform: scale(.95); }
  .tam-rp-more[aria-expanded="true"] { background: rgba(255, 255, 255, .09); }
  html.tam .chart-panel .css-lfpfpRTWE.active .tam-rp-speed { display: inline-flex; }
  html.tam .chart-panel .css-lfpfpRTWE.active .tam-rp-more { display: grid; }

  /* small popovers under the replay row: speed choices, more options */
  .tam-pop {
    position: absolute;
    z-index: 70;
    box-sizing: border-box;
    max-width: calc(100% - 16px);
    padding: 6px;
    background: var(--tam-surface);
    border: 1px solid rgba(138, 216, 229, .14);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px) scale(.98);
    transform-origin: top right;
    transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s;
  }
  html.tam .tam-pop { display: block;z-index: 100; }
  .tam-pop.open { opacity: 1; visibility: visible; transform: none; transition: opacity .16s ease, transform .16s ease; }
  .tam-pop-speed { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  html.tam .tam-pop-speed { display: flex;z-index: 100;}
  .tam-pop-chip {
    flex: 0 0 auto;
    min-width: 48px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid rgba(148, 163, 184, .24);
    border-radius: 20px;
    background: rgba(255, 255, 255, .03);
    color: #cfd8e3;
    font: 500 14px Inter, system-ui, Arial;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tam-pop-chip.on { border-color: #809beb; background: rgba(128, 155, 235, .18); color: #e3e9ff; font-weight: 600; }
  .tam-pop-chip:active { transform: scale(.95); }
  .tam-pop-menu { min-width: 220px; }
  .tam-pop-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--tam-text);
    font: 500 14.5px Inter, system-ui, Arial;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tam-pop-item i { width: 18px; text-align: center; color: var(--tam-muted); }
  .tam-pop-item:active { background: rgba(255, 255, 255, .06); }
  .tam-pop-item.danger, .tam-pop-item.danger i { color: #f87171; }
  @media (prefers-reduced-motion: reduce) { .tam-pop, .tam-pop.open { transition: none; } }
  /* narrow phones (< 375px): tighter row, same touch targets (≥ 40px) */
  @media (max-width: 374.98px) {
    html.tam .chart-panel .css-lfpfpRTWE { gap: 5px; padding: 0 8px; }
    html.tam .chart-panel .css-lfpfpRTWE > .css-lfofpkkRTT { width: 40px; }
    html.tam .chart-panel .css-lfpfpRTWE > .css-lfofpfkioRR { width: 44px; }
    .tam-rp-speed { min-width: 0; padding: 0 10px 0 12px; gap: 5px; font-size: 13px; }
  }
  html .chart-panel .css-lfpfpRTWEW .css-yfufjkloE,
  html .chart-panel .css-lfpfpRTWEW .css-oWmlERG {
    flex: 0 0 auto;
    box-sizing: border-box;
    min-height: 36px;
    padding: 0 12px;
    border-radius: 10px;
    white-space: nowrap;
  }

  /* drawing tools pencil + virtual position pill share the bottom-left corner */
  html.tam .vp-root.collapsed {
    left: 52px;
    bottom: calc(34px + var(--vp-nav, 0px) + env(safe-area-inset-bottom, 0px)); /* above the time axis */
  }

  /* ---------------------------------------------------------------- during bar replay */
  /* contract row (instrument chip + full-screen button) hides while replay is set up / runs:
     the chart grows by that height and is re-fitted (mobile.js watches the chart's size) */
  html.tam body:has(.chart-panel .css-jfklIUJW.back_play.active, .chart-panel .css-lfpfpRTWE.active) .tam-head { display: none; }

  /* ---------------------------------------------------------------- bar replay button (portrait) */
  /* the toolbar chip is replaced by a round button above the drawing pencil (mobile.js) */
  html.tam:not(.tam-land) .chart-panel .css-ffjkTHUI .css-jfklIUJW.back_play { display: none; }
  /* drawing-tools pencil and replay button: both 40 x 40 */
  html.tam .chart-panel .chart-canvas > .dt-show { box-sizing: border-box; width: 40px; height: 40px; }
  .tam-replay-fab.on {
    position: absolute;
    z-index: 112;                      /* above the chart and drawing layer, below fly-outs */
    display: grid;
    place-items: center;
    box-sizing: border-box;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid #9dd19e;         /* same colours as the Bar Replay chip */
    border-radius: 50%;
    background: #0d1c32;
    color: #3da978;
    font-size: 15px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, .45);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform .12s ease, background .15s ease;
  }
  .tam-replay-fab.on:active { transform: scale(.92); background: #12284a; }
  /* replay running: same blue as the active toolbar chip, with a glow */
  .tam-replay-fab.on.running {
    border: 2px solid #809beb;
    color: #809beb;
    background: #13213d;
    box-shadow: 0 0 0 3px rgba(128, 155, 235, .22), 0 0 16px 2px rgba(128, 155, 235, .55);
    animation: tam-replay-glow 2s ease-in-out infinite;
  }
  @keyframes tam-replay-glow {
    0%, 100% { box-shadow: 0 0 0 3px rgba(128, 155, 235, .22), 0 0 14px 1px rgba(128, 155, 235, .45); }
    50%      { box-shadow: 0 0 0 4px rgba(128, 155, 235, .3), 0 0 22px 4px rgba(128, 155, 235, .7); }
  }
  @media (prefers-reduced-motion: reduce) { .tam-replay-fab.on.running { animation: none; } }
  .tam-replay-fab.on:disabled { color: #8080803b; border-color: #8080806b; cursor: not-allowed; }
  .tam-replay-hint {
    position: absolute;
    z-index: 112;
    display: flex;
    align-items: center;
    height: 30px;
    padding: 0 12px;
    border-radius: 15px;
    background: #12284a;
    border: 1px solid rgba(157, 209, 158, .5);
    color: #cfe9d0;
    font: 500 13px Inter, system-ui, Arial;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity .25s ease, transform .25s ease;
  }
  .tam-replay-hint.on { opacity: 1; transform: none; }
  html.tam-land .tam-replay-fab, html.tam-land .tam-replay-hint { display: none; }

  /* ---------------------------------------------------------------- virtual Buy / Sell (bar replay) */
  /* portrait: docked bar under the chart (the chart ends above it, time axis included).
     The virtual-portfolio script still sets left/top for the desktop floating position;
     on phones those are overridden here. */
  html .chart-panel .chart-canvas > .vp-trade.active {
    position: absolute;
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--tam-trade);
    padding: 9px 12px;
    z-index: 44;
    background: #0b1a30;
    border-top: 1px solid var(--tam-line);
    box-shadow: 0 -6px 16px rgba(0, 0, 0, .25);
  }
  html .chart-panel .chart-canvas > .vp-trade .vp-trade-btn {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 12px;
    box-shadow: none;
    font: 600 15px Inter, system-ui, Arial;
    letter-spacing: .3px;
    -webkit-tap-highlight-color: transparent;
    transition: transform .12s ease, filter .12s ease;
  }
  html .chart-panel .chart-canvas > .vp-trade .vp-trade-btn:active { transform: scale(.97); filter: brightness(1.12); }
  html .chart-panel .chart-canvas > .vp-trade .vp-trade-btn[hidden] { display: none !important; }
  /* the virtual position pill sits above the bar */
  html.tam:not(.tam-land) body:has(.chart-panel .chart-canvas > .vp-trade.active) .vp-root {
    bottom: calc(8px + var(--vp-nav, 0px) + var(--tam-trade) + env(safe-area-inset-bottom, 0px));
  }
  html.tam:not(.tam-land) body:has(.chart-panel .chart-canvas > .vp-trade.active) .vp-root.collapsed {
    bottom: calc(34px + var(--vp-nav, 0px) + var(--tam-trade) + env(safe-area-inset-bottom, 0px));
  }

  /* ---------------------------------------------------------------- technical screen */
  html .workspace > #right_side_widow {
    position: fixed;
    left: 0; right: 0;
    top: var(--tam-top);
    bottom: var(--tam-nav);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    width: auto !important;
    height: auto !important;
    max-width: none;
    margin: 0;
    padding: 10px 10px 0;
    z-index: 6;
    background: var(--tam-bg);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateX(100%);
    transition: transform .24s cubic-bezier(.2, .8, .2, 1), opacity .2s ease;
  }
  html .workspace > #right_side_widow.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
    padding: 0;
  }
  html .workspace > #right_side_widow > .ui-resizable-handle { display: none !important; }
  /* the open analysis fills the screen and is the only scroller (no empty band on top,
     no gap above the tab bar) */
  html .workspace > #right_side_widow > .analysis {
    min-width: 0;
    margin: 0;
  }
  html .workspace > #right_side_widow > .analysis.active {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    margin: 0;
    padding: 0px 7px 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-radius:0;
  }

  html .workspace > #right_side_widow > .analysis .css-fkwfjwjUI,
  html .workspace > #right_side_widow > .analysis .css-lfkfopRTYLOP,
  html .workspace > #right_side_widow > .analysis .css-lfofpRTYYHMM {
    gap: 10px;
    max-height: none;
    overflow: visible;
  }

  /* ---------------------------------------------------------------- bottom tab bar */
  html .css-lfpfoRTYU {
    bottom: 0;
    box-sizing: border-box;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    align-items: stretch;
    background: #0b1426;
    border-top: 1px solid var(--tam-line);
    border-radius: 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .35);
  }
  html .css-lfpfoRTYU .css-lfpRfoRTYU {
    flex: 1;
    display: flex;
    justify-content: space-around;
    gap: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    -webkit-backdrop-filter: none;
            backdrop-filter: none;
  }
  html .css-lfpfoRTYU .css-lfpfoYRTYU,
  html .css-lfpfoRTYU .css-lfpfoYRTYU.active {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-height: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #7f90a8;
    font: 500 12px Inter, system-ui, Arial;
    letter-spacing: .3px;
    -webkit-tap-highlight-color: transparent;
  }
  html .css-lfpfoRTYU .css-lfpfoYRTYU.active { color: var(--tam-text); font-weight: 600; }
  /* the buttons' own icons become the Material-style active indicator */
  html .css-lfpfoRTYU .css-lfpfoYRTYU > i {
    display: grid;
    place-items: center;
    width: 58px;
    height: 30px;
    border-radius: 15px;
    font-size: 17px;
    line-height: 1;
    transition: background .2s ease, color .2s ease, transform .15s ease;
  }
  html .css-lfpfoRTYU .css-lfpfoYRTYU.active > i { background: rgba(112, 209, 116, .16); color: var(--tam-nav-accent); }
  html .css-lfpfoRTYU .css-lfpfoYRTYU:active > i { transform: scale(.92); }
  html .css-lfpfoRTYU .css-lfpfoYRTYU > span { line-height: 1.1; }

  /* ---------------------------------------------------------------- bottom sheets */
  .tam-sheet-bg {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    background: rgba(2, 8, 20, .58);
    -webkit-backdrop-filter: blur(2px);
            backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .24s ease;
  }
  .tam-sheet-bg.open { opacity: 1; pointer-events: auto; }
  .tam-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 2147483001;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    max-width: 640px;
    max-height: 88dvh;
    margin: 0 auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--tam-surface);
    border: 1px solid rgba(138, 216, 229, .12);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -16px 48px rgba(0, 0, 0, .5);
    color: var(--tam-text);
    font-family: Inter, system-ui, Arial;
    transform: translateY(105%);
    visibility: hidden;
    transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .3s;
    will-change: transform;
  }
  .tam-sheet.open { transform: translateY(0); visibility: visible; transition: transform .3s cubic-bezier(.2, .8, .2, 1); }
  .tam-sheet.tam-drag { transition: none; }
  .tam-grab { flex: 0 0 auto; display: flex; justify-content: center; padding: 9px 0 5px; touch-action: none; cursor: grab; }
  .tam-grab::before { content: ""; width: 40px; height: 4px; border-radius: 2px; background: rgba(148, 163, 184, .45); }
  .tam-sheet-hd {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 16px 12px;
    border-bottom: 1px solid var(--tam-line);
    touch-action: none;
  }
  .tam-sheet-title { font-size: 17px; font-weight: 600; letter-spacing: .2px; }
  .tam-sheet-done {
    height: 34px;
    padding: 0 16px;
    border: none;
    border-radius: 17px;
    background: rgba(138, 216, 229, .14);
    color: var(--tam-accent);
    font: 600 14px Inter, system-ui, Arial;
    cursor: pointer;
  }
  .tam-sheet-bd {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 4px 16px 20px;
  }

  /* ---------------------------------------------------------------- indicator search sheet */
  html .css-kflopHJU.indicator {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 2147482000;
    background: rgba(2, 8, 20, .58);
    -webkit-backdrop-filter: blur(2px);
            backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: none;
    transition: opacity .24s ease, visibility 0s linear .3s;
  }
  html .css-kflopHJU.indicator.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity .24s ease;
  }
  html .css-kflopHJU.indicator > .css-kflopHJY {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 640px;
    height: 74dvh;
    max-height: 88dvh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--tam-surface);
    border: 1px solid rgba(138, 216, 229, .12);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -16px 48px rgba(0, 0, 0, .5);
    color: var(--tam-text);
    font-family: Inter, system-ui, Arial;
    transform: translateY(105%);
    transition: transform .3s cubic-bezier(.2, .8, .2, 1);
    will-change: transform;
  }
  html .css-kflopHJU.indicator.active > .css-kflopHJY { transform: translateY(0); }
  html .css-kflopHJU.indicator > .css-kflopHJY.tam-drag { transition: none; }
  .tam-ind-hd { display: block; flex: 0 0 auto; touch-action: none; cursor: grab; }
  .tam-ind-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 12px 10px 16px;
  }
  .tam-ind-close {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .06);
    color: #cfd8e3;
    font-size: 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tam-ind-close:active { transform: scale(.92); }
  html .css-kflopHJU.indicator .css-mvdlkduif {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0;
    padding: 0 16px !important;
  }
  /* search field */
  html .css-kflopHJU.indicator .css-ufifen {
    flex: 0 0 auto;
    max-width: none;
    opacity: 1;
    transform: none;
  }
  html .css-kflopHJU.indicator .css-lfkee { height: 48px; font-size: 16px; }
  html .css-kflopHJU.indicator #ind_search_bar {
    box-sizing: border-box;
    width: 100% !important;
    height: 48px;
    padding: 0 14px 0 44px;
    border: 1px solid rgba(148, 163, 184, .25);
    border-radius: 14px;
    background: rgba(255, 255, 255, .05);
    color: var(--tam-text);
    font: 400 16px Inter, system-ui, Arial;  /* 16px: no zoom-in on iPhone */
    -webkit-appearance: none;
            appearance: none;
  }
  html .css-kflopHJU.indicator #ind_search_bar:focus {
    border-color: rgba(138, 216, 229, .6);
    background: rgba(255, 255, 255, .07);
  }
  html .css-kflopHJU.indicator .css-ljffjfoER {
    top: 0; bottom: 0;
    left: 15px;
    gap: 12px;
    color: var(--tam-muted);
    font-size: 15px;
    pointer-events: none;          /* the tap reaches the field and opens the keyboard */
  }
  html .css-kflopHJU.indicator .css-ljffjfoER i { margin-top: 0 !important; font-size: 15px; }
  html .css-kflopHJU.indicator .css-ljffjfoER span { font-size: 15px; }
  /* result list */
  html .css-kflopHJU.indicator .css-mvkdkdy {
    display: block !important;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none !important;
    margin: 0 -16px;
    padding: 2px 16px 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: transparent !important;
    border-radius: 0;
  }
  html .css-kflopHJU.indicator .css-mvkdkdy .css-kkldvdkr {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr) 30px;
    grid-template-rows: auto;
    align-items: center;
    column-gap: 12px;
    min-height: 62px;
    padding: 8px 0;
    border-bottom: 1px solid var(--tam-line) !important;
    -webkit-tap-highlight-color: transparent;
    transition: background .12s ease;
  }
  html .css-kflopHJU.indicator .css-mvkdkdy .css-kkldvdkr:active { background: rgba(255, 255, 255, .04); }
  html .css-kflopHJU.indicator .css-kkldvdkr .css-lcjkff {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    place-items: center;
    height: 38px;
    padding: 0 4px;
    border-radius: 10px;
    background: rgba(138, 216, 229, .1);
    color: var(--tam-accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  html .css-kflopHJU.indicator .css-kkldvdkr .css-ovpdmdr {
    grid-column: 2;
    grid-row: 1;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--tam-text);
  }
  html .css-kflopHJU.indicator .css-kkldvdkr:not(.not-found)::after {
    content: "+";
    grid-column: 3;
    grid-row: 1;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 1px solid rgba(148, 163, 184, .3);
    border-radius: 50%;
    color: var(--tam-muted);
    font: 400 19px/1 Inter, system-ui, Arial;
  }
  html .css-kflopHJU.indicator .css-kkldvdkr.not-found {
    grid-template-columns: 1fr;
    color: var(--tam-muted);
    text-align: center;
    border-bottom: none !important;
  }
  html .css-kflopHJU.indicator .css-mvkdkdy .css-wwvndnd {
    justify-content: flex-start;
    padding: 16px 0 6px;
    color: var(--tam-muted);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-bottom: none !important;
  }

  /* bar replay first-time sheet */
  .tam-sheet-x {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .06);
    color: #cfd8e3;
    font-size: 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tam-sheet-x:active { transform: scale(.92); }
  .tam-ri .tam-sheet-hd { border-bottom: none; padding-bottom: 4px; }
  .tam-ri .tam-sheet-bd { display: flex; flex-direction: column; align-items: center; padding: 8px 20px 22px; text-align: center; }
  .tam-ri-icon {
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    margin: 4px 0 14px;
    border: 2px solid #809beb;
    border-radius: 50%;
    background: #13213d;
    color: #809beb;
    font-size: 20px;
    box-shadow: 0 0 0 4px rgba(128, 155, 235, .18), 0 0 18px 2px rgba(128, 155, 235, .35);
  }
  .tam-ri-sub {
    max-width: 320px;
    margin: 0 0 20px;
    color: var(--tam-muted);
    font-size: 15px;
    line-height: 1.5;
  }
  .tam-ri-cta {
    width: 100%;
    max-width: 420px;
    min-height: 48px;
    border: none;
    border-radius: 14px;
    background: #809beb;
    color: #0b1430;
    font: 600 16px Inter, system-ui, Arial;
    letter-spacing: .2px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(128, 155, 235, .25);
    -webkit-tap-highlight-color: transparent;
  }
  .tam-ri-cta:active { transform: scale(.98); filter: brightness(1.08); }

  /* contract sheet content */
  .tam-lbl {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 16px 0 9px;
    color: var(--tam-muted);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
  }
  .tam-lbl small { font-size: 11.5px; letter-spacing: .3px; text-transform: none; font-weight: 500; color: #64748b; }
  .tam-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px;
    padding: 0 16px 2px;
    scroll-padding: 0 16px;
  }
  .tam-row::-webkit-scrollbar { display: none; }
  .tam-chip {
    flex: 0 0 auto;
    box-sizing: border-box;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid rgba(148, 163, 184, .24);
    border-radius: 20px;
    background: rgba(255, 255, 255, .03);
    color: #cfd8e3;
    font: 500 14px Inter, system-ui, Arial;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s ease, border-color .15s ease, transform .12s ease;
  }
  .tam-chip:active { transform: scale(.95); }
  .tam-chip.on {
    border-color: rgba(138, 216, 229, .7);
    background: rgba(138, 216, 229, .15);
    color: #effcff;
    font-weight: 600;
  }
  .tam-chip:disabled { opacity: .35; }
  .tam-chip.sm { min-height: 32px; padding: 0 13px; font-size: 13px; border-radius: 16px; }
  .tam-exp {
    display: grid;
    place-items: center;
    gap: 2px;
    min-width: 64px;
    min-height: 54px;
    padding: 6px 10px;
    border-radius: 14px;
    line-height: 1.1;
  }
  .tam-exp b { font-size: 15px; font-weight: 600; }
  .tam-exp span { font-size: 11px; color: var(--tam-muted); }
  .tam-exp.on span { color: #bfeff6; }

  .tam-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .tam-seg .tam-chip { min-height: 46px; border-radius: 12px; font-size: 15px; }
  .tam-seg .tam-chip small { margin-left: 6px; font-size: 12px; opacity: .75; }
  .tam-seg .tam-chip.on.ce { border-color: rgba(34, 197, 94, .7); background: rgba(34, 197, 94, .14); color: #dcfce7; }
  .tam-seg .tam-chip.on.pe { border-color: rgba(248, 113, 113, .7); background: rgba(248, 113, 113, .14); color: #fee2e2; }

  .tam-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .tam-grid .tam-chip { min-height: 44px; padding: 0 4px; border-radius: 12px; font-variant-numeric: tabular-nums; }
  .tam-busy { position: relative; pointer-events: none; opacity: .45; transition: opacity .2s ease; }
  .tam-empty { padding: 12px 0; color: #64748b; font-size: 13px; }
}

/* 5 strike columns on wide phones / tablets */
@media (min-width: 520px) and (max-width: 1049.98px) {
  .tam-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .tam-sheet { max-width: 560px; }
}

/* ==========================================================================
   Phone landscape: full-screen chart with its toolbar (no top bar / tab bar)
   ========================================================================== */
@media (max-width: 1049.98px) and (orientation: landscape) and (max-height: 540px) {
  html .topbar { display: none !important; }
  html .css-lfpfoRTYU { display: none !important; }
  :root { --tam-tool: 44px; }

  html .workspace > .chart-panel,
  html .workspace > .chart-panel.exit {
    top: 0;
    bottom: 0;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }
  html .workspace > #right_side_widow { display: none !important; }

  /* contract chip sits at the left end of the toolbar row */
  .tam-head {
    position: absolute;
    top: 0; left: env(safe-area-inset-left, 0px);
    z-index: 45;
    height: var(--tam-tool);
    padding: 0 6px 0 10px;
    border-bottom: none;
    background: var(--tam-bg);
    box-shadow: 10px 0 10px -6px var(--tam-bg);
  }
  .tam-contract { height: 34px; font-size: 14px; padding: 0 10px 0 12px; }
  .tam-fs-btn, .tam-fs-exit { display: none !important; }
  html .chart-panel .css-ffjkTHUI > .css-fdrGTeTHUI { padding-left: calc(var(--tam-chipw, 220px) + 8px); }
  html body:has(.chart-panel .css-jfklIUJW.back_play.active, .chart-panel .css-lfpfpRTWE.active) .chart-panel .css-ffjkTHUI > .css-fdrGTeTHUI { padding-left: 12px; }

  .tam-sheet { max-height: 94dvh; max-width: 560px; }
  .tam-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  html .css-kflopHJU.indicator > .css-kflopHJY { height: 92dvh; max-width: 560px; }

  /* virtual Buy / Sell: right end of the replay strip (height is too precious for a bottom bar) */
  html .chart-panel .chart-canvas:has(> .vp-trade.active) { --tam-cbot: 0px; }
  html .chart-panel .chart-canvas > .vp-trade.active {
    top: var(--tam-tool) !important;
    bottom: auto;
    left: auto !important;
    right: env(safe-area-inset-right, 0px);
    height: var(--tam-strip);
    gap: 8px;
    padding: 0 12px 0 16px;
    background: #0b1a30;
    border-top: none;
    box-shadow: -12px 0 12px -6px #0b1a30;
  }
  html .chart-panel .chart-canvas > .vp-trade .vp-trade-btn {
    flex: 0 0 auto;
    height: 36px;
    min-height: 36px;
    padding: 0 14px;
    border-radius: 10px;
    font-size: 13.5px;
  }
  html .chart-panel .chart-canvas:has(> .vp-trade.active) > .css-lfpfpRTDF > .css-lfpfpRTWE { padding-right: calc(var(--tam-tradew, 330px) + 8px); }
}