/**
 * iPhone mobile formatting of the full Waypoint platform.
 * ADDITIVE ONLY. Every rule is scoped under html.waypoint-iphone.
 * Does not change desktop, laptop, monitor, or Fold interior tablet layout.
 */

html.waypoint-iphone,
html[data-device-mode="iphone"] {
  --iphone-safe-top: env(safe-area-inset-top, 0px);
  --iphone-safe-right: env(safe-area-inset-right, 0px);
  --iphone-safe-bottom: env(safe-area-inset-bottom, 0px);
  --iphone-safe-left: env(safe-area-inset-left, 0px);
  --nav-rail-w: 0px;
  --shell-max: 100%;
  --shell-pad-x: 8px;
  --shell-pad-y: 8px;
  --shell-gap: 8px;
  --touch-min: 44px;
  --btn-h: 44px;
  --btn-h-sm: 40px;
  --type-root: 15px;
  --card-pad: 12px;
  --msg-dock-inset: 10px;
  --desk-header-h: 52px;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

html.waypoint-iphone body,
html[data-device-mode="iphone"] body {
  overflow-x: hidden;
  min-height: 100dvh;
  min-height: 100svh;
  padding-left: var(--iphone-safe-left);
  padding-right: var(--iphone-safe-right);
}

html.waypoint-iphone input,
html.waypoint-iphone select,
html.waypoint-iphone textarea {
  font-size: 16px !important;
}

html.waypoint-iphone .btn,
html.waypoint-iphone .btn-sm,
html.waypoint-iphone .nav-rail-btn,
html.waypoint-iphone .ws-nav-btn,
html.waypoint-iphone .ws-chrome-btn,
html.waypoint-iphone .ws-tab,
html.waypoint-iphone .gate-choice-btn {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
}

/* ===== Disclaimer ===== */

.iphone-format-disclaimer {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  background: rgba(2, 8, 16, 0.72);
}

.iphone-format-disclaimer[hidden] {
  display: none !important;
}

.iphone-format-disclaimer-card {
  width: min(440px, 92vw);
  padding: 24px 20px 18px;
  border-radius: 14px;
  border: 1px solid rgba(212, 177, 95, 0.28);
  background: linear-gradient(180deg, rgba(18, 32, 52, 0.98), rgba(8, 16, 28, 0.98));
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  text-align: left;
}

.iphone-format-disclaimer-card h2 {
  margin: 6px 0 12px;
  font-family: Cinzel, "Times New Roman", serif;
  font-size: 1.18rem;
  color: #f0e6c8;
}

.iphone-format-disclaimer-body {
  margin: 0 0 18px;
  font-size: 0.92rem;
  line-height: 1.55;
  color: rgba(232, 238, 246, 0.86);
}

.iphone-format-disclaimer-actions {
  display: flex;
  justify-content: flex-end;
}

.iphone-format-disclaimer-actions .btn {
  width: 100%;
}

/* ===== Shell / navigation ===== */

html.waypoint-iphone .command-deck-layout {
  grid-template-columns: 1fr !important;
  width: 100%;
  max-width: none;
  min-width: 0;
  min-height: 0;
  height: auto;
  max-height: none;
  overflow: visible;
  padding-bottom: calc(64px + var(--iphone-safe-bottom));
}

html.waypoint-iphone .nav-rail {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  top: auto !important;
  z-index: 300 !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  width: 100% !important;
  min-width: 0 !important;
  height: auto !important;
  max-height: none !important;
  min-height: 56px;
  padding: 6px 8px calc(6px + var(--iphone-safe-bottom)) !important;
  gap: 4px !important;
  border-right: 0 !important;
  border-top: 1px solid rgba(201, 162, 39, 0.18) !important;
  background: rgba(8, 18, 28, 0.98) !important;
  -webkit-overflow-scrolling: touch;
}

html.waypoint-iphone .nav-rail-brand {
  display: none !important;
}

html.waypoint-iphone .nav-rail-btn,
html.waypoint-iphone .nav-rail-btn-labeled,
html.waypoint-iphone .nav-rail-btn-pirate {
  width: auto !important;
  min-width: 56px !important;
  min-height: 48px !important;
  flex: 0 0 auto !important;
}

html.waypoint-iphone .desk-header {
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px calc(6px + var(--iphone-safe-top));
  max-width: 100%;
}

html.waypoint-iphone .desk-product-line,
html.waypoint-iphone .display-mode-control,
html.waypoint-iphone #openMyAccountLabel {
  display: none !important;
}

html.waypoint-iphone .desk-title {
  font-size: 0.95rem;
}

