/**
 * Mobile UI Improvements CSS
 * Fixes for mobile layout issues identified in QA testing
 *
 * Issues addressed:
 * 1. Header layout - simplify crowded icons
 * 2. Headline text truncation
 * 3. Asset cards touch targets
 * 4. Collapsible sections (charts, orderbook)
 * 5. Overall compact layout
 */

/* =============================================================================
   1. HEADER SIMPLIFICATION FOR MOBILE
   ============================================================================= */

@media (max-width: 480px) {
  /* Simplify header - hide less important buttons */
  .chat-header-right .social-btn {
    display: none !important;
  }

  /* Keep only essential header buttons on small screens */
  .chat-header-right {
    gap: 2px !important;
    flex-shrink: 0;
  }

  /* Make header title not wrap - CRITICAL */
  .chat-header-left {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  .chat-header-info {
    min-width: 0 !important;
    flex-shrink: 1 !important;
    overflow: hidden !important;
  }

  .chat-title {
    font-size: 15px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
    max-width: 100% !important;
  }

  .chat-status {
    display: none !important;
  }

  /* Hide avatar on very small screens to give title more room */
  .chat-avatar {
    display: none !important;
  }

  /* Header buttons - iOS HIG requires 44px minimum touch targets */
  .chat-header-btn {
    padding: 8px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    flex-shrink: 0 !important;
  }

  .chat-header-btn svg {
    width: 16px !important;
    height: 16px !important;
  }

  /* Hide text in auth buttons */
  .auth-text,
  .wallet-text,
  .fund-text {
    display: none !important;
  }

  /* Hide chat controls bar on mobile - access via menu */
  .chat-controls-bar {
    display: none !important;
  }

  /* Only show: hamburger, login, signup, wallet */
}

@media (max-width: 768px) {
  /* Header row layout */
  .chat-header {
    padding: 8px 12px !important;
  }

  .chat-header-left {
    gap: 8px !important;
    flex: 1;
    min-width: 0;
  }

  .chat-header-right {
    gap: 6px;
  }

  /* Reduce header icon sizes */
  .chat-header-btn {
    padding: 8px !important;
  }
}


/* =============================================================================
   2. HEADLINE / MARKET TITLE - FIX TRUNCATION
   ============================================================================= */

@media (max-width: 768px) {
  /* Market headline - ensure full display */
  .market-headline,
  .featured-market-title,
  .top-market-title,
  .fp-url-preview-title,
  h1.market-title {
    font-size: 18px !important;
    line-height: 1.4 !important;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-wrap: break-word;
    hyphens: auto;
  }

  /* Featured market panel headline */
  .featured-market-panel h1,
  .market-card-title,
  .wta-market-title,
  .fp-panel-title {
    font-size: 16px !important;
    line-height: 1.35 !important;
    max-height: none !important;
    overflow: visible !important;
    text-overflow: initial !important;
    white-space: normal !important;
    display: block !important;
  }

  /* Top markets leaderboard title */
  .top-market-entry .market-title {
    font-size: 14px !important;
    line-height: 1.3 !important;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  /* URL preview card title - ensure readable */
  .fp-url-preview-title {
    font-size: 15px !important;
    line-height: 1.35 !important;
    -webkit-line-clamp: 3;
    line-clamp: 3;
  }
}


/* =============================================================================
   3. ASSET CARDS - LARGER TOUCH TARGETS
   ============================================================================= */

@media (max-width: 768px) {
  /* Asset selection cards */
  .asset-card,
  .mover-card,
  .predicted-mover-card {
    min-height: 56px !important;
    padding: 12px 16px !important;
    margin-bottom: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 207, 255, 0.2);
  }

  /* Asset card inner content */
  .asset-card-content,
  .mover-content {
    gap: 12px !important;
  }

  /* Asset icons */
  .asset-icon,
  .mover-icon {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
  }

  .asset-icon img,
  .mover-icon img {
    width: 32px !important;
    height: 32px !important;
  }

  /* Asset text */
  .asset-symbol,
  .mover-symbol {
    font-size: 16px !important;
    font-weight: 600;
  }

  .asset-name,
  .mover-name {
    font-size: 12px !important;
  }

  /* Price display */
  .asset-price,
  .mover-price {
    font-size: 14px !important;
    font-weight: 500;
  }

  /* Selection state */
  .asset-card.selected,
  .mover-card.selected {
    border-width: 2px !important;
    transform: scale(1.02);
  }
}


/* =============================================================================
   4. COLLAPSIBLE SECTIONS - CHARTS & ORDERBOOK
   ============================================================================= */

@media (max-width: 768px) {
  /* Collapsible section header */
  .collapsible-section {
    border: 1px solid rgba(0, 150, 255, 0.2);
    border-radius: 12px;
    margin-bottom: 12px;
    overflow: hidden;
  }

  .collapsible-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(0, 30, 60, 0.4);
    cursor: pointer;
    min-height: 48px;
    touch-action: manipulation;
  }

  .collapsible-header h3,
  .collapsible-header .section-title {
    font-size: 14px !important;
    margin: 0 !important;
  }

  .collapsible-toggle {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
  }

  .collapsible-toggle svg {
    width: 16px;
    height: 16px;
  }

  .collapsible-section.collapsed .collapsible-toggle {
    transform: rotate(-90deg);
  }

  .collapsible-content {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .collapsible-section.collapsed .collapsible-content {
    max-height: 0;
    padding: 0;
  }

  /* Charts container - collapsed by default on mobile */
  .chart-container,
  .price-chart-container,
  .performance-chart {
    max-height: 200px;
    overflow: hidden;
  }

  /* Orderbook - collapsed by default on mobile */
  .orderbook-container,
  .mm-orderbook {
    max-height: 250px;
    overflow: hidden;
  }

  /* Pool distribution - more compact */
  .pool-distribution {
    padding: 12px !important;
  }

  .pool-bar {
    height: 8px !important;
  }

  /* Hide time & sales, top traders by default on mobile */
  .time-sales-section,
  .top-traders-section {
    display: none;
  }

  /* Add "Show More" button for hidden sections */
  .show-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    background: rgba(0, 150, 255, 0.1);
    border: 1px solid rgba(0, 150, 255, 0.2);
    border-radius: 8px;
    color: #00cfff;
    font-size: 13px;
    cursor: pointer;
    touch-action: manipulation;
  }

  .show-more-btn:active {
    background: rgba(0, 150, 255, 0.2);
  }
}


