/* ==========================================================================
   WEB INTERN PLATFORM - MOBILE APP SYSTEM & NATIVE PWA UX
   ========================================================================== */

/* Mobile App Global Touch & Smooth Scroll Settings */
html, body {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: contain;
}

/* Standalone PWA Mode Enhancements (App Mode) */
@media (display-mode: standalone) {
  body {
    -webkit-user-select: none;
    user-select: none;
    padding-top: env(safe-area-inset-top, 0px);
  }
  
  /* Allow text selection inside inputs and content blocks */
  input, textarea, p, span, h1, h2, h3, h4, h5, h6, table, code {
    -webkit-user-select: text;
    user-select: text;
  }
}

/* Mobile Nav Drawer (Slide-out) */
.mobile-drawer-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  z-index: 250;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mobile-drawer-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.mobile-drawer {
  position: fixed;
  top: 0; left: -300px; bottom: 0;
  width: 290px;
  background-color: #ffffff;
  z-index: 260;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding: max(20px, env(safe-area-inset-top)) 20px 20px;
}

.mobile-drawer.active {
  transform: translateX(300px);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.drawer-links {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-link {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--secondary);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  transition: background-color 0.2s ease;
}

.drawer-link:active {
  background-color: var(--primary-light);
  color: var(--primary);
}

/* Fixed Bottom Navigation Bar (Native App Bar) */
.bottom-app-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background-color: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
}

@media (min-width: 769px) {
  .bottom-app-bar {
    display: none;
  }
}

.app-bar-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none !important;
  flex: 1;
  height: 100%;
  position: relative;
  transition: color 0.2s ease, transform 0.1s ease;
}

.app-bar-tab:active {
  transform: scale(0.92);
}

.app-bar-tab.active {
  color: var(--primary);
  font-weight: 700;
}

.app-bar-tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 32px;
  height: 3px;
  background-color: var(--primary);
  border-radius: 0 0 4px 4px;
}

.app-bar-tab .tab-icon {
  font-size: 1.3rem;
  line-height: 1;
}

/* Bottom Sheet Modal */
.bottom-sheet-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  z-index: 220;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.bottom-sheet-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  position: fixed;
  bottom: -100%;
  left: 0;
  right: 0;
  background-color: #ffffff;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 230;
  transition: bottom 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -10px 30px rgba(0,0,0,0.15);
}

.bottom-sheet.active {
  bottom: 0;
}

.bottom-sheet-handle {
  width: 44px;
  height: 5px;
  background-color: var(--border-color);
  border-radius: var(--radius-full);
  margin: 0 auto 18px;
}

/* Mobile Web App Styling & Touch Layout (Scoped to max-width: 768px) */
@media (max-width: 768px) {
  body {
    padding-bottom: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom, 0px) + 24px);
  }

  .main-header {
    position: sticky;
    top: 0;
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background-color: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
  }
  
  .header-container {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    height: 100% !important;
  }

  .header-actions {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    margin-left: auto !important;
  }

  /* Hide redundant 'Dashboard' / 'Sign In' text button from top header on mobile 
     (since 'Portal' is in bottom navbar and drawer) */
  #auth-header-btn {
    display: none !important;
  }

  /* Compact Log Out button for mobile view */
  #header-logout-btn {
    font-size: 0.78rem !important;
    padding: 5px 9px !important;
    height: 36px !important;
    white-space: nowrap !important;
    border-radius: 10px !important;
    display: inline-flex !important;
    align-items: center !important;
  }

  .menu-toggle {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    min-height: 38px !important;
    border-radius: 10px !important;
    background-color: var(--bg-main, #f1f5f9) !important;
    border: 1px solid var(--border-color, #e2e8f0) !important;
    color: var(--text-main, #0f172a) !important;
    cursor: pointer !important;
    padding: 0 !important;
    margin-left: 2px !important;
    flex-shrink: 0 !important;
  }

  .menu-toggle:active {
    transform: scale(0.92) !important;
    background-color: var(--primary-light, #eff6ff) !important;
    color: var(--primary, #2563eb) !important;
  }

  .container {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  /* App Card Polish */
  .card, .stat-box, .bottom-sheet {
    border-radius: 16px !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.04);
  }

  /* App Native Button Press Feedback */
  .btn {
    border-radius: 12px;
    font-weight: 600;
    transition: transform 0.1s ease, background-color 0.2s ease;
  }
  .btn:active {
    transform: scale(0.97);
  }
  
  /* Horizontal Scroll Tabs (Swipeable) */
  .tabs-container {
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    margin-bottom: 18px;
    scrollbar-width: none; /* Hide scrollbar for Chrome/Safari/Firefox */
  }
  .tabs-container::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    padding: 10px 16px;
    font-size: 0.88rem;
    flex-shrink: 0;
    border-radius: 20px;
  }

  /* Prevent Mobile Safari Auto-Zoom on Input Focus */
  input[type="text"], input[type="email"], input[type="password"], input[type="tel"], select, textarea {
    font-size: 16px !important;
    border-radius: 10px;
  }

  /* Mobile Stream & Cards Layout */
  .grid, .grid-2, .grid-3, .grid-4 {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .stats-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  /* Hero Section App Polish */
  .hero-section {
    padding: 24px 0 20px;
    text-align: center;
  }

  .hero-title {
    font-size: 1.65rem !important;
    line-height: 1.3 !important;
  }

  .hero-subtitle {
    font-size: 0.95rem !important;
    margin-bottom: 20px;
  }

  /* Mobile Tables - Horizontally Scrollable Container */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--border-color);
  }
}
