/* shared/mobile-fix.css — v62 late mobile overrides.
   Loaded AFTER the legacy inline dashboard CSS, so mobile shell receives taps/scroll. */

@media (max-width: 767px) {
  html,
  body {
    height: auto !important;
    min-height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
  }

  body.has-mobile-menu,
  body.has-altiora-overlay {
    overflow: hidden !important;
    touch-action: none !important;
  }

  body.has-bottom-sheet {
    overflow-y: auto !important;
    touch-action: pan-y !important;
  }

  .app {
    height: auto !important;
    min-height: 100dvh !important;
    display: block !important;
    overflow: visible !important;
  }

  .topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 90 !important;
    height: auto !important;
    min-height: 64px !important;
    overflow: visible !important;
  }

  .mobile-home {
    position: relative !important;
    z-index: 2 !important;
    display: block !important;
    pointer-events: auto !important;
    touch-action: pan-y !important;
  }

  .mobile-home,
  .mobile-home * {
    pointer-events: auto;
  }

  /* Keep the legacy dashboard only as a holder for fixed panels/bottom sheets. */
  .layout {
    display: block !important;
    position: relative !important;
    z-index: 1 !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow: visible !important;
    pointer-events: none !important;
  }

  .sidebar,
  .metrics,
  .mobile-quick-actions,
  .footer-band,
  .map-stage,
  .map-glow,
  .map-toolbar,
  .map-legend,
  .zoom-controls,
  .loading-map,
  .fallback-map {
    display: none !important;
    pointer-events: none !important;
  }

  .main,
  .workspace-content,
  .center-column,
  .map-wrap {
    display: block !important;
    height: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    overflow: visible !important;
    pointer-events: none !important;
    background: transparent !important;
    box-shadow: none !important;
    clip-path: none !important;
  }

  .workspace-content {
    position: static !important;
  }

  /* Reactivate only intentionally opened layers. */
  .markets-panel-backdrop.open,
  .markets-panel.open,
  .market-card.open,
  .preview-card.open,
  .altiora-sheet-backdrop.open,
  .altiora-overlay.open,
  .altiora-mobile-menu.open {
    pointer-events: auto !important;
  }

  .markets-panel-backdrop.open {
    display: block !important;
  }

  .markets-panel.open {
    display: flex !important;
    position: fixed !important;
    z-index: 96 !important;
    inset: 10px !important;
    width: auto !important;
    max-height: none !important;
    overflow: hidden !important;
    touch-action: pan-y !important;
  }

  .market-card,
  .preview-card {
    pointer-events: none !important;
  }

  .market-card.open,
  .preview-card.open {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: fixed !important;
    z-index: 94 !important;
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: 8px !important;
    width: auto !important;
    max-height: 76dvh !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    transform: translateY(0) !important;
  }

  .altiora-sheet-backdrop.open {
    z-index: 93 !important;
    pointer-events: auto !important;
  }

  .panel-controls,
  .market-list,
  .panel-head,
  .market-row,
  .card-head,
  .card-body,
  .preview-section,
  .preview-actions {
    pointer-events: auto !important;
  }

  .market-list,
  .altiora-modal-body,
  .altiora-catalog-grid,
  .altiora-mobile-menu-panel {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
  }
}


/* v63 — mobile header/menu and market list fixes */
@media (max-width: 767px) {
  .header-right {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    flex: 0 0 auto !important;
    min-width: 0 !important;
  }

  .lang-switcher {
    flex: 0 0 auto !important;
    max-width: 116px !important;
    overflow: hidden !important;
  }

  .lang-btn {
    min-width: 0 !important;
    width: 34px !important;
    padding: 0 4px !important;
    font-size: 10px !important;
    white-space: nowrap !important;
  }

  .lang-btn[data-lang="zh"] {
    width: 40px !important;
    font-size: 9.5px !important;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 38px !important;
    width: 38px !important;
    height: 38px !important;
    position: relative !important;
    z-index: 93 !important;
    pointer-events: auto !important;
  }

  .nav {
    display: flex !important;
    flex: 0 0 auto !important;
  }

  .markets-theme-group {
    display: inline-flex !important;
  }

  .markets-theme-group > a {
    display: none !important;
  }

  .markets-theme-group .theme-toggle {
    display: inline-flex !important;
    max-width: 104px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    pointer-events: auto !important;
  }
}


