/* Mobile Optimizations for TNT Enterprise */
/* Touch-friendly, responsive, and performant */

/* ==================== Touch Optimizations ==================== */

/* Größere Touch-Targets für bessere Bedienbarkeit */
@media (max-width: 768px) {
  button,
  .btn,
  a.button,
  .nav-link {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1.5rem;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px; /* Verhindert Zoom auf iOS */
  }
}

/* Touch-Feedback */
button:active,
.btn:active,
a.button:active,
.product-card:active {
  transform: scale(0.97);
  opacity: 0.9;
}

/* ==================== Safe Area für iPhone X+ ==================== */
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ==================== Image Lazy Loading (Native) ==================== */
img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.3s ease-in;
}

img[loading="lazy"].loaded {
  opacity: 1;
}

/* ==================== Smooth Scrolling ==================== */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* ==================== Mobile Navigation Verbesserungen ==================== */
@media (max-width: 768px) {
  .navbar {
    padding: 0.75rem 1rem;
  }


  .nav-menu.active {
    display: flex;
  }

  .nav-link {
    padding: 1rem;
    width: 100%;
    text-align: left;
    border-radius: 8px;
  }

  .hamburger {
    display: flex;
  }
}

/* Mobile Overlay für Navigation */
.mobile-nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 998;
}

.mobile-nav-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* ==================== Swipe-freundliche Galerien ==================== */
.product-gallery,
.image-gallery {
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  display: flex;
  gap: 1rem;
}

.product-gallery::-webkit-scrollbar,
.image-gallery::-webkit-scrollbar {
  display: none;
}

.product-gallery > *,
.image-gallery > * {
  scroll-snap-align: center;
  flex-shrink: 0;
}

/* ==================== Responsive Grid Improvements ==================== */
@media (max-width: 1200px) {
  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

@media (max-width: 768px) {
  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
  }

  .product-card {
    border-radius: 12px;
  }
}

@media (max-width: 480px) {
  .products-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* ==================== Bessere Modal-Darstellung auf Mobile ==================== */
@media (max-width: 768px) {
  .modal-content,
  .login-modal-content {
    width: 95%;
    max-width: 95%;
    margin: 1rem;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-header h2 {
    font-size: 1.5rem;
  }
}

/* ==================== Form Verbesserungen ==================== */
@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
    gap: 1rem;
  }

  .form-group {
    width: 100%;
  }
}

/* ==================== Cart Sidebar Mobile ==================== */
@media (max-width: 768px) {
  .cart-sidebar {
    width: 100%;
    max-width: 100%;
  }
}

/* ==================== Prevent Horizontal Scroll ==================== */
body,
html {
  overflow-x: hidden;
}

* {
  box-sizing: border-box;
}

/* ==================== iOS Specific Fixes ==================== */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari */
  input,
  textarea,
  select {
    font-size: 16px !important; /* Verhindert Zoom */
  }

  /* Safe Area Insets für iPhone X+ */
  body {
    padding-top: constant(safe-area-inset-top);
    padding-top: env(safe-area-inset-top);
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Fix für Safari Bounce-Effekt */
  body {
    overscroll-behavior: none;
  }
}

/* ==================== Android Specific Optimizations ==================== */
@media screen and (max-width: 768px) {
  /* Verhindert horizontales Bouncing */
  html,
  body {
    overscroll-behavior-x: none;
  }

  /* Smooth Scrolling auf Touch-Geräten */
  * {
    -webkit-overflow-scrolling: touch;
  }
}

