/**
 * 🌍 TrackMyIVF Global Styles
 * Consolidated global styles using design tokens
 * Includes: base styles, utilities, accessibility
 */

/* =================================================================
   IMPORTS
   ================================================================= */

/* Design tokens must be loaded first */
@import "design-tokens.css";

/* =================================================================
   CSS RESET & BASE STYLES
   ================================================================= */

/* Box sizing rules */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Remove default margin and padding */
* {
  margin: 0;
  padding: 0;
}

/* Prevent font size inflation */
html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  scroll-padding-top: var(--nav-height);
  scroll-behavior: smooth;
}

/* Core body defaults */
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-gray-900);
  background-color: var(--color-white);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  text-rendering: optimizeSpeed;
  overflow-x: hidden;
}

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

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  color: var(--color-gray-900);
  margin-bottom: var(--space-4);
}

h1 {
  font-size: var(--text-5xl);
  line-height: var(--leading-none);
  letter-spacing: var(--tracking-tight);
}

h2 {
  font-size: var(--text-4xl);
}

h3 {
  font-size: var(--text-3xl);
}

h4 {
  font-size: var(--text-2xl);
}

h5 {
  font-size: var(--text-xl);
}

h6 {
  font-size: var(--text-lg);
}

/* Paragraphs */
p {
  margin-bottom: var(--space-4);
  line-height: var(--leading-relaxed);
  color: var(--color-gray-700);
}

/* Links */
a {
  color: var(--color-purple-600);
  text-decoration: none;
  transition: color var(--transition-fast) var(--ease-out);
  cursor: pointer;
}

a:hover {
  color: var(--color-purple-700);
  text-decoration: underline;
}

/* Lists */
ul, ol {
  margin-bottom: var(--space-4);
  padding-left: var(--space-6);
}

li {
  margin-bottom: var(--space-2);
  line-height: var(--leading-relaxed);
}

/* =================================================================
   MEDIA & EMBEDS
   ================================================================= */

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

img {
  object-fit: cover;
}

/* =================================================================
   FORMS & INPUTS (with accessibility enhancements)
   ================================================================= */

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

/* Text inputs with tremor-safe sizing */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea,
select {
  width: 100%;
  min-height: var(--space-14); /* 56px for tremor-safe */
  padding: var(--space-4);
  font-size: var(--text-lg); /* 18px prevents iOS zoom */
  border: 2px solid var(--color-purple-200);
  border-radius: var(--radius-md);
  background-color: var(--color-white);
  transition: all var(--transition-base) var(--ease-out);
  -webkit-appearance: none;
  appearance: none;
}

/* Focus states for low vision */
input:focus,
textarea:focus,
select:focus,
button:focus,
a:focus {
  outline: 3px solid var(--color-purple-500);
  outline-offset: 4px;
  box-shadow: 0 0 0 4px var(--color-purple-500-10);
}

/* Placeholders */
::placeholder {
  color: var(--color-gray-400);
  opacity: 1;
}

/* Disabled states */
input:disabled,
textarea:disabled,
select:disabled,
button:disabled {
  background-color: var(--color-gray-50);
  color: var(--color-gray-500);
  cursor: not-allowed;
  opacity: 0.7;
}

/* =================================================================
   BUTTONS (Guardian Framework compliant)
   ================================================================= */

button {
  min-height: var(--space-15); /* 60px tremor-safe */
  padding: var(--space-4) var(--space-6);
  margin: var(--space-2-5) 0;
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
  border-radius: var(--radius-lg);
  border: none;
  background: none;
  cursor: pointer;
  transition: all var(--transition-base) var(--ease-out);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

/* Spacing between buttons */
button + button {
  margin-left: var(--space-5);
}

/* =================================================================
   ACCESSIBILITY ENHANCEMENTS
   ================================================================= */

/* Larger clickable areas for links */
a:not(.nav-link):not(.btn-base) {
  padding: var(--space-2) var(--space-1);
  margin: calc(var(--space-2) * -1) calc(var(--space-1) * -1);
  display: inline-block;
}

/* Larger checkboxes and radio buttons */
input[type="checkbox"],
input[type="radio"] {
  width: var(--space-6);
  height: var(--space-6);
  margin: var(--space-1) var(--space-2);
  cursor: pointer;
}

/* Error messages (warm, not harsh) */
.error,
.error-message {
  color: var(--color-warning-600);
  background-color: var(--color-warning-100);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-warning-500);
  font-size: var(--text-base);
  margin: var(--space-2) 0;
}

/* Success messages */
.success,
.success-message {
  color: var(--color-success-600);
  background-color: var(--color-success-100);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-success-500);
  font-size: var(--text-base);
  margin: var(--space-2) 0;
}

