/* ===== EasyBG Comprehensive Responsive Adaptation =====
   Supports: All desktops, tablets (iPad), phones (Android 320px+, iPhone SE to Pro Max)
   ===== */

/* ===== BASE FIXES ===== */
html, body {
  overflow-x: hidden !important;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* iOS safe areas */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .site-footer {
    padding-bottom: calc(24px + env(safe-area-inset-bottom)) !important;
  }
}

html {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Prevent zoom on input focus on iOS (font-size must be >= 16px) */
@media screen and (max-width: 767px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

/* ===== VERY SMALL PHONES (max 359px) - iPhone SE, old Androids ===== */
@media screen and (max-width: 359px) {
  .max-w-4xl.mx-auto, .max-w-3xl.mx-auto {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  .text-lg { font-size: 1rem !important; }
  .text-xl { font-size: 1.125rem !important; }
  .text-2xl { font-size: 1.25rem !important; }
  .bg-white.rounded-xl.shadow-sm.border {
    border-radius: 0.625rem !important;
  }
  .max-w-md { max-width: calc(100vw - 16px) !important; }
  .mx-4 { margin-left: 0.5rem !important; margin-right: 0.5rem !important; }
  .site-footer { padding: 20px 8px 16px !important; }
  .site-footer .footer-disclaimer { font-size: 10px !important; }
  .site-footer .footer-brand { font-size: 12px !important; }
  .flex.gap-1.flex-wrap button {
    padding: 0.375rem 0.5rem !important;
    font-size: 11px !important;
  }
  .uppercase.tracking-wider {
    font-size: 10px !important;
    letter-spacing: 0.03em !important;
  }
}

/* ===== SMALL PHONES (max 413px) ===== */
@media screen and (max-width: 413px) {
  .max-w-4xl.mx-auto, .max-w-3xl.mx-auto {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
  .bg-white.rounded-xl.shadow-sm.border.p-3 {
    padding: 0.75rem !important;
  }
  input[type="date"] {
    max-width: 100% !important;
  }
  .fixed.bottom-4.left-4.right-4 {
    left: 0.5rem !important;
    right: 0.5rem !important;
    bottom: 0.5rem !important;
  }
}

/* ===== ALL PHONES (max 639px) ===== */
@media screen and (max-width: 639px) {
  .max-w-4xl { max-width: 100% !important; }
  .max-w-3xl { max-width: 100% !important; }
  .font-medium.truncate,
  .font-semibold.truncate {
    max-width: calc(100vw - 160px) !important;
  }
  .w-\[90px\] { width: 80px !important; }
  .w-full.table-fixed {
    table-layout: auto !important;
  }
  .bg-blue-50.border.border-blue-200.rounded-xl.p-4 {
    padding: 0.75rem !important;
  }
  .grid.grid-cols-2.md\:grid-cols-4 {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
  }
  .bg-white.rounded-xl.shadow-sm.border.overflow-hidden {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  .bg-white.rounded-2xl.shadow-2xl.w-full.max-w-md {
    max-width: calc(100vw - 2rem) !important;
    margin: 1rem !important;
    max-height: calc(100vh - 2rem) !important;
    overflow-y: auto !important;
  }
  .mt-6.flex.justify-center.gap-3 {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
    padding: 0 1rem !important;
  }
  .mt-6.flex.justify-center.gap-3 a,
  .mt-6.flex.justify-center.gap-3 button {
    width: 100% !important;
    justify-content: center !important;
    display: inline-flex !important;
  }
  .grid.grid-cols-1.md\:grid-cols-3 {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }
  .site-footer {
    padding: 24px 12px 20px !important;
  }
  .site-footer .footer-disclaimer {
    font-size: 10.5px !important;
    line-height: 1.7 !important;
    padding: 0 4px !important;
  }
  .fixed.bottom-4.left-4.right-4.md\:left-auto.md\:right-4.md\:w-96 {
    left: 0.5rem !important;
    right: 0.5rem !important;
    bottom: 0.5rem !important;
    width: auto !important;
    max-width: none !important;
  }
  .flex.flex-wrap.items-center.gap-2 {
    gap: 0.375rem !important;
  }
}

/* ===== TABLETS (640px - 1023px) ===== */
@media screen and (min-width: 640px) and (max-width: 1023px) {
  .max-w-4xl { max-width: 95% !important; }
  .max-w-3xl { max-width: 90% !important; }
  .grid.grid-cols-1.md\:grid-cols-3 {
    grid-template-columns: 1fr 1fr !important;
  }
  .grid.grid-cols-2.md\:grid-cols-4 {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* ===== LARGE TABLETS (1024px - 1279px) ===== */
@media screen and (min-width: 1024px) and (max-width: 1279px) {
  .max-w-4xl { max-width: 960px !important; }
  .max-w-3xl { max-width: 860px !important; }
}

/* ===== LARGE DESKTOPS (1920px+) ===== */
@media screen and (min-width: 1920px) {
  .max-w-4xl { max-width: 64rem !important; }
  .max-w-3xl { max-width: 56rem !important; }
}

/* ===== LANDSCAPE PHONE ===== */
@media screen and (max-height: 500px) and (orientation: landscape) {
  .sticky.top-0.z-50 .h-14 {
    height: 2.75rem !important;
  }
  .fixed.inset-0.z-50 .bg-white.rounded-2xl {
    max-height: 95vh !important;
    overflow-y: auto !important;
  }
}

/* ===== PRINT ===== */
@media print {
  .sticky { position: relative !important; }
  .fixed { display: none !important; }
  .shadow-sm, .shadow-lg, .shadow-xl, .shadow-2xl { box-shadow: none !important; }
  .site-footer { break-inside: avoid; }
}

/* ===== REDUCED MOTION ===== */
@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;
  }
}

/* ===== TOUCH DEVICES ===== */
@media (hover: none) and (pointer: coarse) {
  button:active, a:active, [role="button"]:active {
    opacity: 0.7 !important;
    transition: all 0.1s ease !important;
  }
}

/* ===== DROPDOWN FIXES ===== */
.absolute.left-0.right-0.bg-white.border {
  max-height: 200px !important;
  overflow-y: auto !important;
  z-index: 100 !important;
}
.absolute.top-full.right-0 {
  z-index: 100 !important;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 3px; }
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

#root { min-height: 100vh; }

/* ===== HEADER NAV FIX - center items, no scroll ===== */
header .h-14 {
  overflow: visible !important;
  flex-wrap: nowrap !important;
  position: relative !important;
}

/* Mobile: ensure desktop nav stays hidden */
@media screen and (max-width: 767px) {
  header .h-14 > nav.hidden {
    display: none !important;
  }
}

/* Desktop: nav absolutely centered in header */
@media screen and (min-width: 768px) {
  header .h-14 > nav {
    position: absolute !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow: visible !important;
    align-items: center !important;
    gap: 0.25rem !important;
    z-index: 1 !important;
  }
  header .h-14 > div:last-child {
    margin-left: auto !important;
    z-index: 2 !important;
  }
}

/* ===== Mobile top-nav: horizontal swipe bar (instead of burger) ===== */
@media screen and (max-width: 767px) {
  /* Show the desktop nav on mobile, make it horizontally scrollable */
  nav.hidden.md\:flex.items-center.justify-center.gap-1.flex-1.mx-2 {
    display: flex !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    margin-left: 0.25rem !important;
    margin-right: 0.25rem !important;
    padding: 4px 4px !important;
    width: auto !important;
    min-width: 0 !important;
  }
  nav.hidden.md\:flex.items-center.justify-center.gap-1.flex-1.mx-2::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
  }
  nav.hidden.md\:flex.items-center.justify-center.gap-1.flex-1.mx-2 > * {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  /* Hide the burger button (no longer needed) */
  button.md\:hidden.text-white\/70.p-2.rounded-lg {
    display: none !important;
  }

  /* Hide the old mobile dropdown nav (burger popup) */
  nav.md\:hidden.bg-gray-900\/95 {
    display: none !important;
  }
}

/* ===== Mobile top-nav: fix v2 — remove flex-1 spacer & use full width ===== */
@media screen and (max-width: 767px) {
  /* The spacer 'flex-1 md:hidden' sibling was competing for width with our nav.
     Hide it on mobile so our nav gets full remaining row width. */
  header .h-14 > div.flex-1.md\:hidden {
    display: none !important;
  }
  /* Ensure nav fills remaining row width */
  nav.hidden.md\:flex.items-center.justify-center.gap-1.flex-1.mx-2 {
    flex: 1 1 0 !important;
    width: auto !important;
  }
}

/* ===== Mobile: show user email/logout dropdown button (avatar) ===== */
@media screen and (max-width: 767px) {
  /* Un-hide the desktop-only email button; render as compact round avatar */
  header button.hidden.md\:flex.cursor-pointer.px-2.py-1 {
    display: inline-flex !important;
    align-items: center !important;
    gap: 2px !important;
    font-size: 0 !important;
    line-height: 1 !important;
    padding: 6px 6px !important;
    margin-left: 4px !important;
    background: rgba(255,255,255,0.12) !important;
    border-radius: 9999px !important;
    flex: 0 0 auto !important;
    max-width: 56px !important;
  }
  /* Avatar icon drawn via CSS so no JS change needed */
  header button.hidden.md\:flex.cursor-pointer.px-2.py-1::before {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/><circle cx='12' cy='7' r='4'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    flex: 0 0 auto;
  }
  /* Keep chevron visible (inline width/height already set) */
  header button.hidden.md\:flex.cursor-pointer.px-2.py-1 svg {
    color: white !important;
    stroke: white !important;
    flex: 0 0 auto !important;
    margin-left: 0 !important;
  }
  /* Hide unverified '!' badge on mobile to save space */
  header button.hidden.md\:flex.cursor-pointer.px-2.py-1 span.rounded-full {
    display: none !important;
  }
  /* Tighten nav right margin so avatar fits */
  nav.hidden.md\:flex.items-center.justify-center.gap-1.flex-1.mx-2 {
    margin-right: 2px !important;
  }
}

/* ===== Admin panel: hide cooldown/mailing-related UI ===== */
/* 1. Hide 'На cooldown' counter card (orange) */
div.bg-orange-50.border.border-orange-200.rounded-lg.p-3.text-center {
  display: none !important;
}
/* 2. Hide 'Выгрузить для рассылки' purple button */
button.bg-purple-600.text-white.px-3.py-1\.5.rounded.text-sm.font-bold {
  display: none !important;
}
/* 3. Hide 'Как использовать' yellow instruction box (mailings-specific) */
div.text-xs.text-gray-500.bg-yellow-50.border.border-yellow-200.rounded.p-2 {
  display: none !important;
}
/* 4. Hide mailing-related cells that appear AFTER the 6 standard columns
   (Email/ФИО/Телефон/Компания/ИНН/Добавлен). Works regardless of total count. */
table tbody tr td:nth-child(n+7) { display: none !important; }
table thead tr th:nth-child(n+7) { display: none !important; }

/* 5. Hide 'Доступно' counter card (blue) — user wants only Всего контактов */
div.bg-blue-50.border.border-blue-200.rounded-lg.p-3.text-center {
  display: none !important;
}
