/**
 * Native Mobile UI Styling
 * iOS and Android platform-specific designs
 * Desktop UI remains unchanged
 */

/* Platform Detection and Variables */
:root {
  --mobile-bottom-nav-height: 60px;
  --mobile-safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-safe-area-top: env(safe-area-inset-top, 0px);
  --ios-tab-bar-height: calc(50px + var(--mobile-safe-area-bottom));
  --android-nav-height: calc(56px + var(--mobile-safe-area-bottom));
}

/* Mobile universal fixes - ensure bottom nav doesn't hide content */
@media (max-width: 768px) {
  html.mobile-native {
    height: 100vh;
    height: 100dvh;
    overflow: visible !important;
    position: relative;
    pointer-events: auto !important;
  }

  body.mobile-native {
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    position: relative !important;
    transform: none !important;
    filter: none !important;
    perspective: none !important;
    will-change: auto !important;
    pointer-events: auto !important;
  }

  /* Ensure nav is clickable on mobile */
  nav {
    pointer-events: auto !important;
  }

  #mobileMoreMenuBtn {
    pointer-events: auto !important;
    cursor: pointer !important;
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 10001 !important;
  }

  .mobile-bottom-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 10000 !important;
    display: flex !important;
    justify-content: space-around !important;
    align-items: center !important;
    transform: translateZ(0) !important;
    -webkit-transform: translateZ(0) !important;
    backface-visibility: hidden !important;
    -webkit-backface-visibility: hidden !important;
  }

  /* Override any global nav link styles */
  .mobile-bottom-nav a,
  .mobile-bottom-nav a:link,
  .mobile-bottom-nav a:visited,
  .mobile-bottom-nav a:hover,
  .mobile-bottom-nav a:active {
    text-decoration: none !important;
  }

  /* Prevent any inherited styles from affecting nav tabs */
  .mobile-bottom-nav .nav-tab,
  .mobile-bottom-nav .nav-tab *:not(.nav-badge),
  .mobile-bottom-nav .nav-tab span:not(.nav-badge) {
    background: transparent !important;
    border: none !important;
    text-shadow: none !important;
    filter: none !important;
  }
}

