/* 
 * Mobile Base Styles
 * Universal mobile compatibility rules for all pages
 * Import this file in all HTML pages for consistent mobile behavior
 */

/* Prevent text size adjustment on orientation change (iOS) */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Better box model */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Smooth scrolling on all devices */
html {
  scroll-behavior: smooth;
}

/* Better font rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Remove tap highlight on mobile (custom colors will be used) */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Better focus outline for accessibility */
*:focus-visible {
  outline: 2px solid rgba(33, 82, 255, 0.6);
  outline-offset: 2px;
}

/* Prevent iOS zoom on input focus */
@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* Minimum touch target size (44x44px recommended by Apple, Google) */
@media (max-width: 768px) {
  button,
  a,
  input[type="button"],
  input[type="submit"],
  input[type="reset"],
  label[for],
  .clickable,
  [role="button"],
  [role="link"] {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Better select styling on mobile */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  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='%23374151' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Better checkbox and radio button sizing on mobile */
@media (max-width: 768px) {
  input[type="checkbox"],
  input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
    width: 20px;
    height: 20px;
  }
}

/* Responsive images */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Responsive videos and iframes */
iframe,
video,
embed,
object {
  max-width: 100%;
}

/* Better table overflow on mobile */
@media (max-width: 768px) {
  .table-responsive,
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }

  table {
    min-width: 600px;
  }
}

/* Safe area insets for notched devices (iPhone X and newer) */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  .fixed-header,
  .fixed-footer {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* Prevent horizontal scroll */
body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* Better button active states on mobile */
@media (max-width: 768px) {
  button:active,
  a:active,
  [role="button"]:active {
    opacity: 0.7;
    transform: scale(0.98);
  }
}

/* Remove default button styles but keep accessibility */
button {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Better form field spacing on mobile */
@media (max-width: 768px) {
  form {
    max-width: 100%;
  }

  input,
  textarea,
  select,
  button {
    max-width: 100%;
  }
}

/* Prevent zoom on double-tap */
@media (max-width: 768px) {
  * {
    touch-action: manipulation;
  }

  /* Allow pinch-zoom on images */
  img,
  video,
  canvas {
    touch-action: pinch-zoom;
  }
}

/* Better scrollbar on mobile (when visible) */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.5);
}

/* Hide scrollbar but keep functionality on mobile */
@media (max-width: 768px) {
  .hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  .hide-scrollbar::-webkit-scrollbar {
    display: none;
  }
}

/* Better text selection */
::selection {
  background: rgba(33, 82, 255, 0.3);
  color: inherit;
}

::-moz-selection {
  background: rgba(33, 82, 255, 0.3);
  color: inherit;
}

/* Landscape orientation optimizations */
@media (max-width: 896px) and (orientation: landscape) {
  .mobile-landscape-adjust {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  /* Reduce vertical spacing in landscape */
  h1,
  h2,
  h3 {
    margin-top: 0.75em;
    margin-bottom: 0.5em;
  }
}

/* Print optimizations */
@media print {
  /* Remove interactive elements */
  button,
  .btn,
  nav,
  .navigation,
  .sidebar,
  footer,
  .no-print {
    display: none !important;
  }

  /* Better page breaks */
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    page-break-after: avoid;
  }

  img,
  table,
  figure {
    page-break-inside: avoid;
  }

  /* Remove backgrounds and shadows */
  * {
    background: transparent !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  /* Black text for printing */
  body {
    color: #000 !important;
  }

  a {
    text-decoration: underline;
  }

  /* Show URLs after links */
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }

  /* Don't show URLs for anchor links */
  a[href^="#"]:after,
  a[href^="javascript:"]:after {
    content: "";
  }
}

/* Accessibility improvements */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip to main content link */
.skip-to-content {
  position: absolute;
  top: -40px;
  left: 0;
  background: #2152ff;
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
}

.skip-to-content:focus {
  top: 0;
}

/* Reduced motion for users who prefer it */
@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;
  }
}

/* Dark mode support (if implemented) */
@media (prefers-color-scheme: dark) {
  /* Base dark mode variables can be defined here */
  :root {
    color-scheme: dark;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }

  button,
  a {
    text-decoration: underline;
  }
}

/* Loading state for better UX */
.loading {
  pointer-events: none;
  opacity: 0.6;
  cursor: wait;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid rgba(33, 82, 255, 0.3);
  border-top-color: #2152ff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Utility classes for mobile */
@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .show-mobile {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .hide-mobile-sm {
    display: none !important;
  }
}

/* Text utilities */
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .text-truncate-mobile {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Spacing utilities for mobile */
@media (max-width: 768px) {
  .mt-mobile-sm {
    margin-top: 0.5rem;
  }
  .mt-mobile-md {
    margin-top: 1rem;
  }
  .mt-mobile-lg {
    margin-top: 1.5rem;
  }

  .mb-mobile-sm {
    margin-bottom: 0.5rem;
  }
  .mb-mobile-md {
    margin-bottom: 1rem;
  }
  .mb-mobile-lg {
    margin-bottom: 1.5rem;
  }

  .px-mobile-sm {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  .px-mobile-md {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .px-mobile-lg {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  .py-mobile-sm {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }
  .py-mobile-md {
    padding-top: 1rem;
    padding-bottom: 1rem;
  }
  .py-mobile-lg {
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
  }
}

/* Full width on mobile */
@media (max-width: 768px) {
  .full-width-mobile {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* Stack items vertically on mobile */
@media (max-width: 768px) {
  .stack-mobile {
    flex-direction: column !important;
  }

  .stack-mobile > * {
    width: 100% !important;
  }
}
