/**
 * EasyStream Responsive Design System
 * Mobile-first responsive breakpoints and utilities
 * Version: 1.0
 */

/* ==================== BREAKPOINT VARIABLES ==================== */
:root {
  --breakpoint-xs: 0;
  --breakpoint-sm: 640px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1280px;
  --breakpoint-2xl: 1536px;

  /* Container max widths */
  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1280px;
  --container-2xl: 1536px;
}

/* ==================== CONTAINER SYSTEM ==================== */

.container {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-md, 16px);
  padding-right: var(--space-md, 16px);
}

@media (min-width: 640px) {
  .container {
    max-width: var(--container-sm);
  }
}

@media (min-width: 768px) {
  .container {
    max-width: var(--container-md);
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: var(--container-lg);
    padding-left: var(--space-lg, 24px);
    padding-right: var(--space-lg, 24px);
  }
}

@media (min-width: 1280px) {
  .container {
    max-width: var(--container-xl);
  }
}

@media (min-width: 1536px) {
  .container {
    max-width: var(--container-2xl);
  }
}

/* Fluid container */
.container-fluid {
  width: 100%;
  padding-left: var(--space-md, 16px);
  padding-right: var(--space-md, 16px);
}

/* ==================== GRID SYSTEM ==================== */

.grid {
  display: grid;
  gap: var(--space-md, 16px);
}

/* Auto-fit grid - responsive by default */
.grid-auto {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

/* 12 column grid */
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.grid-cols-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }

/* Column spans */
.col-span-1 { grid-column: span 1 / span 1; }
.col-span-2 { grid-column: span 2 / span 2; }
.col-span-3 { grid-column: span 3 / span 3; }
.col-span-4 { grid-column: span 4 / span 4; }
.col-span-6 { grid-column: span 6 / span 6; }
.col-span-12 { grid-column: span 12 / span 12; }
.col-span-full { grid-column: 1 / -1; }

