/* Shared phone/tablet UX. Desktop feature styles remain the source of truth above 900px. */
.mobile-bottom-nav, .mobile-page-title, .mobile-account-btn { display: none; }
.mobile-bottom-nav [hidden] { display: none !important; }

@media (max-width: 900px) {
  html { scroll-padding-top: calc(var(--top-bar-h) + env(safe-area-inset-top, 0px) + 16px); }
  /* The nav sits on the home-indicator inset rather than above all of it (owner, 12 Oct 2026: "fair
     bit of dead space below the icons"): 34px on a Face ID iPhone left the labels floating. 12px of
     the inset stays clear, so the labels still clear the indicator; ~76px tall vs a native 83. */
  body.has-mobile-nav { --mobile-nav-bottom: max(6px, env(safe-area-inset-bottom, 0px) - 12px); --mobile-nav-height: calc(54px + var(--mobile-nav-bottom)); }
  body.mobile-menu-open {
    position: fixed;
    top: var(--mobile-scroll-y, 0px);
    width: 100%;
    overflow: hidden;
  }
  .has-mobile-nav .dashboard { padding-bottom: calc(var(--mobile-nav-height) + 24px); }
  .dashboard, .dashboard > .tab-content, .sub-tab-content, .panel,
  .market-row, .cw-toolbar-main > *, .ai-grid > * { min-width: 0; }
  .mobile-bottom-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: var(--z-fab);
    display: flex;
    gap: 4px;
    padding: 6px max(8px, env(safe-area-inset-right, 0px)) var(--mobile-nav-bottom, 6px) max(8px, env(safe-area-inset-left, 0px));
    min-height: var(--mobile-nav-height);
    box-sizing: border-box;
    background: var(--surface-elevated);
    border-top: 1px solid var(--border-light);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, .18);
  }
  .mobile-bottom-nav button {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    min-height: 48px;
    padding: 6px 2px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font: 600 11px/1.2 var(--font-sans);
    cursor: pointer;
    touch-action: manipulation;
  }
  .mobile-bottom-nav button.active { background: var(--accent-muted); color: var(--accent); }
  .mobile-bottom-nav .icon { width: 20px; height: 20px; }
  .mobile-bottom-nav button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .mobile-page-title {
    display: block;
    max-width: 32vw;
    color: var(--text);
    font: 600 13px/1.3 var(--font-sans);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .top-bar-right { min-width: 0; }
  .mobile-menu { overscroll-behavior: contain; }
  .mobile-menu-header { position: sticky; top: 0; background: var(--surface-elevated); z-index: 1; }
  .has-mobile-nav .contact-desk-fab { bottom: calc(var(--mobile-nav-height) + 12px); }
  .has-mobile-nav .notif-toast { bottom: calc(var(--mobile-nav-height) + 12px); }
  .has-mobile-nav .dashboard-load-status:not([hidden]) {
    z-index: var(--z-fab);
    bottom: calc(var(--mobile-nav-height) + 12px);
    left: 12px;
    right: 12px;
    max-width: none;
    transform: none;
  }
  .hamburger-btn, .mobile-menu-close { min-width: 44px; min-height: 44px; }

  /* Keep each screen's subnavigation on one swipeable row, without fading the last item. */
  .dashboard .sub-tab-bar {
    max-width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    padding-right: 0;
    mask-image: none;
  }
  .dashboard .sub-tab-bar::after { content: none; }
  .dashboard .sub-tab-btn { flex: 0 0 auto; min-height: 44px; font-size: 13px; padding: 10px 14px; }

  /* Shared control floor, including dynamically loaded pricing and research screens.
     !important is intentional: several legacy widgets set their sizes inline. */
  .dashboard button, .dashboard select,
  .dashboard input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  .spot-msg-modal button, .notif-modal button, .pricer-modal button,
  .admin-app .btn, .admin-app .mobile-toggle, .admin-app .admin-sidebar a {
    min-height: 44px !important;
  }
  .dashboard select, .dashboard textarea,
  .dashboard input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  .notif-modal input, .notif-modal select, .spot-msg-modal textarea,
  .pricer-modal input, .pricer-modal select,
  .admin-app input:not([type="checkbox"]):not([type="radio"]), .admin-app select, .admin-app textarea {
    font-size: 16px !important;
    max-width: 100%;
    box-sizing: border-box;
  }
  .dashboard button { min-width: 44px; touch-action: manipulation; }
  .dashboard :is(.filter-bar, .curve-toolbar, .curve-toolbar-left, .curve-toolbar-right,
    .curve-history-toggle, .curve-product-toggle, .vol-region-tabs, .vol-table-actions,
    .renewable-controls, .renewable-custom-range, .intraday-custom-dates) {
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
  }
  .dashboard :is(.data-table-scroll, .cw-table-scroll, .vol-table-wrap, .hist-table-wrap,
    .ai-table-scroll, .shape-table-wrap, .pw-table-wrap, .reports-table-scroll-wrap,
    .comm-table-scroll-wrap) {
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }
  .dashboard .data-table { font-size: 12px; }
  .dashboard .data-table :is(th, td) { padding: 10px 8px; }
  .dashboard .section-hdr { flex-wrap: wrap; row-gap: 6px; }
  .dashboard .section-hdr-sub { white-space: normal; overflow-wrap: anywhere; }

  /* Pricing first. Keep the map available without consuming an entire phone screen. */
  #tab-nem.active #sub-overview.active #panel-spot-prices { order: 1; }
  #tab-nem.active #sub-overview.active #panel-intraday-price { order: 2; }
  #tab-nem.active #sub-overview.active #panel-nem-map { order: 3; }
  #panel-nem-map #nem-map-container { height: 340px; min-height: 0; max-height: 45dvh; }
  #panel-nem-map #nem-map-container svg { width: 100%; height: 100%; }

  .cw-detail { inset: calc(env(safe-area-inset-top, 0px) + 8px) 8px calc(env(safe-area-inset-bottom, 0px) + 8px); width: auto; }
  .cw-detail-head { padding: 12px; }
  .cw-detail-head button { min-width: 44px; min-height: 44px; }
  .spot-msg-modal, .notif-modal, body .pricer-modal {
    width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .spot-msg-overlay, .notif-overlay, .pricer-modal-overlay {
    padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 600px) {
  .dashboard { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  /* The bottom nav's More opens the same menu, so phones get one route to it. */
  .has-mobile-nav .hamburger-btn { display: none; }
  /* The bottom nav already holds Physical, Screens and Trades: More lists only the rest. */
  .has-mobile-nav .mobile-nav-item[data-tab="nem"], .has-mobile-nav .mobile-nav-item[data-tab="asx"] { display: none; }
  /* Clients' phones: the four phone tabs, no More (owner, 11 Oct 2026). Their account, help and
     sign-out open from the account button at the top right, in a menu that lists no other pages. */
  .has-mobile-nav.mobile-client .mobile-bottom-nav [data-mobile-more],
  .has-mobile-nav.mobile-client .mobile-menu-nav,
  .has-mobile-nav.mobile-client .mobile-menu-nav + .mobile-menu-divider,
  .has-mobile-nav.mobile-client .mobile-tour-btn,
  .has-mobile-nav.mobile-client #startTourBtn { display: none; }
  .has-mobile-nav.mobile-client .mobile-account-btn {
    display: flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0;
    border: 0; border-radius: 50%; background: transparent; color: var(--text-muted); cursor: pointer; touch-action: manipulation;
  }
  .mobile-account-btn .icon { width: 22px; height: 22px; }
  .mobile-account-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  /* The help bubble covered tables on the More pages. On phones it opens from More > Help & feedback. */
  .has-mobile-nav .contact-desk-fab:not(.fab-open) { display: none !important; }
  .has-mobile-nav .contact-desk-fab.fab-open { display: flex !important; }
  .nav-live-compact .compact-time-label { display: none; }
  .mobile-page-title { max-width: 42vw; }
  .dashboard .spot-cards-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .dashboard .spot-card { padding: 12px; min-width: 0; }
  .dashboard .spot-card-price { font-size: clamp(22px, 6vw, 30px); overflow-wrap: anywhere; }
  .dashboard .nem-strip { padding: 12px; gap: 12px; }
  .dashboard .nem-strip-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .dashboard .nem-strip-value { font-size: 20px; }
  .dashboard .nem-strip-hero .nem-strip-value { font-size: 26px; }
  .dashboard .nem-strip-label { font-size: 10px; }
  .dashboard .cw-toolbar-main { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard .cw-toolbar-main label { min-width: 0; }
  .dashboard .cw-toolbar-main :is(select, input) { width: 100%; }
  .dashboard .cw-toolbar-main > :is(.cw-inline, button) { grid-column: 1 / -1; width: 100%; margin: 0; }
  .dashboard .curve-toolbar-right { margin-left: 0; width: 100%; }
  .dashboard .curve-history-toggle { width: 100%; }
  .dashboard .cw-pair-controls label { min-width: 0; flex-basis: 100%; }
  .dashboard .ai-toolbar { align-items: stretch; }
  .dashboard .ai-toolbar > label { flex: 1 1 140px; min-width: 0; }
  .dashboard .ai-toolbar :is(select, input) { width: 100%; }
  .dashboard .ai-views { width: 100%; }
  .dashboard .ai-views button { flex: 1 1 auto; }
  .dashboard .pw-contract-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard .pw-contract-row > * { min-width: 0; }
  .dashboard .pw-heading > div { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-menu { transition: none; }
}

.admin-mobile-close, .admin-nav-scrim { display: none; }
@media (max-width: 900px) {
  .mobile-bottom-nav button[aria-busy="true"] { opacity: .6; }
  .login-page .login-card :is(input, select) { min-height: 48px; font-size: 16px; }
  .login-page .login-btn { min-height: 48px; }
  .login-page :is(.login-footer a, .login-back) { display: inline-flex; align-items: center; min-height: 44px; }
}
@media (max-width: 600px) {
  .dashboard .spot-card .sparkline-container { height: 56px; min-height: 56px; margin-top: 10px; }
  .dashboard .spot-card-head { flex-wrap: wrap; gap: 4px; }
  .dashboard .spot-card-stamp { font-size: 10px; }
  .dashboard .spot-card .sc-stat { flex-wrap: wrap; font-size: 11px; }
  .dashboard .spot-card .spot-chg { font-size: 12px; }
  .login-page { min-height: 100dvh; padding: max(16px, env(safe-area-inset-top, 0px)) 12px max(16px, env(safe-area-inset-bottom, 0px)); box-sizing: border-box; }
  .login-page .login-container { width: 100%; min-width: 0; }
  .login-page .login-card { margin: 0; padding: 24px 20px; }
}
@media (max-width: 768px) {
  body.admin-app .admin-sidebar { visibility: hidden; width: min(320px, 88vw); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); box-sizing: border-box; }
  body.admin-app .admin-sidebar.open { visibility: visible; }
  body.admin-app .admin-sidebar-header { position: relative; padding-right: 60px; }
  body.admin-app .admin-mobile-close { display: block; position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 6px; background: transparent; color: var(--text); font-size: 26px; }
  body.admin-app .admin-nav-scrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 99; border: 0; background: var(--scrim); }
  body.admin-app.admin-nav-open { position: fixed; top: var(--admin-scroll-y, 0px); width: 100%; overflow: hidden; }
  body.admin-app .admin-sidebar-nav { overscroll-behavior: contain; }
  body.admin-app .admin-sidebar-nav a { font-size: 14px; }
  body.admin-app .admin-main { min-width: 0; width: 100%; }
  body.admin-app .admin-content { padding: 16px 12px; min-width: 0; }
  body.admin-app .admin-topbar { flex-wrap: wrap; gap: 8px; }
  body.admin-app .admin-topbar > div { min-width: 0; }
  body.admin-app .breadcrumb { flex-wrap: wrap; }
  body.admin-app :is(.admin-table-wrap, .scroll-table) { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
}

@media (max-width: 600px) {
  #panel-spot-prices .section-hdr { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  #panel-spot-prices .section-hdr > :is(.section-hdr-title, .section-hdr-sub, .section-hdr-ts) { grid-column: 1; margin: 0; }
  #panel-spot-prices .section-hdr .spot-sync-btn { grid-column: 2; grid-row: 1 / 4; align-self: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
  .dashboard .comm-date-pickers { flex-wrap: wrap; width: 100%; }
  .dashboard .comm-date-input { flex: 1 1 140px; min-width: 0; }
}

@media (max-width: 900px) {
  .mobile-menu button.mobile-nav-link { width: 100%; background: transparent; border: 0; text-align: left; cursor: pointer; }
  .mobile-menu button.mobile-nav-link:hover { background: var(--surface-tint-2); }
  .mobile-menu .mobile-nav-link .icon { margin-right: 8px; }
}

.mobile-filter-toggle { display: none; }
@media (max-width: 900px) {
  .dashboard .mobile-filter-toggle {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 12px;
    width: 100%;
    padding: 10px 0;
    background: transparent;
    border: 0;
    color: var(--text);
    font: 600 14px/1.4 var(--font-sans);
    text-align: left;
    cursor: pointer;
  }
  .mobile-filter-hint { grid-column: 1; font-size: 12px; font-weight: 400; color: var(--text-muted); }
  .mobile-filter-chevron { grid-column: 2; grid-row: 1 / 3; align-self: center; color: var(--accent); font-size: 24px; }
  .dashboard .mobile-filter-toggle[aria-expanded="false"] + .mobile-filter-fields { display: none; }
  .dashboard .mobile-filter-toggle[aria-expanded="true"] { margin-bottom: 12px; border-bottom: 1px solid var(--border); }
  .onboarding-page :is(input, .login-btn) { min-height: 48px; }
  .login-page .forgot-link { display: inline-flex; align-items: center; min-height: 44px; }
}