/* Only apply native mobile styles on screens <= 768px */
@media (max-width: 768px) {

  /* Mobile More Menu Button in Top Nav */
  .mobile-more-menu-btn {
    display: none !important; /* Hidden by default */
  }

  .mobile-native .mobile-more-menu-btn {
    display: inline-flex !important; /* Show only when native mobile UI is active */
  }

  /* Ensure button is visible on mobile with native UI */
  body.mobile-native .mobile-more-menu-btn,
  html.mobile-native .mobile-more-menu-btn {
    display: inline-flex !important;
  }

  /* Mobile More Menu - Using inline styles, minimal CSS needed */

  /* ========================================
     iOS NATIVE STYLING
     ======================================== */

  .platform-ios body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* iOS Bottom Tab Bar
     Native iOS tab bar: 49px content + 34px home-indicator safe area = 83px.
     We add an extra 34px below the safe area so the rubber-band bounce
     never reveals a gap beneath the bar. */
  .platform-ios .mobile-bottom-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: #F9F9F9;
    border-top: 0.5px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    min-height: calc(84px + env(safe-area-inset-bottom, 0px));
    padding-top: 10px;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 34px);
    z-index: 10000;
    box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.04);
  }

  .platform-ios.dark-mode .mobile-bottom-nav {
    background: #1C1C1E;
    border-top: 0.5px solid rgba(255, 255, 255, 0.1);
  }

  .platform-ios .nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex: 1;
    padding: 4px 0 8px 0;
    text-decoration: none !important;
    color: #8E8E93 !important;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    min-width: 50px;
    min-height: 48px;
  }

  .platform-ios .nav-tab.active {
    color: #1B0081 !important;
  }

  /* Ensure all child elements inherit the tab color */
  .platform-ios .nav-tab *:not(.nav-badge),
  .platform-ios .nav-tab .nav-tab-icon,
  .platform-ios .nav-tab .nav-tab-label {
    color: inherit !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* Force inactive state color */
  .platform-ios .nav-tab:not(.active) {
    color: #8E8E93 !important;
  }

  .platform-ios .nav-tab:not(.active) *:not(.nav-badge),
  .platform-ios .nav-tab:not(.active) .nav-tab-icon,
  .platform-ios .nav-tab:not(.active) .nav-tab-label {
    color: #8E8E93 !important;
  }

  /* Force active state color */
  .platform-ios .nav-tab.active *:not(.nav-badge),
  .platform-ios .nav-tab.active .nav-tab-icon,
  .platform-ios .nav-tab.active .nav-tab-label {
    color: #1B0081 !important;
  }

  .platform-ios .nav-tab-icon {
    width: 28px;
    height: 28px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px !important;
    flex-shrink: 0;
    color: inherit !important;
  }

  .platform-ios .nav-tab-label {
    line-height: 1.2;
    white-space: nowrap;
    overflow: visible !important;
    color: inherit !important;
    font-size: 10px !important;
    font-weight: 500 !important;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    text-decoration: none !important;
  }

  /* iOS Card Style */
  .platform-ios .card-native {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    margin: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  }

  /* iOS Large Title */
  .platform-ios .page-title-large {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.02em;
    padding: 16px 20px 8px;
    margin: 0;
  }

  /* iOS List Item */
  .platform-ios .list-item-native {
    background: white;
    border-radius: 12px;
    padding: 12px 16px;
    margin: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    transition: transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .platform-ios .list-item-native:active {
    transform: scale(0.98);
  }

  /* iOS Button */
  .platform-ios .btn-native {
    background: #1B0081;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px 24px;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
    transition: opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .platform-ios .btn-native:active {
    opacity: 0.7;
  }

  /* iOS Navigation Bar (top) - Position below notch/safe area */
  .platform-ios nav.gradient-romantic {
    background: linear-gradient(135deg, #1B0081 0%, #81007F 50%, #FF0080 100%) !important;
    border-bottom: none !important;
    box-shadow: 0 2px 8px rgba(27, 0, 129, 0.25) !important;
    padding-top: max(12px, env(safe-area-inset-top, 0px)) !important;
  }

  .platform-ios nav a[href="/dashboard"] {
    color: #FFFFFF !important;
    font-size: 17px !important;
    font-weight: 600 !important;
  }

  .platform-ios .mobile-more-menu-btn {
    font-size: 14px !important;
    font-weight: 600 !important;
  }

  /* iOS More Menu - Simplified */

  .platform-ios #mobileMenuBtn {
    display: none !important;
  }

  /* Hide mobile menu on iOS (using bottom tabs instead) */
  .platform-ios #mobileMenu {
    display: none !important;
  }

  /* iOS Content Padding for Bottom Tab Bar (matches taller bar) */
  .platform-ios .app-page-bg {
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .platform-ios main,
  .platform-ios article,
  .platform-ios section {
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* iOS Body Padding - fallback for pages without app-page-bg */
  .platform-ios body {
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* iOS Main Content */
  .platform-ios main, .platform-ios > div:not(.mobile-bottom-nav) {
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* iOS Input Style */
  .platform-ios input, .platform-ios select, .platform-ios textarea {
    background: rgba(118, 118, 128, 0.12);
    border: none !important;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 17px;
  }

  .platform-ios input:focus, .platform-ios select:focus, .platform-ios textarea:focus {
    background: rgba(118, 118, 128, 0.18);
    outline: none;
    box-shadow: none !important;
  }

  /* iOS Badge (notification) */
  .platform-ios .badge-ios {
    background: #FF0080;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
    position: absolute;
    top: 4px;
    right: 12px;
  }


  /* ========================================
     ANDROID NATIVE STYLING (Material Design 3)
     ======================================== */

  .platform-android body {
    font-family: 'Roboto', 'Noto Sans', Arial, sans-serif !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* Android Bottom Navigation Bar */
  .platform-android .mobile-bottom-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: #FFFFFF;
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    min-height: 64px;
    padding-bottom: max(48px, env(safe-area-inset-bottom, 24px));
    padding-top: 8px;
    z-index: 10000;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.12), 0 -1px 2px rgba(0, 0, 0, 0.24);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }

  .platform-android.dark-mode .mobile-bottom-nav {
    background: #1C1B1F;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.3), 0 -1px 2px rgba(0, 0, 0, 0.4);
  }

  .platform-android .nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex: 1;
    padding: 8px 8px 12px;
    text-decoration: none !important;
    color: #49454F !important;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    border-radius: 16px;
    margin: 0 2px;
    min-width: 50px;
    min-height: 52px;
  }

  .platform-android .nav-tab::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: currentColor;
    opacity: 0;
    border-radius: 16px;
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .platform-android .nav-tab:active::before {
    opacity: 0.12;
  }

  .platform-android .nav-tab.active {
    color: #1B0081 !important;
    background: rgba(27, 0, 129, 0.12);
  }

  /* Ensure all child elements inherit the tab color */
  .platform-android .nav-tab *:not(.nav-badge),
  .platform-android .nav-tab .nav-tab-icon,
  .platform-android .nav-tab .nav-tab-label {
    color: inherit !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* Force inactive state color */
  .platform-android .nav-tab:not(.active) {
    color: #49454F !important;
  }

  .platform-android .nav-tab:not(.active) *:not(.nav-badge),
  .platform-android .nav-tab:not(.active) .nav-tab-icon,
  .platform-android .nav-tab:not(.active) .nav-tab-label {
    color: #49454F !important;
  }

  /* Force active state color */
  .platform-android .nav-tab.active *:not(.nav-badge),
  .platform-android .nav-tab.active .nav-tab-icon,
  .platform-android .nav-tab.active .nav-tab-label {
    color: #1B0081 !important;
  }

  .platform-android .nav-tab-icon {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px !important;
    flex-shrink: 0;
    color: inherit !important;
  }

  .platform-android .nav-tab-label {
    line-height: 1.2;
    white-space: nowrap;
    overflow: visible !important;
    color: inherit !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    text-decoration: none !important;
  }

  /* Android Material Card */
  .platform-android .card-native {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    margin: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    transition: box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .platform-android .card-native:active {
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  }

  /* Android Material Button */
  .platform-android .btn-native {
    background: #1B0081;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 14px 24px;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
  }

  .platform-android .btn-native::before {
    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.4s ease, height 0.4s ease;
  }

  .platform-android .btn-native:active::before {
    width: 300px;
    height: 300px;
  }

  /* Android Top App Bar */
  .platform-android nav.gradient-romantic {
    background: linear-gradient(135deg, #1B0081 0%, #81007F 50%, #FF0080 100%) !important;
    box-shadow: 0 4px 12px rgba(27, 0, 129, 0.25) !important;
    border-bottom: none;
  }

  .platform-android nav a[href="/dashboard"] {
    color: #FFFFFF !important;
    font-size: 20px !important;
    font-weight: 500 !important;
    letter-spacing: 0.15px;
  }

  .mobile-more-menu-btn {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  #mobileMoreMenu {
    pointer-events: none !important; /* Blocked by default */
    position: fixed !important;
    top: 60px !important;
    right: 8px !important;
    z-index: 99999 !important;
  }

  /* Menu content always clickable */
  #mobileMoreMenu > div {
    pointer-events: auto !important;
  }

  /* All menu items clickable */
  #mobileMoreMenu > div > div {
    pointer-events: auto !important;
    cursor: pointer !important;
  }

  .platform-android .mobile-more-menu-btn {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Android More Menu - Simplified */

  .platform-android #mobileMenuBtn {
    display: none !important;
  }

  .platform-android #mobileMenu {
    display: none !important;
  }

  /* Android Content Padding for Bottom Nav */
  .platform-android .app-page-bg {
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .platform-android main,
  .platform-android article,
  .platform-android section {
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Android Body Padding - fallback for pages without app-page-bg */
  .platform-android body {
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Android Main Content */
  .platform-android main, .platform-android > div:not(.mobile-bottom-nav) {
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Android Input Style */
  .platform-android input, .platform-android select, .platform-android textarea {
    background: transparent;
    border: none !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.38) !important;
    border-radius: 4px 4px 0 0;
    padding: 16px 12px 8px;
    font-size: 16px;
  }

  .platform-android input:focus, .platform-android select:focus, .platform-android textarea:focus {
    border-bottom: 2px solid #1B0081 !important;
    outline: none;
    box-shadow: none !important;
  }

  /* Android FAB (Floating Action Button) */
  .platform-android .fab {
    position: fixed;
    bottom: calc(120px + env(safe-area-inset-bottom, 0px) + 16px);
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: #1B0081;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2), 0 6px 10px rgba(0, 0, 0, 0.14);
    z-index: 998;
    font-size: 24px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .platform-android .fab:active {
    transform: scale(0.95);
  }

  /* Android Material Ripple Effect */
  .platform-android .ripple-effect {
    position: relative;
    overflow: hidden;
  }

  .platform-android .ripple-effect::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
  }

  .platform-android .ripple-effect:active::after {
    width: 300px;
    height: 300px;
  }

  /* Android Snackbar */
  .platform-android .snackbar {
    position: fixed;
    bottom: calc(120px + env(safe-area-inset-bottom, 0px) + 16px);
    left: 16px;
    right: 16px;
    background: #323232;
    color: white;
    padding: 14px 16px;
    border-radius: 4px;
    font-size: 14px;
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2), 0 6px 10px rgba(0, 0, 0, 0.14);
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .platform-android .snackbar.show {
    transform: translateY(0);
    opacity: 1;
  }


  /* ========================================
     SHARED MOBILE STYLES (Both iOS & Android)
     ======================================== */

  /* Hide desktop navigation completely on mobile */
  .mobile-native .nav-desktop {
    display: none !important;
  }

  /* Ensure content doesn't go under bottom nav */
  .mobile-native .app-page-bg {
    min-height: 100vh;
    overflow-y: visible !important;
    position: static !important;
    transform: none !important;
  }

  /* Prevent any parent containers from breaking fixed positioning */
  .mobile-native > div:not(.mobile-bottom-nav),
  .mobile-native main,
  .mobile-native article {
    transform: none !important;
    filter: none !important;
    perspective: none !important;
    will-change: auto !important;
  }

  /* Larger touch targets */
  .mobile-native button,
  .mobile-native a.btn,
  .mobile-native .nav-tab {
    min-height: 44px;
    min-width: 44px;
  }

  /* Better tap highlighting */
  .mobile-native * {
    -webkit-tap-highlight-color: transparent;
  }

  /* Smooth scrolling */
  .mobile-native {
    -webkit-overflow-scrolling: touch;
  }

  /* Pull to refresh indicator space */
  .mobile-native .page-content {
    padding-top: 8px;
  }

  /* Mobile-optimized typography */
  .mobile-native h1 {
    font-size: 28px;
    line-height: 1.2;
  }

  .mobile-native h2 {
    font-size: 24px;
    line-height: 1.3;
  }

  .mobile-native h3 {
    font-size: 20px;
    line-height: 1.4;
  }

  .mobile-native p {
    font-size: 16px;
    line-height: 1.5;
  }

  /* Mobile card spacing */
  .mobile-native .max-w-6xl,
  .mobile-native .max-w-4xl {
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
  }
}

/* Desktop - keep everything unchanged */
@media (min-width: 769px) {
  .mobile-bottom-nav {
    display: none !important;
  }

  .fab {
    display: none !important;
  }
}

/* Hide bottom nav on desktop */
@media (min-width: 768px) {
  .mobile-bottom-nav {
    display: none !important;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .platform-ios.dark-mode nav.gradient-romantic {
    background: #1C1C1E !important;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
  }

  .platform-ios.dark-mode nav a[href="/dashboard"] {
    color: #FF0080 !important;
  }

  .platform-android.dark-mode nav.gradient-romantic {
    background: #1C1B1F !important;
  }

  .platform-android.dark-mode nav a[href="/dashboard"] {
    color: #FF0080 !important;
  }
}
