/* ==========================================================================
   CONVERTMASTER PRO — RESPONSIVE STYLESHEET (responsive.css)
   Mobile-First Breakpoint Engine (320px to 1920px+)
   Zero CLS, Zero Horizontal Overflow, Touch Ergonomics
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Large Displays & Desktops (1440px to 1920px+)
   -------------------------------------------------------------------------- */
@media (min-width: 1440px) {
  :root {
    --container-max: 1400px;
  }

  .category-cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .electrical-cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .popular-cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1920px) {
  :root {
    --container-max: 1600px;
  }

  .category-cards-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .electrical-cards-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .hero-headline {
    font-size: 4.5rem;
  }
}

/* --------------------------------------------------------------------------
   2. Standard Desktop & Laptop (1025px to 1439px)
   -------------------------------------------------------------------------- */
@media (max-width: 1280px) {
  .footer-top-grid {
    grid-template-columns: 1.5fr repeat(3, 1fr);
    gap: 2rem;
  }

  .footer-brand-col {
    grid-column: span 3;
    margin-bottom: 1rem;
  }
}

/* --------------------------------------------------------------------------
   3. Tablet Landscape & Medium Desktops (769px to 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1220px) {
  .site-header {
    height: auto !important;
    padding-bottom: 0.35rem !important;
  }

  .header-inner {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
  }

  .desktop-nav {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap !important;
    width: 100% !important;
    margin: 0.25rem 0 0 0 !important;
    padding: 0.35rem 0 !important;
    gap: 0.45rem !important;
    border-top: 1px solid var(--border-color, rgba(226, 232, 240, 0.6));
    scrollbar-width: none !important;
  }

  .desktop-nav::-webkit-scrollbar {
    display: none !important;
  }

  .desktop-nav .nav-link {
    font-size: 0.78rem !important;
    padding: 0.3rem 0.65rem !important;
    background: var(--bg-surface-subtle, rgba(241, 245, 249, 0.85));
    border-radius: var(--radius-full, 9999px);
    border: 1px solid var(--border-color, #e2e8f0);
    flex-shrink: 0 !important;
  }

  .desktop-nav .nav-link.is-active {
    background: var(--color-primary-600, #2563eb) !important;
    color: #ffffff !important;
    border-color: var(--color-primary-600, #2563eb) !important;
  }

  .mobile-menu-toggle {
    display: flex !important;
  }
}

@media (max-width: 1024px) {
  .search-trigger-pill span {
    display: none;
  }

  .search-trigger-pill {
    padding: 0.5rem;
    width: 42px;
    height: 42px;
    justify-content: center;
  }

  /* Live converter adjustments */
  .converter-body-grid {
    gap: 1rem;
  }

  .category-cards-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.85rem;
  }

  .electrical-cards-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .popular-cards-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
  }

  .blog-cards-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }

  .blog-card-img-wrap {
    aspect-ratio: 5 / 3;
    height: auto;
    width: 100%;
    overflow: hidden;
  }

  .blog-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  .footer-top-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .footer-brand-col {
    grid-column: span 2;
  }
}

