/* ==========================================================================
   Floating Bottom Navigation & Ultimate Mobile Ergonomics Design System
   Be Right Back — Unified Responsive Engine (iPhone, Samsung Galaxy, Pixel, iPad)
   ========================================================================== */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --bottom-nav-height: 64px;
}

/* ==========================================================================
   1. CORE VIEWPORT & FLUID RESET (Prevents squishing & forced zoom-out)
   ========================================================================== */
html, body {
  max-width: 100vw !important;
  overflow-x: hidden !important;
  -webkit-text-size-adjust: 100% !important;
  text-size-adjust: 100% !important;
}

body {
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  -webkit-tap-highlight-color: transparent;
}

/* Ensure all elements respect viewport boundaries */
*, *::before, *::after {
  box-sizing: border-box;
}

/* ==========================================================================
   2. RESPONSIVE SIDEBAR & MAIN CONTAINER (CRITICAL FIX FOR MOBILE)
   ========================================================================== */
@media (max-width: 1023px) {
  /* Hide static left desktop sidebar on mobile & tablet */
  aside,
  .sidebar,
  #desktop-sidebar {
    display: none !important;
  }

  /* Slide-over Mobile Drawer mode when opened */
  aside.mobile-drawer-open,
  .sidebar.mobile-drawer-open {
    display: flex !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 290px !important;
    max-width: 82vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 1000 !important;
    background: rgba(255, 255, 255, 0.96) !important;
    backdrop-filter: blur(28px) saturate(190%) !important;
    -webkit-backdrop-filter: blur(28px) saturate(190%) !important;
    box-shadow: 20px 0 50px rgba(15, 23, 42, 0.25) !important;
    border-right: 1px solid rgba(226, 232, 240, 0.8) !important;
    animation: slideInDrawer 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 24px) 16px !important;
    overflow-y: auto !important;
  }

  @keyframes slideInDrawer {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
  }

  /* Backdrop for mobile drawer */
  .mobile-drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

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

  /* Main viewport expands to 100% width on mobile */
  .viewport-main-container,
  main {
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    flex: 1 1 100% !important;
    padding: 14px 14px calc(var(--bottom-nav-height) + var(--safe-bottom) + 32px) 14px !important;
    overflow-x: hidden !important;
  }

  /* Top Header responsive compactness */
  header {
    padding-left: max(12px, var(--safe-left)) !important;
    padding-right: max(12px, var(--safe-right)) !important;
    height: 58px !important;
  }

  /* Hide bulky search and date greeting on mobile header */
  header #global-search,
  header .w-64,
  header #header-greeting,
  header #header-date {
    display: none !important;
  }

  /* Responsive Grids & Sections */
  .stat-cards-layout-grid {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    gap: 12px !important;
  }

  .overview-three-section-grid {
    grid-template-columns: 1fr !important;
    height: auto !important;
    min-height: auto !important;
    gap: 20px !important;
  }

  .quick-actions-layout-grid {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    gap: 12px !important;
  }
}

/* Tablet Adjustments (640px to 1023px) */
@media (min-width: 640px) and (max-width: 1023px) {
  .stat-cards-layout-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .quick-actions-layout-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* ==========================================================================
   3. FLOATING GLASSMORPHIC BOTTOM NAVIGATION BAR
   ========================================================================== */
.brb-floating-nav-wrap {
  position: fixed;
  bottom: calc(12px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateZ(0);
  width: calc(100% - 24px);
  max-width: 420px;
  height: var(--bottom-nav-height);
  z-index: 990;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 34px;
  box-shadow: 0 16px 40px -6px rgba(15, 23, 42, 0.16),
              0 6px 18px -2px rgba(99, 102, 241, 0.12),
              0 0 0 1px rgba(99, 102, 241, 0.05);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  user-select: none;
}

/* Desktop Hide */
@media (min-width: 1024px) {
  .brb-floating-nav-wrap {
    display: none !important;
  }
  .mobile-menu-toggle-btn {
    display: none !important;
  }
}

/* Hide on scroll down, show on scroll up */
.brb-floating-nav-wrap.nav-hidden {
  transform: translateX(-50%) translateY(130%);
  opacity: 0;
  pointer-events: none;
}

/* Navigation Items */
.brb-nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  padding: 3px 2px;
  color: #64748b;
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  border-radius: 18px;
}

.brb-nav-item i,
.brb-nav-item svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.2;
  margin-bottom: 2px;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease;
}

.brb-nav-item:active {
  transform: scale(0.92);
}

.brb-nav-item.active {
  color: #4f46e5;
  font-weight: 800;
}

.brb-nav-item.active i,
.brb-nav-item.active svg {
  color: #4f46e5;
  transform: translateY(-1.5px) scale(1.1);
}

/* Center Highlight Action Button (Apply Leave / Action) */
.brb-nav-item.brb-nav-action {
  flex: 1.12;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #ec4899 100%);
  color: #ffffff !important;
  border-radius: 24px;
  box-shadow: 0 8px 18px -2px rgba(79, 70, 229, 0.45);
  margin: 0 4px;
  padding: 6px 3px;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.brb-nav-item.brb-nav-action i,
.brb-nav-item.brb-nav-action svg {
  color: #ffffff !important;
  width: 22px;
  height: 22px;
  stroke-width: 2.5;
  margin-bottom: 1px;
}

.brb-nav-item.brb-nav-action span {
  color: #ffffff !important;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.brb-nav-item.brb-nav-action:active {
  transform: scale(0.94);
}

/* ==========================================================================
   4. MOBILE BOTTOM SHEET MODALS
   ========================================================================== */
@media (max-width: 767px) {
  .modal-backdrop {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .modal-backdrop .modal-card,
  .modal-backdrop .bg-white {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 26px 26px 0 0 !important;
    max-height: 88dvh !important;
    overflow-y: auto !important;
    padding: 20px 16px calc(20px + var(--safe-bottom)) 16px !important;
    transform: translateY(100%) !important;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
    box-shadow: 0 -12px 45px rgba(15, 23, 42, 0.2) !important;
  }

  .modal-backdrop.active .modal-card,
  .modal-backdrop.active .bg-white {
    transform: translateY(0) !important;
  }

  .sheet-drag-handle {
    width: 42px;
    height: 5px;
    background: #cbd5e1;
    border-radius: 99px;
    margin: -8px auto 14px auto;
  }
}
