/**
 * Admin Portal - Native Mobile & Tablet App UI Stylesheet
 * Optimized for Mobile-First experience, thumb navigation, tactile micro-interactions,
 * responsive in-page sliding drawers, and 100% desktop preservation.
 *
 * ALL RULES ARE STRICTLY SCOPED WITHIN MEDIA QUERIES (max-width: 991.98px).
 * Desktop view (>= 992px) is 100% untouched.
 */

/* ==========================================================================
   1. Mobile App Global Resets & Safe-Area Setup (< 992px)
   ========================================================================== */
@media (max-width: 991.98px) {
  html, body {
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  body.admin-mobile-mode {
    background-color: #f8fafc !important;
  }

  /* Completely eliminate sidebar margin gap on mobile: full 100% width flush to screen edges */
  body.admin-mobile-mode,
  body.admin-mobile-mode .wrapper,
  body.admin-mobile-mode .content-wrapper,
  body.admin-mobile-mode.sidebar-collapse .content-wrapper,
  body.admin-mobile-mode:not(.sidebar-collapse) .content-wrapper,
  body.admin-mobile-mode.sidebar-closed .content-wrapper,
  body.admin-mobile-mode.sidebar-open .content-wrapper,
  body.admin-mobile-mode.sidebar-is-opening .content-wrapper,
  body.admin-mobile-mode .main-header,
  body.admin-mobile-mode.sidebar-collapse .main-header,
  body.admin-mobile-mode:not(.sidebar-collapse) .main-header,
  body.admin-mobile-mode.sidebar-closed .main-header,
  body.admin-mobile-mode.sidebar-open .main-header,
  body.admin-mobile-mode .main-footer,
  body.admin-mobile-mode.sidebar-collapse .main-footer,
  body.admin-mobile-mode:not(.sidebar-collapse) .main-footer,
  body.admin-mobile-mode.sidebar-closed .main-footer,
  body.admin-mobile-mode.sidebar-open .main-footer {
    margin-left: 0 !important;
    padding-left: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    transform: none !important;
  }

  /* Mobile Off-Canvas Slide-Out Drawer Sidebar (0 Page Content Gap) */
  body.admin-mobile-mode .main-sidebar,
  body.admin-mobile-mode .main-sidebar::before {
    display: block !important;
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 280px !important;
    max-width: 84vw !important;
    height: 100vh !important;
    z-index: 1060 !important;
    overflow-y: auto !important;
    background-color: #0f172a !important;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.28s ease !important;
  }

  /* When closed: hidden off-screen to the left (content has ZERO gap) */
  body.admin-mobile-mode:not(.sidebar-open) .main-sidebar,
  body.admin-mobile-mode.sidebar-collapse:not(.sidebar-open) .main-sidebar,
  body.admin-mobile-mode.sidebar-closed .main-sidebar {
    margin-left: -280px !important;
    transform: translate3d(-100%, 0, 0) !important;
    box-shadow: none !important;
    pointer-events: none !important;
  }

  /* When opened via hamburger: slides in smoothly over content */
  body.admin-mobile-mode.sidebar-open .main-sidebar {
    margin-left: 0 !important;
    transform: translate3d(0, 0, 0) !important;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.6) !important;
    pointer-events: auto !important;
  }

  /* Backdrop overlay when sidebar is open */
  body.admin-mobile-mode.sidebar-open #sidebar-overlay {
    display: block !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 1055 !important;
    background: rgba(15, 23, 42, 0.6) !important;
    backdrop-filter: blur(2px) !important;
    -webkit-backdrop-filter: blur(2px) !important;
  }

  /* Compact content wrapper padding for bottom navigation bar */
  body.admin-mobile-mode .content-wrapper {
    padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    margin-left: 0 !important;
  }

  /* Hide main-footer on mobile to prevent clutter */
  body.admin-mobile-mode .main-footer {
    display: none !important;
  }

  /* Prevent Safari from auto-zooming on form focus */
  body.admin-mobile-mode input[type="text"],
  body.admin-mobile-mode input[type="number"],
  body.admin-mobile-mode input[type="date"],
  body.admin-mobile-mode input[type="email"],
  body.admin-mobile-mode select,
  body.admin-mobile-mode textarea {
    font-size: 16px !important;
  }

  /* Snappy touch interaction */
  a, button, .btn, .nav-link, .erp-filter-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
}

/* ==========================================================================
   2. Sticky Mobile App Bottom Navigation Bar (Admin Thumb Zone)
   ========================================================================== */
