/* ============================================================
   PROFESSIONAL MOBILE OPTIMIZATION (Up to 768px)
   Covers: All iPhones (inc. Pro Max), Androids, Small Tablets
   ============================================================ */

@media (max-width: 768px) {

  /* --- 1. GLOBAL RESET & CONTAINER --- */
  
  html, body {
    overflow-x: hidden; /* Запобігає горизонтальній прокрутці */
    width: 100%;
  }

  /* Головний контейнер: єдині відступи для всього сайту */
  .container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important; /* Безпечний відступ з країв */
    box-sizing: border-box !important;
    margin: 0 auto !important;
  }

  /* Скидаємо відступи секцій, щоб вони підкорялися контейнеру */
  section {
    padding-left: 0 !important;
    padding-right: 0 !important;
    box-sizing: border-box !important;
  }

  /* Зменшуємо масштаб фонових зображень для мобільних */
  .background-about,
  .background-contacts {
    background-size: cover !important;
    background-attachment: scroll !important; /* Краща продуктивність на моб */
  }

  /* --- 2. NAVBAR (НАВІГАЦІЯ) --- */
  
  #navbar {
    height: auto !important;
    min-height: 60px;
    padding: 10px 0;
    position: fixed; /* Фіксуємо шапку */
  }

  #navbar .nav-logo { display: none !important; }

  #navbar .nav-container {
    width: 100%;
    padding: 0 15px;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    justify-content: center;
    gap: 10px;
  }

  /* Кнопка "Наші сервіси" */
  #navbar .services {
    display: block;
    width: 100%;
    text-align: center;
  }

  #navbar .services ul li {
    padding: 12px;
    display: block;
    width: 100%;
    text-align: center;
    background: rgba(255, 255, 255, 0.1); /* Легкий фон для кнопки */
    border-radius: 4px;
  }

  /* Основні посилання (Про нас, Контакти) */
  #navbar .nav-info ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    padding: 0;
  }

  #navbar .nav-info ul li a {
    padding: 5px;
    font-size: 14px;
    white-space: nowrap;
  }

  /* Випадаюче меню сервісів */
  #navbar .services ul li ul {
    position: relative;
    width: 100%;
    left: 0;
    top: 0;
    background: rgba(1, 50, 85, 0.95); /* Темніший фон для читабельності */
    padding: 0;
    margin-top: 10px;
    display: none; /* JS вмикає display: flex */
    flex-direction: column;
  }

  #navbar .services ul li ul li {
    background: transparent;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    padding: 12px 0;
    text-align: center;
  }

  #navbar .services ul li ul div {
    margin: 0 !important; /* Скидання відступів JS */
    display: flex;
    flex-direction: column;
  }
