/**
 * Wisdom Group (wisdomgroup.pk) - Enterprise Multi-Brand Ecosystem
 * Master UI/UX & All-Device Responsive Stylesheet
 * 
 * Supports: Mobile Phones (320px - 480px), Tablets/iPads (481px - 1024px),
 * Laptops (1025px - 1440px), High-Resolution Desktop Displays (1440px+),
 * Retina screens & Print Media.
 */

/* ==========================================================================
   1. GLOBAL RESET & MOBILE OVERFLOW CONTROLS
   ========================================================================== */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  box-sizing: border-box;
  scroll-behavior: smooth;
  overflow-x: hidden;
  max-width: 100vw;
}

*,
*::before,
*::after {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  margin: 0;
  padding: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#root {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

/* ==========================================================================
   2. TOUCH ACCESSIBILITY & MOBILE INPUT CONTROLS
   ========================================================================== */
@media screen and (max-width: 768px) {

  /* Prevent iOS Safari auto-zoom on input focus while keeping crisp layout */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="search"],
  input[type="date"],
  input[type="datetime-local"],
  select,
  textarea {
    font-size: 16px !important;
    line-height: 1.4 !important;
    min-height: 42px;
  }
}

button,
a,
input,
select,
textarea {
  touch-action: manipulation;
}

/* Focus styles for keyboard accessibility */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #0284c7 !important;
  outline-offset: 2px !important;
}

/* ==========================================================================
   3. MODERN SLEEK SCROLLBARS
   ========================================================================== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(241, 245, 249, 0.7);
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.6);
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.85);
}

/* Dark layout scrollbars */
.bg-\[\#0f172a\] ::-webkit-scrollbar-track,
.bg-\[\#1e293b\] ::-webkit-scrollbar-track,
aside ::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.8);
}

