/* Mobile-Responsive Styles */
/* Priority 3: Mobile UX improvements from Codex audit */

/* Prevent off-canvas panels (notifications, trollbox) from widening mobile body */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
  }
}

/* ===============================
   Touch-Friendly Buttons
   =============================== */

/* Ensure all interactive elements meet minimum touch target size (44x44px) */
@media (max-width: 768px) {

  /* Buttons - minimum touch target size */
  button,
  .btn,
  .button,
  a.button,
  input[type="button"],
  input[type="submit"],
  input[type="reset"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    line-height: 1.2;
    touch-action: manipulation; /* Disable double-tap zoom */
  }

  /* Small buttons - still meet touch target */
  .btn-sm,
  .button-sm {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
    font-size: 14px;
  }

  /* Icon buttons - ensure they're tappable */
  .icon-btn,
  .btn-icon,
  button[aria-label] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
  }

  /* Link buttons */
  a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 4px 0;
  }

  /* Navigation links */
  nav a,
  .nav-link {
    min-height: 44px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
  }

  /* Form inputs - prevent iOS zoom */
  input,
  select,
  textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 44px;
    padding: 12px 16px;
  }

  /* Checkboxes and radio buttons */
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 24px;
    min-width: 24px;
    transform: scale(1.5);
    margin: 10px;
  }

  /* Labels for checkboxes/radios */
  label {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 8px 0;
  }

  /* Spacing between interactive elements */
  button + button,
  .btn + .btn {
    margin-top: 12px;
    margin-left: 0;
  }

  /* Horizontal button groups */
  .button-group,
  .btn-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .button-group button,
  .btn-group .btn {
    width: 100%;
  }

  /* Touch-friendly tables */
  table {
    font-size: 14px;
  }

  th,
  td {
    padding: 12px 8px;
  }

  /* Dropdown menus */
  select {
    min-height: 44px;
    padding: 12px;
    font-size: 16px;
  }

  /* Close buttons (X) */
  .close,
  .btn-close,
  button[aria-label*="close"],
  button[aria-label*="Close"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
  }

  /* Card actions */
  .card-actions button,
  .card-actions a {
    min-height: 44px;
    width: 100%;
    margin-bottom: 8px;
  }

  /* Modal buttons */
  .modal-footer button {
    min-height: 44px;
    flex: 1;
    margin: 4px;
  }

  /* Tabs */
  .tabs button,
  .tab-item {
    min-height: 44px;
    padding: 12px 20px;
  }

  /* Toggle switches */
  .toggle,
  .switch {
    min-height: 44px;
    min-width: 80px;
  }

  /* Increase spacing for better touch targets */
  .metric-card,
  .card {
    padding: 20px;
    margin-bottom: 16px;
  }

  /* Larger touch targets for icons */
  .icon {
    font-size: 24px;
    padding: 10px;
  }

  /* List items */
  li button,
  li a {
    min-height: 44px;
    padding: 12px;
  }

  /* Pagination */
  .pagination button,
  .pagination a {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
    margin: 4px;
  }

  /* Search bar */
  input[type="search"],
  .search-input {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 16px;
  }

  /* Alerts/notifications */
  .alert button,
  .notification button {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ===============================
   Responsive Layout Adjustments
   =============================== */

@media (max-width: 768px) {

  /* Stack columns on mobile */
  .grid,
  .metrics-grid,
  .analytics-grid {
    grid-template-columns: 1fr !important;
  }

  /* Full-width cards */
  .card,
  .metric-card {
    width: 100%;
  }

  /* Reduce padding on mobile */
  body {
    padding: 12px;
  }

  /* Smaller headings on mobile */
  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 24px;
  }

  h3 {
    font-size: 20px;
  }

  h4 {
    font-size: 18px;
  }

  /* Responsive text */
  p,
  li {
    font-size: 16px;
    line-height: 1.6;
  }

  /* Navigation improvements */
  nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Modal improvements */
  .modal {
    width: 95vw;
    max-width: 95vw;
    margin: 20px auto;
  }

  .modal-content {
    padding: 20px;
  }

  /* Form improvements */
  form {
    padding: 16px;
  }

  .form-group {
    margin-bottom: 20px;
  }

  /* Table scroll - wrapper class */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 600px;
  }

  /* Global table overflow safety net - catch tables without .table-container wrapper */
  .page-tab-content table,
  .card-body table,
  .tab-pane table,
  .modal-body table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
    width: 100%;
  }

  .page-tab-content thead,
  .page-tab-content tbody,
  .page-tab-content tr,
  .card-body thead,
  .card-body tbody,
  .card-body tr {
    min-width: 600px;
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  /* Hide non-essential columns on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Show mobile-only elements */
  .show-mobile {
    display: block !important;
  }
}

