/* ==========================================================================
   BQ24 MOBILE NAVIGATION & LIVE QUIZ QR — STRICT REFERENCE IMPLEMENTATION
   Matches reference:
     1. Басты (Home, filled when active, with active dot underneath)
     2. Оқу (Open book)
     3. QR Button (Geometric center, elevated, circular, blue with glow & notch)
     4. Кесте (Calendar)
     5. Бағалар (Bar chart)
   ========================================================================== */

:root {
  --mnav-height: 68px;
  --mnav-bg: #FFFFFF;
  --mnav-text: #64748B;
  --mnav-text-active: #2563EB;
  --mnav-border: rgba(226, 232, 240, 0.85);
  --mnav-qr-bg: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
  --mnav-qr-shadow: 0 10px 25px -2px rgba(37, 99, 235, 0.48), 0 4px 12px rgba(37, 99, 235, 0.25);
  --mnav-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
  --mnav-bg: #111C2E;
  --mnav-text: #94A3B8;
  --mnav-text-active: #60A5FA;
  --mnav-border: #1E2D42;
  --mnav-qr-bg: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
  --mnav-qr-shadow: 0 10px 25px -2px rgba(37, 99, 235, 0.5), 0 4px 12px rgba(37, 99, 235, 0.3);
  --mnav-shadow: 0 -4px 25px rgba(0, 0, 0, 0.35);
}

/* Hide on Desktop (>= 901px) */
@media (min-width: 901px) {
  #mobileNav.bq24-mobile-nav {
    display: none !important;
  }
  .lq-scanner-modal-backdrop {
    display: none !important;
  }
}

/* Strict View Isolation: Hide when not in student dashboard or explicitly hidden */
body:not([data-view="student-dashboard"]) #mobileNav.bq24-mobile-nav,
body[data-view="teacher"] #mobileNav.bq24-mobile-nav,
body[data-view="auth"] #mobileNav.bq24-mobile-nav,
body[data-view="quiz"] #mobileNav.bq24-mobile-nav,
body[data-view="maintenance"] #mobileNav.bq24-mobile-nav,
body[data-view="result"] #mobileNav.bq24-mobile-nav,
#mobileNav.bq24-mobile-nav[style*="display: none"] {
  display: none !important;
}

/* Mobile Display (< 901px) */
@media (max-width: 900px) {
  /* Prevent content overlap on student dashboard */
  body[data-view="student-dashboard"] {
    padding-bottom: calc(var(--mnav-height) + 18px + env(safe-area-inset-bottom, 0px));
  }

  /* Fixed Bottom Dock */
  #mobileNav.bq24-mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mnav-height);
    background: var(--mnav-bg);
    border-top: 1px solid var(--mnav-border);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    box-shadow: var(--mnav-shadow);
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 1000;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
  }

  /* Smooth Notch Background behind Central QR Button */
  .mobile-nav-bar-bg {
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    width: 108px;
    height: 26px;
    pointer-events: none;
    z-index: 1;
  }

  .mobile-nav-curve-svg {
    width: 100%;
    height: 100%;
    display: block;
  }

  .mobile-nav-curve-svg path {
    fill: var(--mnav-bg);
  }

  /* Navigation Items (4 items: 2 on left, 2 on right) */
  .bq24-mobile-nav .mobile-nav-item {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    padding: 6px 0 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    text-decoration: none;
    color: var(--mnav-text);
    transition: color 0.15s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }

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

  .bq24-mobile-nav .mobile-nav-icon-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin-bottom: 2px;
  }

  .bq24-mobile-nav .mobile-nav-item i,
  .bq24-mobile-nav .mobile-nav-item svg {
    width: 22px;
    height: 22px;
    stroke-width: 2.2;
    stroke: currentColor;
    transition: stroke 0.15s ease;
  }

  .bq24-mobile-nav .mobile-nav-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1;
    color: inherit;
    transition: color 0.15s ease;
  }

  /* Active Indicator Dot under text */
  .bq24-mobile-nav .nav-active-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--mnav-text-active);
    margin-top: 3px;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Active State (Matches reference image) */
  .bq24-mobile-nav .mobile-nav-item.active {
    color: var(--mnav-text-active) !important;
  }

  .bq24-mobile-nav .mobile-nav-item.active .nav-active-dot {
    opacity: 1;
    transform: scale(1);
  }

  /* Active Home Icon solid fill */
  .bq24-mobile-nav .mobile-nav-item.active[id="mobileNavOverview"] i,
  .bq24-mobile-nav .mobile-nav-item.active[id="mobileNavOverview"] svg {
    fill: var(--mnav-text-active);
  }

  /* Central QR Button Cradle */
  .mobile-nav-qr-cradle {
    position: relative;
    z-index: 5;
    flex: 0 0 76px;
    width: 76px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Elevated Circular QR Button (Strict Reference) */
  .mobile-nav-qr-btn {
    position: absolute;
    top: -24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--mnav-qr-bg);
    border: 4.5px solid var(--mnav-bg);
    box-shadow: var(--mnav-qr-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s ease;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    box-sizing: border-box;
  }

  .mobile-nav-qr-btn:active {
    transform: scale(0.9);
    box-shadow: 0 6px 16px -2px rgba(37, 99, 235, 0.4);
  }

  .mobile-nav-qr-btn .qr-btn-svg {
    width: 28px;
    height: 28px;
    display: block;
  }
}