/* --------------------------------------------------------------------------
   4. Tablets Portrait & Large Handhelds (426px to 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  :root {
    --header-height: 68px;
  }

  /* Prevent iOS Safari auto-zoom on input focus */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="search"],
  select,
  textarea,
  .tool-input,
  .unit-select {
    font-size: 16px !important;
  }

  .hero-section {
    padding-top: calc(var(--header-height) + 1rem);
    padding-bottom: 2rem;
    overflow: hidden;
  }

  .hero-top-flanked-layout {
    flex-direction: column;
    gap: 1.5rem;
  }

  .center-flank {
    order: -1;
    margin-bottom: 0.5rem;
  }

  .hero-split-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  /* Converter stack becomes vertical on tablets/mobiles */
  .converter-body-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 0.75rem;
  }

  .converter-swap-btn {
    margin: -0.5rem auto;
    transform: rotate(90deg);
  }

  .converter-swap-btn:hover {
    transform: rotate(90deg) scale(1.1);
  }

  .unit-input-box {
    padding: 1rem;
  }

  .hero-cta-group {
    flex-direction: column;
    width: 100%;
  }

  .hero-cta-group .btn {
    width: 100%;
  }

  .category-cards-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .electrical-cards-grid,
  .why-us-grid,
  .blog-cards-grid {
    grid-template-columns: 1fr;
    gap: 1.15rem;
  }

  .quick-tool-card {
    padding: 1rem;
    gap: 0.75rem;
  }

  .tool-btn-row .btn,
  .tool-action-btn,
  .blog-read-btn,
  .popular-card-btn,
  .related-tool-pill {
    min-height: 44px;
    touch-action: manipulation;
  }

  .tool-form-row {
    display: flex;
    flex-direction: row;
    gap: 0.75rem;
  }

  .popular-cards-grid {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.75rem;
  }

  .footer-top-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  /* Category Filter Bar becomes sleek touch scrollable pill bar on mobile & tablets */
  .category-filter-nav {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    justify-content: flex-start;
    padding: 0.35rem var(--container-pad) 0.85rem var(--container-pad);
    margin-left: calc(-1 * var(--container-pad));
    margin-right: calc(-1 * var(--container-pad));
    gap: 0.5rem;
  }

  .category-filter-nav::-webkit-scrollbar {
    display: none;
  }

  .category-filter-btn {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 0.825rem;
    padding: 0.45rem 1rem;
  }

  /* Trending strip on tablets/phones */
  .trending-strip-section {
    padding: 0.65rem 0;
  }

  .trending-strip-inner {
    gap: 0.75rem;
  }

  .trending-badge-label {
    font-size: 0.7rem;
    padding: 0.35rem 0.65rem;
    gap: 0.35rem;
  }

  .trending-badge-label svg {
    width: 13px;
    height: 13px;
  }

  .trending-chip {
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
  }

  /* Top AdSense slot responsive scaling */
  .ad-leaderboard {
    min-height: 60px;
    padding: 0.75rem 0.5rem;
  }

  .ad-spec-label {
    font-size: 0.75rem;
  }

  .footer-brand-col {
    grid-column: span 1;
  }

  .footer-bottom-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .newsletter-form {
    flex-direction: column;
    width: 100%;
  }

  .newsletter-form .btn {
    width: 100%;
  }

  .floating-actions-wrap {
    bottom: 1.25rem;
    right: 1.25rem;
  }
}

/* --------------------------------------------------------------------------
   5. Standard Mobile (375px to 425px)
   -------------------------------------------------------------------------- */
@media (max-width: 425px) {
  :root {
    --container-pad: 1rem;
  }

  .hero-headline {
    font-size: 2.25rem;
  }

  .hero-subheadline {
    font-size: 1rem;
  }

  .live-converter-card {
    padding: 1.25rem;
    border-radius: var(--radius-xl);
  }

  .converter-footer-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .conversion-formula-pill {
    justify-content: center;
    text-align: center;
  }

  .converter-action-btns {
    justify-content: center;
  }

  .unit-value-input,
  .unit-value-output {
    font-size: 1.6rem;
  }

  .section-title {
    font-size: 1.85rem;
  }

  .category-card {
    padding: 0.75rem 0.65rem;
    min-height: 95px;
    border-radius: var(--radius-md);
  }

  .category-card-title {
    font-size: 0.84rem;
    line-height: 1.25;
    margin-bottom: 0.2rem;
  }

  .category-card-desc {
    font-size: 0.72rem;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .category-card-footer {
    font-size: 0.74rem;
    margin-top: 0.35rem;
  }

  .category-icon-box {
    width: 32px;
    height: 32px;
  }

  .category-unit-count {
    font-size: 0.68rem;
  }

  .popular-card {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-16);
  }

  .popular-card-title {
    font-size: 0.92rem;
  }

  .popular-card-desc {
    font-size: 0.78rem;
    margin-bottom: 0.6rem;
  }

  .electrical-card,
  .why-card {
    padding: 1rem;
    border-radius: var(--radius-lg);
  }
}

/* --------------------------------------------------------------------------
   6. Small Mobile (320px to 360px)
   -------------------------------------------------------------------------- */
@media (max-width: 360px) {
  .brand-logo span {
    font-size: 1.15rem;
  }

  .logo-icon-wrap {
    width: 34px;
    height: 34px;
  }

  .header-actions {
    gap: 0.4rem;
  }

  .action-btn {
    width: 36px;
    height: 36px;
  }

  .unit-value-input,
  .unit-value-output {
    font-size: 1.35rem;
  }

  .category-filter-btn {
    padding: 0.4rem 0.85rem;
    font-size: 0.75rem;
  }
}