/* ===============================
   Small Mobile (< 480px)
   =============================== */

@media (max-width: 480px) {

  /* Even smaller headings */
  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 18px;
  }

  /* Reduce padding further */
  body {
    padding: 8px;
  }

  .card,
  .metric-card {
    padding: 16px;
  }

  /* Stack button groups vertically */
  .button-group,
  .btn-group,
  .modal-footer {
    flex-direction: column;
  }

  .button-group button,
  .btn-group .btn,
  .modal-footer button {
    width: 100%;
    margin: 4px 0;
  }

  /* Simplify charts on small screens */
  .chart-container {
    height: 250px;
  }

  /* Compact metrics */
  .metric-value {
    font-size: 24px;
  }

  .metric-label {
    font-size: 12px;
  }
}

/* ===============================
   Landscape Mobile
   =============================== */

@media (max-width: 896px) and (orientation: landscape) {

  /* Adjust for landscape mode */
  .modal {
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Reduce vertical padding in landscape */
  .card,
  .metric-card {
    padding: 12px 20px;
  }

  /* Optimize button layout for landscape */
  .button-group,
  .btn-group {
    flex-direction: row;
    justify-content: space-between;
  }

  .button-group button,
  .btn-group .btn {
    flex: 1;
    margin: 0 4px;
  }
}

/* ===============================
   Tablet (768px - 1024px)
   =============================== */

@media (min-width: 769px) and (max-width: 1024px) {

  /* Two-column grid on tablets */
  .grid,
  .metrics-grid,
  .analytics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Maintain touch-friendly sizes on tablets */
  button,
  .btn,
  input,
  select {
    min-height: 44px;
    font-size: 16px;
  }

  /* Comfortable spacing */
  .card,
  .metric-card {
    padding: 20px;
  }
}

/* ===============================
   Accessibility Improvements
   =============================== */

/* Focus styles for keyboard navigation on mobile */
@media (max-width: 768px) {

  button:focus,
  a:focus,
  input:focus,
  select:focus,
  textarea:focus {
    outline: 3px solid var(--brand, #3182ce);
    outline-offset: 2px;
  }

  /* High contrast for better visibility */
  button:active,
  .btn:active {
    opacity: 0.8;
    transform: scale(0.98);
  }

  /* Larger tap feedback */
  button::after,
  .btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
  }

  button:active::after,
  .btn:active::after {
    width: 100%;
    height: 100%;
  }
}

/* ===============================
   Dashboard Mobile Fixes
   =============================== */

@media (max-width: 768px) {
  /* Dashboard tabs - horizontal scroll instead of wrapping to 2 lines */
  .dashboard-container .page-tabs--pill {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 4px !important;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .dashboard-container .page-tabs--pill::-webkit-scrollbar {
    display: none;
  }

  .dashboard-container .page-tabs--pill .page-tab {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    min-height: 36px !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }

  /* D1: Slow down market ticker tape on mobile - 60s instead of 30s */
  .ticker-content {
    animation-duration: 60s !important;
  }

  /* D2: Stats cards should be 2x2 grid on mobile, not single column */
  .performance-summary-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-3) !important;
  }

  .perf-stat-card {
    padding: var(--space-3) !important;
  }

  .perf-stat-value {
    font-size: var(--text-xl) !important;
  }

  .perf-stat-period {
    font-size: var(--text-xs) !important;
  }

  /* D5/D6/D7: Fix text cutoff in dashboard cards */
  /* Root cause: .card has overflow:hidden - override for mobile */
  .card,
  .card-premium {
    overflow: visible !important;
    min-width: 0 !important; /* Critical for grid/flex children */
  }

  .card-body,
  .card-header {
    overflow: visible !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    min-width: 0 !important;
  }

  /* Fix Edge Analyzer recommendation text cutoff */
  #edgeMount,
  #edgeMount .daily-insight-description,
  #edgeMount .daily-insight-title,
  #edgeMount li {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /* Force all daily-insights-list items to wrap text */
  .daily-insights-list,
  .daily-insights-list li,
  .daily-insight-title,
  .daily-insight-description {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* Fix Recent Analyses text cutoff */
  #analysesMount,
  #analysesMount .empty-widget,
  #analysesMount .empty-subtitle {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    max-width: 100% !important;
    text-align: center !important;
  }

  /* Override max-width constraint on empty states */
  .empty-state,
  .empty-widget,
  .empty-state-title,
  .empty-state-description,
  .empty-subtitle {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    text-align: center !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Fix Daily AI Insights text cutoff */
  #dailyInsightsContainer,
  #dailyInsightsContainer .empty-state,
  #dailyInsightsContainer .empty-state-title,
  #dailyInsightsContainer .empty-state-description {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    max-width: 100% !important;
  }

  .daily-insight-title,
  .daily-insight-description,
  .daily-insights-encouragement {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    max-width: 100% !important;
  }

  /* Recent Trades table - hide less important columns on mobile */
  .trades-table-header,
  .trade-row {
    grid-template-columns: 1.5fr 1fr 1.5fr !important;
    gap: 12px !important;
  }

  /* Hide entry, exit columns on mobile - show only symbol, side, pnl */
  .trades-col-entry,
  .trades-col-exit,
  .trades-col-date {
    display: none !important;
  }
}

