/* ═════════════════════════════════════════════════════════════
   PRIME SELF — MOBILE-OPTIMIZED COMPONENTS
   Mobile-first responsive design for touch-friendly UX
   ═════════════════════════════════════════════════════════════ */

/* ── Touch Target Standards ────────────────────────────────── */
/* All interactive elements minimum 44px (iOS/Android guidelines) */
:root {
  /* --touch-target-min inherited from design-tokens.css */
  --mobile-padding: 16px;
  --mobile-header-height: 56px;
  --mobile-nav-height: 64px;
}

/* ── Responsive Breakpoints ────────────────────────────────── */
@media (max-width: 768px) {
  
  /* ── Header: Mobile Compact ────────────────────────────── */
  header {
    height: var(--mobile-header-height);
    padding: 0 var(--mobile-padding);
    z-index: var(--z-sticky); /* Above content, below modals */
  }
  
  .logo {
    font-size: 1.1rem;
  }
  
  .logo span {
    display: none; /* Hide tagline on mobile */
  }
  
  /* ── Buttons: Touch-Friendly ───────────────────────────── */
  button, .btn {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    padding: 12px 20px;
    font-size: var(--text-sm);
    -webkit-tap-highlight-color: rgba(201, 168, 76, 0.3);
  }
  
  /* Increase tap area for icon buttons */
  button[aria-label] {
    padding: 12px;
  }
  
  /* ── Forms: Mobile Input Optimization ──────────────────── */
  input, textarea, select {
    min-height: var(--touch-target-min);
    font-size: var(--text-base); /* Prevents iOS zoom on focus (>=16px) */
    padding: 12px 16px;
  }
  
  input[type="date"],
  input[type="time"] {
    min-height: var(--touch-target-min);
  }
  
  /* ── Bottom Navigation Bar ─────────────────────────────── */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background: linear-gradient(180deg, rgba(13,13,26,0.95) 0%, rgba(10,10,15,0.98) 100%);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-emphasis, #7a6030);
    justify-content: space-around;
    align-items: center;
    padding: 8px 0;
    z-index: 100;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
  }
  
  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    border-radius: 8px;
    color: var(--text-secondary, #8882a0);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: rgba(201, 168, 76, 0.2);
  }
  
  .mobile-nav-item:active {
    transform: scale(0.95);
    background: rgba(201, 168, 76, 0.1);
  }
  
  .mobile-nav-item.active {
    color: var(--interactive-primary, #c9a84c);
    background: rgba(201, 168, 76, 0.15);
  }
  
  .mobile-nav-icon {
    font-size: 1.5rem;
    line-height: 1;
  }
  
  .mobile-nav-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  
  /* ── Main Content: Bottom Padding for Nav ──────────────── */
  main {
    padding-bottom: calc(var(--mobile-nav-height) + 20px);
  }
  
  /* ── Tabs: Touch-Friendly ──────────────────────────────── */
  .tabs {
    display: none; /* Hide desktop tabs on mobile (use bottom nav instead) */
  }
  
  .tab-content {
    padding: var(--mobile-padding);
  }
  
  /* ── Cards: Mobile Stacking ────────────────────────────── */
  .card, .profile-card, .transit-card {
    margin-bottom: 16px;
  }
  
  /* ── Modals: Full-Screen on Mobile ─────────────────────── */
  .modal, .pricing-modal, .auth-modal {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
  }
  
  .modal-header {
    position: sticky;
    top: 0;
    background: var(--bg-secondary, #111118);
    z-index: 10;
    border-bottom: 1px solid var(--border-subtle, #2a2a3a);
    padding: 16px;
  }
  
  .modal-close {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
  }
  
  /* ── Swipeable Sections ────────────────────────────────── */
  .swipeable-container {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
  }
  
  .swipeable-container::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }
  
  .swipeable-item {
    scroll-snap-align: start;
    scroll-snap-stop: always;
    flex-shrink: 0;
    width: 100%;
  }
  
  /* ── Collapsible Sections (Accordion) ──────────────────── */
  .collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    cursor: pointer;
    user-select: none;
    min-height: var(--touch-target-min);
    -webkit-tap-highlight-color: rgba(201, 168, 76, 0.2);
  }
  
  .collapsible-header:active {
    background: rgba(255, 255, 255, 0.05);
  }
  
  .collapsible-icon {
    transition: transform 0.3s;
    font-size: 1.2rem;
  }
  
  .collapsible-header[aria-expanded="true"] .collapsible-icon {
    transform: rotate(180deg);
  }
  
  .collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
  }
  
  .collapsible-content.expanded {
    max-height: 2000px; /* Large enough for content */
  }
  
  /* ── Pull-to-Refresh ───────────────────────────────────── */
  .pull-to-refresh {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
  }
  
  .pull-to-refresh.pulling {
    top: 10px;
  }
  
  .pull-to-refresh.refreshing {
    animation: spin-centered 1s linear infinite;
  }
  
  @keyframes spin-centered {
    from { transform: translateX(-50%) rotate(0deg); }
    to { transform: translateX(-50%) rotate(360deg); }
  }
  
  /* ── Touch-Friendly Chart Viewer ───────────────────────── */
  .chart-container {
    touch-action: pan-x pan-y pinch-zoom;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .bodygraph-canvas {
    max-width: 100%;
    height: auto;
    min-height: 400px;
  }
  
  /* ── Improved Form Layouts ─────────────────────────────── */
  .form-row {
    flex-direction: column;
    gap: 12px;
  }
  
  .form-group {
    margin-bottom: 20px;
  }
  
  label {
    font-size: var(--text-sm);
    margin-bottom: 8px;
  }
  
  /* ── Pricing Grid: Mobile Stacking ─────────────────────── */
  .pricing-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: var(--mobile-padding);
  }
  
  .pricing-card {
    width: 100%;
  }
  
  /* ── Auth Bar: Compact ─────────────────────────────────── */
  .auth-bar {
    gap: 8px;
  }
  
  .auth-status {
    display: none; /* Hide text, show only tier badge on mobile */
  }
  
  .tier-badge {
    font-size: 0.65rem;
    padding: 4px 8px;
  }
  
  /* ── Alerts: Full-Width ────────────────────────────────── */
  .alert {
    border-radius: 8px;
    margin: var(--mobile-padding);
  }
  
  /* ── Loading Indicators: Larger ────────────────────────── */
  .loading {
    font-size: 1.2rem;
    padding: 32px;
  }
  
  /* ── Empty States: Centered ────────────────────────────── */
  .empty-state {
    padding: 48px var(--mobile-padding);
    text-align: center;
  }
  
  /* ── Horizontal Scroll Prevention ──────────────────────── */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }
  
  * {
    max-width: 100%;
  }
  
  /* ── Text: Readable Sizes ──────────────────────────────── */
  html {
    font-size: 15px;
  }
  
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-xl); }
  h4 { font-size: var(--text-base); }
  
  p, li {
    line-height: 1.6;
  }
  
  /* ── Spacing: Mobile-Friendly ──────────────────────────── */
  section {
    padding: 20px var(--mobile-padding);
  }
  
  .container {
    padding: 0 var(--mobile-padding);
  }
  
  /* ── Hide Desktop-Only Elements ────────────────────────── */
  .desktop-only {
    display: none !important;
  }
  
  /* ── Show Mobile-Only Elements ─────────────────────────── */
  .mobile-only {
    display: block !important;
  }
}