/* Responsive grid columns */
@media (min-width: 640px) {
  .sm\:grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sm\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 768px) {
  .md\:grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .md\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .md\:grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
  .lg\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lg\:grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .lg\:grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* ==================== FLEXBOX UTILITIES ==================== */

.flex {
  display: flex;
}

.inline-flex {
  display: inline-flex;
}

/* Flex direction */
.flex-row { flex-direction: row; }
.flex-col { flex-direction: column; }
.flex-row-reverse { flex-direction: row-reverse; }
.flex-col-reverse { flex-direction: column-reverse; }

/* Flex wrap */
.flex-wrap { flex-wrap: wrap; }
.flex-nowrap { flex-wrap: nowrap; }

/* Justify content */
.justify-start { justify-content: flex-start; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }
.justify-evenly { justify-content: space-evenly; }

/* Align items */
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.items-stretch { align-items: stretch; }

/* Gap utilities */
.gap-xs { gap: var(--space-xs, 4px); }
.gap-sm { gap: var(--space-sm, 8px); }
.gap-md { gap: var(--space-md, 16px); }
.gap-lg { gap: var(--space-lg, 24px); }
.gap-xl { gap: var(--space-xl, 32px); }

/* ==================== DISPLAY UTILITIES ==================== */

.hidden { display: none; }
.block { display: block; }
.inline { display: inline; }
.inline-block { display: inline-block; }

/* Responsive display */
@media (max-width: 639px) {
  .xs\:hidden { display: none; }
  .xs\:block { display: block; }
}

@media (min-width: 640px) {
  .sm\:hidden { display: none; }
  .sm\:block { display: block; }
  .sm\:flex { display: flex; }
}

@media (min-width: 768px) {
  .md\:hidden { display: none; }
  .md\:block { display: block; }
  .md\:flex { display: flex; }
}

@media (min-width: 1024px) {
  .lg\:hidden { display: none; }
  .lg\:block { display: block; }
  .lg\:flex { display: flex; }
}

@media (min-width: 1280px) {
  .xl\:hidden { display: none; }
  .xl\:block { display: block; }
  .xl\:flex { display: flex; }
}

/* ==================== MOBILE-FIRST VIDEO GRID ==================== */

/* Video thumbnail grid - responsive */
.video-grid,
.content-grid {
  display: grid;
  gap: var(--space-md, 16px);
  grid-template-columns: 1fr; /* Mobile: 1 column */
}

@media (min-width: 640px) {
  .video-grid,
  .content-grid {
    grid-template-columns: repeat(2, 1fr); /* Tablet: 2 columns */
  }
}

@media (min-width: 768px) {
  .video-grid,
  .content-grid {
    grid-template-columns: repeat(3, 1fr); /* Desktop: 3 columns */
  }
}

@media (min-width: 1024px) {
  .video-grid,
  .content-grid {
    grid-template-columns: repeat(4, 1fr); /* Large: 4 columns */
  }
}

@media (min-width: 1280px) {
  .video-grid,
  .content-grid {
    grid-template-columns: repeat(5, 1fr); /* XL: 5 columns */
  }
}

@media (min-width: 1536px) {
  .video-grid,
  .content-grid {
    grid-template-columns: repeat(6, 1fr); /* 2XL: 6 columns */
  }
}

/* Compact video grid for sidebars */
.video-grid-compact {
  display: grid;
  gap: var(--space-sm, 8px);
  grid-template-columns: 1fr;
}

/* ==================== RESPONSIVE TYPOGRAPHY ==================== */

/* Fluid typography using clamp */
.text-responsive-sm {
  font-size: clamp(0.875rem, 2vw, 1rem);
}

.text-responsive-md {
  font-size: clamp(1rem, 2.5vw, 1.125rem);
}

.text-responsive-lg {
  font-size: clamp(1.125rem, 3vw, 1.5rem);
}

.text-responsive-xl {
  font-size: clamp(1.5rem, 4vw, 2.25rem);
}

/* ==================== RESPONSIVE SPACING ==================== */

/* Responsive padding */
.p-responsive {
  padding: var(--space-sm);
}

@media (min-width: 768px) {
  .p-responsive {
    padding: var(--space-md);
  }
}

@media (min-width: 1024px) {
  .p-responsive {
    padding: var(--space-lg);
  }
}

/* Responsive margin */
.m-responsive {
  margin: var(--space-sm);
}

@media (min-width: 768px) {
  .m-responsive {
    margin: var(--space-md);
  }
}

@media (min-width: 1024px) {
  .m-responsive {
    margin: var(--space-lg);
  }
}

/* ==================== SIDEBAR LAYOUTS ==================== */

.layout-with-sidebar {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: 1fr; /* Mobile: stacked */
}

@media (min-width: 1024px) {
  .layout-with-sidebar {
    grid-template-columns: 250px 1fr; /* Desktop: sidebar + content */
  }

  .layout-with-sidebar.sidebar-right {
    grid-template-columns: 1fr 300px;
  }
}

/* Collapsible sidebar */
.sidebar {
  width: 100%;
}

@media (min-width: 1024px) {
  .sidebar.collapsed {
    width: 64px;
    overflow: hidden;
  }

  .sidebar.collapsed + .main-content {
    margin-left: 64px;
  }
}

/* ==================== TOUCH OPTIMIZATIONS ==================== */

/* Larger touch targets on mobile */
@media (max-width: 767px) {
  button,
  a,
  .btn,
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Increase spacing between interactive elements */
  .button-group > *,
  .nav-menu > * {
    margin: var(--space-sm) 0;
  }
}

/* ==================== IMAGE RESPONSIVENESS ==================== */

img,
video,
iframe {
  max-width: 100%;
  height: auto;
}

.aspect-video {
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

.aspect-square {
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.aspect-video img,
.aspect-video video,
.aspect-square img,
.aspect-square video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==================== TABLE RESPONSIVENESS ==================== */

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
  /* Stack table on mobile */
  .table-stack thead {
    display: none;
  }

  .table-stack tr {
    display: block;
    margin-bottom: var(--space-md);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--border-radius-md);
  }

  .table-stack td {
    display: flex;
    justify-content: space-between;
    padding: var(--space-sm);
    border-bottom: 1px solid var(--color-border-secondary);
  }

  .table-stack td:last-child {
    border-bottom: none;
  }

  .table-stack td::before {
    content: attr(data-label);
    font-weight: 600;
    margin-right: var(--space-sm);
  }
}

/* ==================== MOBILE NAVIGATION ==================== */

/* Hamburger menu */
.mobile-menu-toggle {
  display: block;
  cursor: pointer;
  padding: var(--space-sm);
}

@media (min-width: 768px) {
  .mobile-menu-toggle {
    display: none;
  }
}

.mobile-menu {
  position: fixed;
  top: 0;
  left: -100%;
  width: 80%;
  max-width: 300px;
  height: 100vh;
  background: var(--color-bg-primary);
  box-shadow: var(--shadow-xl);
  transition: left var(--transition-base);
  z-index: var(--z-index-modal);
  overflow-y: auto;
}

.mobile-menu.open {
  left: 0;
}

.mobile-menu-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
  z-index: calc(var(--z-index-modal) - 1);
}