/* Very small screens: even more compact stats */
@media (max-width: 375px) {
  .performance-summary-grid {
    gap: var(--space-2) !important;
  }

  .perf-stat-card {
    padding: var(--space-2) !important;
  }

  .perf-stat-value {
    font-size: var(--text-lg) !important;
  }
}

/* ===============================
   Performance Optimizations
   =============================== */

@media (max-width: 768px) {

  /* Reduce animations on mobile for better performance */
  /* Note: ticker/pulse elements excluded - they need slow scrolling */
  *:not(.ticker-content):not(.pulse-content):not(.pulse-tape):not(.pulse-item) {
    animation-duration: 0.2s !important;
    transition-duration: 0.2s !important;
  }

  /* Disable hover effects on touch devices */
  @media (hover: none) {
    .hover-lift:hover,
    .hover-scale:hover {
      transform: none;
    }
  }

  /* Hardware acceleration for smooth scrolling */
  body,
  .modal,
  .dropdown-menu {
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }

  /* Guest Mode Banner - Mobile Responsive */
  #guest-mode-banner {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 12px 16px !important;
    gap: 12px !important;
  }

  #guest-mode-banner > div:first-child {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }

  #guest-mode-banner > div:first-child > div {
    font-size: 13px !important;
  }

  #guest-mode-banner > div:first-child > div span {
    display: block !important;
    margin-left: 0 !important;
    margin-top: 4px !important;
    font-size: 12px !important;
  }

  #guest-mode-banner > div:last-child {
    flex-direction: column !important;
    width: 100% !important;
  }

  #guest-mode-banner button {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Sample Data Banner - Mobile */
  .sample-data-banner {
    padding: var(--space-3) !important;
    margin-bottom: var(--space-4) !important;
  }

  .sample-data-banner__content {
    flex-direction: column !important;
    text-align: center !important;
    gap: var(--space-2) !important;
  }

  .sample-data-banner__title {
    font-size: 14px !important;
  }

  .sample-data-banner__message {
    font-size: 12px !important;
  }

  .sample-data-banner__action {
    width: 100% !important;
  }

  /* Upgrade Banner / Demo Preview Banner - Mobile */
  .demo-banner-premium,
  div.demo-banner-premium[style] {
    padding: 16px !important;
    margin-bottom: 16px !important;
  }

  .demo-banner-content,
  div.demo-banner-content[style] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    display: flex !important;
  }

  .demo-banner-text,
  div.demo-banner-text[style] {
    order: 2 !important;
    flex: none !important;
    width: 100% !important;
  }

  .demo-banner-text h3,
  .demo-banner-text h3[style] {
    font-size: 14px !important;
    line-height: 1.3 !important;
  }

  .demo-banner-text p,
  .demo-banner-text p[style] {
    font-size: 12px !important;
    line-height: 1.4 !important;
  }

  .demo-banner-content .btn,
  .demo-banner-content button,
  .demo-banner-content button[style] {
    order: 3 !important;
    width: 100% !important;
    justify-content: center !important;
    padding: 10px 16px !important;
    white-space: normal !important;
    min-height: 44px !important;
  }

  .demo-badge,
  div.demo-badge[style] {
    order: 1 !important;
    align-self: flex-start !important;
    flex-shrink: 0 !important;
  }

  /* Demo Toggle Banner */
  .demo-toggle {
    flex-shrink: 0 !important;
  }

  /* Additional specificity for inline styled elements */
  #demoBanner[style] .demo-banner-content[style] {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  #demoBanner[style] .demo-banner-text[style] {
    flex: none !important;
    width: 100% !important;
  }
}

