/* Tablet / all-device fit (loaded last).
   Fixes bottom/side clipping on tablets: 100vh in mobile browsers is taller than
   the visible area (address bar + bottom toolbar), and desktop rules (>1100px,
   e.g. iPad landscape) still used 100vh. */

/* <=1100px the variable is set by mobile-terminal.css */
@media (min-width: 1101px) {
  :root { --terminal-header-height: 56px; }
}

html, body {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}
@supports not (height: 100dvh) {
  html, body { height: -webkit-fill-available; }
}

/* Desktop & tablet (phones keep their own dock layout) */
@media (min-width: 651px) {
  body {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
  main {
    height: calc(100dvh - var(--terminal-header-height)) !important;
    max-height: calc(100dvh - var(--terminal-header-height)) !important;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    width: 100%;
    min-width: 0;
  }
  @supports not (height: 100dvh) {
    main {
      height: calc(100vh - var(--terminal-header-height)) !important;
      max-height: calc(100vh - var(--terminal-header-height)) !important;
    }
  }
  main > *, .workspace, .split-grid, .chart-area { min-width: 0; }
  .trade-sidebar { padding-bottom: env(safe-area-inset-bottom, 0px); }
  .acc-dropdown, .profile-dropdown { max-width: calc(100vw - 16px); }
  .asset-modal.asset-flyout-panel {
    max-height: calc(100dvh - var(--terminal-header-height) - 12px) !important;
  }
  .webapp-frame-container.maximized {
    height: calc(100dvh - 48px) !important;
    max-height: 100dvh !important;
  }
}

/* Touch tablets in landscape that get the desktop layout (1101–1400px):
   tighter header so nothing is pushed off the right edge. */
@media (min-width: 1101px) and (max-width: 1400px) and (pointer: coarse) {
  header { padding-left: 10px !important; padding-right: 10px !important; gap: 8px !important; }
  .header-left { gap: 8px !important; min-width: 0; }
  .header-end { gap: 10px !important; min-width: 0; }
  .header-left .brand-name, .header-left .brand small, header .unofficial-badge { display: none !important; }
  .header-tab { padding: 6px 9px !important; }
  .header-nav-tabs { min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .header-nav-tabs::-webkit-scrollbar { display: none; }
  .official { display: none !important; }
  .toolbar { overflow-x: auto; scrollbar-width: none; touch-action: pan-x; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex-shrink: 0; }
}

/* Short landscape tablets (e.g. 1024x600, split-screen): compact panels */
@media (min-width: 651px) and (max-height: 700px) {
  .trade-sidebar .order-panel { padding: 8px !important; }
  .panel-heading { margin-bottom: 8px !important; }
  .payout { margin: 8px 0 !important; }
  .chart-controls { bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
}

/* Touch targets on tablets */
@media (min-width: 651px) and (pointer: coarse) {
  .trade { min-height: 44px; }
  .chart-controls button { min-width: 36px; min-height: 36px; }
}