/* Ultra-compact screen adjustments (<= 360px) */
@media (max-width: 360px) {
  :root {
    --mnav-height: 64px;
  }
  .mobile-nav-qr-cradle {
    flex: 0 0 66px;
    width: 66px;
  }
  .mobile-nav-qr-btn {
    width: 54px;
    height: 54px;
    top: -20px;
    border-width: 3.5px;
  }
  .mobile-nav-qr-btn .qr-btn-svg {
    width: 25px;
    height: 25px;
  }
  .bq24-mobile-nav .mobile-nav-label {
    font-size: 10px;
  }
  .bq24-mobile-nav .mobile-nav-icon-wrap {
    width: 22px;
    height: 22px;
  }
  .bq24-mobile-nav .mobile-nav-item i,
  .bq24-mobile-nav .mobile-nav-item svg {
    width: 19px;
    height: 19px;
  }
}

/* ==========================================
   LIVE QUIZ QR SCANNER MODAL
   ========================================== */
.lq-scanner-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 18, 32, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  animation: lqScannerFadeIn 0.2s ease;
}

.lq-scanner-modal-backdrop.hidden {
  display: none !important;
}

@keyframes lqScannerFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lq-scanner-modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--mnav-bg, #FFFFFF);
  border-radius: 24px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--mnav-border, #E2E8F0);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: lqScannerPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes lqScannerPop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.lq-scanner-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--mnav-border, #E2E8F0);
}

.lq-scanner-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lq-scanner-header-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(37, 99, 235, 0.12);
  color: #2563EB;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lq-scanner-header-icon svg {
  width: 20px;
  height: 20px;
}

.lq-scanner-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--ink, #0F172A);
}

[data-theme="dark"] .lq-scanner-title {
  color: #F8FAFC;
}

.lq-scanner-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted, #64748B);
}

