/*!
 * UI/UX Fixes for OBDWhiz
 * Addresses critical design inconsistencies, accessibility issues, and mobile usability
 */

/* =================
   1. BUTTON DESIGN CONSISTENCY FIXES
   ================= */

/* Standardize all button sizes to consistent system */
.btn {
  /* Base button styles */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-primary);
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
  user-select: none;
  position: relative;
  
  /* Minimum touch target size for mobile (44x44px minimum) */
  min-height: 44px;
  padding: 0.75rem 1.5rem;
  font-size: var(--text-base);
  border-radius: var(--radius-lg);
}

/* Button size variants - consistent system */
.btn-small {
  min-height: 36px;
  padding: 0.5rem 1rem;
  font-size: var(--text-sm);
}

.btn-medium {
  min-height: 44px;
  padding: 0.75rem 1.5rem;
  font-size: var(--text-base);
}

.btn-large {
  min-height: 52px;
  padding: 1rem 2rem;
  font-size: var(--text-lg);
}

/* Fix button hover states */
.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-md);
}

/* Fix disabled state */
.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* =================
   2. COLOR CONTRAST ACCESSIBILITY FIXES
   ================= */

/* Fix primary button contrast */
.btn-primary {
  background-color: var(--primary-600); /* Darker for better contrast */
  color: var(--white);
}

.btn-primary:hover {
  background-color: var(--primary-700);
}

.btn-primary:focus-visible {
  outline: 3px solid var(--primary-300);
  outline-offset: 2px;
}

/* Fix ghost button contrast */
.btn-ghost {
  background-color: transparent;
  color: var(--gray-700); /* Darker text for better contrast */
  border: 2px solid var(--gray-300);
}

.btn-ghost:hover {
  background-color: var(--gray-50);
  border-color: var(--gray-400);
}

/* Fix secondary button contrast */
.btn-secondary {
  background-color: var(--gray-100);
  color: var(--gray-800); /* Darker text */
  border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
  background-color: var(--gray-200);
  border-color: var(--gray-400);
}

/* Fix text contrast throughout */
body {
  color: var(--gray-900); /* Ensure dark enough text */
}

.hero-subtitle,
.section-header p {
  color: var(--gray-700); /* Darker subtitle text */
}

/* Fix link contrast */
a {
  color: var(--primary-700); /* Darker link color */
}

a:hover {
  color: var(--primary-800);
}

/* =================
   3. MOBILE FORM USABILITY FIXES
   ================= */

/* Fix form input sizing for mobile */
.form-input,
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="search"],
select,
textarea {
  min-height: 48px; /* Larger touch target */
  padding: 0.75rem 1rem;
  font-size: 16px; /* Prevents zoom on iOS */
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-md);
  width: 100%;
  transition: all var(--transition-base);
}

/* Fix input focus states */
.form-input:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Fix input group spacing on mobile */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .input-group {
    flex-direction: row;
    align-items: stretch;
  }
  
  .input-group .form-input {
    flex: 1;
  }
}

/* Fix form labels */
.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--gray-800);
  font-size: var(--text-sm);
}

/* Required field indicator */
.form-label.required::after {
  content: " *";
  color: var(--error);
}

/* =================
   4. NAVIGATION KEYBOARD ACCESSIBILITY FIXES
   ================= */

/* Fix skip links visibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary-600);
  color: white;
  padding: 0.5rem 1rem;
  text-decoration: none;
  border-radius: var(--radius-md);
  z-index: 9999;
}

.skip-link:focus {
  top: 10px;
  left: 10px;
}

/* Fix navigation keyboard focus */
.nav-link {
  position: relative;
  padding: 0.5rem 1rem;
  color: var(--gray-700);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}

.nav-link:focus-visible {
  outline: 3px solid var(--primary-500);
  outline-offset: 2px;
  background-color: var(--primary-50);
}

.nav-link:hover {
  background-color: var(--gray-50);
  color: var(--primary-700);
}

/* Fix mobile menu button accessibility */
.mobile-nav-toggle {
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
}

.mobile-nav-toggle:focus-visible {
  outline: 3px solid var(--primary-500);
  outline-offset: 2px;
}

.mobile-nav-toggle:hover {
  background-color: var(--gray-50);
}

/* Fix hamburger menu icon */
.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 24px;
  height: 3px;
  background-color: var(--gray-800);
  border-radius: 2px;
  transition: all var(--transition-base);
}

.hamburger {
  position: relative;
}

.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  left: 0;
}

.hamburger::before {
  top: -8px;
}

.hamburger::after {
  top: 8px;
}

/* Animate hamburger to X when active */
.mobile-nav-toggle[aria-expanded="true"] .hamburger {
  background-color: transparent;
}

.mobile-nav-toggle[aria-expanded="true"] .hamburger::before {
  top: 0;
  transform: rotate(45deg);
}