/* =============================================================================
   5. QUICK TRADE MODAL - DON'T AUTO-OPEN
   ============================================================================= */

@media (max-width: 768px) {
  /* Quick trade panel - ensure closed by default */
  .quick-trade-sheet:not(.open) {
    transform: translateY(100%) !important;
    visibility: hidden;
  }

  .quick-trade-sheet-backdrop:not(.open) {
    opacity: 0;
    pointer-events: none;
  }

  /* Quick trade button in nav - more prominent */
  .mobile-bottom-nav .nav-trade .trade-btn {
    box-shadow: 0 0 20px rgba(0, 207, 255, 0.4);
  }
}


/* =============================================================================
   6. COMPACT MOBILE LAYOUT
   ============================================================================= */

@media (max-width: 768px) {
  /* Reduce overall padding */
  .premium-chat,
  .chat3 {
    padding: 0 !important;
  }

  .chat-messages {
    padding: 8px !important;
  }

  /* Featured market panel - more compact */
  .featured-market-panel {
    padding: 12px !important;
    margin-bottom: 12px !important;
  }

  /* Top markets leaderboard - compact */
  .top-markets-leaderboard {
    padding: 8px !important;
  }

  .top-market-entry {
    padding: 10px 12px !important;
    margin-bottom: 8px !important;
  }

  /* Agent leaderboard - compact */
  .agent-leaderboard-compact {
    padding: 8px !important;
  }

  /* Reduce vertical spacing between sections */
  .section-spacing,
  .content-section {
    margin-bottom: 16px !important;
  }

  /* Footer - more compact on mobile */
  .footer-bar {
    padding: 6px 8px !important;
    gap: 8px !important;
  }

  .footer-link {
    padding: 4px !important;
  }

  .footer-divider {
    display: none !important;
  }

  .footer-ai-logos {
    display: none !important;
  }

  /* Bet amount buttons - larger touch targets */
  .bet-amount-btn,
  .quick-trade-preset {
    min-height: 44px !important;
    min-width: 60px !important;
    font-size: 15px !important;
  }

  /* Submit/confirm buttons - full width, large */
  .bet-submit-btn,
  .quick-trade-submit,
  .confirm-btn {
    min-height: 52px !important;
    font-size: 16px !important;
    font-weight: 600;
    border-radius: 12px !important;
  }

  /* Input fields - larger for mobile */
  .bet-amount-input input,
  .quick-trade-input,
  input[type="number"] {
    min-height: 48px !important;
    font-size: 18px !important;
    padding: 12px 16px !important;
  }
}

/* Extra small screens - further simplification */
@media (max-width: 375px) {
  /* Even more compact header */
  .chat-title {
    font-size: 14px !important;
  }

  /* Smaller market titles */
  .market-headline,
  .featured-market-title {
    font-size: 16px !important;
  }

  /* Tighter spacing */
  .chat-messages {
    padding: 6px !important;
  }

  .featured-market-panel {
    padding: 10px !important;
  }
}


/* =============================================================================
   7. SAFE AREA ADJUSTMENTS (Notch devices)
   ============================================================================= */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    /* Bottom nav safe area is now handled in mobile-polish.css via max() */
    /* Do NOT override here to avoid conflicts */

    /* Quick trade sheet accounts for safe area */
    .quick-trade-sheet {
      padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    }

    /* Content padding for bottom nav + safe area */
    .chat-messages,
    .main-content {
      padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
    }
  }
}


/* =============================================================================
   8. PERFORMANCE OPTIMIZATIONS
   ============================================================================= */

@media (max-width: 768px) {
  /* GPU acceleration for smooth animations */
  .quick-trade-sheet,
  .mobile-menu,
  .collapsible-content {
    will-change: transform;
    transform: translateZ(0);
  }

  /* Reduce repaints */
  .chat-messages {
    contain: layout style;
  }

  /* Smoother scrolling */
  .chat-messages,
  .main-content {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
}