.bg-\[\#0f172a\] ::-webkit-scrollbar-thumb,
.bg-\[\#1e293b\] ::-webkit-scrollbar-thumb,
aside ::-webkit-scrollbar-thumb {
  background: rgba(51, 65, 85, 0.8);
}

/* ==========================================================================
   4. NAVIGATION & HEADER RESPONSIVENESS
   ========================================================================== */
header {
  width: 100%;
  max-width: 100vw;
}

@media screen and (max-width: 640px) {

  /* Subtitle hidden on extra small phones so logo and actions fit */
  header .group p.text-\[11px\] {
    display: none;
  }

  header .h-16 {
    height: 3.75rem;
  }

  /* Compact header buttons on small screens */
  header .flex.items-center.gap-2\.5 {
    gap: 0.375rem;
  }

  /* Ensure brand logo doesn't overflow */
  header .font-extrabold.text-base {
    font-size: 0.875rem !important;
  }

  /* Mobile slide-down menu safe touch targets & momentum scroll */
  .lg\:hidden.border-t.border-slate-200 {
    max-height: calc(100vh - 4rem);
    max-height: calc(100dvh - 4rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2rem;
  }

  .lg\:hidden.border-t.border-slate-200 a,
  .lg\:hidden.border-t.border-slate-200 button {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ==========================================================================
   5. RESPONSIVE FORMS & MODAL DIALOGS (ALL 35 MODALS)
   ========================================================================== */
/* Ensure all overlay modals are centered, fully visible, and scrollable on phones */
div[class*="fixed inset-0"][class*="z-50"] {
  padding: 0.75rem !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

@media screen and (max-width: 768px) {

  /* Inner modal container */
  div[class*="fixed inset-0"][class*="z-50"]>div[class*="bg-white"],
  div[class*="fixed inset-0"][class*="z-50"]>div[class*="rounded-2xl"],
  div[class*="fixed inset-0"][class*="z-50"]>div[class*="rounded-3xl"] {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 90vh !important;
    max-height: 90dvh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 1.25rem 1rem !important;
    margin: auto !important;
    border-radius: 1rem !important;
  }

  /* Responsive Grid inside modals: Collapse rigid 2-col and 3-col forms on mobile */
  div[class*="fixed inset-0"][class*="z-50"] form .grid-cols-2,
  div[class*="fixed inset-0"][class*="z-50"] form .grid-cols-3,
  div[class*="fixed inset-0"][class*="z-50"] .grid.grid-cols-2,
  div[class*="fixed inset-0"][class*="z-50"] .grid.grid-cols-3 {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
  }

  /* Modal action buttons: Cancel / Save should span nicely on mobile */
  div[class*="fixed inset-0"][class*="z-50"] form .flex.justify-end,
  div[class*="fixed inset-0"][class*="z-50"] .flex.items-center.justify-end {
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    width: 100%;
  }

  div[class*="fixed inset-0"][class*="z-50"] form .flex.justify-end>button,
  div[class*="fixed inset-0"][class*="z-50"] .flex.items-center.justify-end>button {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px !important;
  }
}

/* ==========================================================================
   6. ADMIN & ACADEMY CMS ERP RESPONSIVE LAYOUT
   ========================================================================== */
/* Main wrapper in CMS */
div[class*="flex-1 flex overflow-hidden"] {
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

@media screen and (max-width: 1023px) {

  /* Admin Sidebar on mobile / tablets (< 1024px) */
  aside.bg-\[\#0f172a\],
  aside.bg-\[\#1e293b\] {
    position: fixed;
    top: 3.5rem;
    left: 0;
    bottom: 0;
    z-index: 45;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 80vw;
  }

  /* Main content takes full screen */
  main[class*="flex-1 overflow-y-auto"] {
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    padding: 1rem 0.875rem !important;
  }

  /* Admin Header adjustment on small devices */
  header .flex.items-center.justify-between {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

@media screen and (min-width: 1024px) {

  /* Desktop sidebars stay side-by-side with main content */
  aside.bg-\[\#0f172a\],
  aside.bg-\[\#1e293b\] {
    position: relative;
    top: auto;
    left: auto;
    bottom: auto;
  }
}

/* ==========================================================================
   7. DATA TABLES, STATS & RECORDS RESPONSIVE CONTROLS
   ========================================================================== */
/* Enable smooth touch horizontal scrolling on all data tables and records */
table,
.overflow-x-auto,
div[class*="overflow-x-auto"],
div[class*="border border-slate-200"][class*="rounded"]>div {
  -webkit-overflow-scrolling: touch !important;
  scroll-behavior: smooth;
}

table {
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

@media screen and (max-width: 640px) {

  /* Table cell touch padding on small screens */
  th,
  td {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    font-size: 0.75rem !important;
  }

  /* Badge labels compact on mobile */
  span[class*="rounded-full"][class*="text-\[10px\]"],
  span[class*="rounded"][class*="text-\[10px\]"],
  span[class*="rounded-full"][class*="text-xs"] {
    padding: 0.15rem 0.4rem !important;
    font-size: 0.65rem !important;
  }
}

/* ==========================================================================
   8. STATS CARDS & HERO METRICS RESPONSIVE GRIDS
   ========================================================================== */
@media screen and (max-width: 640px) {

  /* 4-column metric grids collapse cleanly to 2 columns on mobile */
  .grid.grid-cols-2.md\:grid-cols-4,
  .grid.grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
  }

  /* Metric cards compact text */
  .grid.grid-cols-2.md\:grid-cols-4>div,
  .grid.grid-cols-4>div {
    padding: 0.75rem 0.5rem !important;
  }

  /* Hero headline scale */
  h1.text-4xl,
  h1.text-5xl,
  h1.text-6xl {
    font-size: 1.875rem !important;
    line-height: 1.2 !important;
  }

  /* Button rows in hero wrap gracefully */
  .flex.items-center.justify-center.gap-4,
  .flex.flex-col.sm\:flex-row {
    width: 100%;
  }

  .flex.items-center.justify-center.gap-4>a,
  .flex.items-center.justify-center.gap-4>button {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
}

/* ==========================================================================
   9. WISDOM MART CART & CHECKOUT RESPONSIVENESS
   ========================================================================== */
@media screen and (max-width: 640px) {

  /* Slide-over cart drawer takes full width on mobile */
  div[class*="w-screen max-w-md"] {
    width: 100vw !important;
    max-width: 100vw !important;
  }

  /* Sticky checkout bar on mobile */
  div[class*="w-screen max-w-md"] .border-t.border-slate-100 {
    padding: 1rem !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
  }
}

/* ==========================================================================
   10. PRINT MEDIA & CERTIFICATE / VOUCHER STYLES
   ========================================================================== */
@media print {

  /* Hide UI navigation, buttons, and footers when printing */
  header,
  footer,
  aside,
  button,
  .no-print,
  div[class*="fixed inset-0 bg-slate-900"] {
    display: none !important;
  }

  body,
  html,
  #root,
  main {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    max-width: 100% !important;
  }

  /* Print certificate & fee voucher card */
  div[class*="print:m-0"],
  div[class*="max-w-3xl"],
  div[class*="max-w-xl"] {
    box-shadow: none !important;
    border: 1px solid #cbd5e1 !important;
    width: 100% !important;
    max-width: 100% !important;
    page-break-inside: avoid !important;
  }
}

/* ==========================================================================
   11. ACADEMY SUBPANELS: FULL-WIDTH LISTS & MODAL RECORD FORMS
   ========================================================================== */

/* Split Grid Layout: Expand list to 100% full width */
.grid.grid-cols-1.lg\:grid-cols-12.gap-6.items-start>.lg\:col-span-8,
.grid.grid-cols-1.lg\:grid-cols-12>.lg\:col-span-8,
.wg-enhanced-grid>.wg-subpanel-list,
.grid.grid-cols-1.lg\:grid-cols-12>.lg\:col-span-8.wg-subpanel-list,
.grid.grid-cols-1.lg\:grid-cols-12:has(> .wg-subpanel-form)>div:nth-child(2),
.grid.grid-cols-1.lg\:grid-cols-12>div.wg-subpanel-list,
.wg-subpanel-list {
  grid-column: span 12 / span 12 !important;
  width: 100% !important;
  max-width: 100% !important;
  flex: 1 1 100% !important;
}

/* Hide form panel by default from inline layout (until modal opens) */
.grid.grid-cols-1.lg\:grid-cols-12.gap-6.items-start>.lg\:col-span-4:not(.wg-modal-active),
.grid.grid-cols-1.lg\:grid-cols-12>.lg\:col-span-4:not(.wg-modal-active),
.wg-subpanel-form:not(.wg-modal-active) {
  display: none !important;
}

/* Hide redundant "Search all records" inside the form / popup modal */
.lg\:col-span-4>div:has(input[placeholder*="Name, ID, father name or mobile"]),
.wg-subpanel-form>div:has(input[placeholder*="Name, ID, father name or mobile"]),
.wg-modal-active>div:has(input[placeholder*="Name, ID, father name or mobile"]) {
  display: none !important;
}

/* Hide standalone duplicate search bar right before the table */
.lg\:col-span-8>div:has(> input[placeholder*="Name, ID, father name or mobile"]),
.wg-subpanel-list>div:has(> input[placeholder*="Name, ID, father name or mobile"]),
.wg-subpanel-list div.w-full:has(> input[placeholder*="Name, ID, father name or mobile"]):not(.p-3 div) {
  display: none !important;
}

/* Prevent body scroll when modal is open */
body.wg-modal-open {
  overflow: hidden !important;
}

/* Modal Backdrop */
.wg-record-modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-in-out;
}

.wg-record-modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* Form as centered popup modal */
.wg-subpanel-form.wg-modal-active,
.lg\:col-span-4.wg-modal-active {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: min(640px, 94vw) !important;
  max-height: 88vh !important;
  overflow-y: auto !important;
  z-index: 99999 !important;
  display: block !important;
  background-color: #ffffff !important;
  border-radius: 1.25rem !important;
  border: 1px solid #cbd5e1 !important;
  box-shadow: 0 25px 65px -12px rgba(15, 23, 42, 0.35), 0 0 0 1px rgba(15, 23, 42, 0.05) !important;
  animation: wgModalScaleIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) !important;
  padding: 1.5rem !important;
}

@keyframes wgModalScaleIn {
  from {
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Modal header close button */
.wg-modal-close-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-left: auto;
}

.wg-modal-close-btn:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #ef4444;
}

/* ==========================================================================
   12. BULK IMPORT & EXPORT TOOLBAR AND MODAL CONTROLS
   ========================================================================== */
.wg-import-export-group {
  display: inline-flex !important;
  align-items: center;
  gap: 0.375rem;
}

.wg-import-btn,
.wg-export-btn {
  font-family: inherit;
  font-size: 0.75rem !important;
  line-height: 1rem !important;
  font-weight: 600 !important;
  cursor: pointer;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  transition: all 0.15s ease-in-out;
}

.wg-import-btn:hover {
  background-color: #f0f9ff !important;
  border-color: #7dd3fc !important;
  color: #0369a1 !important;
}

.wg-export-btn:hover {
  background-color: #f0fdf4 !important;
  border-color: #86efac !important;
  color: #15803d !important;
}

#wg-import-data-modal {
  animation: wgModalScaleIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

#wg-toast-notification {
  pointer-events: none;
}

/* ==========================================================================
   13. LIST VIEW vs GRID VIEW (CARDS) CONTROLS
   ========================================================================== */
.wg-view-switcher {
  display: inline-flex !important;
  align-items: center;
}

.wg-view-btn-list,
.wg-view-btn-grid {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  outline: none;
}

.wg-view-btn-list.active,
.wg-view-btn-grid.active {
  background-color: #ffffff !important;
  color: #0f172a !important;
  font-weight: 700 !important;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1) !important;
}

.wg-cards-grid-container {
  width: 100%;
}

.wg-record-card {
  position: relative;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.wg-record-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
}

/* Ensure toolbar wraps smoothly on mobile screens */
@media screen and (max-width: 768px) {
  .wg-enhanced-toolbar-group {
    flex-wrap: wrap;
    gap: 0.375rem;
  }
}

/* ==========================================================================
   14. REDESIGNED CLEAN TABLE HEADER & STREAMLINED TOOLBAR
   ========================================================================== */

/* 1. Hide the redundant full-width 3rd search input box below the toolbar */
.wg-subpanel-list input.w-full.px-3.py-2.border.border-slate-200.rounded-lg.text-xs.bg-slate-50\/50,
.wg-subpanel-list input[placeholder*="Name, ID, father name"]:not(.wg-primary-search-input) {
  display: none !important;
}

/* 2. Hide the duplicate second search input in the filter box ("Search name, code or scope") */
.wg-subpanel-list .p-3.bg-slate-50\/70 div:has(> input[placeholder*="Search name, code"]),
.wg-subpanel-list .p-3.bg-slate-50\/70 div.w-full.flex-1:has(input[placeholder*="code or scope"]) {
  display: none !important;
}

/* 3. Hide the clunky "Click a heading to sort this page" row */
.wg-subpanel-list div.flex.items-center.justify-between.text-xs.text-slate-400 {
  display: none !important;
}

/* 4. Streamlined Filter Bar (Single clean row) */
.wg-streamlined-filter-bar {
  background: #f8fafc !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 0.875rem !important;
  padding: 0.625rem 0.875rem !important;
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
  flex-wrap: wrap !important;
}

.wg-primary-search-input {
  min-height: 38px !important;
  font-size: 0.8125rem !important;
  background-color: #ffffff !important;
  border-color: #cbd5e1 !important;
  border-radius: 0.625rem !important;
  padding-left: 0.875rem !important;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03) !important;
  transition: all 0.15s ease-in-out !important;
}

.wg-primary-search-input:focus {
  border-color: #0284c7 !important;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15) !important;
}

/* Header toolbar buttons styling */
.wg-header-columns-btn {
  font-family: inherit;
  font-size: 0.75rem !important;
  line-height: 1rem !important;
  font-weight: 600 !important;
  cursor: pointer;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  transition: all 0.15s ease-in-out;
}

.wg-header-columns-btn:hover {
  background-color: #f8fafc !important;
  border-color: #94a3b8 !important;
  color: #0f172a !important;
}

/* Header layout responsive wrapping */
.wg-header-left-group {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.wg-header-left-group h2 {
  font-size: 0.9375rem !important;
  font-weight: 800 !important;
  color: #0f172a !important;
  letter-spacing: -0.015em !important;
}

/* ==========================================================================
   15. TUTOR LMS COURSE BUILDER & LEARNING PLAYER STYLES
   ========================================================================== */
.wg-subject-lms-btn,
.wg-card-lms-btn {
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 1px 2px 0 rgba(79, 70, 229, 0.2);
}

.wg-lms-section-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.wg-lms-section-card:hover {
  box-shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.08);
}

.wg-lms-item-card {
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.wg-lms-item-card:hover {
  transform: translateX(2px);
}

/* Drag over highlight */
.wg-lms-items-dropzone.drag-over {
  background-color: rgba(99, 102, 241, 0.08) !important;
  border: 2px dashed #6366f1 !important;
}

/* ==========================================================================
   16. UNIVERSAL MULTI-PURPOSE USER PORTAL ENHANCEMENTS
   ========================================================================== */
.wg-portal-container {
  animation: wgPortalFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes wgPortalFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.wg-portal-tab-content {
  animation: wgPortalFadeIn 0.2s ease-out forwards;
}

#wg-portal-toast {
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
}