/* --- FIX: Service Menu Layout & Centering --- */
  
  /* 1. Main Menu Container */
  #navbar .service-menu.service-menu_active .service-menu_nav {
    display: flex !important;
    flex-direction: column !important;
    position: fixed;
    /* Pushes menu BELOW the navbar so button stays visible */
    top: 80px !important; 
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(1, 50, 85, 0.98);
    overflow-y: auto;
    z-index: 999;
    padding: 0 !important;
    align-items: center !important; /* Horizontal Center */
  }

  /* 2. Fix the split: Force the two inner DIVs to stack and center */
  #navbar .service-menu_nav > div {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important; 
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
    
    /* FIX: Reset the "right: 30px" shift from tablet.css */
    position: static !important;
    right: auto !important; 
    left: auto !important;
  }

  /* 3. Style the links */
  #navbar .service-menu_nav li {
    width: 100% !important;
    text-align: center !important;
    padding: 15px 0 !important;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: block !important;
  }
  
  /* 4. Ensure the link text inside is centered */
  #navbar .service-menu_nav li a {
    display: block !important;
    width: 100% !important;
    text-align: center !important;
  }
  /* --- 3. HERO SECTION (ГОЛОВНИЙ ЕКРАН) --- */
  
  #showcase {
    padding: 80px 15px 20px 15px; /* Відступ зверху для фіксованого меню */
    height: 100vh; /* На весь екран */
    min-height: 500px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
  }

  #showcase .logo-showcase {
    margin-top: 0;
    width: 140px;
    margin-bottom: 20px;
  }

  #showcase h1 {
    /* Адаптивний шрифт: мін 32px, макс 50px */
    font-size: clamp(32px, 8vw, 50px) !important;
    line-height: 1.1;
    margin-bottom: 15px;
  }

  #showcase .border-bottom {
    width: 100px;
    margin: 20px auto;
    border-bottom-width: 5px;
  }

  #showcase h3 {
    font-size: clamp(18px, 5vw, 24px) !important;
    max-width: 100%;
    line-height: 1.4;
  }

  #showcase .logo-iso {
    width: 100px;
    margin-top: 30px;
  }

  /* --- 4. ABOUT US (UPDATED) --- */
  #leverans-baltic-introduction {
    display: block;
    height: auto !important;
    padding: 40px 20px !important; /* Added side padding (Fix #1) */
    
    /* Grid Background matching Brands (Fix #4) */
    --grid-size: 28px;
    --grid-line: rgba(0,0,0,0.06);
    background:
      linear-gradient(0deg, var(--grid-line) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) !important;
    background-size: var(--grid-size) var(--grid-size), var(--grid-size) var(--grid-size) !important;
    background-color: #fff !important;
  }

  #leverans-baltic-introduction .introduction {
    width: 100% !important;
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #leverans-baltic-introduction .introduction-item {
    text-align: left !important;
    /* Шрифт читабельний на будь-якому екрані */
    font-size: clamp(18px, 5vw, 24px) !important; 
    line-height: 1.6;
    margin-bottom: 25px;
    padding: 0 !important;
    width: 100% !important;
  }

  /* Приховуємо складні десктопні елементи */
  .slide-footer, 
  .logo, 
  #ship-layout { 
    display: none !important; 
  }

  /* --- 5. BRANDS (БРЕНДИ) --- */
  
  /* Вирівнюємо заголовок Бренди з текстом Про нас */
  #brands.brands-sticky {
    padding-top: 0 !important;
    padding-bottom: 40px !important;
  }
  /* --- FIX: Remove Container Gap & Resize Filters --- */

  /* 1. Remove the gap (padding) from the container */
  .brands-sticky .container {
    padding-left: 0 !important;
    padding-right: 0 !important;
    width: 100% !important;
  }

  /* 2. Add padding back to the Text so it doesn't touch the screen edge */
  .brands-sticky h2,
  .brands-sticky p.lead {
    padding-left: 15px !important;
    padding-right: 15px !important;
  }

  /* 3. Filter Buttons: Bigger Text & Click Area */
  .brands-sticky .filter-btn {
    font-size: 15px !important;    /* Bigger font */
    padding: 9px 18px !important; /* Bigger button */
    margin: 4px !important;        /* Spacing */
  }
  
    /* 5. Buttons: Auto-width to fit more per line */
  .brands-sticky .filter-btn {
    flex-grow: 1 !important;       /* Still expands to fill gaps */
    flex-basis: auto !important;   /* CHANGED: Let button size match its text length */
    width: auto !important;
    text-align: center !important;
    font-size: 16px !important;    /* Keeps the big text size */
    padding: 8px 5px !important;  /* Reduced side padding slightly to help fit 3 buttons */
    margin: 0 !important;
  }

  /* 5. Add slight padding to the grid so sticky notes don't get cut off */
  .brands-sticky .brands-grid {
    padding: 0 10px !important;
  }
/* --- FIX: Bigger Lead Text --- */
  .brands-sticky p.lead {
    font-size: 22px !important; /* Increased size */
    line-height: 1.4 !important;
    margin-bottom: 25px !important;
  }
  .brands-sticky .container {
    padding: 0 px !important; /* Такий же padding як у всього сайту */
  }

  .brands-sticky h2, 
  .brands-sticky p.lead {
    text-align: left !important;
    margin-left: 0 !important;
    padding-left: 0 !important;
  }
  
  #brands h2 {
    font-size: clamp(28px, 6vw, 40px);
    margin-bottom: 15px;
  }
