/**
 * Responsive Fixes - Optimized and Conservative
 * Fixes touch targets, text readability, and mobile UX without breaking existing layouts
 */

/* ===== TOUCH TARGET OPTIMIZATION ===== */

/* Ensure interactive elements meet minimum 44x44px touch target - non-breaking */
button:not(.navbar-toggler):not(.carousel-control-prev):not(.carousel-control-next),
a.btn,
input[type="submit"],
input[type="button"],
[role="button"]:not(.carousel-control-prev):not(.carousel-control-next) {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  box-sizing: border-box;
}

/* Navigation links - gentle touch target enhancement */
.navbar-nav .nav-link {
  min-height: 44px;
  padding-top: 10px;
  padding-bottom: 10px;
  display: inline-flex;
  align-items: center;
}

/* Skill chips - ensure tappable */
.skill-chip, .tech-badge {
  min-height: 38px;
  padding: 8px 14px;
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Form inputs minimum touch target */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
textarea,
select {
  min-height: 44px;
  padding: 8px 12px;
  box-sizing: border-box;
}

textarea {
  min-height: 100px;
}

@media (max-width: 768px) {
  /* Enhanced mobile touch targets */
  button:not(.navbar-toggler):not(.carousel-control-prev):not(.carousel-control-next),
  a.btn,
  input[type="submit"],
  input[type="button"],
  [role="button"]:not(.carousel-control-prev):not(.carousel-control-next) {
    min-height: 48px;
    padding: 12px 20px;
  }

  .navbar-nav .nav-link {
    min-height: 48px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .skill-chip, .tech-badge {
    min-height: 42px;
    padding: 10px 16px;
    font-size: 0.9rem;
  }

  /* Form inputs mobile optimization */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  textarea,
  select {
    min-height: 48px;
    padding: 10px 14px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  textarea {
    min-height: 120px;
  }

  /* Toggle switches need to be touchable */
  input[type="checkbox"],
  input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
  }

  .form-check-input,
  .form-switch-checkbox {
    min-width: 40px;
    min-height: 24px;
  }
}

/* ===== TEXT READABILITY - CONSERVATIVE ===== */

/* Only fix text that's too small - don't override existing good sizes */
.tech-badge.skill-chip {
  font-size: max(0.875rem, 14px);
}

small, .small {
  font-size: max(0.875rem, 13px);
  line-height: 1.5;
}

@media (max-width: 768px) {
  /* Ensure readable mobile text without forcing sizes everywhere */
  .tech-badge.skill-chip {
    font-size: max(0.9rem, 14px);
  }

  /* Only adjust if too small */
  p, li, td, th {
    font-size: max(1em, 14px);
  }

  label {
    font-size: max(0.95rem, 14px);
    font-weight: 500;
  }
}

/* ===== MOBILE VIEWPORT FIXES ===== */

@media (max-width: 768px) {
  /* Prevent horizontal scroll */
  body {
    overflow-x: hidden;
  }

  /* Images mobile responsive */
  img:not(.navbar-brand img):not(.icon) {
    max-width: 100%;
    height: auto;
  }

  /* Ensure containers don't overflow */
  .container, .container-fluid {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Cards mobile optimization */
  .card {
    margin-bottom: 1rem;
  }

  .card-body {
    padding: 1rem;
  }

  /* Form spacing */
  .form-group, .mb-3 {
    margin-bottom: 1.5rem;
  }
}

/* ===== FORM UX IMPROVEMENTS ===== */

/* Better form focus states */
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--bs-primary, #0d6efd);
  outline-offset: 2px;
  border-color: var(--bs-primary, #0d6efd);
}

/* Checkbox and radio focus */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
  outline: 2px solid var(--bs-primary, #0d6efd);
  outline-offset: 2px;
}

/* Form validation visual improvement */
.was-validated .form-control:invalid,
.form-control.is-invalid {
  border-color: #dc3545;
  padding-right: calc(1.5em + 0.75rem);
}

.was-validated .form-control:valid,
.form-control.is-valid {
  border-color: #198754;
  padding-right: calc(1.5em + 0.75rem);
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--bs-primary, #0d6efd);
  outline-offset: 2px;
}

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--bs-primary, #0d6efd);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
  border-radius: 0 0 4px 0;
}

.skip-link:focus {
  top: 0;
}

/* Better link focus states */
a:focus-visible {
  outline: 2px solid var(--bs-primary, #0d6efd);
  outline-offset: 2px;
  text-decoration: underline;
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Hardware acceleration for smooth animations */
.carousel-item,
.fade,
.collapse,
.modal {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Smooth scrolling with user preference respect */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* Respect reduced motion preference */
@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;
  }
}

/* ===== FOOTER ICONS FIX ===== */

/* Ensure footer social icons meet touch target requirements */
.footer-social-icons a,
.social-icons a,
footer .btn-icon {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

@media (max-width: 768px) {
  .footer-social-icons a,
  .social-icons a,
  footer .btn-icon {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
  }
}

/* ===== LANGUAGE TOGGLE FIX ===== */

/* Ensure language toggle is always accessible */
.language-switch {
  position: relative;
  z-index: 10;
}

.language-switch-input {
  min-width: 48px;
  min-height: 28px;
}

@media (max-width: 768px) {
  .language-switch {
    margin: 1rem auto;
    display: block !important;
  }

  .language-switch-input {
    min-height: 32px;
  }
}

/* ===== FORM TOGGLE SWITCH FIX ===== */

/* Ensure form toggle switch is always clickable */
.form-switch-container {
  margin: 1rem 0;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.form-switch-checkbox {
  cursor: pointer;
  z-index: 1;
}

@media (max-width: 768px) {
  .form-switch-container {
    margin: 1.5rem 0;
    min-height: 60px;
  }
}

/* ===== GENERAL MOBILE IMPROVEMENTS ===== */

@media (max-width: 768px) {
  /* Better button spacing on mobile */
  .btn + .btn {
    margin-top: 0.5rem;
  }

  /* Stack buttons vertically on very small screens */
  @media (max-width: 400px) {
    .btn-group-vertical .btn,
    .d-grid .btn {
      width: 100%;
      margin-bottom: 0.5rem;
    }
  }

  /* Improve modal readability */
  .modal-body {
    padding: 1.5rem;
    font-size: 1rem;
  }

  /* Better table mobile view */
  table {
    font-size: 0.9rem;
  }

  th, td {
    padding: 0.5rem;
  }
}

/* ===== FINAL RESPONSIVE FIXES (10 ISSUES REMAINING) ===== */

/* FIX 1: Privacy consent checkbox - 34px width → 44px/48px */
#privacy_consent.form-check-input {
  min-width: 44px !important;
  min-height: 44px !important;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

@media (max-width: 768px) {
  #privacy_consent.form-check-input {
    min-width: 48px !important;
    min-height: 48px !important;
    width: 48px;
    height: 48px;
  }
}

/* FIX 2: Footer links touch targets - Conservative approach */
footer a:not(.btn),
.footer-link,
footer .nav-link {
  min-height: 44px;
  padding: 8px 4px;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 768px) {
  footer a:not(.btn),
  .footer-link,
  footer .nav-link {
    min-height: 48px;
    padding: 10px 6px;
  }
}

/* FIX 3: Client names text size - 13px → 14px/15px */
.client-name {
  font-size: 14px !important;
  line-height: 1.5 !important;
}

@media (max-width: 768px) {
  .client-name {
    font-size: 15px !important;
  }
}

/* FIX 4: Skill chips text enhancement - 14px → 15px mobile */
.tech-badge.skill-chip {
  font-size: 14px !important;
  line-height: 1.4 !important;
}

@media (max-width: 768px) {
  .tech-badge.skill-chip {
    font-size: 15px !important;
    min-height: 48px !important;
  }
}

/* FIX 5: Section padding mobile - 15px → 16px minimum */
@media (max-width: 768px) {
  section {
    padding: max(16px, 1rem) !important;
  }

  .container, .container-fluid {
    padding-left: max(16px, 1rem) !important;
    padding-right: max(16px, 1rem) !important;
  }
}

/* FIX 6: Fixed elements optimization - reduce on mobile */
@media (max-width: 768px) {
  /* Reading timer - make thinner on mobile */
  .reading-timer-container {
    height: 3px !important;
  }

  /* CSS debug tool - hide on mobile */
  #css-debug-tool {
    display: none !important;
  }

  /* Back to top button - smaller on mobile */
  #backToTopBtn.show {
    width: 48px !important;
    height: 48px !important;
    font-size: 1.2rem !important;
    padding: 10px !important;
  }
}

/* FIX 7: Link touch targets - conservative approach */
a.btn, a[role="button"] {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 768px) {
  a.btn, a[role="button"] {
    min-height: 48px;
  }
}

/* FIX 8: Language toggle desktop height - 28px → 44px */
#languageToggleDesktop.language-switch-input,
.language-switch-input {
  min-height: 44px !important;
  height: 44px !important;
}

/* FIX 9: Budget slider track height - 8px → 44px clickable area */
#daily_rate_slider.budget-slider,
.form-range.budget-slider {
  min-height: 44px !important;
  height: 44px !important;
  cursor: pointer;
}

/* Increase slider track visibility */
.form-range::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 6px;
}

.form-range::-moz-range-track {
  height: 12px;
  border-radius: 6px;
}

/* Larger slider thumb for touch */
.form-range::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -6px;
}

.form-range::-moz-range-thumb {
  width: 24px;
  height: 24px;
}

/* FIX 10: Budget slider labels text size - 13px → 14px */
.budget-slider-labels,
.budget-slider-labels span,
.budget-slider-labels div {
  font-size: 14px !important;
  line-height: 1.5 !important;
}

/* CSS debug tool text readability */
#css-debug-tool,
#css-debug-tool div,
#viewport-size,
#current-breakpoint {
  font-size: 14px !important;
  line-height: 1.4 !important;
}
