/**
 * ExamFlo Responsive Styles
 * Mobile-first approach with progressive enhancement
 */

/* ========================================
   BASE & MOBILE-FIRST (360px - 767px)
   ======================================== */

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
}

/* Prevent horizontal overflow on all pages */
body, html {
  max-width: 100vw;
  overflow-x: hidden;
}

/* Container responsive widths */
.container {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: 0.75rem; /* 12px on mobile */
  padding-right: 0.75rem;
  max-width: 100%;
}

@media (min-width: 640px) {
  .container {
    padding-left: 1rem; /* 16px */
    padding-right: 1rem;
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 768px;
    padding-left: 1.5rem; /* 24px */
    padding-right: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 1024px;
  }
}

@media (min-width: 1280px) {
  .container {
    max-width: 1280px;
  }
}

/* Prevent horizontal scroll */
.no-scroll-x {
  overflow-x: hidden;
  max-width: 100vw;
}

/* ========================================
   RESPONSIVE IMAGES & MEDIA
   ======================================== */

img, video, iframe {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ========================================
   MOBILE NAVIGATION
   ======================================== */

.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-menu-overlay.active {
  opacity: 1;
  visibility: visible;
}

.mobile-menu {
  position: fixed;
  top: 0;
  right: -100%;
  width: 80%;
  max-width: 320px;
  height: 100vh;
  background: white;
  z-index: 999;
  transition: right 0.3s ease;
  overflow-y: auto;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
}

.mobile-menu.active {
  right: 0;
}

/* Hamburger menu - now styled inline in Header.js with circular blue design */

/* ========================================
   DARK MODE SUPPORT
   ======================================== */

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
}

[data-theme="dark"] {
  --bg-primary: #1f2937;
  --bg-secondary: #111827;
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --border-color: #374151;
}

[data-theme="dark"] body {
  background: var(--bg-primary);
  color: var(--text-primary);
}

[data-theme="dark"] .bg-white {
  background: #1f2937 !important;
}

[data-theme="dark"] .text-gray-900 {
  color: #f9fafb !important;
}

[data-theme="dark"] .border-gray-200 {
  border-color: #374151 !important;
}

/* ========================================
   TABLET (768px - 1023px)
   ======================================== */

@media (min-width: 768px) {
  .container {
    max-width: 720px;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  .mobile-menu,
  .mobile-menu-overlay {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}

/* ========================================
   LAPTOP (1024px - 1279px)
   ======================================== */

@media (min-width: 1024px) {
  .container {
    max-width: 960px;
  }

  html {
    font-size: 16px;
  }
}

/* ========================================
   DESKTOP (1280px+)
   ======================================== */

@media (min-width: 1280px) {
  .container {
    max-width: 1200px;
  }
}

@media (min-width: 1536px) {
  .container {
    max-width: 1400px;
  }
}

/* ========================================
   RESPONSIVE UTILITIES
   ======================================== */

/* Hide on mobile */
@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }
}

/* Hide on tablet */
@media (min-width: 768px) and (max-width: 1023px) {
  .hide-tablet {
    display: none !important;
  }
}

/* Hide on desktop */
@media (min-width: 1024px) {
  .hide-desktop {
    display: none !important;
  }
}

/* Show only on mobile */
.show-mobile {
  display: block;
}

@media (min-width: 768px) {
  .show-mobile {
    display: none !important;
  }
}

/* ========================================
   RESPONSIVE GRID ADJUSTMENTS
   ======================================== */

.responsive-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 640px) {
  .responsive-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .responsive-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }
}

@media (min-width: 1280px) {
  .responsive-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ========================================
   CHART RESPONSIVENESS
   ======================================== */

.chart-container {
  position: relative;
  width: 100%;
  height: 250px;
}

@media (min-width: 768px) {
  .chart-container {
    height: 300px;
  }
}

@media (min-width: 1024px) {
  .chart-container {
    height: 350px;
  }
}

canvas {
  max-width: 100%;
  height: auto !important;
}

/* ========================================
   RESPONSIVE TYPOGRAPHY
   ======================================== */

h1 {
  font-size: 2rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.5rem;
  line-height: 1.3;
}

h3 {
  font-size: 1.25rem;
  line-height: 1.4;
}

@media (min-width: 768px) {
  h1 {
    font-size: 2.5rem;
  }
  h2 {
    font-size: 2rem;
  }
  h3 {
    font-size: 1.5rem;
  }
}

@media (min-width: 1024px) {
  h1 {
    font-size: 3rem;
  }
  h2 {
    font-size: 2.25rem;
  }
  h3 {
    font-size: 1.75rem;
  }
}

/* ========================================
   SAFE AREA (for iOS notch)
   ======================================== */

@supports (padding: env(safe-area-inset-left)) {
  .safe-padding {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* ========================================
   MOBILE-SPECIFIC FIXES (HIGH PRIORITY)
   ======================================== */

@media (max-width: 767px) {
  /* Force proper container sizing on mobile */
  .container {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  
  /* Fix dashboard cards on mobile */
  .bg-white.rounded-2xl,
  .bg-white.rounded-xl {
    padding: 0.75rem !important;
  }
  
  /* Ensure grids don't overflow */
  [class*="grid"] {
    width: 100%;
    overflow-x: hidden;
  }
  
  /* Reduce gaps on mobile */
  .gap-6 {
    gap: 1rem !important;
  }
  
  .gap-4 {
    gap: 0.75rem !important;
  }
  
  .gap-3 {
    gap: 0.5rem !important;
  }
  
  /* Fix text sizes for mobile */
  .text-3xl {
    font-size: 1.5rem !important;
  }
  
  .text-2xl {
    font-size: 1.25rem !important;
  }
  
  /* Answer Distribution: Stack KPI and chart vertically on mobile */
  .flex-col.md\:flex-row {
    flex-direction: column !important;
    gap: 1.5rem !important;
  }
  
  /* Answer Distribution: Full width KPI cards on mobile */
  .flex-col.md\:flex-row > div {
    width: 100% !important;
    max-width: 100% !important;
    min-width: auto !important;
  }
  
  /* Answer Distribution: Adjust chart container for mobile */
  .chart-container {
    min-height: 280px !important;
    max-width: 100% !important;
  }
  
  /* Fix icon sizes on mobile */
  .w-14 {
    width: 3rem !important;
  }
  
  .h-14 {
    height: 3rem !important;
  }
}

/* ========================================
   SMOOTH SCROLLING
   ======================================== */

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}
