/* The parent Trade page supplies the surrounding LaneGecko chrome. */
html[data-embed="1"] .app { min-height: 0; }
html[data-embed="1"] .brand-text,
html[data-embed="1"] .site-link-wrap,
html[data-embed="1"] .auth-site-link,
html[data-embed="1"] .menu-item.site-item { display: none; }
html[data-embed="1"] .auth-page { min-height: 0; padding-top: 24px; }
html[data-embed="1"] .auth-brand { display: none; }
html[data-embed="1"] .app-footer { padding-bottom: 12px; }

/* 2026-10-04 (user: "take the scroll bar off"): no page scrollbar inside the parent frame; wheel/touch scrolling still works. */
html[data-embed="1"], html[data-embed="1"] body { scrollbar-width: none; -ms-overflow-style: none; }
html[data-embed="1"]::-webkit-scrollbar, html[data-embed="1"] body::-webkit-scrollbar { display: none; width: 0; height: 0; }

/* 2026-10-04 (user: "the scroll bar is gone but you can still scroll, I want it fixed"): on the Trade
   screen the embedded desk now fits the parent's frame exactly, exchange-terminal style. The page itself
   never scrolls: the chart takes the free height, the bottom tables get a bounded share, and the order
   book, ticket and tables scroll inside their own panels (thin, muted scrollbars).
   Scope: embedded + signed in + Trade route, i.e. #app.signed-in > .main[data-route="trade"] (body[data-route]
   stays "trade" after sign-out, so it is not used). Applies to frames 901 px and wider, and to 600-900 px wide
   frames at least 860 px tall (tablet portrait). Other narrow frames (phones) keep the scrolling mobile layout.
   Other routes and the sign-in page are unchanged: they scroll with the hidden scrollbar above.
   Browsers without :has() skip the whole block and keep the previous (scrolling) layout. */