/* ===============================
   Analytics Page Mobile Fixes
   =============================== */

@media (max-width: 768px) {
  /* Analytics has 8 tabs - need horizontal scroll, not wrap */
  .analytics-page .page-tabs--pill,
  #performance-content ~ .page-tabs--pill,
  [data-tab="performance"] ~ .page-tabs--pill {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 4px !important;
    padding-bottom: 4px;
  }

  .analytics-page .page-tabs--pill .page-tab,
  .page-container > .page-tabs--pill .page-tab {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    min-height: 36px !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }

  /* Hide scrollbar but keep functionality */
  .analytics-page .page-tabs--pill::-webkit-scrollbar {
    display: none;
  }

  /* Analytics filter chips - horizontal scroll */
  .analytics-page .filter-chips,
  #analyticsFilterChips {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .analytics-page .filter-chip-group {
    flex-shrink: 0;
  }

  /* Analytics grids - single column */
  .analytics-page .analytics-grid,
  .analytics-page .metrics-grid,
  #performance-content .analytics-grid {
    grid-template-columns: 1fr !important;
  }

  /* Keep KPI metrics 2x2 */
  .analytics-page .summary-metrics,
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Charts need full width */
  .analytics-page .chart-container,
  .analytics-page canvas {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Compare tool mobile */
  .compare-selectors-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .compare-vs-label {
    text-align: center !important;
    padding: 8px 0 !important;
  }

  .comparison-grid {
    grid-template-columns: 1fr !important;
  }

  /* Published detail page - collapse sidebar below content */
  .published-detail-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ===============================
   Dex Alpha Page Mobile Fixes
   =============================== */

@media (max-width: 768px) {
  /* Dex Alpha tabs - horizontal scroll */
  .dex-alpha-page .page-tabs--pill {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 4px !important;
  }

  .dex-alpha-page .page-tabs--pill .page-tab {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    min-height: 36px !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }

  /* Positions layout - stack vertically */
  .dex-alpha-page .positions-layout {
    flex-direction: column !important;
  }

  .dex-alpha-page .positions-heatmap-column {
    width: 100% !important;
    order: -1; /* Heatmap first on mobile */
  }

  /* Flow table - horizontal scroll */
  .dex-alpha-page .flow-table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Leaderboard cards */
  .dex-alpha-page .leaderboard-grid {
    grid-template-columns: 1fr !important;
  }

  /* Watchlist - compact */
  .dex-alpha-page .watchlist-grid {
    grid-template-columns: 1fr !important;
  }

  /* Alert cards */
  .dex-alpha-page .alerts-grid {
    grid-template-columns: 1fr !important;
  }

  /* Positions filter chips - horizontal scroll instead of vertical stack */
  .dex-alpha-page #positions-filter-chips,
  .dex-alpha-page .filter-chips {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    padding-bottom: 4px;
  }

  .dex-alpha-page #positions-filter-chips::-webkit-scrollbar,
  .dex-alpha-page .filter-chips::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }

  .dex-alpha-page #positions-filter-chips .filter-chip,
  .dex-alpha-page .filter-chips .filter-chip {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }

  /* Data tab filter chips - same horizontal scroll */
  .dex-alpha-page #data-filter-chips {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 4px;
  }

  .dex-alpha-page #data-filter-chips::-webkit-scrollbar {
    display: none;
  }

  .dex-alpha-page #data-filter-chips .filter-chip {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }
}

