/* ================================
   RESPONSIVE UTILITIES
   Additional responsive helpers
   ================================ */

/* ========== Responsive Images ========== */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

.img-fluid {
  max-width: 100%;
  height: auto;
}

.img-cover {
  object-fit: cover;
  width: 100%;
  height: 100%;
}

.img-contain {
  object-fit: contain;
  width: 100%;
  height: 100%;
}

/* ========== Responsive Embeds ========== */
.embed-responsive {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
}

.embed-responsive::before {
  display: block;
  content: "";
}

.embed-responsive-16by9::before {
  padding-top: 56.25%;
}

.embed-responsive-4by3::before {
  padding-top: 75%;
}

.embed-responsive-1by1::before {
  padding-top: 100%;
}

.embed-responsive iframe,
.embed-responsive embed,
.embed-responsive object,
.embed-responsive video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ========== Mobile-First Container ========== */
.container-responsive {
  width: 100%;
  padding-right: var(--space-4);
  padding-left: var(--space-4);
  margin-right: auto;
  margin-left: auto;
}

@media (min-width: 576px) {
  .container-responsive {
    max-width: 540px;
    padding-right: var(--space-5);
    padding-left: var(--space-5);
  }
}

@media (min-width: 768px) {
  .container-responsive {
    max-width: 720px;
    padding-right: var(--space-6);
    padding-left: var(--space-6);
  }
}

@media (min-width: 992px) {
  .container-responsive {
    max-width: 960px;
  }
}

@media (min-width: 1200px) {
  .container-responsive {
    max-width: 1140px;
  }
}

@media (min-width: 1400px) {
  .container-responsive {
    max-width: 1320px;
  }
}

/* ========== Responsive Typography ========== */
.responsive-text {
  font-size: clamp(1rem, 2vw, 1.125rem);
  line-height: 1.6;
}

.responsive-heading-1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.2;
}

.responsive-heading-2 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  line-height: 1.3;
}

.responsive-heading-3 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  line-height: 1.4;
}

/* ========== Responsive Spacing ========== */
@media (max-width: 575px) {
  .spacing-mobile-sm {
    padding: var(--space-4);
  }

  .spacing-mobile-md {
    padding: var(--space-6);
  }

  .spacing-mobile-lg {
    padding: var(--space-8);
  }
}

/* ========== Responsive Grid Helpers ========== */
.grid-responsive {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}

@media (min-width: 576px) {
  .grid-responsive {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
  }
}

@media (min-width: 768px) {
  .grid-responsive {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-8);
  }
}

@media (min-width: 992px) {
  .grid-responsive {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ========== Overflow Handling ========== */
.overflow-x-auto {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.overflow-x-auto::-webkit-scrollbar {
  height: 8px;
}

.overflow-x-auto::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: var(--radius-base);
}

.overflow-x-auto::-webkit-scrollbar-thumb {
  background: var(--gray-400);
  border-radius: var(--radius-base);
}

.overflow-x-auto::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* ========== Table Responsiveness ========== */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space-6);
}

@media (max-width: 767px) {
  .table-responsive table {
    min-width: 600px;
  }
}

/* ========== Flexbox Helpers ========== */
.flex-mobile-column {
  display: flex;
}

@media (max-width: 767px) {
  .flex-mobile-column {
    flex-direction: column;
  }
}

.flex-mobile-wrap {
  display: flex;
}

@media (max-width: 767px) {
  .flex-mobile-wrap {
    flex-wrap: wrap;
  }
}

/* ========== Visibility Helpers ========== */
.visible-mobile {
  display: none !important;
}

@media (max-width: 767px) {
  .visible-mobile {
    display: block !important;
  }

  .visible-mobile-flex {
    display: flex !important;
  }

  .visible-mobile-inline {
    display: inline !important;
  }

  .hidden-mobile {
    display: none !important;
  }
}

@media (min-width: 768px) {
  .visible-tablet {
    display: block !important;
  }

  .hidden-tablet {
    display: none !important;
  }
}

@media (min-width: 992px) {
  .visible-desktop {
    display: block !important;
  }

  .hidden-desktop {
    display: none !important;
  }
}

/* ========== Touch Targets ========== */
@media (hover: none) and (pointer: coarse) {
  /* Ensure minimum touch target size of 44x44px */
  a,
  button,
  input[type="button"],
  input[type="submit"],
  input[type="reset"],
  .btn,
  .nav-link,
  .dropdown-item {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-3) var(--space-4);
  }

  /* Remove hover effects on touch devices */
  *:hover {
    transition: none;
  }
}

/* ========== Orientation Specific ========== */
@media (orientation: landscape) and (max-height: 600px) {
  .landscape-reduce-height {
    min-height: auto !important;
    padding-top: var(--space-8) !important;
    padding-bottom: var(--space-8) !important;
  }
}

/* ========== Performance Optimizations ========== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========== Dark Mode Support ========== */
@media (prefers-color-scheme: dark) {
  /* Optional: Add dark mode styles if needed in the future */
  .auto-dark-mode {
    /* Placeholder for future dark mode implementation */
  }
}

/* ========== High DPI / Retina Displays ========== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Optimizations for high DPI displays */
  img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* ========== Print Optimizations ========== */
@media print {
  * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }

  .no-print {
    display: none !important;
  }
}

