/* OT Terminal — Responsive Behaviour
 * Desktop-first. Laptop tightens spacing; tablet auto-collapses the
 * drawing-tools rail; mobile turns both side panels into off-canvas
 * drawers so the chart always gets the full viewport by default.
 */

/* ===== Laptop (~1280px and down): tighter rails ===== */
@media (max-width: 1280px) {
  .ot-terminal {
    --ot-watchlist-w: 208px;
    --ot-drawing-w: 148px;
  }
  .ot-header__tagline { display: none; }
}

/* ===== Tablet (~1024px and down) ===== */
@media (max-width: 1024px) {
  .ot-terminal {
    --ot-watchlist-w: 196px;
  }
  /* Drawing tools default to collapsed; the Hide/Show control still works,
     it just now expands as an overlay instead of pushing the grid. */
  .ot-shell-body:not(.ot-drawing-force-open) {
    grid-template-columns: var(--ot-wl-track) minmax(0, 1fr) 0px !important;
  }
  .ot-shell-body.ot-drawing-force-open {
    grid-template-columns: var(--ot-wl-track) minmax(0, 1fr) var(--ot-drawing-w) !important;
  }
  .ot-header__nav-link:nth-child(n+6) { display: none; }
}

/* ===== Mobile / narrow tablet (~760px and down) ===== */
@media (max-width: 760px) {
  .ot-terminal { --ot-strip-h: 72px; --ot-header-h: 52px; }

  .ot-header__nav { display: none; }
  .ot-header__search { flex-basis: auto; width: 120px; min-width: 90px; }
  .ot-header__status { display: none; }
  .ot-header__divider { display: none; }

  .ot-mobile-panel-toggle {
    display: inline-flex !important;
  }

  /* The tablet rule above targets `.ot-shell-body:not(.ot-drawing-force-open)`,
     whose `:not()` pseudo-class counts toward specificity — (0,2,0) — which
     beats a plain `.ot-shell-body` (0,1,0) even with `!important` on both,
     regardless of media-query source order. Match that specificity here
     (three classes, safely above it) so the mobile override reliably wins
     at narrow widths instead of leaving the watchlist's grid track at its
     tablet width. */
  .ot-terminal .ot-shell .ot-shell-body {
    grid-template-columns: 0px minmax(0, 1fr) 0px !important;
    position: relative;
  }

  .ot-watchlist,
  .ot-drawing-panel {
    position: fixed;
    top: var(--ot-header-h);
    bottom: var(--ot-strip-h);
    width: min(78vw, 300px);
    z-index: 50;
    box-shadow: 0 0 32px rgba(0,0,0,0.55);
    transition: transform var(--ot-transition-base);
  }

  .ot-watchlist {
    left: 0;
    transform: translateX(-100%);
    display: flex !important;
  }
  .ot-drawing-panel {
    right: 0;
    transform: translateX(100%);
    display: flex !important;
  }

  .ot-shell.ot-mobile-watchlist-open .ot-watchlist {
    transform: translateX(0);
  }
  .ot-shell.ot-mobile-drawing-open .ot-drawing-panel {
    transform: translateX(0);
  }

  .ot-mobile-scrim {
    display: none;
    position: fixed;
    inset: var(--ot-header-h) 0 var(--ot-strip-h) 0;
    background: rgba(0,0,0,0.5);
    z-index: 45;
  }
  .ot-shell.ot-mobile-watchlist-open .ot-mobile-scrim,
  .ot-shell.ot-mobile-drawing-open .ot-mobile-scrim {
    display: block;
  }

  .ot-drawing-toggle { display: none; }

  /* Watchlist edge arrow on mobile: opens/closes the off-canvas drawer
     (closed by default), riding on the drawer's edge when open. */
  .ot-terminal .ot-watchlist-toggle {
    left: 0 !important;
    z-index: 46;
    width: 16px;
    height: 48px;
  }
  .ot-terminal .ot-shell.ot-mobile-watchlist-open .ot-watchlist-toggle {
    left: min(78vw, 300px) !important;
    z-index: 60;
  }
  .ot-terminal .ot-watchlist-toggle svg { transform: rotate(180deg) !important; }
  .ot-terminal .ot-shell.ot-mobile-watchlist-open .ot-watchlist-toggle svg { transform: none !important; }

  .ot-chart-toolbar { gap: 6px; }
  .ot-chart-toolbar__btn span { display: none; }

  .ot-market-strip { padding: 8px 10px; gap: 8px; }
  .ot-market-card { min-width: 148px; padding: 0 12px; }
  .ot-market-card__spark { width: 44px; }

  .ot-chart-pane-sub { flex-basis: 64px; height: auto; min-height: 30px; }
}

@media (max-width: 420px) {
  .ot-header__tagline { display: none; }
  .ot-watchlist, .ot-drawing-panel { width: 84vw; }
  .ot-terminal .ot-shell.ot-mobile-watchlist-open .ot-watchlist-toggle { left: 84vw !important; }

  /* Free up enough header width for a genuinely tappable search icon
     at phone widths (~390px) — without these, the header's fixed-size
     content (brand block + "OT Terminal" pill + actions + both mobile
     toggle buttons) already exceeds the viewport on its own, pushing
     the search icon off-screen. Neither of these carries information
     the brand mark/name itself doesn't already convey at this width. */
  .ot-header__brand-sub { display: none; }
  .ot-header__product { display: none; }

  /* Advanced Symbol Search phase — there's no longer room for even a
     narrow always-visible search input at this width, but the brief
     requires mobile search to actually work (not just be hidden), so
     the search box collapses to a tappable icon and expands into a
     fixed-position overlay bar when tapped (JS toggles `.is-mobile-open`
     on `.ot-header__search` — see SymbolSearch.js's icon click
     handler). Collapsed state: */
  .ot-header__search {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    position: static;
  }
  .ot-header__search input {
    width: 0;
    min-width: 0;
    padding: 0;
    border-color: transparent;
    background: transparent;
    opacity: 0;
  }
  .ot-header__search-icon {
    position: static;
    transform: none;
    width: 20px;
    height: 20px;
    cursor: pointer;
    pointer-events: auto;
  }
  /* Expanded (tapped) state: a fixed-position bar under the header,
     wide enough to actually type/read into, with the results dropdown
     anchored below it exactly as on desktop. */
  .ot-header__search.is-mobile-open {
    position: fixed;
    left: 8px;
    right: 8px;
    top: calc(var(--ot-header-h) + 6px);
    z-index: 70;
  }
  .ot-header__search.is-mobile-open input {
    width: 100%;
    min-width: 0;
    opacity: 1;
    padding: 0 32px 0 12px;
    border-color: var(--ot-border);
    background: var(--ot-bg-input);
  }
  .ot-header__search.is-mobile-open .ot-header__search-icon {
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
  }
  .ot-header__search.is-mobile-open .ot-search-results {
    width: 100%;
  }
}
