/* ── Mobile Native Layer ────────────────────────────────────────────────
   iOS-native polish on top of the desktop CSS.

   Sections:
     [A] Body / scroll model
     [B] Header (sticky glass)
     [C] KPI strip / Filter bar (horizontal scroll)
     [D] Vehicle grid + cards
     [E] Vehicle detail panel (full-screen, swipe-to-close)
     [F] Modal (bottom sheet with drag handle)
     [G] Map overlay (full-screen)
     [H] Bottom tab bar
     [I] Toast / pull-to-refresh indicator
     [J] Forms / inputs
     [K] iOS chrome — typography, tap targets, press states

   Only kicks in at ≤900px; desktop is untouched.
   ───────────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {

  /* ──────────────────────────────────────────────────────────────────
     [A] Body / scroll model
     iOS Safari is built around natural body scroll. Override the
     desktop-app overflow:hidden so the URL bar auto-hides and
     pull-to-refresh works.
     ────────────────────────────────────────────────────────────────── */
  html {
    height: auto;
    -webkit-text-size-adjust: 100%;
  }
  html, body {
    overflow: visible;
    height: auto;
    min-height: 100dvh;
    overscroll-behavior-y: none;
    -webkit-tap-highlight-color: transparent;
  }
  body {
    display: block;
    /* iOS system font stack — Apple's "looks native" anchor */
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter',
                 'Segoe UI', system-ui, sans-serif;
  }

  /* When an overlay is open, lock background scroll (the existing JS
     already sets body.style.overflow=hidden — this keeps it working) */
  body.overlay-locked {
    overflow: hidden !important;
    position: fixed;
    inset: 0;
    width: 100%;
  }

  .main {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  /* ──────────────────────────────────────────────────────────────────
     [B] Header — sticky glass nav
     ────────────────────────────────────────────────────────────────── */
  .header {
    position: sticky;
    top: 0;
    z-index: 80;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
    flex-wrap: wrap;
    gap: 8px;
    background: rgba(10, 14, 26, 0.85);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
  }
  .header-title { font-size: 17px; letter-spacing: -0.4px; }
  .header-subtitle { font-size: 11px; }
  .header-btn { display: none; }
  .search-box {
    width: 100%;
    order: 3;
    padding: 9px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid transparent;
    border-radius: 10px;
  }
  .search-box:focus-within {
    background: rgba(255, 255, 255, 0.09);
    border-color: var(--neon);
  }
  .search-box input { font-size: 16px; } /* prevents iOS focus-zoom */
  .header-right {
    width: 100%;
    margin: 0;
    justify-content: flex-end;
  }

  /* ──────────────────────────────────────────────────────────────────
     [C] KPI strip + Filter bar — horizontal scroll like iOS
     ────────────────────────────────────────────────────────────────── */
  .kpi-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 12px 14px 0;
    gap: 8px;
    scroll-snap-type: x proximity;
  }
  .kpi-strip::-webkit-scrollbar { display: none; }
  .kpi-item {
    flex: 0 0 auto;
    min-width: 80px;
    padding: 10px 12px;
    scroll-snap-align: start;
  }

  .filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 12px 14px;
    gap: 6px;
  }
  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 14px;
    min-height: 36px;
    transition: transform 0.12s ease, background 0.18s ease, color 0.18s ease;
  }
  .filter-btn:active { transform: scale(0.94); }

  /* ──────────────────────────────────────────────────────────────────
     [D] Vehicle grid + cards — single column, native press feedback
     ────────────────────────────────────────────────────────────────── */
  .vehicle-grid {
    grid-template-columns: 1fr;
    padding: 12px 14px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
    overflow: visible;
    height: auto;
    flex: 0 0 auto;
  }
  .vehicle-card {
    padding: 14px;
    border-radius: 14px;
    transition: transform 0.14s cubic-bezier(.25, .1, .25, 1),
                background 0.18s ease;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    touch-action: manipulation;
  }
  .vehicle-card:active {
    transform: scale(0.985);
    background: var(--bg-panel);
  }

  /* ──────────────────────────────────────────────────────────────────
     [E] Vehicle detail panel — full-screen, slide from right (iOS push)
     ────────────────────────────────────────────────────────────────── */
  .vehicle-panel {
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    border-left: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    transition: transform 0.32s cubic-bezier(.32, .72, 0, 1);
    will-change: transform;
  }
  .panel-overlay {
    background: rgba(0, 0, 0, 0.55);
    transition: opacity 0.28s ease;
  }
  .panel-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
  }
  .panel-close:active { transform: scale(0.9); }

  /* Edge-swipe-to-close hint zone (left edge, invisible) */
  .vehicle-panel .panel-edge-grabber {
    position: absolute;
    top: 0;
    left: 0;
    width: 24px;
    height: 100%;
    z-index: 1;
  }

  /* ──────────────────────────────────────────────────────────────────
     [F] Modal — iOS bottom sheet with drag handle
     ────────────────────────────────────────────────────────────────── */
  .modal-overlay {
    align-items: flex-end;
    transition: opacity 0.28s ease;
  }
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 18px 18px 0 0 !important;
    padding: 30px 20px calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    transform: translateY(100%);
    transition: transform 0.36s cubic-bezier(.32, .72, 0, 1);
    will-change: transform;
    position: relative;
  }
  .modal-overlay.open .modal { transform: translateY(0); }

  /* The grabber pill iOS sheets show at the top */
  .modal::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.22);
  }

  .modal-actions {
    flex-direction: column;
    gap: 8px !important;
  }
  .modal-btn {
    width: 100%;
    min-height: 48px !important;
    border-radius: 12px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    transition: transform 0.12s ease, background 0.18s ease;
  }
  .modal-btn:active { transform: scale(0.97); }

  /* ──────────────────────────────────────────────────────────────────
     [G] Map overlay
     ────────────────────────────────────────────────────────────────── */
  .map-overlay { height: 100dvh !important; }
  .map-close-btn {
    top: calc(14px + env(safe-area-inset-top, 0px)) !important;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }
  .map-close-btn:active { transform: scale(0.95); }

  /* ──────────────────────────────────────────────────────────────────
     [H] Bottom tab bar — iOS standard
     ────────────────────────────────────────────────────────────────── */
  .mobile-tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 90;
    display: flex;
    background: rgba(15, 20, 36, 0.92);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
    backdrop-filter: saturate(180%) blur(22px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-tabbar .tab {
    flex: 1;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: none;
    border: 0;
    font-family: inherit;
    cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    touch-action: manipulation;
    transition: color 0.15s ease;
  }
  .mobile-tabbar .tab svg {
    width: 22px;
    height: 22px;
    transition: transform 0.18s cubic-bezier(.34, 1.56, .64, 1);
  }
  .mobile-tabbar .tab.active { color: var(--neon); }
  .mobile-tabbar .tab.active svg {
    transform: scale(1.05);
    filter: drop-shadow(0 0 6px var(--neon-glow));
  }
  .mobile-tabbar .tab:active svg {
    transform: scale(0.85);
    transition: transform 0.06s ease;
  }
  .mobile-tabbar .tab .badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 18px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--red);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 0 0 2px rgba(15, 20, 36, 0.92);
  }
  .mobile-tabbar .tab .badge.show { display: flex; }

  /* ──────────────────────────────────────────────────────────────────
     [I] Toast + pull-to-refresh indicator
     ────────────────────────────────────────────────────────────────── */
  .toast {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .ptr-indicator {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 50%;
    transform: translate(-50%, calc(var(--ptr-offset, -40px)));
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 95;
    pointer-events: none;
    opacity: var(--ptr-opacity, 0);
    transition: opacity 0.18s ease;
  }
  .ptr-indicator svg {
    width: 18px;
    height: 18px;
    color: var(--neon);
    transform: rotate(var(--ptr-rotation, 0deg));
    transition: transform 0.06s linear;
  }
  .ptr-indicator.refreshing svg {
    animation: ptr-spin 0.9s linear infinite;
  }
  @keyframes ptr-spin {
    to { transform: rotate(360deg); }
  }

  /* ──────────────────────────────────────────────────────────────────
     [J] Forms / inputs — kill iOS focus zoom, native-style fields
     ────────────────────────────────────────────────────────────────── */
  .panel-form input,
  .panel-form textarea,
  .panel-form select {
    font-size: 16px !important;
    border-radius: 10px !important;
    padding: 12px 14px !important;
  }
  .panel-form input:focus,
  .panel-form textarea:focus,
  .panel-form select:focus {
    outline: none;
    border-color: var(--neon) !important;
  }

  /* ──────────────────────────────────────────────────────────────────
     [K] iOS chrome — tap targets, press states everywhere
     ────────────────────────────────────────────────────────────────── */
  button,
  .nav-item,
  .filter-btn,
  .map-vehicle-card,
  .tab-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
  }

  .tab-btn {
    min-height: 44px;
    padding: 10px 14px !important;
  }

  /* Sidebar nav items get a tap-to-shrink press feel even though
     the sidebar is hidden by default (in case user opens via menu later) */
  .nav-item:active { transform: scale(0.98); }
}

/* Always hide the tab bar on desktop */
@media (min-width: 901px) {
  .mobile-tabbar { display: none !important; }
  .ptr-indicator { display: none !important; }
}