html.waypoint-iphone .desk-header-meta {
  width: 100%;
  justify-content: flex-start;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

html.waypoint-iphone .quote-strip,
html.waypoint-iphone #liveQuoteStrip {
  flex-wrap: nowrap;
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

html.waypoint-iphone .deck-persistent-shell,
html.waypoint-iphone body:not(.helm-mode):not(.trade-log-mode):not(.store-mode):not(.training-portal-mode):not(.competitive-intel-mode):not(.development-mode):not(.admin-hub-mode):not(.event-radar-mode):not(.social-mode) .deck-persistent-shell {
  display: flex !important;
  flex-direction: column !important;
  grid-template-columns: 1fr !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  padding: 8px !important;
  gap: 8px !important;
}

html.waypoint-iphone #instrumentRail,
html.waypoint-iphone .panel-avatar {
  display: none !important;
}

html.waypoint-iphone .panel,
html.waypoint-iphone .deck-workspace,
html.waypoint-iphone .ad-win,
html.waypoint-iphone .th-win {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

/* ===== Analysis / Trade Hub — stacked full-platform mobile ===== */

html.waypoint-iphone .ad-desk-host,
html.waypoint-iphone body.analysis-mode .ad-desk-host:not([hidden]) {
  height: auto;
  max-height: none;
  min-height: 0;
}

html.waypoint-iphone body.analysis-mode.ad-full-desk .deck-persistent-shell {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  padding: 8px !important;
}

html.waypoint-iphone .ad-layout-canvas,
html.waypoint-iphone .th-layout-canvas {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

html.waypoint-iphone .ad-win,
html.waypoint-iphone .th-win {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  width: 100% !important;
  height: auto !important;
  min-height: 160px;
  max-width: 100% !important;
}

html.waypoint-iphone .ad-win[data-layout-id="chart"],
html.waypoint-iphone .th-win[data-layout-id="chart"] {
  order: -3;
  min-height: min(46dvh, 420px);
}

html.waypoint-iphone .ad-win[data-layout-id="pete"] {
  order: -2;
  min-height: min(32dvh, 280px);
}

html.waypoint-iphone .ad-win-resize,
html.waypoint-iphone .th-win-resize,
html.waypoint-iphone .ad-win-chrome,
html.waypoint-iphone .th-win-chrome,
html.waypoint-iphone .ws-chrome-drag {
  display: none !important;
}

html.waypoint-iphone .ad-win-title,
html.waypoint-iphone .th-win-title {
  cursor: default;
  min-height: 40px;
  touch-action: manipulation;
}

html.waypoint-iphone #analysisChartPanel,
html.waypoint-iphone .chart-host,
html.waypoint-iphone .tv-chart,
html.waypoint-iphone [data-chart],
html.waypoint-iphone iframe {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

html.waypoint-iphone canvas {
  max-width: 100%;
}

/* ===== Gate / login ===== */

html.waypoint-iphone #launchOverlay.gate-auth-visible .gate-phase-auth,
html.waypoint-iphone .gate-phase-auth {
  width: min(400px, calc(100vw - 20px)) !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%);
  bottom: max(12px, var(--iphone-safe-bottom));
}

html.waypoint-iphone .gate-auth-card,
html.waypoint-iphone .site-card {
  max-width: 100%;
}

html.waypoint-iphone .site-wrap {
  padding-left: 12px;
  padding-right: 12px;
}

/* ===== Messenger ===== */

html.waypoint-iphone .crew-messenger {
  right: 0;
  bottom: calc(56px + var(--iphone-safe-bottom));
  left: auto;
}

html.waypoint-iphone .crew-messenger.is-open .crew-msg-panel,
html.waypoint-iphone .crew-msg-panel {
  width: 100vw;
  max-width: 100vw;
  height: calc(100dvh - 56px - var(--iphone-safe-top));
  border-radius: 14px 14px 0 0;
}

/* ===== Brain scan / overlays ===== */

html.waypoint-iphone .pete-brainscan-panel:not(.is-minimized) {
  left: 4px !important;
  right: 4px !important;
  top: calc(var(--desk-header-h, 52px) + 4px) !important;
  bottom: calc(64px + var(--iphone-safe-bottom)) !important;
  width: auto !important;
  height: auto !important;
  max-width: none !important;
}

html.waypoint-iphone .ws-workspace,
html.waypoint-iphone .social-root,
html.waypoint-iphone .social-shell {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

@media (max-width: 400px) {
  html.waypoint-iphone,
  html[data-device-mode="iphone"] {
    --type-root: 14px;
    --shell-pad-x: 6px;
    --card-pad: 10px;
    --desk-header-h: 48px;
  }
}

@media (min-width: 401px) and (max-width: 480px) {
  html.waypoint-iphone,
  html[data-device-mode="iphone"] {
    --type-root: 15px;
    --shell-pad-x: 10px;
    --card-pad: 14px;
    --desk-header-h: 52px;
  }
}
