/* ============================================================
   UNIFIED RESPONSIVE SYSTEM — 2026 Statistics + Lebedev Studio
   Based on: DeviceAtlas/Statcounter May 2026, Lebedev 8px grid
   Viewport bands covering 85%+ mobile traffic:
   - ≤320px   : 7%   (iPhone SE, accessibility zoom)
   - 360px    : 18%  (Samsung base, budget Android)
   - 384px    : 17%  (Samsung Ultra, A-series FHD+)
   - 390-393px: 7%   (iPhone 12-16 base, Pro)
   - 412-414px: 20%  (Pixel, large Android, iPhone Plus/Max)
   - 430px+   : 17%  (Pro Max, foldables)
   Tablet: 768×1024 (9.8%), 800×1280 (6.6%), 820×1180 (6%)
   Desktop: 1920×1080 (20%), 1366×768 (5.7%)
============================================================ */

/* === 8px BASE GRID (Lebedev) === */
:root {
  --space-1: 4px;   /* half-step */
  --space-2: 8px;   /* base */
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --space-9: 96px;
  
  /* Touch targets (Apple/Google HIG minimum) */
  --touch-min: 44px;
  --touch-comfortable: 48px;
  
  /* Container max-widths (Lebedev 12-col) */
  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1200px;
  --container-2xl: 1280px;
}

/* === CSS RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* === FLUID TYPOGRAPHY (clamp) === */
/* Lebedev: H1 28-48px, H2 24-30px, H3 18-22px, Body 15-16px */

:root {
  /* Fluid clamp: min @320px, preferred @vw, max @1440px */
  --fs-h1: clamp(1.75rem, 4.5vw, 3rem);      /* 28px → 48px */
  --fs-h2: clamp(1.5rem, 3.2vw, 1.875rem);   /* 24px → 30px */
  --fs-h3: clamp(1.125rem, 2.4vw, 1.375rem); /* 18px → 22px */
  --fs-body: clamp(0.9375rem, 1.2vw, 1rem);  /* 15px → 16px */
  --fs-sm: clamp(0.75rem, 1vw, 0.8125rem);   /* 12px → 13px */
  --fs-xs: clamp(0.6875rem, 0.9vw, 0.75rem); /* 11px → 12px */
  
  --lh-tight: 1.1;
  --lh-normal: 1.5;
  --lh-relaxed: 1.6;
}

h1 { font-size: var(--fs-h1); line-height: var(--lh-tight); font-weight: 700; }
h2 { font-size: var(--fs-h2); line-height: var(--lh-tight); font-weight: 600; }
h3 { font-size: var(--fs-h3); line-height: var(--lh-normal); font-weight: 600; }
p, li { font-size: var(--fs-body); line-height: var(--lh-normal); }
small, .caption, .meta { font-size: var(--fs-sm); line-height: var(--lh-normal); }
.micro, .fine-print { font-size: var(--fs-xs); line-height: var(--lh-normal); }