.admin-bottom-nav {
  display: none;
}

@media (max-width: 991.98px) {
  .admin-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(62px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(226, 232, 240, 0.9);
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
    z-index: 1045;
    justify-content: space-around;
    align-items: center;
    user-select: none;
  }

  .admin-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #64748b;
    text-decoration: none !important;
    position: relative;
    padding: 6px 0 4px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }

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

  .admin-bottom-nav-item .nav-icon-box {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    font-size: 1.25rem;
    transition: transform 0.2s ease;
  }

  .admin-bottom-nav-item .nav-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-top: 2px;
    transition: color 0.2s ease;
    line-height: 1.1;
  }

  .admin-bottom-nav-item.active {
    color: #1e40af;
  }

  .admin-bottom-nav-item.active .nav-icon-box {
    transform: translateY(-2px);
    color: #2563eb;
  }

  .admin-bottom-nav-item.active .nav-label {
    color: #1e3a8a;
    font-weight: 700;
  }

  .admin-bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    width: 28px;
    height: 3px;
    background: linear-gradient(90deg, #2563eb, #3b82f6);
    border-radius: 0 0 4px 4px;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
  }
}

/* ==========================================================================
   3. In-Page Sliding Drawers Responsive Framework (< 992px & < 768px)
   ========================================================================== */
@media (min-width: 768px) and (max-width: 991.98px) {
  /* Tablet: 85vw width for all in-page sliding drawers */
  .erp-inpage-drawer,
  div[id^="inline"][id$="Drawer"],
  #studentQuickLookupDrawer {
    width: 85vw !important;
    max-width: 85vw !important;
  }
}

@media (max-width: 767.98px) {
  /* Mobile Phone: Full-screen sliding sheet (100vw) */
  .erp-inpage-drawer,
  div[id^="inline"][id$="Drawer"],
  #studentQuickLookupDrawer {
    width: 100% !important;
    max-width: 100vw !important;
    height: 100vh !important;
    right: -100% !important;
    border-radius: 0 !important;
  }

  /* When drawer has right: 0 or style is active */
  .erp-inpage-drawer[style*="right: 0"],
  .erp-inpage-drawer[style*="right:0"],
  div[id^="inline"][id$="Drawer"][style*="right: 0"],
  div[id^="inline"][id$="Drawer"][style*="right:0"],
  #studentQuickLookupDrawer[style*="right: 0"],
  #studentQuickLookupDrawer[style*="right:0"],
  .drawer-open {
    right: 0 !important;
  }

  /* Drawer Header on Mobile */
  .erp-inpage-drawer .drawer-header,
  #studentQuickLookupDrawer .drawer-header {
    padding: 12px 14px !important;
  }

  .erp-inpage-drawer .drawer-header h5,
  #studentQuickLookupDrawer .drawer-header h5 {
    font-size: 1.05rem !important;
  }

  /* Drawer Body scrolling */
  .erp-inpage-drawer .drawer-body,
  #studentQuickLookupDrawer .drawer-body {
    padding: 14px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Sticky Drawer Footer sitting above safe area */
  .erp-inpage-drawer .drawer-footer,
  #studentQuickLookupDrawer .drawer-footer {
    padding: 10px 14px !important;
    padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
  }
}

/* ==========================================================================
   4. 32px Compact Filter Toolbar Responsive Stacking (< 992px & < 768px)
   ========================================================================== */
@media (max-width: 991.98px) {
  .erp-filter-card {
    padding: 10px 12px !important;
    margin-bottom: 12px !important;
  }

  .erp-filter-card form .row {
    margin-left: -4px !important;
    margin-right: -4px !important;
  }

  .erp-filter-card form .row > [class*="col-"] {
    padding-left: 4px !important;
    padding-right: 4px !important;
  }
}

@media (max-width: 767.98px) {
  .erp-filter-card {
    border-radius: 10px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
  }

  .erp-filter-card form .row > [class*="col-"] {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    margin-bottom: 6px !important;
  }

  .erp-filter-group {
    width: 100% !important;
  }

  .erp-filter-control,
  .erp-filter-group input,
  .erp-filter-group select {
    font-size: 16px !important;
    height: 38px !important;
  }

  .erp-filter-group .input-group-text {
    height: 38px !important;
  }

  .erp-filter-btn {
    height: 38px !important;
    width: 100% !important;
    margin-top: 4px !important;
  }

  /* Quick action buttons flex row */
  .erp-filter-actions {
    display: flex !important;
    width: 100% !important;
    gap: 8px !important;
  }

  .erp-filter-actions .btn {
    flex: 1 !important;
  }
}