/* --- BRANDS MOBILE ADJUSTMENTS (Forced Text Size) --- */
  
  /* 1. Force the background image */
  .brands-sticky .brand-sticky-bg {
    background-image: url('../assets/img/brands_hand/sticky-note-mobile.png') !important;
    opacity: 1 !important;
    visibility: visible !important;
    background-size: 100% 100% !important;
    inset: 0 !important;
  }

  /* 2. Tiles: Wide and fixed height */
  .brands-sticky .brand-tile {
    width: 100% !important;
    height: 140px !important; /* Adjust if note looks too tall/short */
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important; 
    align-items: center !important;
    justify-content: center !important;
  }

  /* 3. Text: HIGH SPECIFICITY to override JavaScript */
  html body .brands-sticky .brand-label {
    font-size: 26px !important; /* Forces 26px regardless of JS calculation */
    line-height: 1.0 !important;
    padding: 0 4px !important;
    z-index: 2 !important;
    width: 95% !important; /* maximize width for text */
    display: flex !important;
    align-items: center;
    justify-content: center;
    height: 100% !important;
  }

  /* 4. Grid: 2 Columns */
  .brands-sticky .brands-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  /* --- 6. CERTIFICATES (СЕРТИФІКАТИ) --- */
  
  #certificates {
    height: auto !important;
    padding-bottom: 60px;
  }

  #certificates h2 {
    font-size: clamp(28px, 6vw, 40px);
    padding: 30px 0;
    text-align: center;
  }

  .certificates-container {
    display: flex;
    flex-direction: column;
    align-items: center !important; /* Центрування по горизонталі */
    justify-content: center;
    width: 100%;
    gap: 30px; /* Відстань між сертифікатами */
  }

  .certificates-container a {
    display: block;
    width: 100%;
    text-align: center;
  }

  .certificates-container img {
    margin: 0 !important; /* Прибираємо старі margin */
    width: 90% !important;
    max-width: 400px; /* Обмеження ширини */
    height: auto;
    box-shadow: 0px 5px 15px rgba(0,0,0,0.3) !important;
    border: 4px solid rgba(1, 80, 133, 0.8) !important;
  }

  /* --- 7. GALLERY (ГАЛЕРЕЯ) --- */
  
  #gallery .gallery-items {
    grid-template-columns: 1fr !important; /* 1 колонка */
    gap: 15px !important;
  }

 /* --- 8. CONTACTS (Optimized Layout) --- */
  
  #contacts {
    display: flex !important;
    flex-direction: column !important;
    padding: 30px 15px !important; /* Safe internal padding */
    width: 100% !important;
    box-sizing: border-box !important;
    background-size: cover !important;
    align-items: center !important;
  }

  /* Unpack the sections to re-order children */
  #contacts .section-a, 
  #contacts .section-b, 
  #contacts .section-c {
    display: contents !important;
  }

  /* Reset all desktop positioning */
  #contacts .section-a > *,
  #contacts .section-b > *,
  #contacts .section-c > *,
  #contacts .sponsor {
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    text-align: center !important;
    width: 100% !important;
    float: none !important;
  }

  /* --- ORDERING & SPACING --- */

  /* 1. Header & Address */
  #contacts .section-a { order: 1; }
  
  #contacts .section-a div:first-of-type {
    margin-bottom: 30px !important;
  }
  
  /* Main Email Block (with separator) */
  #contacts .section-a div:last-of-type { 
    margin-bottom: 40px !important;
    padding-bottom: 20px !important;
    border-bottom: 2px solid rgba(0,0,0,0.1) !important;
  }

  /* 2. Director Group */
  #contacts .section-b .technical { order: 2; margin-top: 10px !important; }
  #contacts .section-c .name-mail-1 { order: 3; margin-bottom: 40px !important; }

  /* 3. Tech Assistant Group */
  #contacts .section-b .navigation-safety { order: 4; }
  #contacts .section-c .name-mail-2 { order: 5; margin-bottom: 40px !important; }

  /* 4. Assistant Group */
  #contacts .section-b .assistant { order: 6; }
  #contacts .section-c .name-mail-3 { order: 7; margin-bottom: 40px !important; }

  /* 5. Accountant Group */
  #contacts .section-b .accountant { order: 8; }
  #contacts .section-c .name-mail-4 { order: 9; margin-bottom: 40px !important; }

  /* 6. Footer Link */
  #contacts .sponsor { 
    order: 10; 
    margin-top: 20px !important; 
    opacity: 0.8; 
    font-size: 25px !important;
  }

  /* --- TEXT STYLING (Bigger Fonts & Consistent Spacing) --- */

  /* 1. Titles/Positions (Red Text) */
  #contacts .section-b div p,
  #contacts .section-b div span {
    color: #ce0000 !important;
    font-size: 22px !important;    /* Increased from 18px */
    font-weight: bold !important;
    text-transform: uppercase;
    line-height: 1.2 !important;
    
    /* Strict Spacing Control */
    margin-bottom: 8px !important; /* Consistent gap to the Name below */
    margin-top: 40px !important;   /* Consistent gap from the person above */
    display: block !important;
  }

  /* 2. Names (Black Text) */
  #contacts .section-c h3 {
    font-size: 28px !important;    /* Increased from 22px */
    color: #000 !important;
    font-weight: 600 !important;
    
    /* Strict Spacing Control */
    margin-top: 0 !important;      /* Forces name to stick to the Red Title */
    margin-bottom: 10px !important;
  }

  /* 3. Links/Contact Info (Blue/Black Text) */
  #contacts .section-c a,
  #contacts .section-c p,
  #contacts .section-a a {
    font-size: 22px !important;    /* Increased from 18px */
    color: #015085 !important;
    text-decoration: underline !important;
    word-break: normal !important;
    overflow-wrap: anywhere !important;
    line-height: 1.4 !important;
    display: block !important;
    margin-bottom: 5px !important;
  }

  /* Hide decorative elements */
  #contacts .section-b i, 
  #contacts .logo-contacts,
  #contacts .section-a .underline-1::after { 
    display: none !important; 
  }

  /* Main Title */
  #contacts h2 { 
    font-size: 36px !important; 
    margin-bottom: 15px !important; 
    display: inline-block;
    border-bottom: 3px solid #ce0000;
  }
  
  /* --- 9. FOOTER --- */
  #main-footer {
    height: auto !important;
    padding: 15px 0;
    font-size: 14px !important;
  }
  /* --- BRANDS TOGGLE (Mobile Only) --- */
  .brands-grid.brands-collapsed {
    max-height: 400px; /* Limits height to show only first few rows */
    overflow: hidden;
    position: relative;
    mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
  }

  /* --- FIX: Toggle Button Design (Pill Shape like Filters) --- */
  .brands-toggle-btn {
    display: block !important;
    width: auto !important;
    min-width: 180px !important; /* Ensures it's wide enough to tap easily */
    margin: 25px auto 0 auto !important;
    padding: 12px 30px !important;
    background: #015085 !important;
    color: #fff !important;
    
    /* Adopt Filter Button "Look" */
    border: none !important;
    border-radius: 999px !important; /* Creates the "Pill" shape */
    font-size: 18px !important;      /* Matches filter font size */
    font-weight: 600 !important;     /* Matches filter font weight */
    text-align: center !important;
    cursor: pointer !important;
  }
  /* --- FIX: Reset Inner Contact Spans (Stop shifting left) --- */
  #contacts .another-mails,
  #contacts .another-phones,
  #contacts .fourth-mail,
  #contacts .main-mail,
  #contacts .number {
    position: static !important; /* Removes 'relative' positioning */
    right: auto !important;      /* Removes 'right: 100px' shift */
    left: auto !important;
    width: auto !important;      /* Allows natural width */
    display: inline-block !important; /* Keeps them centered */
  }

  /* --- FIX: Text Breaking (Stop cutting numbers in half) --- */
  #contacts .section-c a,
  #contacts .section-c p,
  #contacts .section-a a {
    word-break: normal !important;      /* Stop breaking in middle of words */
    overflow-wrap: anywhere !important; /* Only break if string is too wide for screen */
  }
