/* ============================================
   CLASS-MARKET - MOBILE OPTIMIZATION CSS
   Touch-Friendly, Accessibility & Performance
============================================ */

/* ============================================
   TOUCH DEVICE OPTIMIZATION
============================================ */

@media (hover: none) and (pointer: coarse) {
  /* Increase touch target sizes for mobile devices */
  a, button, input[type="button"], input[type="submit"] {
    min-height: 48px;
    min-width: 48px;
    padding: 12px 16px;
  }

  /* Remove hover effects on touch devices */
  .btn::before,
  .btn::after {
    display: none;
  }

  /* Simplify transitions for touch */
  * {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  }
}

/* ============================================
   MOBILE LANDSCAPE MODE
============================================ */

@media (max-height: 500px) and (orientation: landscape) {
  main {
    padding-top: 40px;
  }

  section {
    padding: 20px 0;
  }

  h1, h2, h3, h4 {
    margin: 10px 0;
  }

  .header {
    height: auto;
    padding: 4px 0;
  }

  .logo-image {
    max-height: 24px;
  }
}

/* ============================================
   SMALL MOBILE SCREENS (320px and below)
============================================ */

@media (max-width: 320px) {
  .container {
    padding: 0 8px;
  }

  h1 {
    font-size: 1.25rem;
    line-height: 1.3;
  }

  h2 {
    font-size: 1.1rem;
    line-height: 1.3;
  }

  h3 {
    font-size: 0.95rem;
  }

  p {
    font-size: 0.8rem;
    line-height: 1.5;
  }

  .btn {
    padding: 10px 14px;
    font-size: 0.75rem;
  }

  form {
    display: flex;
    flex-direction: column;
  }

  input, select, textarea {
    margin-bottom: 8px;
    font-size: 16px;
  }
}

/* ============================================
   IMAGE OPTIMIZATION FOR MOBILE
============================================ */

img {
  max-width: 100%;
  height: auto;
  display: block;
}

picture {
  display: block;
  width: 100%;
}

/* Optimize hero images and background images */
[class*="hero"] img,
[class*="Hero"] img {
  width: 100%;
  height: auto;
  object-fit: cover;
  object-position: center;
}

/* ============================================
   TEXT READABLE ON MOBILE
============================================ */

/* Ensure minimum font size for readability */
@media (max-width: 768px) {
  body {
    font-size: 15px;
  }

  input, select, textarea {
    font-size: 16px;
  }
}

/* ============================================
   FORM OPTIMIZATION FOR MOBILE
============================================ */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
input[type="time"],
textarea,
select {
  width: 100%;
  padding: 12px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-family: inherit;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
  background-color: white;
}

select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 24px;
  padding-right: 32px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}

/* Checkbox and radio optimization */
input[type="checkbox"],
input[type="radio"] {
  width: 20px;
  height: 20px;
  margin-right: 8px;
  cursor: pointer;
}

/* ============================================
   MODAL & POPUP OPTIMIZATION FOR MOBILE
============================================ */

@media (max-width: 768px) {
  [class*="modal"],
  [class*="Modal"],
  [class*="dialog"],
  [class*="Dialog"] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    padding: 0;
    margin: 0;
  }

  [class*="modal-content"],
  [class*="Modal-content"],
  [class*="dialog-content"],
  [class*="Dialog-content"] {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================
   SCROLL OPTIMIZATION
============================================ */

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Momentum scrolling for mobile */
body, [class*="scroll"] {
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   NAVIGATION MOBILE OPTIMIZATION
============================================ */

/* Ensure mobile menu is full width and properly positioned */
.nav {
  position: fixed;
  top: 100%;
  left: 0;
  right: 0;
  width: 100%;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 999;
}

/* ============================================
   TABLE MOBILE OPTIMIZATION
============================================ */

@media (max-width: 768px) {
  table {
    width: 100%;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
  }

  tbody {
    display: block;
  }

  tr {
    display: block;
    margin-bottom: 15px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
  }

  td, th {
    display: block;
    text-align: right;
    padding: 8px;
    position: relative;
    padding-left: 50%;
  }

  td:before, th:before {
    content: attr(data-label);
    position: absolute;
    left: 8px;
    font-weight: bold;
    width: 45%;
    text-align: left;
  }
}

/* ============================================
   SAFE AREA INSETS FOR NOTCHED PHONES
============================================ */

@supports (padding: max(0px)) {
  body {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .header {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
}

/* ============================================
   PERFORMANCE OPTIMIZATION
============================================ */

/* Disable expensive animations on low-end devices */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================
   DARK THEME SUPPORT (Optional)
============================================ */

@media (prefers-color-scheme: dark) {
  input, select, textarea {
    background-color: #1e293b;
    color: white;
    border-color: #334155;
  }

  input:focus, select:focus, textarea:focus {
    border-color: #0ea5e9;
  }

  label {
    color: white;
  }
}

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

@media (prefers-contrast: more) {
  * {
    border-width: 2px;
  }

  button, input[type="button"], input[type="submit"] {
    font-weight: bold;
    text-transform: uppercase;
  }
}

/* ============================================
   PRINT STYLES
============================================ */

@media print {
  header, footer, nav, [class*="menu"], [class*="sidebar"] {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  a {
    text-decoration: underline;
  }

  section {
    page-break-inside: avoid;
    margin: 0;
    padding: 10px 0;
  }
}

/* ============================================
   UTILITY CLASSES FOR RESPONSIVE
============================================ */

.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none;
  }
}

.container-fluid {
  width: 100%;
  max-width: none;
}

/* Safe spacing for mobile */
.p-mobile { padding: 12px 16px; }
.m-mobile { margin: 12px 16px; }
.pt-mobile { padding-top: 12px; }
.pb-mobile { padding-bottom: 12px; }
.mt-mobile { margin-top: 12px; }
.mb-mobile { margin-bottom: 12px; }

@media (max-width: 768px) {
  .p-mobile { padding: 10px 12px; }
  .m-mobile { margin: 10px 12px; }
}

@media (max-width: 480px) {
  .p-mobile { padding: 8px 10px; }
  .m-mobile { margin: 8px 10px; }
}
