/* ============================================
   مقياس جاهزية الحجاج - Mobile Stylesheet
   Professional Mobile-First Responsive Design
   ============================================ */

/* ============ SAFE AREA + BASE ============ */
: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);
  --nav-h: 64px;
  --bottom-nav-h: 64px;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Prevent horizontal overflow */
*, *::before, *::after {
  max-width: 100%;
}

img, canvas, svg {
  max-width: 100%;
  height: auto;
}

/* ============ MOBILE DRAWER OVERLAY ============ */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  z-index: 990;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.drawer-overlay.active {
  display: block;
  opacity: 1;
}

/* ============ MOBILE NAV DRAWER ============ */
.mobile-drawer {
  position: fixed;
  top: 0;
  right: -320px;
  width: 300px;
  height: 100%;
  background: white;
  z-index: 1001;
  transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  box-shadow: -8px 0 40px rgba(0,0,0,0.15);
  padding-bottom: calc(var(--safe-bottom) + 24px);
}

.mobile-drawer.open {
  right: 0;
}

.drawer-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  padding: 48px 20px 24px;
  position: relative;
}

.drawer-close {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.drawer-close:hover { background: rgba(255,255,255,0.25); }

.drawer-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.drawer-logo-icon {
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 1px solid rgba(255,255,255,0.2);
}

.drawer-logo-title {
  font-size: 15px;
  font-weight: 800;
  color: white;
  line-height: 1.2;
}

.drawer-logo-sub {
  font-size: 11px;
  color: var(--gold-light);
}

.drawer-user {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  padding: 12px 14px;
}

.drawer-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
}

.drawer-nav {
  padding: 16px 12px;
  list-style: none;
}

.drawer-nav-section {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 12px 8px 6px;
}

.drawer-nav a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 14px;
  border-radius: 12px;
  color: var(--text-dark);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: var(--transition);
  margin-bottom: 2px;
}

.drawer-nav a:hover,
.drawer-nav a.active {
  background: rgba(26,92,56,0.08);
  color: var(--primary);
}

.drawer-nav a .nav-icon { font-size: 20px; }

.drawer-cta {
  padding: 0 12px 16px;
}

/* ============ BOTTOM NAVIGATION (Dashboard/Admin) ============ */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  z-index: 500;
  background: white;
  border-top: 1px solid var(--cream-border);
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
}

.bottom-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: var(--bottom-nav-h);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  padding: 8px 4px;
  text-decoration: none;
  color: var(--text-light);
  font-size: 10px;
  font-weight: 600;
  transition: var(--transition);
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: 'Tajawal', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-item .bn-icon {
  font-size: 22px;
  transition: transform 0.2s;
}

.bottom-nav-item.active .bn-icon {
  transform: scale(1.15);
}

.bottom-nav-item .bn-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--primary);
  margin-top: 1px;
  opacity: 0;
  transition: opacity 0.2s;
}

.bottom-nav-item.active .bn-dot {
  opacity: 1;
}