/* === CONTAINER SYSTEM === */
.container {
  width: 100%;
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

@media (min-width: 768px) {
  .container { padding: 0 var(--space-6); }
}

@media (min-width: 1024px) {
  .container { padding: 0 var(--space-7); }
}

.container-narrow { max-width: 760px; } /* Lebedev reading width */

/* === TOUCH-FRIENDLY INTERACTIVE ELEMENTS === */
button, a[role="button"], input[type="button"], input[type="submit"],
input[type="checkbox"], input[type="radio"], select,
.nav-item, .tab, .chip, .pill, .dropdown-trigger {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Comfortable touch for primary actions */
.btn-primary, .btn-main, .cta-button {
  min-height: var(--touch-comfortable);
  padding: 12px var(--space-5);
}

/* Form inputs */
input, textarea, select {
  min-height: var(--touch-min);
  padding: 12px var(--space-3);
  font-size: 16px !important; /* Strictly prevents iOS Safari zoom on focus */
}

/* === RESPONSIVE GRID (12-col, 8px gutter) === */
.grid {
  display: grid;
  gap: var(--space-4);
}

@media (min-width: 768px) {
  .grid { gap: var(--space-5); }
}

@media (min-width: 1024px) {
  .grid { gap: var(--space-6); }
}

/* Auto-fit columns with Lebedev minmax */
.grid-auto-200 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-auto-180 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-auto-160 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-auto-140 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

/* Explicit column counts */
.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-6 { grid-template-columns: repeat(6, 1fr); }
.grid-12 { grid-template-columns: repeat(12, 1fr); }

/* Mobile: single column by default */
@media (max-width: 767px) {
  .grid-2, .grid-3, .grid-4, .grid-6, .grid-12 {
    grid-template-columns: 1fr;
  }
}

/* Tablet: 2 columns */
@media (min-width: 768px) and (max-width: 1023px) {
  .grid-3, .grid-4, .grid-6, .grid-12 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* === BREAKPOINT UTILITIES (Lebedev + 2026 stats) === */

/* xs: ≤320px (iPhone SE, zoom) */
@media (max-width: 320px) {
  .hide-xs { display: none !important; }
  .container { padding: 0 var(--space-2); }
  :root { --fs-h1: 1.625rem; --fs-h2: 1.375rem; --fs-body: 0.875rem; }
}

/* sm: 360-383px (Samsung base, budget) */
@media (min-width: 360px) and (max-width: 383px) {
  :root { --fs-h1: 1.75rem; --fs-h2: 1.5rem; }
}

/* sm-md: 384-389px (Samsung Ultra/A-series) */
@media (min-width: 384px) and (max-width: 389px) {
  :root { --fs-h1: 1.875rem; --fs-h2: 1.5rem; }
}

/* md: 390-411px (iPhone 12-16 base, Pro) */
@media (min-width: 390px) and (max-width: 411px) {
  :root { --fs-h1: 2rem; --fs-h2: 1.625rem; }
}

/* md-lg: 412-429px (Pixel, large Android, iPhone Plus) */
@media (min-width: 412px) and (max-width: 429px) {
  :root { --fs-h1: 2.125rem; --fs-h2: 1.75rem; }
}

/* lg: 430-767px (Pro Max, foldables, small tablets) */
@media (min-width: 430px) and (max-width: 767px) {
  :root { --fs-h1: 2.25rem; --fs-h2: 1.875rem; }
}

/* tablet: 768-1023px */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --fs-h1: 2.5rem; --fs-h2: 2rem; --fs-body: 1rem; }
  .hide-tablet { display: none !important; }
}

/* desktop: 1024-1439px */
@media (min-width: 1024px) and (max-width: 1439px) {
  :root { --fs-h1: 2.75rem; --fs-h2: 2.125rem; }
}

/* xl: 1440px+ */
@media (min-width: 1440px) {
  :root { --fs-h1: 3rem; --fs-h2: 1.875rem; }
}

/* === FLEXBOX RESPONSIVE PATTERNS === */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }

/* Stack on mobile, row on tablet+ */
@media (max-width: 767px) {
  .stack-mobile { flex-direction: column; }
  .stack-mobile > * { width: 100%; }
}

@media (min-width: 768px) {
  .row-tablet { flex-direction: row; }
}

/* === NAVIGATION PATTERNS === */
/* Desktop: horizontal pills, Mobile: hamburger drawer */
.nav-desktop,
.nav-desktop.nav-pill-container,
header .nav-pill-container { display: none !important; }
.nav-mobile-toggle { display: inline-flex !important; }

@media (min-width: 1024px) {
  .nav-desktop,
  .nav-desktop.nav-pill-container,
  header .nav-pill-container { display: inline-flex !important; }
  .nav-mobile-toggle { display: none !important; }
}

/* Phone number: text on desktop, icon on mobile */
.phone-text { display: inline-flex; }
.phone-icon { display: none; }

@media (max-width: 767px) {
  .phone-text { display: none; }
  .phone-icon { display: inline-flex; }
}

/* === CARD RESPONSIVE === */
.card {
  border-radius: var(--space-5);
  padding: var(--space-5);
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border-color, #e4e2dc);
  transition: all 0.2s ease;
}

@media (max-width: 767px) {
  .card { border-radius: var(--space-4); padding: var(--space-4); }
}

.card-hover:hover {
  box-shadow: 0 8px 24px -4px rgba(0,0,0,0.1), 0 4px 12px -2px rgba(0,0,0,0.05);
  transform: translateY(-2px);
}

/* === MODAL / DRAWER RESPONSIVE === */
.modal, .drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-content, .drawer-content {
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--space-5);
  background: var(--bg-surface, #fff);
}

@media (min-width: 768px) {
  .modal-content, .drawer-content { max-width: 480px; }
}

/* Bottom sheet on mobile */
.drawer-bottom .drawer-content {
  align-items: flex-end;
  border-radius: var(--space-5) var(--space-5) 0 0;
  max-height: 85vh;
}