.lq-scanner-close-btn {
  background: transparent;
  border: none;
  color: var(--muted, #64748B);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.lq-scanner-close-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* Viewfinder Viewport */
.lq-scanner-viewport {
  position: relative;
  width: 100%;
  height: 250px;
  background: #0B1220;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lqScannerVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  background: #0B1220;
}

/* Strictly hide native video controls and Play button overlays */
#lqScannerVideo::-webkit-media-controls,
#lqScannerVideo::-webkit-media-controls-enclosure,
#lqScannerVideo::-webkit-media-controls-panel,
#lqScannerVideo::-webkit-media-controls-overlay-play-button,
#lqScannerVideo::-webkit-media-controls-start-playback-button {
  display: none !important;
  -webkit-appearance: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Camera Stream Loading State */
.lq-scanner-loading {
  position: absolute;
  inset: 0;
  background: #0B1220;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #94A3B8;
  font-size: 13px;
  font-weight: 600;
  z-index: 10;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.lq-scanner-loading.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.lq-scanner-loading-text {
  letter-spacing: -0.01em;
}

/* Reticle & Scanning Animation */
.lq-scanner-reticle {
  position: absolute;
  width: 180px;
  height: 180px;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.2s ease;
}

.lq-scanner-reticle.hidden {
  display: none !important;
}

.reticle-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: #3B82F6;
  border-style: solid;
}
.reticle-corner.tl { top: 0; left: 0; border-width: 3.5px 0 0 3.5px; border-top-left-radius: 8px; }
.reticle-corner.tr { top: 0; right: 0; border-width: 3.5px 3.5px 0 0; border-top-right-radius: 8px; }
.reticle-corner.bl { bottom: 0; left: 0; border-width: 0 0 3.5px 3.5px; border-bottom-left-radius: 8px; }
.reticle-corner.br { bottom: 0; right: 0; border-width: 0 3.5px 3.5px 0; border-bottom-right-radius: 8px; }

.reticle-laser {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 2.5px;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.1), #60A5FA, rgba(59, 130, 246, 0.1));
  box-shadow: 0 0 12px #3B82F6;
  animation: lqLaserSweep 2s ease-in-out infinite alternate;
}

@keyframes lqLaserSweep {
  0% { top: 6px; opacity: 0.6; }
  100% { top: calc(100% - 8px); opacity: 1; }
}

.lq-scanner-tip {
  position: absolute;
  bottom: 12px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  padding: 6px 14px;
  border-radius: 999px;
  color: #FFFFFF;
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 6;
  transition: opacity 0.2s ease;
}

.lq-scanner-tip.hidden {
  display: none !important;
}
.lq-scanner-tip svg { width: 14px; height: 14px; }

/* Notice Banner */
.lq-scanner-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(245, 158, 11, 0.1);
  border-bottom: 1px solid rgba(245, 158, 11, 0.25);
  color: #D97706;
  font-size: 12.5px;
  line-height: 1.4;
}
.lq-scanner-notice.hidden { display: none !important; }
.lq-scanner-notice-icon { flex: 0 0 18px; width: 18px; height: 18px; margin-top: 2px; }

/* Status Box */
.lq-scanner-status-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  background: rgba(37, 99, 235, 0.1);
  color: #2563EB;
  font-size: 13px;
  font-weight: 700;
}
.lq-scanner-status-box.hidden { display: none !important; }

.lq-scanner-spinner {
  width: 16px;
  height: 16px;
  border: 2.5px solid rgba(37, 99, 235, 0.3);
  border-top-color: #2563EB;
  border-radius: 50%;
  animation: lqSpin 0.7s linear infinite;
}
@keyframes lqSpin { to { transform: rotate(360deg); } }

/* Manual Code Form */
.lq-manual-code-section {
  padding: 16px 20px 20px;
  background: var(--mnav-bg, #FFFFFF);
}

.lq-manual-code-header {
  margin-bottom: 10px;
}
.lq-manual-divider-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted, #64748B);
}
.lq-manual-code-form {
  display: flex;
  gap: 10px;
}
.lq-manual-input-wrap {
  position: relative;
  flex: 1;
}
.lq-manual-input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted, #64748B);
  pointer-events: none;
}
.lq-manual-input {
  width: 100%;
  height: 44px;
  padding: 0 12px 0 36px;
  border-radius: 12px;
  border: 1.5px solid var(--mnav-border, #E2E8F0);
  background: var(--mnav-bg, #FFFFFF);
  color: var(--ink, #0F172A);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
[data-theme="dark"] .lq-manual-input {
  color: #F8FAFC;
}
.lq-manual-input:focus {
  border-color: #2563EB;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.lq-manual-submit-btn {
  height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  background: #2563EB;
  color: #FFFFFF;
  border: none;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.lq-manual-submit-btn:hover {
  background: #1D4ED8;
}
.lq-manual-submit-btn svg {
  width: 16px;
  height: 16px;
}
.lq-manual-error {
  margin-top: 8px;
  font-size: 12px;
  color: #EF4444;
  font-weight: 600;
}
.lq-manual-error.hidden { display: none !important; }
