/* ==========================================================
   MOBILE RESPONSIVENESS OVERHAUL — Bijoy Academy
   Fixes all 7 critical mobile issues identified by audit.
   Load AFTER main.css and design-system-2026.css
   ========================================================== */

/* ==================================================
   1. HAMBURGER BUTTON (Hidden on desktop, shown <768px)
   ================================================== */
.mobile-menu-btn {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  gap: 5px;
  z-index: 1001;
  -webkit-tap-highlight-color: transparent;
}

.burger-line {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-heading, #fff);
  border-radius: 2px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.2s ease;
  transform-origin: center;
}

.mobile-menu-btn.is-active .burger-line-1 {
  transform: translateY(7px) rotate(45deg);
}
.mobile-menu-btn.is-active .burger-line-2 {
  opacity: 0;
  transform: scaleX(0);
}
.mobile-menu-btn.is-active .burger-line-3 {
  transform: translateY(-7px) rotate(-45deg);
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex;
  }
}

/* ==================================================
   2. MOBILE SLIDE-OUT DRAWER
   ================================================== */
.mobile-drawer {
  display: none;
}

@media (max-width: 768px) {
  .mobile-drawer {
    display: block;
    position: fixed;
    top: 0;
    right: -100%;
    width: 85%;
    max-width: 360px;
    height: 100vh;
    height: 100dvh;
    background: var(--surface-primary, #111);
    border-left: 1px solid var(--border-subtle, rgba(255,255,255,0.1));
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
    padding-top: 80px;
  }

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

  .mobile-drawer-inner {
    padding: 8px 20px 40px 20px;
  }

  .mobile-drawer-section {
    margin-bottom: 28px;
  }

  .mobile-drawer-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent-primary, #F97316);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.08));
  }

  .mobile-drawer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 12px;
    color: var(--text-body, #ccc);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 10px;
    transition: background 0.2s ease, color 0.2s ease;
    min-height: 48px;
  }

  .mobile-drawer-link:hover,
  .mobile-drawer-link:active {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-heading, #fff);
  }

  .mobile-drawer-link--hot {
    color: var(--accent-primary, #F97316);
    font-weight: 600;
  }

  .mobile-drawer.is-open::before {
    content: '';
    position: fixed;
    top: 0;
    left: -100vw;
    width: 200vw;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
}

/* ==================================================
   3. FORCE INLINE GRID OVERRIDES ON MOBILE
   ================================================== */
@media (max-width: 768px) {
  .form-grid,
  .bento-grid,
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ==================================================
   4. INVOICE A4 PREVIEW SCALING ON MOBILE
   ================================================== */
@media (max-width: 820px) {
  .a4-frame {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .pdf {
    transform: scale(0.48) !important;
    transform-origin: top left !important;
    width: 794px !important;
    margin-bottom: -400px !important;
  }
}

@media (max-width: 480px) {
  .pdf {
    transform: scale(0.38) !important;
    margin-bottom: -500px !important;
  }
}

/* ==================================================
   5. INVOICE REMOVE-ITEM BUTTON SIZE FIX
   ================================================== */
@media (max-width: 768px) {
  .items-table .remove-row-btn,
  .items-table button[title*="Remove"],
  .items-table button[title*="Delete"],
  button.remove-row-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    font-size: 18px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

/* ==================================================
   6. MINIMUM FONT SIZE ENFORCEMENT
   ================================================== */
@media (max-width: 480px) {
  .feature-pill {
    font-size: 0.8rem !important;
    padding: 4px 10px !important;
  }

  [style*="font-size:0.75rem"],
  [style*="font-size: 0.75rem"] {
    font-size: 0.875rem !important;
  }
}

/* ==================================================
   7. CURRENCY CONVERTER SELECT FIX
   ================================================== */
@media (max-width: 480px) {
  #from-curr,
  #to-curr,
  select[style*="width: 160px"],
  select[style*="width:160px"] {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ==================================================
   8. SMOOTH SCROLLING + REDUCED MOTION
   ================================================== */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .mobile-drawer {
    transition: none !important;
  }
}

/* ==================================================
   9. SAFE AREA INSETS (iPhone notch / home indicator)
   ================================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-drawer-inner {
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
  }
  .footer {
    padding-bottom: calc(2rem + env(safe-area-inset-bottom)) !important;
  }
}

/* ==================================================
   10. GLOBAL TOUCH IMPROVEMENTS
   ================================================== */
@media (max-width: 768px) {
  a, button, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
  }

  button:not(.burger-line),
  .btn-primary-2026,
  .btn-secondary-2026,
  .calculate-btn,
  .btn-primary,
  .faq-button,
  .filter-tab-btn {
    min-height: 48px !important;
  }

  html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
  }

  img, iframe, video, canvas, svg {
    max-width: 100% !important;
    height: auto;
  }
}

/* ==================================================
   11. INVOICE MOBILE EDITOR/PREVIEW STACK
   ================================================== */
@media (max-width: 1200px) {
  .editor-col,
  .preview-col {
    grid-column: span 1 !important;
  }
}

@media (max-width: 768px) {
  .invoice-actions,
  [class*="invoice-btn-row"],
  [class*="action-row"] {
    flex-direction: column !important;
    gap: 8px !important;
  }

  .invoice-actions button,
  .invoice-actions a {
    width: 100% !important;
    justify-content: center !important;
  }
}

/* ==================================================
   12. IMPROVED MOBILE CARD SPACING
   ================================================== */
@media (max-width: 480px) {
  .result-card,
  .metric-card {
    padding: 1rem 0.85rem !important;
    border-radius: 14px !important;
  }

  .results-grid {
    gap: 0.75rem !important;
  }

  .chart-container,
  [id*="chart"] {
    max-width: 100% !important;
    overflow: hidden !important;
  }
}

/* ==================================================
   13. CUSTOM SCROLLBAR ON MOBILE DRAWER
   ================================================== */
@media (max-width: 768px) {
  .mobile-drawer::-webkit-scrollbar {
    width: 4px;
  }
  .mobile-drawer::-webkit-scrollbar-track {
    background: transparent;
  }
  .mobile-drawer::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
  }
}