/* CM Mobile UX Fix — Touch-friendly drawer nav items */
.drawer-nav-item,
.mobile-drawer-header .brand-logo {
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.mobile-drawer-header .brand-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

/* ==========================================================================
   CONVERTMASTER PRO — ENHANCED MOBILE/TABLET UX ADDITIONS
   Additional responsive rules to prevent overflow, improve touch targets,
   and ensure layout stability across all viewport sizes.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Universal Overflow Safety (prevents horizontal scroll on all screens)
   -------------------------------------------------------------------------- */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* All containers must not exceed viewport width */
.container, .hero-section, .section-container, .footer-inner,
.header-inner, .mobile-drawer {
  max-width: 100%;
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   Action Buttons — minimum 44x44px touch target (WCAG 2.5.5)
   -------------------------------------------------------------------------- */
.action-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Mobile: tighten header action gap slightly */
@media (max-width: 430px) {
  .header-actions {
    gap: 0.25rem;
  }
  
  .action-btn {
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    height: 40px;
  }

  .brand-logo span {
    font-size: 1rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 360px) {
  .brand-logo span {
    display: none; /* Show only icon on very small screens */
  }
}

/* --------------------------------------------------------------------------
   Tablet Layout (768px – 1024px)
   Ensure cards use available space; not a stretched mobile layout.
   -------------------------------------------------------------------------- */
@media (min-width: 600px) and (max-width: 1024px) {
  .category-cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .hero-top-flanked-layout {
    gap: 1.25rem;
  }

  .converter-body-grid {
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto;
    gap: 1rem;
  }

  .converter-swap-btn {
    transform: none;
    margin: auto;
    align-self: center;
  }

  .converter-swap-btn:hover {
    transform: scale(1.1);
  }

  .popular-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .electrical-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .blog-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --------------------------------------------------------------------------
   Mobile Drawer — touch target sizing and scrollability
   -------------------------------------------------------------------------- */
.drawer-nav-item {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0 1.25rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  text-decoration: none;
}

.mobile-drawer {
  max-height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* --------------------------------------------------------------------------
   Input fields — prevent iOS auto-zoom (font-size >= 16px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="tel"],
  input[type="search"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px !important;
    -webkit-text-size-adjust: 100%;
  }
}

/* --------------------------------------------------------------------------
   Ad containers — prevent layout shift and overflow
   -------------------------------------------------------------------------- */
.adsense-slot-container,
.adsense-slot,
.ad-leaderboard,
.ad-sticky-bottom {
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.ad-sticky-bottom {
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
}

/* --------------------------------------------------------------------------
   Calculator + Converter cards on mobile
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .calc-card,
  .live-converter-card,
  .quick-tool-card {
    border-radius: var(--radius-lg);
    padding: 1rem;
  }

  .calc-keypad {
    gap: 0.4rem;
  }

  .calc-btn {
    min-height: 44px;
    font-size: 1rem;
  }
  
  .unit-value-input,
  .unit-value-output {
    font-size: 1.5rem;
  }
  
  /* Hero headline at small breakpoints */
  .hero-headline {
    font-size: clamp(1.7rem, 6vw, 2.4rem);
  }
}

/* --------------------------------------------------------------------------
   Footer layout on small screens
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .footer-top-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .footer-bottom-bar {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
    align-items: center;
  }

  .footer-legal-links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
  }
}

/* --------------------------------------------------------------------------
   Desktop max-width content areas
   -------------------------------------------------------------------------- */
@media (min-width: 1440px) {
  .hero-section .container {
    max-width: var(--container-max, 1320px);
  }
}

@media (min-width: 1920px) {
  body {
    font-size: 17px;
  }
}

/* Vertical Stacking for Category Tabs/Pills, Quick Tool Buttons, and Icon Buttons */
.category-tab-btn,
.category-pill,
.category-pills,
.popular-category-pill,
.quick-tool-btn,
.quick-tool-card,
.quick-tool-header,
.icon-btn,
.tool-btn,
.tool-action-btn,
.calc-tool-btn {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  gap: 6px !important;
}

.category-tab-btn svg,
.category-tab-btn img,
.category-pill svg,
.category-pill img,
.quick-tool-btn svg,
.quick-tool-btn img,
.icon-btn svg,
.icon-btn img,
.tool-btn svg,
.tool-btn img,
.tool-action-btn svg,
.tool-action-btn img,
.quick-tool-header svg,
.quick-tool-header img,
.quick-tool-icon {
  order: -1;
}