/* ==================== Loading States ==================== */
.loading {
  pointer-events: none;
  opacity: 0.6;
  position: relative;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 3px solid #14b8a6;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ==================== Pull-to-Refresh Kompatibilität ==================== */
body {
  overscroll-behavior-y: contain;
}

/* ==================== Optimierte Tap Highlights ==================== */
* {
  -webkit-tap-highlight-color: rgba(20, 184, 166, 0.1);
}

button,
a,
.clickable {
  -webkit-tap-highlight-color: rgba(20, 184, 166, 0.2);
}

/* ==================== Keyboard Accessibility auf Mobile ==================== */
@media (max-width: 768px) {
  /* Verhindert dass Keyboard Layout verschiebt */
  .modal.show {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
}

/* ==================== Landscape Mode Optimizations ==================== */
@media (max-width: 768px) and (orientation: landscape) {
  .home-hero {
    min-height: auto;
    padding: 4rem 2rem 2rem;
  }

  .modal-content,
  .login-modal-content {
    max-height: 80vh;
  }
}

/* ==================== High DPI Displays ==================== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  img {
    image-rendering: -webkit-optimize-contrast;
  }
}

/* ==================== Dark Mode Support ==================== */
@media (prefers-color-scheme: dark) {
  /* Bereits dunkel, aber kann hier zusätzliche Anpassungen machen */
  body {
    background-color: #0c1116;
  }
}

/* ==================== Reduced Motion ==================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==================== Print Styles ==================== */
@media print {
  .navbar,
  .footer,
  .cart-sidebar,
  .modal,
  button {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }
}

/* ==================== Bessere Thumb-Scrollbars auf Mobile ==================== */
@media (max-width: 768px) {
  .chatbot-messages,
  .cart-items,
  .product-description {
    scrollbar-width: thin;
    scrollbar-color: rgba(20, 184, 166, 0.3) transparent;
  }

  .chatbot-messages::-webkit-scrollbar,
  .cart-items::-webkit-scrollbar,
  .product-description::-webkit-scrollbar {
    width: 4px;
  }

  .chatbot-messages::-webkit-scrollbar-thumb,
  .cart-items::-webkit-scrollbar-thumb,
  .product-description::-webkit-scrollbar-thumb {
    background: rgba(20, 184, 166, 0.3);
    border-radius: 2px;
  }
}

/* ==================== Sticky Elements auf Mobile ==================== */
@media (max-width: 768px) {
  .header {
    position: sticky;
    top: 0;
  }

  /* Verhindere, dass sticky elements content verdecken */
  .sticky-warning {
    top: calc(var(--header-offset) + 10px);
  }
}

/* ==================== Bessere Button-Abstände auf Mobile ==================== */
@media (max-width: 768px) {
  .btn-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
  }

  .btn-group button,
  .btn-group a {
    width: 100%;
  }
}

/* ==================== Optimierte Tabellen für Mobile ==================== */
@media (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  td {
    text-align: right;
    padding-left: 50%;
    position: relative;
  }

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

/* ==================== Performance: Willchange für animierte Elemente ==================== */
@media (max-width: 768px) {
  .modal,
  .cart-sidebar,
  .nav-menu {
    will-change: transform;
  }

  .product-card:active {
    will-change: transform, opacity;
  }
}

/* ==================== Fokus-Styles für Accessibility ==================== */
@media (max-width: 768px) {
  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 3px solid var(--primary-teal);
    outline-offset: 2px;
  }
}

/* ==================== Bessere Spacing für kleine Screens ==================== */
@media (max-width: 480px) {
  .container {
    padding: 0 1rem;
  }

  section {
    padding: 2rem 0;
  }

  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  h3 {
    font-size: 1.25rem;
  }

  p {
    font-size: 0.95rem;
  }
}

/* ==================== Verbesserte Checkout-Erfahrung auf Mobile ==================== */
@media (max-width: 768px) {
  .checkout-steps {
    flex-direction: column;
    gap: 0.5rem;
  }

  .checkout-step {
    width: 100%;
  }

  .address-card {
    padding: 1rem;
  }

  .payment-method {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ==================== Floating Action Button Spacing ==================== */
@media (max-width: 768px) {
  .floating-buttons {
    bottom: calc(20px + env(safe-area-inset-bottom));
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 1000;
  }

  /* Stelle sicher, dass FABs nicht mit content kollidieren */
  body {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

/* ==================== Optimierte Notification-Positionierung ==================== */
@media (max-width: 768px) {
  .notification {
    left: 1rem;
    right: 1rem;
    width: auto;
    bottom: calc(1rem + env(safe-area-inset-bottom));
  }
}

/* ==================== Bessere Image-Loading-States ==================== */
@media (max-width: 768px) {
  img[loading="lazy"] {
    background: linear-gradient(90deg, #1a202c 25%, #2d3748 50%, #1a202c 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
  }

  @keyframes loading {
    0% {
      background-position: 200% 0;
    }
    100% {
      background-position: -200% 0;
    }
  }

  img[loading="lazy"].loaded {
    animation: none;
    background: none;
  }
}

/* ==================== Swipe-Gesten für Galerien ==================== */
@media (max-width: 768px) {
  .swipeable {
    touch-action: pan-x pan-y;
    user-select: none;
  }

  .product-image-gallery {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .product-image-gallery::-webkit-scrollbar {
    display: none;
  }

  .product-image-gallery img {
    scroll-snap-align: start;
    flex-shrink: 0;
    width: 100%;
  }
}