/* ===========================================
   MOBILE.CSS - Mobile Optimizations
   Safari-Compatible, Touch-Optimized
   =========================================== */

/* Safari Smooth Scrolling - Restricted to scroll containers */
* {
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

/* ===== CAROUSEL MOBILE FIXES ===== */
@media (max-width: 768px) {
  /* Carousel Container: Landscape Format */
  .carousel {
    height: 200px !important; /* Reduced from default */
    max-height: 200px;
    border-radius: 12px;
    overflow: hidden;
  }
  
  .slide {
    height: 200px !important;
  }
  
  .slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
  }
  
  /* Carousel Dots - Better Touch Target */
  .dot {
    width: 10px;
    height: 10px;
    margin: 0 4px;
    cursor: pointer;
  }
}

/* ===== IMAGE OPTIMIZATIONS ===== */
@media (max-width: 768px) {
  /* Hero Images - Responsive on Mobile (maintains aspect ratio, no squeezing) */
  section:first-of-type .image-container {
    width: 100%;
    max-width: 100%;
    height: auto;
  }
  
  section:first-of-type .image-container img {
    object-fit: cover;
    width: 100%;
    height: auto;
    max-height: none;
  }
  
  /* Process Step Images - Compact */
  .process-step {
    height: 220px !important;
  }
  
  /* Profile/Testimonial Images - Flexible Height */
  .image-container.small {
    height: auto;
    max-height: 180px;
  }
  
  /* Gallery/Testimonial Image Containers - Auto Height */
  #bewertungen .image-container,
  #ueber-galerie .image-container {
    height: auto;
    max-height: 200px;
  }
}

/* ===== CHATBOT MOBILE FULLSCREEN ===== */
@media (max-width: 768px) {
  #chatbotContainer {
    position: fixed !important;
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100dvh !important;
    height: 100dvh !important;
    max-height: -webkit-fill-available !important;
    height: -webkit-fill-available !important;
    border-radius: 0 !important;
    margin: 0 !important;
    transform: none !important;
    z-index: 10000 !important; /* Below modals (12000) */
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  #chatbotContainer.hidden {
    display: none !important;
  }
  
  #chatMessages {
    height: calc(100dvh - 140px) !important;
    height: calc(-webkit-fill-available - 140px) !important;
    max-height: calc(100dvh - 140px) !important;
    max-height: calc(-webkit-fill-available - 140px) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Close Button Prominent on Mobile */
  #chatbotClose {
    font-size: 1.25rem;
    padding: 8px;
  }
  
  /* Chatbot Toggle Button - Positioned Above Sticky CTA */
  #chatbotToggle {
    bottom: 80px !important; /* Above sticky CTA bar */
    right: 16px !important;
    width: 56px;
    height: 56px;
    z-index: 9998;
    min-height: 56px;
    min-width: 56px;
  }
  
  /* Input Area - Safe Area for Keyboard */
  #chatbotContainer .chat-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/* ===== TOUCH OPTIMIZATIONS ===== */
@media (max-width: 768px) {
  /* Larger Touch Targets - Scoped to Interactive Elements Only */
  button:not(.inline-link),
  .btn,
  .cta-link,
  .quick-question-btn,
  a.button,
  a[role="button"],
  .nav-link,
  .card-link {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
  }
  
  /* Quick Question Buttons - Better Spacing */
  .bg-navy.text-gold,
  .quick-question-btn {
    padding: 8px 12px !important;
    font-size: 0.8125rem !important;
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Input Fields */
  input[type="text"],
  input[type="email"],
  textarea {
    font-size: 16px !important; /* Prevents iOS zoom */
    padding: 12px;
  }
  
  /* Form Buttons */
  button[type="submit"] {
    min-height: 48px;
    padding: 12px 24px;
  }
}

/* ===== STICKY MOBILE CTA ===== */
@media (max-width: 768px) {
  .md\:hidden.fixed.bottom-0 {
    z-index: 40;
    padding: 12px 16px;
  }
  
  .md\:hidden.fixed.bottom-0 a {
    min-height: 52px;
    font-size: 1rem;
  }
}

/* ===== NAVIGATION MOBILE ===== */
@media (max-width: 768px) {
  /* Mobile Menu */
  nav {
    padding: 12px 16px;
  }
  
  /* Hamburger Menu */
  #mobileMenu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 31, 68, 0.98);
    z-index: 999;
    -webkit-overflow-scrolling: touch;
  }
  
  #mobileMenu a {
    min-height: 52px;
    display: flex;
    align-items: center;
    padding: 16px 24px;
    font-size: 1.125rem;
  }
}