/* === TABLE RESPONSIVE === */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive table {
  min-width: 600px;
  border-collapse: collapse;
}

/* Card layout for tables on mobile */
@media (max-width: 767px) {
  .table-card thead { display: none; }
  .table-card tbody { display: block; }
  .table-card tr { display: block; padding: var(--space-4); border: 1px solid var(--border-color); margin-bottom: var(--space-3); border-radius: var(--space-3); background: var(--bg-surface); }
  .table-card td { display: flex; justify-content: space-between; padding: var(--space-1) 0; border-bottom: 1px solid var(--border-light); }
  .table-card td:last-child { border-bottom: none; }
  .table-card td::before { content: attr(data-label); font-weight: 600; color: var(--text-muted); }
}

/* === PRINT STYLES (Lebedev: clean official blanks) === */
@media print {
  .no-print, header, nav, footer, .nav-mobile-toggle, .btn, button, .modal, .drawer {
    display: none !important;
  }
  
  body { background: #fff !important; color: #000 !important; font-size: 11pt; line-height: 1.4; }
  .container { max-width: none; padding: 0; }
  .card { border: 1px solid #000; box-shadow: none; break-inside: avoid; }
  h1 { font-size: 16pt; }
  h2 { font-size: 13pt; }
  h3 { font-size: 11pt; }
  a { text-decoration: none; color: #000; }
  a[href^="tel:"]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #666; }
}

/* === ACCESSIBILITY === */
@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;
  }
}

@media (prefers-contrast: high) {
  :root {
    --border-color: #000;
    --text-muted: #333;
  }
}

/* Focus visible for keyboard nav */
:focus-visible {
  outline: 2px solid var(--accent, #4338ca);
  outline-offset: 2px;
}

/* === SCROLLBAR (thin, subtle) === */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === UTILITY: TEXT BALANCE (prevents orphans) === */
.text-balance { text-wrap: balance; }
.text-pretty { text-wrap: pretty; }

/* Global: enforce on all headings and body text */
h1, h2, h3, h4, h5, h6 { text-wrap: balance; }
p, li, dt, dd, blockquote, figcaption, article, .prose { text-wrap: pretty; }

/* Prevent text overflow in tight containers */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break-words { overflow-wrap: anywhere; word-break: break-word; }

/* Nowrap for prices, numbers + units */
.nowrap { white-space: nowrap; }

/* === ANIMATION TOKENS === */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scale-in { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.animate-fade { animation: fade-in 0.2s ease-out; }
.animate-slide-up { animation: slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.animate-slide-down { animation: slide-down 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.animate-scale { animation: scale-in 0.2s cubic-bezier(0.16, 1, 0.3, 1); }

/* Stagger children */
.stagger > * { animation: slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) both; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 40ms; }
.stagger > *:nth-child(3) { animation-delay: 80ms; }
.stagger > *:nth-child(4) { animation-delay: 120ms; }
.stagger > *:nth-child(5) { animation-delay: 160ms; }
.stagger > *:nth-child(6) { animation-delay: 200ms; }

/* ==========================================================================
   STRICT MOBILE & TABLET NAVIGATION ENGINE (LEBEDEV DOD & HIG COMPLIANCE)
   ========================================================================== */
@media (max-width: 1023px) {
  /* 1. Complete elimination of desktop nav pills from layout */
  html body header nav.nav-desktop,
  html body header .nav-desktop,
  html body header .nav-pill-container,
  html body .nav-desktop.nav-pill-container,
  .nav-desktop,
  .nav-pill-container.nav-desktop {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
  }

  /* 2. Burger Button: Always visible, properly sized, prominent */
  html body header .nav-mobile-toggle,
  html body header button.nav-mobile-toggle,
  .nav-mobile-toggle,
  button.nav-mobile-toggle {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    z-index: 50 !important;
    background-color: #FFFFFF !important;
    border: 1px solid #E4E2DC !important;
    border-radius: 12px !important;
    color: #18181B !important;
    cursor: pointer !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
  }

  html.dark body header .nav-mobile-toggle,
  html.dark body header button.nav-mobile-toggle {
    background-color: #141620 !important;
    border-color: rgba(255, 255, 255, 0.15) !important;
    color: #FFFFFF !important;
  }

  /* 3. Header Action Bar: Zero overflow on small screens */
  header .max-w-7xl {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
  }
}

@media (max-width: 639px) {
  /* On compact screens (< 640px), keep header clean: Logo, Phone, Cabinet, Theme, Burger */
  header .btn-primary {
    display: none !important;
  }
  header a.phone-mobile {
    min-width: 40px !important;
    min-height: 40px !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 12px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  #mobileMenuDrawer {
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
}

/* === CALCULATOR WORKBENCH TWO-COLUMN DESKTOP LAYOUT === */
.calc-workbench-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (min-width: 1024px) {
  .calc-workbench-grid {
    display: grid !important;
    grid-template-columns: 7fr 5fr !important;
    gap: 2rem !important;
    align-items: start !important;
  }
  .calc-workbench-grid > :first-child {
    grid-column: 1 !important;
  }
  .calc-workbench-grid > :nth-child(2) {
    grid-column: 2 !important;
  }
}

/* === HERO HIT BADGE POSITIONING === */
.hero-hit-badge {
  position: absolute !important;
  top: -8px !important;
  right: 8px !important;
  background-color: #4f46e5 !important;
  color: #ffffff !important;
  font-size: 8.5px !important;
  font-weight: 700 !important;
  font-family: inherit !important;
  line-height: 1 !important;
  padding: 4px 8px !important;
  border-radius: 9999px !important;
  letter-spacing: 0.04em !important;
  box-shadow: 0 1px 3px rgba(79, 70, 229, 0.4) !important;
  pointer-events: none !important;
  white-space: nowrap !important;
  z-index: 10 !important;
}

/* === CALCULATOR MOBILE ADAPTATION SYSTEM (<= 640px) === */
@media (max-width: 639px) {
  #calculator {
    padding-top: 1.5rem !important;
    padding-bottom: 2rem !important;
    overflow-x: hidden !important;
  }

  #calculator .max-w-7xl {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  /* Workbench grid spacing */
  .calc-workbench-grid {
    gap: 1.25rem !important;
  }

  /* Controls Column Container */
  #calculator .calc-workbench-grid > div:first-child {
    padding: 1rem 0.875rem !important;
    border-radius: 1rem !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Niche Buttons in Step 1 */
  .calc-niche-btn {
    padding: 0.875rem 0.75rem !important;
    border-radius: 0.875rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .calc-niche-btn .min-h-\[32px\] {
    min-height: auto !important;
  }

  /* Sliders: touch targets, value badges, scale labels */
  .calc-slider-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.5rem !important;
    margin-bottom: 0.5rem !important;
  }

  .calc-slider-header label {
    font-size: 0.75rem !important;
    line-height: 1.3 !important;
    flex: 1 1 auto !important;
  }

  .calc-slider-badge {
    font-size: 0.875rem !important;
    padding: 0.25rem 0.5rem !important;
    flex-shrink: 0 !important;
  }

  input[type="range"] {
    height: 2rem !important;
    cursor: pointer !important;
    margin: 0.25rem 0 !important;
  }

  /* Slider scale hint rows (15 000 ₽ ... 250 000 ₽) */
  .calc-scale-row {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 0.25rem !important;
    font-size: 10px !important;
    margin-top: 0.25rem !important;
    width: 100% !important;
  }

  /* Results Card (Workbench Output) */
  #calculator .calc-workbench-grid > div:nth-child(2) > div {
    padding: 1.125rem 0.875rem !important;
    border-radius: 1rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Forecast big digits: Leads & CPL */
  #calculator .calc-workbench-grid .grid-cols-2 {
    gap: 0.5rem !important;
  }

  #resLeads,
  #resCpl {
    font-size: 1.5rem !important;
    line-height: 1.2 !important;
  }

  /* Results rows: full flex wrap if needed */
  #calculator .calc-workbench-grid .space-y-3 > div {
    flex-wrap: wrap !important;
    gap: 0.25rem 0.5rem !important;
  }

  /* CTA Button inside calculator */
  #calculator button[onclick="openModalLead()"] {
    padding: 0.875rem 1rem !important;
    font-size: 0.875rem !important;
    min-height: 48px !important;
    width: 100% !important;
    white-space: normal !important;
    text-align: center !important;
    line-height: 1.3 !important;
  }

  /* Hero badge & title on calculator page */
  #badgeContainer {
    max-width: 100% !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 11px !important;
    line-height: 1.3 !important;
  }

  #syncBadgeText {
    white-space: normal !important;
    text-align: left !important;
  }
}

/* === END OF RESPONSIVE.CSS === */