/* ===============================
   Settings Page Mobile Fixes
   =============================== */

@media (max-width: 768px) {
  /* Settings layout - stack nav above content */
  .settings-page .settings-layout {
    grid-template-columns: 1fr !important;
  }

  .settings-page .settings-nav {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 4px !important;
    padding-bottom: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
  }

  .settings-page .settings-nav-item {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    padding: 8px 16px !important;
    font-size: 13px !important;
  }

  /* Form inputs full width */
  .settings-page input,
  .settings-page select,
  .settings-page textarea {
    width: 100% !important;
  }

  /* API key cards */
  .settings-page .api-key-card {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  .settings-page .api-key-actions {
    flex-direction: row !important;
    justify-content: flex-end !important;
  }

  /* Integration cards */
  .settings-page .integration-card {
    flex-direction: column !important;
    text-align: center !important;
  }

  .settings-page .integration-card .integration-actions {
    width: 100% !important;
    justify-content: center !important;
  }
}

/* ===============================
   Modal Mobile Fixes
   =============================== */

@media (max-width: 768px) {
  /* All modals - full width on mobile */
  .modal-content,
  .modal-dialog,
  .modal > div {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
    margin: 20px auto !important;
  }

  /* Modal body scrollable */
  .modal-body {
    max-height: 60vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Modal footer - stack buttons */
  .modal-footer {
    flex-direction: column !important;
    gap: 8px !important;
  }

  .modal-footer button,
  .modal-footer .btn {
    width: 100% !important;
    margin: 0 !important;
  }

  /* Trade modal specific */
  .trade-modal .modal-content {
    padding: 16px !important;
  }

  .trade-modal .form-row {
    flex-direction: column !important;
    gap: 12px !important;
  }

  .trade-modal .form-group {
    width: 100% !important;
  }

  /* Import wizard modal */
  .import-wizard .modal-content {
    width: 95vw !important;
  }

  .import-wizard .step-content {
    padding: 12px !important;
  }

  /* Alert/rule modals */
  .alert-modal .modal-content,
  .rule-modal .modal-content {
    width: 95vw !important;
  }
}

/* ===============================
   Market Intel Table Overflow Fixes
   =============================== */

@media (max-width: 768px) {
  /* All Market Intel tables need horizontal scroll */
  .funding-table-wrapper,
  .sentiment-table-wrapper,
  .market-signals-wrapper,
  .alpha-movers-wrapper,
  .flow-table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    max-width: 100vw;
  }

  .funding-table,
  .sentiment-table,
  .market-signals-table,
  .alpha-movers-table {
    min-width: 500px;
  }

  /* Market Intel grids - single column */
  .market-intel-grid,
  .signals-grid,
  .movers-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ===============================
   Onboarding Wizard Viewport Fix
   =============================== */

@media (max-height: 700px) {
  .bt4t-onboarding-wizard .wizard-content {
    max-height: 90vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 480px) {
  .bt4t-onboarding-wizard .wizard-content {
    max-height: 85vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px !important;
  }

  /* Compact wizard padding on small screens */
  .bt4t-onboarding-wizard .wizard-content > div {
    padding: 24px 20px !important;
  }

  /* Exchange grid: single column on very small screens */
  .bt4t-onboarding-wizard .wizard-content [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ===============================
   Analytics Table Overflow Fixes
   =============================== */

@media (max-width: 768px) {
  /* Analytics comparison table and other inline tables */
  .analytics-page .comparison-grid table,
  .analytics-page .context-table,
  .analytics-page .mfe-mae-table,
  #performance-content table,
  #context-content table,
  #compare-content table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* ===================================================================
   MOBILE AUDIT FIX BLOCK — 2026-04-06
   Fixes from full mobile audit. All rules scoped under max-width
   media queries to avoid any desktop impact.
   =================================================================== */

/* ── 1. Trade chart height: 600px is too tall on mobile ── */
@media (max-width: 768px) {
  .trade-chart-wrapper {
    height: 350px !important;
  }
}

/* ── 2. Chart header stacking on mobile ── */
@media (max-width: 768px) {
  .chart-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
    padding: 8px 12px !important;
  }
  .chart-controls {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px !important;
  }
  .chart-symbol {
    min-width: 0 !important;
    flex: 1;
  }
  .timeframe-buttons {
    flex-wrap: wrap;
  }
}

/* ── 3. Trade modal form grids: collapse to 1 column ── */
@media (max-width: 480px) {
  .trade-modal .form-grid,
  .trade-modal .form-grid-3 {
    grid-template-columns: 1fr !important;
  }
  .trade-modal .modal-content {
    width: 95vw !important;
    max-width: 95vw !important;
  }
}

/* ── 4. Settings modal min-width override ── */
@media (max-width: 768px) {
  .modal-content {
    min-width: 0 !important;
    width: 95vw !important;
  }
}

/* ── 5. Fixed-width drawers (settings connect, sentiment, etc.) ── */
@media (max-width: 768px) {
  #connectDrawer,
  .sentiment-drawer,
  .api-drawer,
  [style*="width: 420px"],
  [style*="width:420px"] {
    width: 100vw !important;
    max-width: 100vw !important;
  }
}

/* ── 6. Analytics multi-column grids → stack on mobile ── */
@media (max-width: 600px) {
  .analytics-page [style*="grid-template-columns: repeat(3"],
  .analytics-page [style*="grid-template-columns: repeat(4"],
  .analytics-page [style*="grid-template-columns: repeat(5"],
  .analytics-page [style*="grid-template-columns:repeat(3"],
  .analytics-page [style*="grid-template-columns:repeat(4"],
  .analytics-page [style*="grid-template-columns:repeat(5"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .analytics-page [style*="grid-template-columns: repeat(7"],
  .analytics-page [style*="grid-template-columns:repeat(7"] {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 4px !important;
    font-size: 10px !important;
  }
}

@media (max-width: 430px) {
  .analytics-page [style*="grid-template-columns: repeat(3"],
  .analytics-page [style*="grid-template-columns: repeat(4"],
  .analytics-page [style*="grid-template-columns: repeat(5"],
  .analytics-page [style*="grid-template-columns:repeat(3"],
  .analytics-page [style*="grid-template-columns:repeat(4"],
  .analytics-page [style*="grid-template-columns:repeat(5"] {
    grid-template-columns: 1fr 1fr !important;
  }
  .analytics-page [style*="grid-template-columns: repeat(7"],
  .analytics-page [style*="grid-template-columns:repeat(7"] {
    grid-template-columns: repeat(4, 1fr) !important;
    font-size: 9px !important;
  }
}

/* ── 7. Journal emotion correlation grid ── */
@media (max-width: 600px) {
  [style*="grid-template-columns: repeat(10"],
  [style*="grid-template-columns:repeat(10"] {
    grid-template-columns: repeat(5, 1fr) !important;
    font-size: 10px !important;
  }
}

/* ── 8. Journal detail grids ── */
@media (max-width: 600px) {
  .detail-metrics[style*="grid-template-columns: repeat(3"],
  .detail-metrics[style*="grid-template-columns:repeat(3"] {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ── 9. Dex Alpha KPI cards and grids ── */
@media (max-width: 600px) {
  #positions-kpi-cards,
  [id="positions-kpi-cards"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
}
@media (max-width: 430px) {
  #positions-kpi-cards,
  [id="positions-kpi-cards"] {
    grid-template-columns: 1fr !important;
  }
}

/* ── 10. Dex Alpha flex items with min-width ── */
@media (max-width: 768px) {
  .dex-alpha-page [style*="min-width: 300px"],
  .dex-alpha-page [style*="min-width:300px"],
  .dex-alpha-page [style*="min-width: 200px"],
  .dex-alpha-page [style*="min-width:200px"],
  .dex-alpha-page [style*="min-width: 180px"],
  .dex-alpha-page [style*="min-width:180px"] {
    min-width: 0 !important;
    flex-basis: 100% !important;
  }
}

/* ── 11. Trades replay select (min-width: 320px) ── */
@media (max-width: 768px) {
  #replayTradeSelect {
    min-width: 0 !important;
    width: 100% !important;
  }
  #trade-replay-content > div > div:first-child {
    flex-wrap: wrap !important;
  }
}

/* ── 12. Filter selects with min-width on narrow screens ── */
@media (max-width: 600px) {
  select[style*="min-width: 180px"],
  select[style*="min-width:180px"],
  select[style*="min-width: 140px"],
  select[style*="min-width:140px"],
  select[style*="min-width: 120px"],
  select[style*="min-width:120px"] {
    min-width: 0 !important;
    width: 100% !important;
  }
}

/* ── 13. Dashboard trade table min-width ── */
@media (max-width: 768px) {
  .dashboard [style*="min-width: 720px"],
  .dashboard [style*="min-width:720px"],
  .dashboard [style*="min-width: 660px"],
  .dashboard [style*="min-width:660px"] {
    min-width: 0 !important;
  }
  .dashboard table,
  .dashboard .trades-table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── 14. Market Intelligence dropdown overflow ── */
@media (max-width: 768px) {
  .asset-dropdown-menu {
    min-width: 0 !important;
    width: calc(100vw - 32px) !important;
    max-width: 300px !important;
    left: 0 !important;
    right: auto !important;
  }
}

/* ── 15. Overflow menus clipping at viewport edge ── */
@media (max-width: 768px) {
  [style*="position: absolute"][style*="min-width: 120px"],
  [style*="position:absolute"][style*="min-width:120px"] {
    min-width: 0 !important;
    right: 0 !important;
    left: auto !important;
    max-width: calc(100vw - 16px) !important;
  }
}

/* ── 16. Generic inline table overflow protection ── */
@media (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Ensure thead/tbody display correctly inside block table */
  table thead,
  table tbody {
    display: table;
    width: 100%;
  }
}

/* ── 17. Content area extra padding reduction on small phones ── */
@media (max-width: 430px) {
  .Content {
    padding: 8px !important;
  }
}

/* ── 18. Market Labs sentiment drawer ── */
@media (max-width: 768px) {
  .sentiment-drawer {
    width: 100vw !important;
    max-width: 100vw !important;
  }
}
