/**
 * Cross-Browser Compatibility Styles
 * Addresses browser-specific issues for Chrome, Firefox, Safari, and Edge
 */

/* ============================================
   FLEXBOX FIXES
   ============================================ */

/* Fix for IE11 and older Edge flexbox bugs */
.d-flex,
.flex-row,
.flex-column {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}
.mt-3
{
    margin-top: 1rem;
}
.d-inline-flex {
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
}

/* Flex direction fixes */
.flex-row {
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
}

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

/* Flex wrap fixes */
.flex-wrap {
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

/* Justify content fixes */
.justify-center {
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}

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

.justify-around {
  -ms-flex-pack: distribute;
  justify-content: space-around;
}

/* Align items fixes */
.align-center {
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

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

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

/* Flex grow/shrink fixes */
.flex-grow-1 {
  -webkit-box-flex: 1;
  -ms-flex-positive: 1;
  flex-grow: 1;
}

.flex-shrink-0 {
  -ms-flex-negative: 0;
  flex-shrink: 0;
}

/* ============================================
   GRID FIXES
   ============================================ */

/* Grid display with fallback */
.d-grid,
.grid {
  display: -ms-grid;
  display: grid;
}

/* Grid gap fallback for older browsers */
@supports not (gap: var(--spacing-4)) {
  .grid > * {
    margin-bottom: var(--spacing-4);
  }

  .grid > *:last-child {
    margin-bottom: 0;
  }
}

/* ============================================
   TRANSFORM FIXES
   ============================================ */

/* Add vendor prefixes for transforms */
.sidebar {
  -webkit-transform: translateX(0);
  -ms-transform: translateX(0);
  transform: translateX(0);
}

.sidebar.mobile-open {
  -webkit-transform: translateX(0);
  -ms-transform: translateX(0);
  transform: translateX(0);
}

/* Transform for modals */
.modal-dialog {
  -webkit-transform: scale(0.9) translateY(-20px);
  -ms-transform: scale(0.9) translateY(-20px);
  transform: scale(0.9) translateY(-20px);
}

.modal.active .modal-dialog {
  -webkit-transform: scale(1) translateY(0);
  -ms-transform: scale(1) translateY(0);
  transform: scale(1) translateY(0);
}

/* Transform for hover effects */
.card-hover:hover {
  -webkit-transform: translateY(-2px);
  -ms-transform: translateY(-2px);
  transform: translateY(-2px);
}

/* ============================================
   TRANSITION FIXES
   ============================================ */

/* Add vendor prefixes for transitions */
.btn,
.nav-item,
.form-input,
.form-select,
.form-textarea,
.card,
.modal-backdrop,
.modal-dialog,
.sidebar {
  -webkit-transition: all var(--transition-base);
  -o-transition: all var(--transition-base);
  transition: all var(--transition-base);
}

/* ============================================
   APPEARANCE FIXES
   ============================================ */

/* Remove default appearance for form elements */
.form-input,
.form-select,
.form-textarea,
.btn {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Fix for select dropdown arrow in Safari */
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--spacing-3) center;
  padding-right: var(--spacing-8);
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */

/* Webkit browsers (Chrome, Safari, Edge) */
.sidebar::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.sidebar::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

.sidebar::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.table-responsive::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Firefox scrollbar styling */
.sidebar,
.table-responsive,
.modal-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.05);
}

/* ============================================
   INPUT TYPE="NUMBER" FIXES
   ============================================ */

/* Remove spinner buttons in Chrome, Safari, Edge */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Remove spinner buttons in Firefox */
input[type="number"] {
  -moz-appearance: textfield;
}

/* ============================================
   PLACEHOLDER FIXES
   ============================================ */

/* Placeholder styling for all browsers */
.form-input::-webkit-input-placeholder,
.form-textarea::-webkit-input-placeholder {
  color: var(--text-light);
  opacity: 1;
}

.form-input::-moz-placeholder,
.form-textarea::-moz-placeholder {
  color: var(--text-light);
  opacity: 1;
}

.form-input:-ms-input-placeholder,
.form-textarea:-ms-input-placeholder {
  color: var(--text-light);
  opacity: 1;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-light);
  opacity: 1;
}

/* ============================================
   FOCUS OUTLINE FIXES
   ============================================ */

/* Remove default focus outline and add custom one */
.btn:focus,
.form-input:focus,
.form-select:focus,
.form-textarea:focus,
.form-check-input:focus {
  outline: none;
  outline: 0;
}

/* Add visible focus for accessibility */
.btn:focus-visible,
.form-input:focus-visible,
.form-select:focus-visible,
.form-textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ============================================
   BUTTON FIXES
   ============================================ */