/* v64 — mobile header button order, centered controls and overlays */
@media (max-width: 767px) {
  .topbar {
    gap: 7px !important;
    padding-left: 9px !important;
    padding-right: 9px !important;
  }

  .brand {
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }

  .brand-logo-link {
    width: 104px !important;
    min-width: 94px !important;
    height: 31px !important;
  }

  .header-right {
    order: 2 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 5px !important;
    flex: 0 0 auto !important;
    max-width: calc(100vw - 122px) !important;
  }

  .lang-switcher {
    order: 1 !important;
    width: auto !important;
    max-width: 104px !important;
    height: 34px !important;
    padding: 2px !important;
    flex: 0 0 auto !important;
  }

  .nav {
    order: 2 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 auto !important;
  }

  .mobile-menu-btn {
    order: 3 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 38px !important;
    width: 38px !important;
    height: 38px !important;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1 !important;
    text-align: center !important;
  }

  .markets-theme-group {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .markets-theme-group .theme-toggle {
    width: 92px !important;
    height: 38px !important;
    padding: 0 7px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    line-height: 1.05 !important;
    white-space: normal !important;
    overflow: hidden !important;
    text-overflow: clip !important;
    font-size: 9.5px !important;
  }

  .lang-btn {
    width: 30px !important;
    height: 28px !important;
    padding: 0 3px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
  }

  .lang-btn[data-lang="zh"] {
    width: 38px !important;
    font-size: 9px !important;
  }

  .card-close,
  .panel-close,
  .altiora-modal-close,
  .altiora-mobile-menu-close {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    line-height: 1 !important;
    text-align: center !important;
    vertical-align: middle !important;
  }

  .card-close,
  .panel-close {
    width: 36px !important;
    height: 36px !important;
    font-size: 22px !important;
  }

  .altiora-modal-close,
  .altiora-mobile-menu-close {
    width: 36px !important;
    height: 36px !important;
    font-size: 22px !important;
  }

  .altiora-market-toolbar {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .altiora-market-filters {
    display: flex !important;
    gap: 7px !important;
    overflow-x: auto !important;
    padding-bottom: 2px !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .altiora-market-filter {
    min-height: 32px !important;
    border-radius: 999px !important;
    border: 1px solid var(--line, rgba(255,255,255,.10)) !important;
    background: rgba(255,255,255,.045) !important;
    color: var(--muted, rgba(240,244,255,.70)) !important;
    padding: 0 12px !important;
    font: inherit !important;
    font-size: 10px !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    cursor: pointer !important;
  }

  .altiora-market-filter.active {
    background: rgba(47,128,255,.12) !important;
    border-color: rgba(47,128,255,.34) !important;
    color: #9fc2ff !important;
  }

  html[data-theme="light"] .altiora-market-filter {
    background: rgba(244,248,255,.78) !important;
    color: rgba(12,23,40,.66) !important;
    border-color: rgba(25,48,82,.12) !important;
  }

  html[data-theme="light"] .altiora-market-filter.active {
    background: rgba(47,128,255,.08) !important;
    color: #174f99 !important;
    border-color: rgba(47,128,255,.22) !important;
  }
}


/* v65 — solid mobile entity sheets and reliable touch targets */
@media (max-width: 767px) {
  .market-card.open,
  .preview-card.open {
    top: 70px !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    max-height: calc(100dvh - 70px) !important;
    min-height: calc(100dvh - 70px) !important;
    border-radius: 22px 22px 0 0 !important;
    border: 1px solid var(--line-2, rgba(112,149,210,.24)) !important;
    border-bottom: 0 !important;
    background: #050f20 !important;
    backdrop-filter: none !important;
    box-shadow: 0 -24px 70px rgba(0,0,0,.48) !important;
    padding: 18px 16px 22px !important;
    color: var(--text, #fff) !important;
  }

  html[data-theme="light"] .market-card.open,
  html[data-theme="light"] .preview-card.open {
    background: #ffffff !important;
    color: #0c1728 !important;
    border-color: rgba(25,48,82,.14) !important;
    box-shadow: 0 -24px 70px rgba(33,57,93,.18) !important;
  }

  .market-card.open .card-head,
  .preview-card.open .card-head {
    position: sticky !important;
    top: -18px !important;
    z-index: 7 !important;
    margin: -18px -16px 12px !important;
    padding: 18px 16px 12px !important;
    background: #050f20 !important;
    border-bottom: 1px solid var(--line, rgba(255,255,255,.08)) !important;
  }

  html[data-theme="light"] .market-card.open .card-head,
  html[data-theme="light"] .preview-card.open .card-head {
    background: #ffffff !important;
    border-bottom-color: rgba(25,48,82,.10) !important;
  }

  .market-card.open .card-section,
  .preview-card.open .preview-section,
  .preview-card.open .preview-desc {
    background: transparent !important;
  }

  .market-card.open .preview-actions,
  .preview-card.open .preview-actions {
    position: sticky !important;
    bottom: -22px !important;
    margin: 18px -16px -22px !important;
    padding: 12px 16px 18px !important;
    background: linear-gradient(0deg, #050f20 0%, rgba(5,15,32,.96) 78%, rgba(5,15,32,0) 100%) !important;
    border-top: 1px solid var(--line, rgba(255,255,255,.08)) !important;
  }

  html[data-theme="light"] .market-card.open .preview-actions,
  html[data-theme="light"] .preview-card.open .preview-actions {
    background: linear-gradient(0deg, #ffffff 0%, rgba(255,255,255,.96) 78%, rgba(255,255,255,0) 100%) !important;
    border-top-color: rgba(25,48,82,.10) !important;
  }

  .card-close,
  .panel-close,
  .altiora-modal-close,
  .altiora-mobile-menu-close {
    border-radius: 999px !important;
    background: rgba(255,255,255,.06) !important;
    border: 1px solid var(--line, rgba(255,255,255,.10)) !important;
    color: var(--text, #fff) !important;
    font-size: 0 !important;
    line-height: 1 !important;
    position: relative !important;
  }

  .card-close::before,
  .panel-close::before,
  .altiora-modal-close::before,
  .altiora-mobile-menu-close::before {
    content: "×";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    transform: translateY(-1px);
  }

  html[data-theme="light"] .card-close,
  html[data-theme="light"] .panel-close,
  html[data-theme="light"] .altiora-modal-close,
  html[data-theme="light"] .altiora-mobile-menu-close {
    background: rgba(244,248,255,.90) !important;
    border-color: rgba(25,48,82,.14) !important;
    color: #0c1728 !important;
  }

  .altiora-sheet-backdrop.open {
    display: block !important;
    background: rgba(0,0,0,.46) !important;
    backdrop-filter: blur(8px) !important;
  }

  html[data-theme="light"] .altiora-sheet-backdrop.open {
    background: rgba(8,20,38,.24) !important;
  }
}


/* v66 — remove transparent background from mobile entity preview sheets */
@media (max-width: 767px) {
  .market-card.open,
  .preview-card.open {
    isolation: isolate !important;
    background-color: #050f20 !important;
    background-image: none !important;
    background: #050f20 !important;
    opacity: 1 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .market-card.open::before,
  .preview-card.open::before {
    content: "";
    position: fixed;
    z-index: -1;
    left: 0;
    right: 0;
    top: 70px;
    bottom: 0;
    border-radius: 22px 22px 0 0;
    background: #050f20;
    pointer-events: none;
  }

  .market-card.open > *,
  .preview-card.open > * {
    position: relative;
    z-index: 1;
  }

  .market-card.open .card-section,
  .preview-card.open .preview-section {
    border: 1px solid rgba(112,149,210,.16) !important;
    border-radius: 14px !important;
    background: #071a33 !important;
    padding: 13px !important;
    margin-top: 10px !important;
  }

  .preview-card.open .preview-desc {
    border: 1px solid rgba(112,149,210,.16) !important;
    border-radius: 14px !important;
    background: #071a33 !important;
    padding: 13px !important;
    margin: 0 0 10px !important;
  }

  .preview-card.open .event-preview-cover {
    background: #071a33 !important;
    border: 1px solid rgba(112,149,210,.16) !important;
  }

  .market-card.open .card-head,
  .preview-card.open .card-head,
  .market-card.open .preview-actions,
  .preview-card.open .preview-actions {
    background-color: #050f20 !important;
    background-image: none !important;
  }

  .market-card.open .preview-actions,
  .preview-card.open .preview-actions {
    background: #050f20 !important;
  }

  .soft-chip,
  .tag,
  .mini-value,
  .market-stat,
  .market-products-overview {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  html[data-theme="light"] .market-card.open,
  html[data-theme="light"] .preview-card.open {
    background-color: #ffffff !important;
    background-image: none !important;
    background: #ffffff !important;
  }

  html[data-theme="light"] .market-card.open::before,
  html[data-theme="light"] .preview-card.open::before {
    background: #ffffff !important;
  }

  html[data-theme="light"] .market-card.open .card-section,
  html[data-theme="light"] .preview-card.open .preview-section,
  html[data-theme="light"] .preview-card.open .preview-desc,
  html[data-theme="light"] .preview-card.open .event-preview-cover {
    background: #f5f8ff !important;
    border-color: rgba(25,48,82,.12) !important;
  }

  html[data-theme="light"] .market-card.open .card-head,
  html[data-theme="light"] .preview-card.open .card-head,
  html[data-theme="light"] .market-card.open .preview-actions,
  html[data-theme="light"] .preview-card.open .preview-actions {
    background: #ffffff !important;
  }
}


/* v67 — hard solid entity sheet fallback for preview components */
@media (max-width: 767px) {
  .solid-entity-sheet.open {
    background: #050f20 !important;
    background-color: #050f20 !important;
    background-image: none !important;
    opacity: 1 !important;
    color: #ffffff !important;
    pointer-events: auto !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .solid-entity-sheet.open * {
    pointer-events: auto;
  }

  .solid-entity-sheet.open .card-head {
    background: #050f20 !important;
    background-color: #050f20 !important;
    background-image: none !important;
  }

  .solid-entity-sheet.open .card-section,
  .solid-entity-sheet.open .preview-section,
  .solid-entity-sheet.open .preview-desc,
  .solid-entity-sheet.open .event-preview-cover,
  .solid-entity-sheet.open .market-products-overview,
  .solid-entity-sheet.open .market-stat {
    background: #071a33 !important;
    background-color: #071a33 !important;
    background-image: none !important;
    opacity: 1 !important;
  }

  html[data-theme="light"] .solid-entity-sheet.open {
    background: #ffffff !important;
    background-color: #ffffff !important;
    color: #0c1728 !important;
  }

  html[data-theme="light"] .solid-entity-sheet.open .card-head {
    background: #ffffff !important;
    background-color: #ffffff !important;
  }

  html[data-theme="light"] .solid-entity-sheet.open .card-section,
  html[data-theme="light"] .solid-entity-sheet.open .preview-section,
  html[data-theme="light"] .solid-entity-sheet.open .preview-desc,
  html[data-theme="light"] .solid-entity-sheet.open .event-preview-cover,
  html[data-theme="light"] .solid-entity-sheet.open .market-products-overview,
  html[data-theme="light"] .solid-entity-sheet.open .market-stat {
    background: #f5f8ff !important;
    background-color: #f5f8ff !important;
  }
}


/* v68 — componentized preview sheets */
@media (max-width: 767px) {
  .solid-entity-sheet.open .altiora-preview-body {
    display: grid;
    gap: 10px;
    background: transparent !important;
    pointer-events: auto !important;
  }

  .solid-entity-sheet.open .altiora-preview-head {
    background: #050f20 !important;
    background-color: #050f20 !important;
    background-image: none !important;
  }

  html[data-theme="light"] .solid-entity-sheet.open .altiora-preview-head {
    background: #ffffff !important;
    background-color: #ffffff !important;
  }

  .solid-entity-sheet.open .preview-actions {
    display: grid !important;
    gap: 8px !important;
  }

  .solid-entity-sheet.open .preview-actions .card-cta,
  .solid-entity-sheet.open .preview-actions .preview-secondary {
    min-height: 42px !important;
  }
}


/* v78 — prevent country preview horizontal scroll on mobile */
@media (max-width: 767px) {
  .altiora-entity-overlay-panel[data-entity-type="country"],
  .altiora-entity-overlay-panel[data-entity-type="country"] .altiora-entity-overlay-content,
  .altiora-entity-overlay-panel[data-entity-type="country"] .altiora-country-preview {
    overflow-x: hidden !important;
    max-width: 100vw !important;
  }
}