.mobile-menu-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* ==================== VIDEO PLAYER RESPONSIVENESS ==================== */

.video-player-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  height: 0;
  overflow: hidden;
}

.video-player-wrapper iframe,
.video-player-wrapper video,
.video-player-wrapper .video-js {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ==================== ORIENTATION SUPPORT ==================== */

@media (orientation: landscape) and (max-height: 500px) {
  /* Optimize for landscape mobile */
  .video-player-wrapper {
    padding-bottom: 0;
    height: 100vh;
  }

  header,
  .sidebar {
    display: none; /* Hide in fullscreen landscape */
  }
}

/* ==================== RESPONSIVE UTILITIES ==================== */

/* Text alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

@media (min-width: 768px) {
  .md\:text-left { text-align: left; }
  .md\:text-center { text-align: center; }
  .md\:text-right { text-align: right; }
}

/* Width utilities */
.w-full { width: 100%; }
.w-auto { width: auto; }
.w-screen { width: 100vw; }

.h-full { height: 100%; }
.h-auto { height: auto; }
.h-screen { height: 100vh; }

/* Max width utilities */
.max-w-xs { max-width: 320px; }
.max-w-sm { max-width: 384px; }
.max-w-md { max-width: 448px; }
.max-w-lg { max-width: 512px; }
.max-w-xl { max-width: 576px; }
.max-w-2xl { max-width: 672px; }
.max-w-full { max-width: 100%; }

/* ==================== PRINT RESPONSIVENESS ==================== */

@media print {
  .no-print,
  .mobile-menu,
  .sidebar,
  nav,
  header,
  footer {
    display: none !important;
  }

  body {
    font-size: 12pt;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }
}

/* ==================== LANDSCAPE MODE OPTIMIZATIONS ==================== */

@media (max-width: 1023px) and (orientation: landscape) {
  /* Reduce vertical spacing in landscape */
  .p-responsive {
    padding-top: var(--space-sm);
    padding-bottom: var(--space-sm);
  }

  /* Make navigation horizontal in landscape */
  .mobile-menu {
    width: 100%;
    max-width: none;
    height: auto;
    max-height: 80vh;
  }
}

/* ==================== SAFE AREAS (iPhone X+) ==================== */

@supports (padding: env(safe-area-inset-left)) {
  .safe-area-padding {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  header,
  .mobile-menu {
    padding-left: max(var(--space-md), env(safe-area-inset-left));
    padding-right: max(var(--space-md), env(safe-area-inset-right));
  }
}