/* ===== FOOTER MOBILE ===== */
@media (max-width: 768px) {
  footer {
    padding-bottom: 80px !important; /* Space for sticky CTA */
  }
  
  footer .grid {
    grid-template-columns: 1fr !important;
    gap: 32px !important;
    text-align: center;
  }
  
  footer ul {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  
  footer button,
  footer a {
    text-align: center;
    width: 100%;
  }
}

/* ===== TYPOGRAPHY MOBILE ===== */
@media (max-width: 768px) {
  /* Headings - Better Hierarchy */
  h1 {
    font-size: 2rem !important;
    line-height: 1.2;
  }
  
  h2 {
    font-size: 1.75rem !important;
    line-height: 1.3;
  }
  
  h3 {
    font-size: 1.5rem !important;
    line-height: 1.3;
  }
  
  h4 {
    font-size: 1.25rem !important;
  }
  
  /* Section Headers */
  .text-3xl {
    font-size: 1.75rem !important;
  }
  
  .text-4xl {
    font-size: 2rem !important;
  }
  
  .md\:text-3xl {
    font-size: 1.75rem !important;
  }
  
  .md\:text-4xl {
    font-size: 2rem !important;
  }
  
  .md\:text-6xl {
    font-size: 2rem !important;
  }
  
  /* Body text sizing */
  .text-lg {
    font-size: 1rem !important;
  }
  
  /* Prevent Orphans */
  p {
    text-wrap: pretty;
    hyphens: auto;
    -webkit-hyphens: auto;
  }
  
  /* Better line height for readability */
  p, li {
    line-height: 1.6;
  }
}

/* ===== MODALS MOBILE ===== */
@media (max-width: 768px) {
  [id$="Modal"] > div {
    max-width: 95vw !important;
    max-height: 95vh !important;
    margin: 20px;
  }
  
  [id$="Modal"] .sticky {
    position: sticky;
    top: 0;
    z-index: 10;
  }
  
  [id$="Modal"] .p-6 {
    padding: 16px !important;
  }
  
  /* Modal Typography */
  [id$="Modal"] h2 {
    font-size: 1.5rem !important;
  }
  
  [id$="Modal"] h3 {
    font-size: 1.125rem !important;
  }
  
  [id$="Modal"] p,
  [id$="Modal"] li {
    font-size: 0.875rem !important;
  }
}

/* ===== HERO SECTION MOBILE FIXES ===== */
@media (max-width: 768px) {
  /* Hero Section - Fix min-h-screen clipping on mobile */
  section:first-of-type {
    min-height: auto !important;
    padding-top: 80px !important; /* Account for fixed header */
    padding-bottom: 32px !important;
  }
  
  /* Hero Grid - Stack vertically on mobile */
  section:first-of-type .grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
  
  /* Hero Content - Optimize spacing */
  section:first-of-type h1 {
    font-size: 2rem !important;
    line-height: 1.2 !important;
  }
  
  section:first-of-type p {
    font-size: 1rem !important;
    margin-top: 16px !important;
  }
  
  /* Hero Image Container - Prevent overflow */
  section:first-of-type .image-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto;
  }
  
  section:first-of-type .image-container img {
    width: 100% !important;
    height: auto !important;
    max-height: 300px !important;
    object-fit: cover !important;
  }
  
  /* Hero Buttons - Stack on very small screens */
  section:first-of-type .flex.flex-wrap {
    flex-direction: column !important;
    width: 100%;
  }
  
  section:first-of-type .flex.flex-wrap > a {
    width: 100%;
    text-align: center;
  }
  
  /* Chatbot Badge - Better mobile sizing */
  section:first-of-type .bg-white\/10 {
    padding: 12px !important;
  }
  
  /* Hero Chips - Better wrapping */
  section:first-of-type .chip {
    font-size: 0.75rem !important;
    padding: 6px 10px !important;
  }
}

/* ===== SECTIONS MOBILE SPACING ===== */
@media (max-width: 768px) {
  /* General Sections - Reduced Padding for Better Fold Usage */
  section {
    padding-top: 24px !important;
    padding-bottom: 24px !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
  
  .max-w-7xl,
  .max-w-6xl,
  .max-w-5xl,
  .max-w-4xl {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
}

/* ===== GRID LAYOUTS MOBILE ===== */
@media (max-width: 768px) {
  .grid {
    gap: 20px !important;
  }
  
  /* Service Cards - Single column on mobile */
  .md\:grid-cols-2,
  .lg\:grid-cols-3,
  .md\:grid-cols-3,
  .md\:grid-cols-4,
  .md\:grid-cols-5,
  .sm\:grid-cols-2,
  .sm\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }
  
  /* Trust Indicators - Stack on very small screens */
  @media (max-width: 480px) {
    .sm\:grid-cols-3 {
      grid-template-columns: 1fr !important;
    }
  }
  
  /* Testimonial Cards */
  .space-y-4 > div {
    margin-bottom: 16px;
  }
  
  /* Service Card Images - Optimize height */
  article .image-container.h-40,
  article .image-container.h-44 {
    height: 180px !important;
  }
  
  /* Glass Effect Cards - Better padding */
  .glass-effect {
    padding: 16px !important;
  }
  
  .glass-effect.p-6,
  .glass-effect.p-8 {
    padding: 20px !important;
  }
}

/* ===== MAP MOBILE ===== */
@media (max-width: 768px) {
  #map {
    height: 300px !important;
    border-radius: 12px;
  }
  
  .leaflet-control-container {
    font-size: 14px;
  }
  
  /* Map Popup */
  .leaflet-popup-content-wrapper {
    border-radius: 12px;
    padding: 12px;
  }
}