/* Remove default button styling in Safari */
button,
.btn {
  -webkit-appearance: button;
  -moz-appearance: button;
  appearance: button;
}

/* Fix button text rendering in Safari */
button,
.btn {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent button text selection */
button,
.btn {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* ============================================
   CHECKBOX AND RADIO FIXES
   ============================================ */

/* Custom checkbox styling for consistency */
.form-check-input[type="checkbox"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-card);
  cursor: pointer;
  position: relative;
}

.form-check-input[type="checkbox"]:checked {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}

.form-check-input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}

/* Custom radio styling for consistency */
.form-check-input[type="radio"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background-color: var(--bg-card);
  cursor: pointer;
  position: relative;
}

.form-check-input[type="radio"]:checked {
  border-color: var(--color-primary);
}

.form-check-input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-primary);
}

/* ============================================
   SVG FIXES
   ============================================ */

/* Fix SVG rendering in IE11 */
svg {
  max-width: 100%;
  height: auto;
}

/* Fix SVG alignment */
svg:not(:root) {
  overflow: hidden;
}

/* ============================================
   POSITION STICKY FIXES
   ============================================ */

/* Add vendor prefix for position sticky */
.top-header {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
}

/* ============================================
   BACKDROP FILTER FIXES (Safari)
   ============================================ */

/* Add vendor prefix for backdrop-filter */
.modal-backdrop {
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* ============================================
   OBJECT-FIT FIXES
   ============================================ */

/* Add vendor prefix for object-fit */
img {
  -o-object-fit: cover;
  object-fit: cover;
}

/* ============================================
   SMOOTH SCROLLING FIXES
   ============================================ */

/* Smooth scrolling for Safari */
html {
  -webkit-overflow-scrolling: touch;
}

/* Smooth scrolling for all browsers */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* ============================================
   TEXT RENDERING FIXES
   ============================================ */

/* Improve text rendering across browsers */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* ============================================
   OVERFLOW FIXES
   ============================================ */

/* Fix overflow scrolling on iOS */
.sidebar,
.modal-body,
.table-responsive {
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   Z-INDEX FIXES
   ============================================ */

/* Ensure proper stacking context */
.sidebar {
  z-index: 1000;
  position: fixed;
}

.top-header {
  z-index: 100;
  position: -webkit-sticky;
  position: sticky;
}

.mobile-backdrop {
  z-index: 999;
  position: fixed;
}

.modal {
  z-index: 2000;
  position: fixed;
}

.modal-dialog {
  z-index: 2001;
  position: relative;
}

/* ============================================
   PRINT FIXES
   ============================================ */

@media print {
  /* Ensure colors print correctly */
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Remove shadows for print */
  .card,
  .btn,
  .modal-dialog {
    box-shadow: none !important;
  }
}

/* ============================================
   SAFARI-SPECIFIC FIXES
   ============================================ */

/* Fix for Safari date input */
input[type="date"],
input[type="time"],
input[type="datetime-local"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

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

/* ============================================
   FIREFOX-SPECIFIC FIXES
   ============================================ */

/* Fix for Firefox button focus */
button::-moz-focus-inner {
  border: 0;
}

/* Fix for Firefox select dropdown */
select:-moz-focusring {
  color: transparent;
  text-shadow: 0 0 0 var(--text-primary);
}

/* ============================================
   EDGE-SPECIFIC FIXES
   ============================================ */

/* Fix for Edge clear button on inputs */
input::-ms-clear,
input::-ms-reveal {
  display: none;
  width: 0;
  height: 0;
}

/* Fix for Edge select dropdown */
select::-ms-expand {
  display: none;
}

/* ============================================
   CHROME-SPECIFIC FIXES
   ============================================ */

/* Fix for Chrome autofill background */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 30px var(--bg-card) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
}

/* ============================================
   MOBILE SAFARI FIXES
   ============================================ */

/* Fix for iOS Safari input zoom */
@media screen and (max-width: 767px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* Fix for iOS Safari button tap highlight */
button,
.btn,
a {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/* Fix for iOS Safari momentum scrolling */
.sidebar,
.modal-body,
.table-responsive {
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   ACCESSIBILITY FIXES
   ============================================ */

/* Ensure focus is visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Remove focus outline for mouse users */
*:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================
   HIGH CONTRAST MODE SUPPORT
   ============================================ */

@media (prefers-contrast: high) {
  .btn {
    border-width: 2px;
  }

  .card {
    border: 2px solid var(--border-color);
  }

  .form-input,
  .form-select,
  .form-textarea {
    border-width: 2px;
  }
}

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    -webkit-animation-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    -webkit-animation-iteration-count: 1 !important;
    animation-iteration-count: 1 !important;
    -webkit-transition-duration: 0.01ms !important;
    -o-transition-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