/* ==========================================================================
   5. Tables & Data Registers Momentum Touch Scrolling (< 992px)
   ========================================================================== */
@media (max-width: 991.98px) {
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto !important;
    border-radius: 8px !important;
    margin-bottom: 12px !important;
  }

  /* Subtle indicator that table scrolls horizontally */
  .table-responsive {
    background:
      linear-gradient(to right, white 30%, rgba(255, 255, 255, 0)),
      linear-gradient(to right, rgba(255, 255, 255, 0), white 70%) 100% 0,
      radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0)),
      radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0)) 100% 0;
    background-repeat: no-repeat;
    background-color: #ffffff;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
  }

  /* Compact cell sizing for high density on mobile */
  .table-responsive table th,
  .table-responsive table td {
    padding: 8px 10px !important;
    font-size: 0.82rem !important;
    vertical-align: middle !important;
  }

  /* Action buttons stay in clean horizontal row */
  .table-responsive table td.text-nowrap,
  .table-responsive table td .btn-group {
    white-space: nowrap !important;
  }

  .table-responsive table td .btn-sm,
  .table-responsive table td .btn-xs {
    padding: 3px 8px !important;
    font-size: 0.75rem !important;
    margin: 1px !important;
  }
}

/* ==========================================================================
   6. Dashboard KPI Grid & Cards Responsive Layout
   ========================================================================== */
@media (max-width: 767.98px) {
  /* 2-column KPI grid on mobile */
  .admin-kpi-grid,
  .row.row-cards {
    margin-left: -4px !important;
    margin-right: -4px !important;
  }

  .admin-kpi-grid > [class*="col-"],
  .row.row-cards > [class*="col-"] {
    padding-left: 4px !important;
    padding-right: 4px !important;
    flex: 0 0 50% !important;
    max-width: 50% !important;
  }

  .small-box,
  .info-box {
    margin-bottom: 8px !important;
    border-radius: 10px !important;
  }

  .small-box .inner {
    padding: 10px !important;
  }

  .small-box .inner h3 {
    font-size: 1.4rem !important;
  }

  .small-box .inner p {
    font-size: 0.75rem !important;
  }
}

/* ==========================================================================
   7. Top Navbar Mobile Search & Profile Alignment (< 992px)
   ========================================================================== */
@media (max-width: 991.98px) {
  .main-header.navbar {
    padding: 6px 12px !important;
  }

  /* Quick search in navbar expands comfortably */
  #studentSearchWrap {
    max-width: 200px !important;
    transition: max-width 0.25s ease !important;
  }

  #studentSearchWrap:focus-within {
    max-width: 260px !important;
  }

  #studentSearchInput {
    font-size: 14px !important;
    height: 34px !important;
  }

  .navbar-nav .nav-link {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
}

@media (max-width: 575.98px) {
  #studentSearchWrap {
    max-width: 140px !important;
  }

  #studentSearchWrap:focus-within {
    max-width: 190px !important;
  }
}

/* ==========================================================================
   8. Dashboard Executive Quick Dock & KPI Cards (< 992px)
   ========================================================================== */
@media (max-width: 991.98px) {
  .dashboard-quick-dock {
    padding: 0.85rem !important;
    margin-bottom: 1rem !important;
  }

  .quick-action-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.65rem !important;
  }

  .quick-action-tile {
    padding: 0.75rem 0.45rem !important;
  }

  .quick-action-tile .tile-icon {
    width: 38px !important;
    height: 38px !important;
    font-size: 1.1rem !important;
    margin-bottom: 0.35rem !important;
  }

  .quick-action-tile .tile-title {
    font-size: 0.78rem !important;
  }

  .quick-action-tile .tile-subtitle {
    font-size: 0.64rem !important;
  }

  .executive-kpi-card {
    min-height: 82px !important;
    padding: 0.75rem 0.85rem !important;
    margin-bottom: 0.65rem !important;
  }

  .executive-kpi-icon {
    width: 38px !important;
    height: 38px !important;
    font-size: 1rem !important;
    margin-right: 0.65rem !important;
  }

  .executive-kpi-value {
    font-size: 1.25rem !important;
  }
}

@media (max-width: 575.98px) {
  .quick-action-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  .executive-kpi-card {
    padding: 0.65rem 0.75rem !important;
  }
}