/* ── Tablet Optimizations (768px - 1024px) ─────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .pricing-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .mobile-nav {
    display: none; /* Hide bottom nav on tablet */
  }
  
  .tabs {
    display: flex; /* Show desktop tabs on tablet */
  }
}

/* ── Desktop Optimizations (Hide Mobile Nav) ───────────────── */
@media (min-width: 769px) {
  .mobile-nav {
    display: none;
  }
  
  .mobile-only {
    display: none !important;
  }
  
  .desktop-only {
    display: block !important;
  }
}

/* ── Extra Small Devices (320px - 480px) ───────────────────── */
@media (max-width: 480px) {
  html {
    font-size: 14px;
  }
  
  .logo {
    font-size: 1rem;
  }
  
  button, .btn {
    font-size: 0.85rem;
    padding: 10px 16px;
  }
  
  .pricing-card h3 {
    font-size: 1.2rem;
  }
  
  .pricing-card .price {
    font-size: 1.8rem;
  }
}

/* ── Landscape Mobile (Height < 500px) ─────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .mobile-nav {
    height: 48px;
    padding: 4px 0;
  }
  
  .mobile-nav-item {
    padding: 4px 8px;
    gap: 2px;
  }
  
  .mobile-nav-icon {
    font-size: 1.2rem;
  }
  
  .mobile-nav-label {
    font-size: 0.6rem;
  }
  
  header {
    height: 48px;
  }
}

/* ── Accessibility: High Contrast Mode ─────────────────────── */
@media (prefers-contrast: high) {
  button, .btn {
    border: 2px solid currentColor;
  }
  
  .mobile-nav {
    border-top: 2px solid var(--interactive-primary, #c9a84c);
  }
}

/* ── Accessibility: Reduced Motion ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .collapsible-content {
    transition: none;
  }
}

/* ── Dark Mode Enhancements (Mobile) ───────────────────────── */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
  .mobile-nav {
    background: linear-gradient(180deg, rgba(10,10,15,0.98) 0%, rgba(5,5,8,0.99) 100%);
  }
}

/* ── Mobile "More" Overflow Drawer ────────────────────────── */
.mobile-more-drawer {
  position: fixed;
  inset: 0;
  z-index: 300;
}

.mobile-more-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.mobile-more-panel {
  position: absolute;
  bottom: 64px; /* above mobile nav */
  left: 0;
  right: 0;
  background: var(--bg-secondary, #111118);
  border-top: 1px solid var(--border-emphasis, #7a6030);
  border-radius: 16px 16px 0 0;
  padding: 8px 16px 16px;
  animation: slideUp 0.2s ease-out;
  max-height: 60vh;
  overflow-y: auto;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.mobile-more-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 12px;
  color: var(--interactive-primary, #c9a84c);
  font-weight: 600;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border-subtle, #2a2a3a);
  margin-bottom: 12px;
}

.mobile-more-header button {
  background: none;
  border: none;
  color: var(--text-secondary, #8882a0);
  font-size: 1.5rem;
  padding: 4px 8px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-more-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.mobile-more-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px;
  border-radius: 10px;
  color: var(--text-primary, #e8e6f0);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  min-height: 44px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: rgba(201, 168, 76, 0.2);
}

.mobile-more-item:active {
  background: rgba(201, 168, 76, 0.15);
}

.mobile-more-icon {
  font-size: 1.4rem;
  line-height: 1;
}

/* Hide drawer on desktop */
@media (min-width: 769px) {
  .mobile-more-drawer {
    display: none !important;
  }
}

/* ═════════════════════════════════════════════════════════════
   END MOBILE OPTIMIZATIONS
   ═════════════════════════════════════════════════════════════ */
