/* Cross-Browser Compatibility Fixes for Atlobly */

/* ========================================
   1. CSS Reset and Normalization
   ======================================== */

/* Apply box-sizing globally */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

/* ========================================
   2. HTML and Body Base Styles
   ======================================== */

html {
  -webkit-text-size-adjust: 100%; /* Prevent font scaling in iOS landscape */
  -ms-text-size-adjust: 100%; /* Prevent font scaling in IE */
  text-size-adjust: 100%;
  font-size: 100%;
  line-height: 1.15; /* Normalize line height */
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

/* ========================================
   3. RTL/LTR Direction Support
   ======================================== */

/* RTL Support for Arabic */
html[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

html[dir="ltr"] {
  direction: ltr;
  text-align: left;
}

/* Body text alignment based on direction */
html[dir="rtl"] body {
  text-align: right;
}

html[dir="ltr"] body {
  text-align: left;
}

/* ========================================
   4. Form Elements Cross-Browser Fixes
   ======================================== */

/* Ensure all form inputs have consistent appearance */
input,
textarea,
select,
button {
  font-family: inherit;
  font-size: 100%;
  line-height: 1.15;
  margin: 0;
}

/* Remove default button styling in Safari */
button,
[type="button"],
[type="reset"],
[type="submit"] {
  -webkit-appearance: button;
  appearance: button;
}

/* Input direction for RTL */
html[dir="rtl"] input,
html[dir="rtl"] textarea,
html[dir="rtl"] select {
  text-align: right;
  direction: rtl;
}

html[dir="ltr"] input,
html[dir="ltr"] textarea,
html[dir="ltr"] select {
  text-align: left;
  direction: ltr;
}

/* Placeholder alignment for RTL */
html[dir="rtl"] input::placeholder,
html[dir="rtl"] textarea::placeholder {
  text-align: right;
  direction: rtl;
}

html[dir="ltr"] input::placeholder,
html[dir="ltr"] textarea::placeholder {
  text-align: left;
  direction: ltr;
}

/* Fix input padding in RTL */
html[dir="rtl"] input[type="text"],
html[dir="rtl"] input[type="email"],
html[dir="rtl"] input[type="password"],
html[dir="rtl"] textarea {
  padding-right: 1rem;
  padding-left: 0.5rem;
}

/* Remove inner padding in Firefox */
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
  border-style: none;
  padding: 0;
}

/* ========================================
   5. Flexbox Compatibility
   ======================================== */

/* Ensure flexbox works consistently across browsers */
.flex {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

.flex-col {
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
}

.items-center {
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

.justify-center {
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}

/* ========================================
   6. Image and Media Elements
   ======================================== */

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

/* Prevent images from being draggable in Safari */
img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
}

/* ========================================
   7. SVG and Icon Fixes
   ======================================== */

svg {
  overflow: hidden;
  vertical-align: middle;
}

/* Ensure SVG icons maintain LTR in RTL layouts */
html[dir="rtl"] svg {
  direction: ltr;
}

/* Material Icons fix for RTL */
.material-icons {
  font-family: 'Material Icons' !important;
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}

/* ========================================
   8. Grid Layout Compatibility
   ======================================== */

.grid {
  display: -ms-grid;
  display: grid;
}

/* ========================================
   9. Smooth Scrolling (with fallback)
   ======================================== */

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* ========================================
   10. Print Styles
   ======================================== */

@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
}

/* ========================================
   11. Browser-Specific Fixes
   ======================================== */

/* Safari-specific fixes */
@supports (-webkit-appearance: none) {
  input[type="search"] {
    -webkit-appearance: textfield;
  }
  
  input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
  }
}

/* Firefox-specific fixes */
@-moz-document url-prefix() {
  /* Add Firefox-specific fixes here if needed */
}

/* Edge-specific fixes */
@supports (-ms-ime-align: auto) {
  /* Add Edge-specific fixes here if needed */
}

/* ========================================
   12. Mobile-Specific Fixes
   ======================================== */

@media (max-width: 768px) {
  /* Prevent text size adjustment on orientation change */
  html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
  }
  
  /* Improve tap targets on mobile */
  button,
  a,
  input,
  select,
  textarea {
    min-height: 44px; /* Apple's recommended minimum touch target */
  }
}

/* ========================================
   13. High Contrast Mode Support
   ======================================== */

@media (prefers-contrast: high) {
  /* Enhance visibility in high contrast mode */
  button,
  input,
  select,
  textarea {
    border: 2px solid currentColor;
  }
}

/* ========================================
   14. Dark Mode Support
   ======================================== */

@media (prefers-color-scheme: dark) {
  /* Base dark mode adjustments handled by Tailwind */
  /* Add any additional dark mode fixes here */
}