/* Loading states with breathing animation */
.loading {
  animation: breathe var(--breathe-duration) ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { 
    opacity: var(--breathe-opacity-min); 
    transform: scale(var(--breathe-scale-min)); 
  }
  50% { 
    opacity: var(--breathe-opacity-max); 
    transform: scale(var(--breathe-scale-max)); 
  }
}

/* =================================================================
   IOS COMPATIBILITY
   ================================================================= */

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* Fix iOS input zoom */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px; /* Prevents zoom */
  }
  
  /* iOS smooth scrolling */
  .mobile-menu-panel {
    -webkit-overflow-scrolling: touch;
  }
  
  /* iOS tap highlight */
  button,
  a {
    -webkit-tap-highlight-color: var(--color-purple-500-10);
  }
}

/* =================================================================
   MOBILE OPTIMIZATIONS
   ================================================================= */

/* Ensure all interactive elements meet 44px minimum */
button, 
a,
input,
textarea,
select,
.clickable,
[role="button"] {
  min-height: var(--space-11);
  min-width: var(--space-11);
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
  /* Full-width buttons on mobile */
  button {
    width: 100%;
    margin: var(--space-3) 0;
  }
  
  button + button {
    margin-left: 0;
  }
  
  /* Stack form elements */
  .flex.gap-4 {
    flex-direction: column;
  }
  
  /* Reduce padding on mobile */
  .container {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }
}

/* Landscape orientation fixes */
@media (max-height: 500px) and (orientation: landscape) {
  /* Reduce vertical spacing */
  .py-20 {
    padding-top: var(--space-8);
    padding-bottom: var(--space-8);
  }
  
  .pt-32 {
    padding-top: var(--space-16);
  }
}

/* =================================================================
   UTILITY CLASSES
   ================================================================= */

/* Display utilities */
/* REMOVED: .hidden class to prevent navigation conflicts - use .nav-hidden for navigation */
.block { display: block; }
.inline-block { display: inline-block; }
.flex { display: flex; }

/* Modal-specific hidden class to prevent navigation conflicts */
#successModal.hidden {
  display: none !important;
}
.inline-flex { display: inline-flex; }
.grid { display: grid; }

/* Navigation-specific visibility classes to avoid conflicts */
.nav-hidden { 
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

.nav-visible {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Flexbox utilities */
.flex-row { flex-direction: row; }
.flex-col { flex-direction: column; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.justify-between { justify-content: space-between; }

/* Gap utilities */
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* Spacing utilities */
.p-0 { padding: var(--space-0); }
.p-2 { padding: var(--space-2); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }

.m-0 { margin: var(--space-0); }
.m-2 { margin: var(--space-2); }
.m-4 { margin: var(--space-4); }
.m-6 { margin: var(--space-6); }
.m-8 { margin: var(--space-8); }

.mx-auto { 
  margin-left: auto; 
  margin-right: auto; 
}

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

/* Width utilities */
.w-full { width: 100%; }
.max-w-full { max-width: 100%; }

/* Container */
.container {
  width: 100%;
  max-width: var(--container-2xl);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

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

/* =================================================================
   THEME UTILITIES
   ================================================================= */

/* Background colors */
.bg-white { background-color: var(--color-white); }
.bg-purple-50 { background-color: var(--color-purple-50); }
.bg-purple-100 { background-color: var(--color-purple-100); }
.bg-purple-500 { background-color: var(--color-purple-500); }
.bg-purple-600 { background-color: var(--color-purple-600); }
.bg-purple-700 { background-color: var(--color-purple-700); }

/* Text colors */
.text-white { color: var(--color-white); }
.text-gray-500 { color: var(--color-gray-500); }
.text-gray-600 { color: var(--color-gray-600); }
.text-gray-700 { color: var(--color-gray-700); }
.text-gray-900 { color: var(--color-gray-900); }
.text-purple-500 { color: var(--color-purple-500); }
.text-purple-600 { color: var(--color-purple-600); }
.text-purple-700 { color: var(--color-purple-700); }

/* Border radius utilities */
.rounded-none { border-radius: var(--radius-none); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-2xl { border-radius: var(--radius-2xl); }
.rounded-3xl { border-radius: var(--radius-3xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Shadow utilities */
.shadow-none { box-shadow: none; }
.shadow-xs { box-shadow: var(--shadow-xs); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-xl { box-shadow: var(--shadow-xl); }

/* =================================================================
   PERFORMANCE & ACCESSIBILITY
   ================================================================= */

/* Reduce motion for accessibility */
@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;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  button,
  .btn-base {
    border: 2px solid currentColor !important;
  }
  
  input,
  textarea,
  select {
    border-width: 3px !important;
  }
}

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-purple-600);
  color: var(--color-white);
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  border-radius: var(--radius-md);
  z-index: var(--z-modal);
}

.skip-link:focus {
  top: var(--space-4);
  left: var(--space-4);
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}