/* ===== SCROLL CONTAINERS - Momentum Scrolling ===== */
/* Apply -webkit-overflow-scrolling only to actual scroll containers */
#chatMessages,
#chatbotContainer,
[id$="Modal"] > div,
.overflow-y-auto,
.overflow-x-auto,
.scroll-container,
#mobileMenu {
  -webkit-overflow-scrolling: touch;
}

/* ===== SAFARI SPECIFIC FIXES ===== */
@supports (-webkit-touch-callout: none) {
  /* Safari iOS 100vh fix */
  body {
    min-height: -webkit-fill-available;
  }
  
  #chatbotContainer {
    height: -webkit-fill-available !important;
  }
  
  /* Input Focus Fix */
  input:focus {
    font-size: 16px;
  }
  
  /* Hero Section Safari viewport fix */
  @media (max-width: 768px) {
    section:first-of-type {
      min-height: auto !important;
      height: auto !important;
    }
  }
}

/* ===== SAFE AREA INSETS (Safari notch support) ===== */
@media (max-width: 768px) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  header {
    padding-top: env(safe-area-inset-top);
  }
  
  /* Sticky CTA respects bottom safe area */
  .md\:hidden.fixed.bottom-0 {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* ===== BUTTONS AND LINKS MOBILE ===== */
@media (max-width: 768px) {
  /* CTA Buttons - Full width for better tap targets */
  a[class*="bg-gradient"],
  button[class*="bg-gradient"],
  .px-6.py-3,
  .px-6.py-2 {
    padding: 14px 20px !important;
    font-size: 0.9375rem !important;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Link buttons - Better spacing */
  a.inline-flex,
  .mt-4.inline-flex {
    font-size: 0.875rem !important;
    min-height: 44px;
  }
  
  /* Contact buttons in About section */
  .px-4.py-2 {
    padding: 12px 16px !important;
    font-size: 0.875rem !important;
  }
}

/* ===== SPECIFIC SECTIONS MOBILE ===== */
@media (max-width: 768px) {
  /* Trust Indicators Section - Better spacing */
  section:nth-of-type(2) .glass-effect {
    padding: 16px !important;
  }
  
  section:nth-of-type(2) .text-3xl {
    font-size: 1.75rem !important;
  }
  
  /* About Section - Profile card optimization */
  #about .flex.items-center {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 16px !important;
  }
  
  #about .image-container {
    width: 80px !important;
    height: 80px !important;
  }
  
  #about h2 {
    font-size: 1.5rem !important;
  }
  
  /* Services Section - Card optimization */
  #services article {
    margin-bottom: 20px;
  }
  
  #services .image-container {
    height: 200px !important;
  }
  
  #services h4 {
    font-size: 1.125rem !important;
  }
  
  /* Process Steps - Better mobile height */
  .process-step {
    height: 240px !important;
  }
  
  .process-content {
    padding: 16px !important;
  }
  
  .process-title {
    font-size: 1.125rem !important;
  }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-width: 768px) and (orientation: landscape) {
  .carousel {
    height: 180px !important;
  }
  
  #chatbotContainer {
    height: 100vh !important;
  }
  
  section {
    padding-top: 16px !important;
    padding-bottom: 16px !important;
  }
  
  /* Hero with adjusted padding in landscape */
  section:first-of-type {
    padding-top: 72px !important;
    padding-bottom: 24px !important;
  }
  
  /* Hero image smaller in landscape */
  section:first-of-type .image-container img {
    max-height: 220px !important;
  }
}

/* ===== SMALL MOBILE (< 375px) ===== */
@media (max-width: 374px) {
  .carousel {
    height: 160px !important;
  }
  
  h1 {
    font-size: 1.75rem !important;
  }
  
  h2 {
    font-size: 1.5rem !important;
  }
  
  h3 {
    font-size: 1.25rem !important;
  }
  
  .bg-navy.text-gold {
    font-size: 0.75rem !important;
    padding: 6px 10px !important;
  }
  
  /* Hero Section - Extra compact on small screens */
  section:first-of-type {
    padding-top: 72px !important;
  }
  
  section:first-of-type h1 {
    font-size: 1.75rem !important;
  }
  
  section:first-of-type .image-container img {
    max-height: 250px !important;
  }
  
  /* Buttons - Slightly smaller on tiny screens */
  a[class*="bg-gradient"],
  button[class*="bg-gradient"] {
    padding: 12px 16px !important;
    font-size: 0.875rem !important;
  }
  
  /* Glass effect cards - More compact */
  .glass-effect {
    padding: 14px !important;
  }
  
  /* Service cards */
  #services .image-container {
    height: 160px !important;
  }
}

/* ===== ACCESSIBILITY - HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
  button,
  a {
    outline: 2px solid currentColor;
    outline-offset: 2px;
  }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
  /* Modals in dark mode */
  [id$="Modal"] > div {
    background: #1a1a1a;
    color: #ffffff;
  }
  
  [id$="Modal"] .bg-white {
    background: #2a2a2a !important;
  }
}