.mobile-nav-toggle[aria-expanded="true"] .hamburger::after {
  top: 0;
  transform: rotate(-45deg);
}

/* =================
   5. FAQ ACCORDION ACCESSIBILITY FIXES
   ================= */

.faq-question {
  width: 100%;
  min-height: 56px; /* Larger touch target */
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--gray-900);
  cursor: pointer;
  transition: all var(--transition-base);
}

.faq-question:hover {
  background-color: var(--gray-50);
  border-color: var(--gray-300);
}

.faq-question:focus-visible {
  outline: 3px solid var(--primary-500);
  outline-offset: 2px;
}

.faq-question[aria-expanded="true"] {
  background-color: var(--primary-50);
  border-color: var(--primary-300);
  color: var(--primary-900);
}

/* Fix FAQ answer visibility and animation */
.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-slow), padding var(--transition-slow);
  padding: 0 1.5rem;
}

.faq-item[data-expanded="true"] .faq-answer,
.faq-question[aria-expanded="true"] + .faq-answer {
  max-height: 1000px;
  padding: 1rem 1.5rem 1.5rem;
}

/* Fix FAQ icon rotation */
.faq-question svg {
  transition: transform var(--transition-base);
  flex-shrink: 0;
}

.faq-question[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

/* =================
   6. CARD COMPONENT FIXES
   ================= */

.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-xl);
  overflow: hidden;
  transition: all var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  background-color: var(--gray-50);
}

.card-header h3 {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--gray-900);
  margin: 0;
}

.card-content {
  padding: 1.5rem;
}

/* =================
   7. MODAL AND OVERLAY ACCESSIBILITY
   ================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-close {
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
}

.modal-close:hover {
  background: var(--gray-200);
}

.modal-close:focus-visible {
  outline: 3px solid var(--primary-500);
  outline-offset: 2px;
}

/* =================
   8. LOADING STATES AND SKELETON SCREENS
   ================= */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--gray-200) 25%,
    var(--gray-100) 50%,
    var(--gray-200) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-title {
  height: 1.5rem;
  width: 60%;
  margin-bottom: 1rem;
}

.skeleton-button {
  height: 44px;
  width: 120px;
}

/* =================
   9. ERROR AND SUCCESS STATES
   ================= */

.form-error {
  display: block;
  margin-top: 0.25rem;
  font-size: var(--text-sm);
  color: var(--error-dark);
}

.form-input.error {
  border-color: var(--error);
  background-color: var(--error-50);
}

.form-input.error:focus {
  border-color: var(--error-dark);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-success {
  display: block;
  margin-top: 0.25rem;
  font-size: var(--text-sm);
  color: var(--success-dark);
}

.form-input.success {
  border-color: var(--success);
  background-color: var(--success-50);
}

/* =================
   10. MOBILE RESPONSIVE IMPROVEMENTS
   ================= */

@media (max-width: 640px) {
  /* Stack buttons vertically on mobile */
  .hero-action {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  
  .btn {
    width: 100%;
  }
  
  /* Improve mobile navigation */
  .nav {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    box-shadow: var(--shadow-lg);
    transform: translateY(-100%);
    transition: transform var(--transition-base);
    z-index: 998;
    padding: 1rem;
  }
  
  .nav.active {
    transform: translateY(0);
  }
  
  .nav-link {
    display: block;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
  }
  
  /* Improve form layout on mobile */
  .lookup-form {
    padding: 1rem;
  }
  
  /* Improve card spacing on mobile */
  .card {
    margin-bottom: 1rem;
  }
  
  .card-header {
    padding: 1rem;
  }
  
  .card-content {
    padding: 1rem;
  }
  
  /* Adjust typography for mobile */
  h1 {
    font-size: var(--text-3xl);
  }
  
  h2 {
    font-size: var(--text-2xl);
  }
  
  h3 {
    font-size: var(--text-xl);
  }
}

/* =================
   11. PRINT STYLES
   ================= */

@media print {
  .no-print,
  .mobile-nav-toggle,
  .skip-link,
  .btn,
  .footer {
    display: none !important;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: black;
    background: white;
  }
  
  .container {
    max-width: 100%;
    padding: 0;
  }
  
  a {
    color: black;
    text-decoration: underline;
  }
  
  .card {
    page-break-inside: avoid;
    border: 1px solid #ccc;
    margin-bottom: 1rem;
  }
}

/* =================
   12. FOCUS TRAP FOR MODALS
   ================= */

.focus-trap {
  position: fixed;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =================
   13. IMPROVED TRANSITIONS
   ================= */

.fade-in {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.slide-in {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(-100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* =================
   14. HIGH CONTRAST MODE SUPPORT
   ================= */

@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }
  
  .form-input {
    border-width: 2px;
  }
  
  .card {
    border-width: 2px;
  }
}

/* =================
   15. REDUCED MOTION SUPPORT
   ================= */

@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;
  }
}