@supports selector(:has(*)) {

  /* A. Fit chain: html > body > #app > main > view > grid, each filling the frame (desktop + tall narrow) */
  @media (min-width: 901px), (min-width: 600px) and (min-height: 860px) {
    html[data-embed="1"]:has(#app.signed-in > .main[data-route="trade"]),
    html[data-embed="1"]:has(#app.signed-in > .main[data-route="trade"]) body { height: 100%; overflow: hidden; }
    html[data-embed="1"]:has(#app.signed-in > .main[data-route="trade"]) body { display: flex; flex-direction: column; }
    html[data-embed="1"]:has(#app.signed-in > .main[data-route="trade"]) #app { flex: 1 1 0; min-height: 0; }
    html[data-embed="1"] #app.signed-in > .app-header,
    html[data-embed="1"] #app.signed-in > .banners { flex: none; }
    html[data-embed="1"] #app.signed-in > .main[data-route="trade"] { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
    html[data-embed="1"] .main[data-route="trade"] > .view-trade { flex: 1 1 0; min-height: 0; width: 100%; display: flex; flex-direction: column; }
    html[data-embed="1"] .view-trade > .trade-grid { flex: 1 1 0; min-height: 0; --td-bottom-h: clamp(190px, 34%, 340px); }
    html[data-embed="1"] .view-trade > .trade-grid > .tg-chart,
    html[data-embed="1"] .view-trade > .trade-grid > .tg-book { min-height: 0; max-height: none; }
    html[data-embed="1"] .view-trade .chart-area,
    html[data-embed="1"] .view-trade .depth-canvas { min-height: 0; }

    /* ticket: when it is taller than its panel it scrolls inside, and the Buy/Sell buttons stay in view */
    html[data-embed="1"] .tg-ticket > .ticket > .submit-btn,
    html[data-embed="1"] .tg-ticket > .ticket > .btn-pair { position: sticky; bottom: 8px; z-index: 2; box-shadow: 0 0 0 8px var(--panel); }
    html[data-embed="1"] .tg-ticket > .ticket > .btn-pair { background: var(--panel); }

    /* bottom panel: tabs stay put; each tab's table scrolls inside with its header row pinned */
    html[data-embed="1"] .view-trade > .trade-grid > .tg-bottom { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
    html[data-embed="1"] .tg-bottom > .tabbed { flex: 1 1 0; height: auto; min-height: 0; }
    html[data-embed="1"] .tg-bottom .tabs { flex: none; scrollbar-color: var(--border) transparent; }
    html[data-embed="1"] .tg-bottom .tabs-body > * { display: flex; flex-direction: column; min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
    html[data-embed="1"] .tg-bottom .tabs-body > * > .panel-toolbar { flex: none; }
    html[data-embed="1"] .tg-bottom .tabs-body > * > .table-wrap { flex: 0 1 auto; min-height: 0; max-height: none; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
    html[data-embed="1"] .tg-bottom .table thead th { position: sticky; top: 0; z-index: 1; background: var(--panel); box-shadow: inset 0 -1px var(--border); }
    html[data-embed="1"] .view-trade .tp-list { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

    /* footer: compact, under the grid (wraps rather than being cut on narrower frames) */
    html[data-embed="1"]:has(#app.signed-in > .main[data-route="trade"]) .app-footer { flex: none; padding: 4px var(--gutter); line-height: 1.35; }
  }

  /* B. Desktop frames: the ticket runs the full height on the right; bottom tables a little denser */
  @media (min-width: 901px) {
    html[data-embed="1"] .view-trade > .trade-grid.advanced {
      grid-template-areas: "chart book ticket" "bottom bottom ticket";
      grid-template-rows: minmax(0, 1fr) minmax(0, var(--td-bottom-h));
    }
    html[data-embed="1"] .view-trade > .trade-grid.simple {
      grid-template-areas: "chart ticket" "bottom ticket";
      grid-template-rows: minmax(0, 1fr) minmax(0, var(--td-bottom-h));
    }
    html[data-embed="1"] .view-trade > .trade-grid > .tg-ticket { min-height: 0; max-height: none; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
    html[data-embed="1"] .tg-bottom .tabs-body > * > .panel-toolbar { padding-top: 4px; padding-bottom: 4px; }
    html[data-embed="1"] .tg-bottom .panel-toolbar .btn-sm { min-height: 26px; }
    html[data-embed="1"] .tg-bottom .table th { padding-top: 5px; padding-bottom: 5px; }
    html[data-embed="1"] .tg-bottom .table td { padding-top: 4px; padding-bottom: 4px; }
    /* row buttons stay on one line (the table scrolls sideways) instead of tripling the row height */
    html[data-embed="1"] .tg-bottom .row-actions,
    html[data-embed="1"] .tg-bottom .close-actions { flex-wrap: nowrap; }
  }

  /* 901-1280 px frames: app.css stacks the advanced grid there (chart 560 px tall, book under the ticket);
     keep three columns instead so the whole terminal fits the frame height. */
  @media (min-width: 901px) and (max-width: 1280px) {
    html[data-embed="1"] .view-trade > .trade-grid.advanced { grid-template-columns: minmax(0, 1fr) 260px 290px; }
    html[data-embed="1"] .view-trade > .trade-grid.simple { grid-template-columns: minmax(0, 1fr) 320px; }
  }

  /* C. Tall narrow frames (tablet portrait): chart on top, order book and tables side by side under it, all
     above the fixed bottom nav; the ticket stays the mobile bottom sheet opened by the Trade button. */
  @media (min-width: 600px) and (max-width: 900px) and (min-height: 860px) {
    html[data-embed="1"]:has(#app.signed-in > .main[data-route="trade"]) body { padding-bottom: calc(57px + env(safe-area-inset-bottom)); }
    html[data-embed="1"] #app.signed-in > .main[data-route="trade"] { padding: 6px; }
    html[data-embed="1"] .view-trade > .trade-grid.advanced {
      grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
      grid-template-areas: "chart chart" "book bottom";
      grid-template-rows: minmax(0, 1fr) minmax(0, clamp(260px, 45%, 420px));
    }
    html[data-embed="1"] .view-trade > .trade-grid.simple {
      grid-template-areas: "chart" "bottom";
      grid-template-rows: minmax(0, 1fr) minmax(0, var(--td-bottom-h));
    }
    html[data-embed="1"] .view-trade .chart-area { height: auto; flex: 1 1 0; }
  }
}

/* D. Short narrow frames (phones) keep the scrolling mobile layout: give back app.css's room under the footer
   for the fixed bottom nav (the 12 px rule above removed it, hiding the footer's last lines behind the nav). */
@media (max-width: 900px) {
  html[data-embed="1"] .app-footer { padding-bottom: 76px; }
}
