/* ==========================================================================
   VOYIQO MOBILE iOS APP STYLES
   Transforms mobile web & "Add to Home Screen" PWA into an authentic iOS app
   Keeps desktop layout 100% intact via strict @media (max-width: 768px)
   ========================================================================== */

/* ── iOS Safe Area Variables ─────────────────────────────────────────────── */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --voyi-blue: #004ac6;
  --voyi-accent: #2563eb;
  --voyi-bg: #f8f9ff;
  --voyi-card: #ffffff;
  --voyi-text: #0b1c30;
  --voyi-muted: #737686;
  --voyi-border: #e2e8f0;
}

/* ── Desktop Guarantee: Keep desktop 100% intact & hide mobile-only elements ─── */
@media (min-width: 769px) {
  .vq-mobile-tab-bar,
  .vq-mobile-fab,
  .vq-mobile-top-bar,
  .vq-mobile-only {
    display: none !important;
  }

  /* Guarantee left sidebar is always visible and correctly sized on desktop */
  aside.app-sidebar,
  .app-sidebar {
    display: flex !important;
    width: 18rem !important;
    flex-shrink: 0 !important;
  }
}

/* ── Overlay Unmounting: Never keep login forms active in DOM when closed ── */
.vq-overlay:not(.open) {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.vq-overlay.open {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* ── Mobile iOS Experience (< 769px) ─────────────────────────────────────── */
@media (max-width: 768px) {
  /* Hide desktop sidebar on mobile since mobile bottom tab bar is used */
  aside.app-sidebar,
  .app-sidebar {
    display: none !important;
  }

  /* Tap and Touch Hygiene */
  html, body {
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation;
    overscroll-behavior-y: none;
  }

  /* Safe Area Top Offset for Navigation Header */
  .hp-nav {
    height: calc(56px + var(--sat)) !important;
    padding-top: var(--sat) !important;
    padding-left: calc(16px + var(--sal)) !important;
    padding-right: calc(16px + var(--sar)) !important;
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(20px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02) !important;
  }

  /* Hide redundant "My Hub" link in mobile header because bottom tab bar has "Trips" */
  #nav-logged-in a[href*="/trips/"] {
    display: none !important;
  }

  /* User avatar in top header matching TopHeaderBar.swift */
  #nav-user-avatar {
    width: 34px !important;
    height: 34px !important;
    border-radius: 50% !important;
    border: 2px solid #ffffff !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08) !important;
  }

  /* Marketing homepage exception: keep landing page clean */
  body.home .vq-mobile-tab-bar,
  body.home .vq-mobile-fab {
    display: none !important;
  }
  body.home .hp-footer {
    display: block !important;
  }

  /* Hide Desktop Marketing Footer on App Pages on Mobile */
  body:not(.home) .hp-footer {
    display: none !important;
  }

  /* Top & Bottom Content Padding for App Pages */
  div[x-data="app()"] {
    padding-top: calc(58px + var(--sat)) !important;
    padding-bottom: calc(84px + var(--sab)) !important;
  }

  main,
  .app-main-content {
    padding-bottom: calc(84px + var(--sab)) !important;
    padding-left: calc(16px + var(--sal)) !important;
    padding-right: calc(16px + var(--sar)) !important;
  }

  /* ── Mobile Bottom Tab Bar ────────────────────────────────────────────── */
  .vq-mobile-tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    height: calc(58px + var(--sab));
    padding-bottom: var(--sab);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(25px) saturate(190%);
    -webkit-backdrop-filter: blur(25px) saturate(190%);
    border-top: 0.5px solid rgba(203, 213, 225, 0.7);
    display: flex;
    align-items: center;
    justify-content: space-around;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
  }

  .vq-tab-item {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: #737686;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.12s cubic-bezier(0.2, 0, 0, 1), color 0.15s ease;
    position: relative;
  }

  .vq-tab-item:active {
    transform: scale(0.9);
  }

  .vq-tab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .vq-tab-icon svg,
  .vq-tab-icon .voyiqo-icon {
    width: 22px !important;
    height: 22px !important;
  }

  .vq-tab-label {
    font-size: 10px;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.01em;
    transition: color 0.15s ease;
  }

  /* Active Tab State */
  .vq-tab-item.active {
    color: #004ac6 !important;
  }

  .vq-tab-item.active .vq-tab-icon {
    transform: translateY(-1px) scale(1.06);
  }

  .vq-tab-item.active .vq-tab-label {
    font-weight: 700 !important;
    color: #004ac6 !important;
  }

  .vq-tab-item.active::after {
    content: '';
    position: absolute;
    bottom: calc(4px + var(--sab));
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #004ac6;
  }

  /* ── Mobile Floating Action Button (FAB) ──────────────────────────────── */
  .vq-mobile-fab {
    position: fixed;
    right: 18px;
    bottom: calc(72px + var(--sab));
    z-index: 990;
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: #ffffff;
    color: #2663eb;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #e2e8f0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(37, 99, 235, 0.15);
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.15s ease, background-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .vq-mobile-fab:active {
    transform: scale(0.92);
    background: #f8fafc;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  .vq-mobile-fab svg,
  .vq-mobile-fab .voyiqo-icon {
    width: 26px !important;
    height: 26px !important;
  }

  /* ── Mobile Modals as Native iOS Bottom Sheets ────────────────────────── */
  .vq-overlay.open {
    align-items: flex-end !important;
    padding: 0 !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
  }

  .vq-overlay .vq-modal {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 26px 26px 0 0 !important;
    max-height: 88vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    margin: 0 !important;
    padding: 24px 20px calc(28px + var(--sab)) 20px !important;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.15) !important;
    animation: vqSlideUpSheet 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    position: relative;
  }

  /* iOS Sheet Grab Handle Bar */
  .vq-overlay .vq-modal::before {
    content: '';
    display: block;
    width: 40px;
    height: 5px;
    border-radius: 99px;
    background: #cbd5e1;
    margin: -8px auto 16px auto;
  }

  @keyframes vqSlideUpSheet {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  /* Trip Cards: Touch Native Elevation & Borders */
  .card-flat {
    border-radius: 16px !important;
    overflow: hidden !important;
    border: 1px solid rgba(226, 232, 240, 0.9) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
    transition: transform 0.15s ease, box-shadow 0.15s ease !important;
  }

  .card-flat:active {
    transform: scale(0.98) !important;
  }

  /* Travel Map on Mobile: Edge-to-Edge with Floating Back Control */
  .travelmap-container {
    height: calc(100vh - 56px - var(--sat) - 58px - var(--sab)) !important;
    border-radius: 0 !important;
  }
}