/* --- FINAL FIX: Absolute Centering for Contacts --- */
  
  /* 1. Force the individual blocks (Director/Accountant/Names) to use Flexbox */
  #contacts .section-b > div,
  #contacts .section-c > div {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important; /* Forces horizontal centering */
    justify-content: center !important;
    text-align: center !important;
    width: 100% !important;
    margin: 0 0 25px 0 !important; /* Consistent vertical spacing */
    padding: 0 !important;
    
    /* Kill all desktop positioning */
    position: static !important;
    float: none !important;
    left: auto !important; 
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
  }

  /* 2. Reset the internal text elements (Titles, Names, Links) */
  #contacts .section-b p,
  #contacts .section-b span,
  #contacts .section-c h3,
  #contacts .section-c a,
  #contacts .section-c p,
  #contacts .section-c span {
    text-align: center !important;
    margin-left: auto !important;
    margin-right: auto !important;
    width: auto !important;      /* Removes fixed desktop widths */
    max-width: 100% !important;
    position: static !important; /* Kill any 'right: 100px' offsets */
    display: block !important;   /* Stacks them vertically */
  }
  /* --- FIX: Aggressive Centering (Reset Desktop Coordinates) --- */
  
  /* 1. Reset Containers (Red Titles & Groups) */
  #contacts .technical,
  #contacts .navigation-safety,
  #contacts .assistant,
  #contacts .accountant,
  #contacts .section-c > div {
    width: 100% !important;        /* Override fixed pixel widths */
    max-width: 100% !important;
    position: static !important;   /* Kill relative positioning offsets */
    left: auto !important;         /* Reset desktop 'left' shifts */
    right: auto !important;        /* Reset desktop 'right' shifts */
    top: auto !important;
    margin: 0 0 20px 0 !important; /* Clean vertical spacing */
    display: flex !important;      /* Use flex to force center alignment */
    flex-direction: column !important;
    align-items: center !important;
  }

  /* 2. Reset Inner Text (Emails, Phones, Names) */
  #contacts .section-c-emails,
  #contacts .section-c-phones,
  #contacts .section-c-names,
  #contacts .section-b span {
    position: static !important;
    right: auto !important;
    left: auto !important;
    margin: 0 !important;
    text-align: center !important;
    width: auto !important;
  }
  /* --- FINAL FIX: Force Reset on Inner Spans --- */
  
  /* 1. Target the specific wrapper spans that have desktop widths/offsets */
  #contacts .section-c-emails, 
  #contacts .section-c-phones,
  #contacts .another-mails, 
  #contacts .another-phones, 
  #contacts .fourth-mail,
  #contacts .section-c span {
    width: 100% !important;       /* Override fixed pixel widths */
    max-width: none !important;
    position: static !important;  /* Kill 'relative' positioning */
    right: auto !important;       /* Kill 'right: 100px' shifts */
    left: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    text-align: center !important; /* Force text center */
    display: block !important;     /* Make them stack cleanly */
  }

  /* 2. Ensure links inside take the centering */
  #contacts .section-c a {
    display: inline-block !important;
    text-align: center !important;
    width: auto !important;
  }
  /* --- FIX: Top Phone & Email Alignment --- */
  #contacts .section-a .number, 
  #contacts .section-a .main-mail {
    width: auto !important;       /* Removes fixed desktop widths */
    display: inline-block !important;
    text-align: center !important;
    margin: 0 !important;
    position: static !important;
  }

  /* Ensure the parent paragraphs force centering */
  #contacts .section-a p {
    text-align: center !important;
    width: 100% !important;
  }
  /* --- FINAL FLEXBOX FIX: Top Section Alignment --- */
  
  /* 1. Force the containers to use Flexbox (This fixes the broken HTML layout) */
  #contacts .section-a > div {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important; /* Forces horizontal centering */
    justify-content: center !important;
    width: 100% !important;
    margin-bottom: 30px !important;
  }

  /* 2. Reset every text element inside to be static and auto-width */
  #contacts .section-a p,
  #contacts .section-a span,
  #contacts .section-a .number,
  #contacts .section-a .main-mail {
    position: static !important;
    display: block !important;
    width: auto !important;
    text-align: center !important;
    margin: 0 auto !important;
    padding: 0 !important;
    float: none !important;
  }

  /* 3. Add spacing between the label (Tel/Email) and the link */
  #contacts .section-a .main-ph-numb,
  #contacts .section-a .email {
    margin-bottom: 5px !important;
    margin-top: 5px !important;
    font-weight: bold !important;
  }
  /* --- FIX: Bigger Lead Text (High Specificity) --- */
  #brands.brands-sticky p.lead {
    font-size: 24px !important; /* Forced larger size */
    line-height: 1.4 !important;
    margin-bottom: 30px !important;
    font-weight: normal !important;
  }
  /* --- Спеціальне стиснення ТІЛЬКИ для вузьких екранів (iPhone 12/13/14/15/Pro - 390px) --- */
  @media (max-width: 390px) {
    
    /* Примусово тримаємо все в один рядок */
    #navbar .nav-info {
      display: flex !important;
      flex-direction: row !important;
      flex-wrap: nowrap !important;
      gap: 0 !important;
      width: 100% !important;
      justify-content: center !important;
    }

    /* Зменшуємо відступи між групами меню */
    #navbar .nav-info ul {
      gap: 6px !important;
      margin: 0 2x !important;
      padding: 0 !important;
    }

    /* Зменшуємо шрифт і відступи, щоб влізло слово "Сертификаты" */
    #navbar .nav-info ul li a {
      font-size: 11.9px !important; /* Трохи менший шрифт */
      padding: 4px 5px !important;  /* Мінімальні відступи збоку */
     
      white-space: nowrap !important; /* Забороняємо перенос слів */
    }
  }
    /* Terms Button Mobile Optimization */
    @media (max-width: 768px) {
      .terms-container {
        margin-top: 30px;
        margin-bottom: 30px;
      }
  
      .terms-btn {
        width: 80%;
        /* Робимо кнопку ширшою на мобільному */
        display: block;
        margin: 0 auto;
        font-size: 16px;
        /* Трохи зменшуємо шрифт */
        padding: 12px 20px;
      }
    }
}