/* ============ MOBILE QUIZ NAV ============ */
.quiz-bottom-bar {
  display: none;
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  z-index: 200;
  background: white;
  border-top: 1px solid var(--cream-border);
  padding: 12px 16px calc(12px + var(--safe-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
}

.quiz-bottom-bar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 600px;
  margin: 0 auto;
}

/* ============ TABLET (768px - 1023px) ============ */
@media (max-width: 1023px) {
  .features-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .axes-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .steps-container { grid-template-columns: repeat(2, 1fr) !important; gap: 32px !important; }
  .steps-container::before { display: none !important; }
  .footer-grid { grid-template-columns: 1fr 1fr !important; gap: 32px !important; }
  .stats-row { grid-template-columns: repeat(2, 1fr) !important; }

  .sidebar, .admin-sidebar { display: none !important; }
  .dashboard-main { margin-right: 0 !important; }
  .admin-main { margin-right: 0 !important; }

  .auth-page { grid-template-columns: 1fr !important; }
  .auth-visual { display: none !important; }
}

/* ============ MOBILE (max 767px) ============ */
@media (max-width: 767px) {

  /* ---- NAVBAR ---- */
  .navbar { height: auto; }
  .navbar-inner {
    padding: 0 16px;
    height: 60px;
  }
  .nav-links, .nav-cta { display: none !important; }
  .hamburger { display: flex !important; }

  .logo-title { font-size: 13px !important; }
  .logo-sub { font-size: 10px !important; }
  .logo-icon { width: 38px !important; height: 38px !important; font-size: 18px !important; }

  /* ---- SECTION BASE ---- */
  .section { padding: 48px 16px !important; }
  .container { padding: 0 !important; }

  /* ---- SECTION HEADERS ---- */
  .section-title { font-size: clamp(22px, 6vw, 32px) !important; }
  .section-subtitle { font-size: 15px !important; }
  .section-badge { font-size: 12px !important; }

  /* ---- HERO ---- */
  .hero { min-height: auto !important; padding-top: 60px !important; }
  .hero-inner {
    grid-template-columns: 1fr !important;
    padding: 40px 16px 48px !important;
    gap: 32px !important;
  }
  .hero-visual { display: none !important; }
  .hero-title { font-size: clamp(26px, 7vw, 38px) !important; }
  .hero-desc { font-size: 15px !important; max-width: 100% !important; }
  .hero-actions { flex-direction: column !important; gap: 12px !important; }
  .hero-actions .btn { width: 100% !important; justify-content: center !important; }
  .hero-stats { gap: 20px !important; flex-wrap: wrap !important; }
  .stat-number { font-size: 24px !important; }
  .stat-label { font-size: 11px !important; }
  .hero-badge { font-size: 12px !important; padding: 6px 14px !important; }

  /* ---- GRIDS ---- */
  .features-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
  .axes-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
  .steps-container { grid-template-columns: 1fr !important; gap: 24px !important; }
  .grid-2 { grid-template-columns: 1fr !important; gap: 14px !important; }
  .grid-3 { grid-template-columns: 1fr !important; gap: 14px !important; }
  .stats-row { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .axes-breakdown { grid-template-columns: 1fr !important; }

  /* ---- CARDS ---- */
  .card { padding: 20px 16px !important; }
  .feature-card { padding: 24px 18px !important; }
  .axis-card { padding: 22px 18px !important; }
  .axis-result-card { padding: 18px !important; }
  .rec-card { flex-direction: row !important; padding: 16px !important; gap: 12px !important; }

  /* ---- STAT CARDS ---- */
  .stat-card { padding: 16px 14px !important; }
  .stat-card-value { font-size: 26px !important; }
  .stat-card-icon { width: 40px !important; height: 40px !important; font-size: 18px !important; margin-bottom: 10px !important; }

  /* ---- BUTTONS ---- */
  .btn { padding: 13px 24px !important; font-size: 15px !important; }
  .btn-lg { padding: 15px 28px !important; font-size: 16px !important; }
  .btn-sm { padding: 9px 18px !important; font-size: 13px !important; }

  /* ---- STEPS ---- */
  .step-num { width: 64px !important; height: 64px !important; font-size: 22px !important; }
  .step-title { font-size: 15px !important; }
  .step-desc { font-size: 13px !important; }

  /* ---- FOOTER ---- */
  .footer { padding: 40px 16px 24px !important; }
  .footer-grid { grid-template-columns: 1fr !important; gap: 24px !important; }
  .footer-bottom { flex-direction: column !important; gap: 8px !important; text-align: center !important; }

  /* ---- LEVEL GRID ---- */
  #levels-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }

  /* ---- QUIZ ---- */
  .quiz-layout { padding-top: 60px !important; }
  .quiz-header { padding: 16px 16px 16px !important; }
  .quiz-layout-grid { grid-template-columns: 1fr !important; padding: 16px !important; gap: 0 !important; }
  #quiz-sidebar { display: none !important; }
  .question-card { padding: 20px 16px !important; }
  .question-text { font-size: 15px !important; }
  .option-btn { padding: 12px 14px !important; font-size: 14px !important; }
  .quiz-nav { display: none !important; }
  .quiz-bottom-bar { display: block !important; }
  #quiz-category-header { margin-bottom: 16px !important; }

  /* ---- RESULTS ---- */
  .results-hero { padding: 80px 16px 32px !important; }
  .results-body { padding: 24px 16px !important; }
  .score-ring-container { width: 160px !important; height: 160px !important; }
  .score-ring-num { font-size: 40px !important; }
  canvas#radar-chart { width: 100% !important; height: auto !important; }

  /* ---- DASHBOARD ---- */
  .dashboard-layout { display: block !important; padding-top: 60px !important; }
  .sidebar { display: none !important; }
  .dashboard-main {
    margin-right: 0 !important;
    padding: 16px !important;
    padding-bottom: calc(80px + var(--safe-bottom)) !important;
  }
  .dash-title { font-size: 22px !important; }

  /* ---- ADMIN ---- */
  .admin-layout { display: block !important; padding-top: 60px !important; }
  .admin-sidebar { display: none !important; }
  .admin-main {
    margin-right: 0 !important;
    padding: 16px !important;
    padding-bottom: calc(80px + var(--safe-bottom)) !important;
  }
  .admin-topbar { padding: 12px 16px !important; margin-bottom: 16px !important; }
  .admin-topbar h1 { font-size: 16px !important; }

  /* ---- AUTH ---- */
  .auth-page { display: block !important; padding-top: 60px !important; min-height: auto !important; }
  .auth-visual { display: none !important; }
  .auth-form-side { padding: 32px 20px !important; min-height: calc(100vh - 60px) !important; }
  .auth-form-container { max-width: 100% !important; }

  /* ---- CONTENT ---- */
  .content-grid { grid-template-columns: 1fr !important; gap: 14px !important; }

  /* ---- PANEL ---- */
  .panel-header { padding: 14px 16px !important; }
  .panel-body { padding: 16px !important; }
  .panel-title { font-size: 14px !important; }

  /* ---- TABLE ---- */
  .data-table { display: block !important; overflow-x: auto !important; white-space: nowrap !important; }
  .data-table thead, .data-table tbody, .data-table tr, .data-table th, .data-table td { display: revert !important; }
  .data-table th, .data-table td { padding: 10px 12px !important; font-size: 13px !important; }

  /* ---- QUIZ HEADER ---- */
  .quiz-header-inner h1 { font-size: 18px !important; }

  /* ---- BOTTOM NAV SHOW ---- */
  .bottom-nav { display: block !important; }

  /* ---- MISC ---- */
  .divider { margin: 16px 0 !important; }
  .mb-32 { margin-bottom: 20px !important; }
  .mb-48 { margin-bottom: 28px !important; }

  /* Hide desktop-only elements */
  .desktop-only { display: none !important; }

  /* ---- AXIS RESULT CARDS (results page) ---- */
  .axes-breakdown {
    grid-template-columns: 1fr !important;
  }

  /* ---- TESTIMONIALS ---- */
  #testimonials-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ============ SMALL MOBILE (max 380px) ============ */
@media (max-width: 380px) {
  .hero-title { font-size: 24px !important; }
  .section-title { font-size: 20px !important; }
  .stats-row { grid-template-columns: 1fr 1fr !important; }
  #levels-grid { grid-template-columns: 1fr !important; }
  .btn-lg { padding: 14px 20px !important; font-size: 15px !important; }
  .stat-card-value { font-size: 22px !important; }
}

/* ============ TOUCH TARGETS (44px min) ============ */
@media (pointer: coarse) {
  .btn { min-height: 48px; }
  .btn-sm { min-height: 40px; }
  .option-btn { min-height: 52px; }
  .nav-links a { min-height: 44px; }
  .form-input { min-height: 48px; }
  .drawer-nav a { min-height: 50px; }
  .bottom-nav-item { min-height: 56px; }
  .hamburger { min-width: 44px; min-height: 44px; }
  .checklist-item { min-height: 52px; }
}

/* ============ SCROLLABLE CONTENT ============ */
.scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scroll-x::-webkit-scrollbar { display: none; }

/* ============ MOBILE CARD STACK ============ */
.mobile-stack > * + * {
  margin-top: 12px;
}

/* ============ MOBILE DRAWER STYLES ============ */
body.drawer-open { overflow: hidden; }

/* ============ PULL-TO-REFRESH PREVENTION ============ */
body { overscroll-behavior-y: none; }

/* ============ SMOOTH MOMENTUM SCROLL ============ */
.panel-body,
.dashboard-main,
.admin-main {
  -webkit-overflow-scrolling: touch;
}

/* ============ QUIZ MOBILE CATEGORY TABS ============ */
.quiz-mobile-tabs {
  display: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 16px 12px;
  gap: 8px;
}

.quiz-mobile-tabs::-webkit-scrollbar { display: none; }

.quiz-mobile-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 50px;
  border: 1.5px solid var(--cream-border);
  background: white;
  font-family: 'Tajawal', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-medium);
  white-space: nowrap;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.quiz-mobile-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

@media (max-width: 767px) {
  .quiz-mobile-tabs { display: flex !important; }
}

/* ============ SWIPEABLE INDICATORS ============ */
.swipe-hint {
  display: none;
  text-align: center;
  font-size: 12px;
  color: var(--text-light);
  padding: 4px;
  gap: 4px;
  align-items: center;
  justify-content: center;
}

@media (max-width: 767px) {
  .swipe-hint { display: flex !important; }
}

/* ============ FIXED POSITIONING FIXES ============ */
@media (max-width: 767px) {
  .quiz-layout { padding-top: 60px !important; }
  .quiz-header { padding-top: 80px !important; }
}

/* ============ MOBILE FORM IMPROVEMENTS ============ */
@media (max-width: 767px) {
  input, select, textarea {
    font-size: 16px !important; /* Prevents iOS zoom */
  }

  .form-input { font-size: 16px !important; }
  .search-input { font-size: 16px !important; }

  /* Register form 2-col -> 1-col */
  .auth-form-container [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ============ ADMIN MOBILE ============ */
@media (max-width: 767px) {
  .stats-row.admin-stats {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Admin section tabs become horizontal scroll */
  .admin-section-tabs {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding-bottom: 8px;
    margin-bottom: 16px;
  }
  .admin-section-tabs::-webkit-scrollbar { display: none; }

  .admin-tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Axes grid in admin */
  #section-questions .panel { margin-bottom: 12px !important; }
}

/* ============ CONTENT PAGE MOBILE ============ */
@media (max-width: 767px) {
  #featured-grid {
    grid-template-columns: 1fr !important;
  }

  #content-cards {
    grid-template-columns: 1fr !important;
  }

  .filter-btn { font-size: 12px !important; padding: 7px 14px !important; }

  .tip-card .content-card-img { height: 120px !important; font-size: 48px !important; }
}

/* ============ RESULTS PAGE MOBILE ============ */
@media (max-width: 767px) {
  .results-hero > div > div:last-child {
    flex-direction: column !important;
    gap: 16px !important;
  }

  #axes-breakdown {
    grid-template-columns: 1fr !important;
  }
}

/* ============ HERO RESPONSIVE FIX ============ */
@media (max-width: 767px) {
  .hero-stats { padding-top: 24px !important; margin-top: 32px !important; }
  .hero-glow { display: none; }
}

/* ============ ANIMATION PERFORMANCE ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ LANDSCAPE MOBILE ============ */
@media (max-width: 767px) and (orientation: landscape) {
  .hero { min-height: auto !important; }
  .hero-inner { padding: 32px 16px !important; }
  .results-hero { padding: 80px 16px 24px !important; }
}
