/* ============================================================
   Responsive Design Fixes for hodi.co.ke
   Ensures proper aspect ratio, scrolling, and content fitting
   ============================================================ */

/* Base responsive fixes */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  width: 100%;
  height: 100%;
}

body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
  /* Prevent horizontal scrolling */
  max-width: 100vw;
}

/* Ensure main content is scrollable */
.main-content {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
  /* Prevent content from being too wide */
  max-width: 100%;
}

/* Container fixes */
.container,
.container-fluid {
  width: 100%;
  max-width: 100%;
  padding-left: 15px;
  padding-right: 15px;
  margin-left: auto;
  margin-right: auto;
  overflow-x: hidden;
}

/* Ensure all content containers are scrollable */
.card,
.card-body,
.table-responsive,
.modal-body,
.navbar,
.sidenav {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix tables to be scrollable */
.table-responsive {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  max-width: 100%;
  margin-bottom: 0;
}

/* Fix images to maintain aspect ratio */
img {
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

/* Fix videos and iframes */
video,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}

/* Fix forms to be responsive */
.form-group,
.form-control,
.input-group {
  width: 100%;
  max-width: 100%;
}

.form-control {
  box-sizing: border-box;
}

/* Fix buttons to not overflow */
.btn {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Fix modals to be responsive */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-dialog {
  width: 90%;
  max-width: 500px;
  margin: 1.75rem auto;
  position: relative;
}

.modal-content {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.modal-body {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix navbar to be responsive */
.navbar {
  width: 100%;
  max-width: 100%;
  flex-wrap: wrap;
}

.navbar-nav {
  flex-direction: column;
  width: 100%;
}

/* Fix sidenav */
.sidenav {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  z-index: 1030;
}

/* Ensure content area adjusts when sidenav is open */
.main-content {
  margin-left: 0;
  transition: margin-left 0.3s ease;
}

/* Fix cards to be responsive */
.card {
  width: 100%;
  max-width: 100%;
  margin-bottom: 1rem;
  overflow: hidden;
}

.card-body {
  padding: 1rem;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix data tables */
.dataTables_wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dataTables_wrapper .dataTables_scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix maps */
#map,
.map-container,
.google-map {
  width: 100%;
  max-width: 100%;
  height: 400px;
  min-height: 300px;
  max-height: 600px;
  overflow: hidden;
  position: relative;
}

/* Fix charts */
canvas {
  max-width: 100%;
  height: auto;
}

.chart-container {
  width: 100%;
  max-width: 100%;
  position: relative;
  overflow: hidden;
}

/* Fix text to prevent overflow */
p,
h1,
h2,
h3,
h4,
h5,
h6,
span,
div {
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  max-width: 100%;
}

/* Fix pre and code blocks */
pre,
code {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Fix lists */
ul,
ol {
  padding-left: 1.5rem;
  max-width: 100%;
}

/* Fix navigation */
.nav {
  flex-wrap: wrap;
}

.nav-item {
  max-width: 100%;
}

.nav-link {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Fix dropdowns */
.dropdown-menu {
  max-width: 100vw;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix tooltips and popovers */
.tooltip,
.popover {
  max-width: 90vw;
  word-wrap: break-word;
}

/* Fix pagination */
.pagination {
  flex-wrap: wrap;
  justify-content: center;
}

/* Fix badges and labels */
.badge,
.label {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Fix alerts */
.alert {
  width: 100%;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Fix progress bars */
.progress {
  width: 100%;
  max-width: 100%;
}

/* Fix breadcrumbs */
.breadcrumb {
  flex-wrap: wrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix tabs */
.nav-tabs {
  flex-wrap: wrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-content {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix accordions */
.accordion {
  width: 100%;
  max-width: 100%;
}

.accordion-item {
  width: 100%;
  max-width: 100%;
}

.accordion-body {
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix carousels */
.carousel {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.carousel-item {
  width: 100%;
  max-width: 100%;
}

.carousel-item img {
  width: 100%;
  height: auto;
  object-fit: cover;
  aspect-ratio: 16 / 9;
}

/* Fix toasts */
.toast-container {
  max-width: 90vw;
  width: auto;
}

.toast {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Mobile-specific fixes */
@media (max-width: 767.98px) {
  /* Ensure body is scrollable on mobile */
  body {
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100vw;
  }

  /* Hide sidenav on mobile or make it overlay */
  .sidenav {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidenav.show {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0 !important;
    width: 100%;
  }

  /* Fix modals on mobile */
  .modal-dialog {
    width: 95%;
    margin: 0.5rem auto;
    max-height: 95vh;
  }

  .modal-content {
    max-height: 95vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-body {
    max-height: calc(95vh - 150px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Fix tables on mobile */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border: 1px solid #dee2e6;
  }

  /* Fix cards on mobile */
  .card {
    margin-bottom: 1rem;
  }

  .card-body {
    padding: 0.75rem;
  }

  /* Fix forms on mobile */
  .form-control,
  .form-select {
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Fix buttons on mobile */
  .btn {
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.75rem 1rem;
  }

  .btn-group {
    width: 100%;
    flex-direction: column;
  }

  .btn-group .btn {
    width: 100%;
    border-radius: 0.25rem !important;
    margin-bottom: 0.25rem;
  }

  /* Fix navbar on mobile */
  .navbar-collapse {
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Fix dropdowns on mobile */
  .dropdown-menu {
    position: static;
    float: none;
    width: 100%;
    max-width: 100%;
    margin-top: 0;
    border: 0;
    box-shadow: none;
  }

  /* Fix pagination on mobile */
  .pagination {
    font-size: 0.875rem;
  }

  .page-link {
    padding: 0.375rem 0.5rem;
  }

  /* Fix maps on mobile */
  #map,
  .map-container,
  .google-map {
    height: 300px;
    min-height: 250px;
  }

  /* Fix toasts on mobile */
  .toast-container {
    right: 5px;
    left: 5px;
    bottom: 5px;
    max-width: calc(100vw - 10px);
  }

  .toast {
    width: 100%;
    max-width: 100%;
  }
}

/* Tablet-specific fixes */
@media (min-width: 768px) and (max-width: 991.98px) {
  .main-content {
    margin-left: 0;
  }

  .sidenav {
    width: 250px;
  }

  .modal-dialog {
    max-width: 600px;
  }

  #map,
  .map-container,
  .google-map {
    height: 400px;
  }
}

/* Desktop fixes */
@media (min-width: 992px) {
  .main-content {
    margin-left: 250px;
  }

  .sidenav {
    width: 250px;
  }
}

/* Large desktop fixes */
@media (min-width: 1200px) {
  .container {
    max-width: 1140px;
  }
}

/* Extra large desktop fixes */
@media (min-width: 1400px) {
  .container {
    max-width: 1320px;
  }
}

/* Fix for very small screens */
@media (max-width: 575.98px) {
  body {
    font-size: 14px;
  }

  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  h3 {
    font-size: 1.25rem;
  }

  .card-body {
    padding: 0.5rem;
  }

  .btn {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
  }
}

/* Fix for landscape orientation on mobile */
@media (max-width: 767.98px) and (orientation: landscape) {
  .modal-dialog {
    max-height: 90vh;
  }

  .modal-body {
    max-height: calc(90vh - 120px);
  }

  #map,
  .map-container,
  .google-map {
    height: 250px;
    min-height: 200px;
  }
}

/* Prevent text selection issues on touch devices */
@media (hover: none) and (pointer: coarse) {
  * {
    -webkit-tap-highlight-color: transparent;
  }

  a,
  button,
  .btn,
  .nav-link {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  }
}

/* Fix for iOS Safari viewport issues */
@supports (-webkit-touch-callout: none) {
  body {
    /* Fix for iOS Safari 100vh issue */
    min-height: -webkit-fill-available;
  }

  .main-content {
    min-height: -webkit-fill-available;
  }
}

/* Ensure all scrollable containers work properly */
.scrollable,
[data-scrollable="true"] {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  max-height: 100%;
}

/* Fix aspect ratios for common media */
.aspect-ratio-16-9 {
  aspect-ratio: 16 / 9;
  width: 100%;
  height: auto;
}

.aspect-ratio-4-3 {
  aspect-ratio: 4 / 3;
  width: 100%;
  height: auto;
}

.aspect-ratio-1-1 {
  aspect-ratio: 1 / 1;
  width: 100%;
  height: auto;
}

/* Utility classes for responsive fixes */
.w-100-mobile {
  width: 100%;
}

@media (min-width: 768px) {
  .w-100-mobile {
    width: auto;
  }
}

.overflow-auto-mobile {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.scroll-smooth {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Fix for print media */
@media print {
  body {
    overflow: visible;
  }

  .sidenav,
  .navbar,
  .btn,
  .pagination {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
}

