/**
 * Nexx Technologies - Design & Layout System (nexx-system.css)
 * Architecture: CSS Cascade Layers (@layer tokens, base, layout, components, utilities)
 * Target: ZERO !important in theme layout and spacing rules.
 * All measurements adhere strictly to the token scale.
 */

@layer tokens, base, layout, components, utilities;

/* ==========================================================================
   LAYER: TOKENS
   ========================================================================== */
@layer tokens {
  :root {
    /* Spacing scale (4, 8, 12, 16, 24, 32, 48, 64, 96 px) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;
    --space-9: 96px;

    /* Section vertical rhythm */
    --section-pad-y: clamp(3.5rem, 6vw, 5.5rem);
    --section-pad-y-tight: clamp(2rem, 4vw, 3rem);
    --section-pad-y-loose: clamp(4.5rem, 8vw, 7rem);

    /* Container & Layout */
    --container: 1280px;
    --gutter: clamp(1rem, 3.5vw, 2rem);
    --radius: 6px;
    --radius-card: 16px;

    /* Color Palette */
    --nx-bg: #1C2031;
    --nx-bg-alt: #171A28;
    --nx-card-bg: rgba(255, 255, 255, 0.03);
    --nx-card-border: rgba(255, 255, 255, 0.08);
    --nx-card-hover-border: rgba(177, 229, 14, 0.3);
    --nx-lime: #B1E50E;
    --nx-lime-hover: #9ed00a;
    --nx-text: #FFFFFF;
    --nx-text-body: #CBD5E1;
    --nx-text-muted: #94A3B8;

    /* Fluid Typography Scale */
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --text-h1: clamp(2.4rem, 5vw, 3.8rem);
    --text-h2: clamp(1.8rem, 3.5vw, 2.6rem);
    --text-h3: clamp(1.3rem, 2.5vw, 1.8rem);
    --text-h4: clamp(1.1rem, 2vw, 1.35rem);
    --text-body: 1rem;
    --text-body-large: clamp(1.05rem, 1.8vw, 1.2rem);
    --text-body-small: 0.875rem;
    --line-height-heading: 1.18;
    --line-height-body: 1.6;

    /* Header & Navigation */
    --header-height: 80px;
    --nav-gap: 24px;
    --nav-font-size: 0.95rem;

    /* Transitions */
    --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }
}

/* ==========================================================================
   LAYER: BASE
   ========================================================================== */
@layer base {
  *, *::before, *::after {
    box-sizing: border-box;
  }

  html {
    scroll-behavior: smooth;
    overflow-x: clip;
  }

  body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    font-size: var(--text-body);
    line-height: var(--line-height-body);
    color: var(--nx-text-body);
    background-color: var(--nx-bg);
    overflow-x: clip;
    -webkit-font-smoothing: antialiased;
  }

  h1, h2, h3, h4, h5, h6 {
    color: var(--nx-text);
    line-height: var(--line-height-heading);
    font-weight: 700;
    margin-top: 0;
    margin-bottom: var(--space-4);
  }

  h1 { font-size: var(--text-h1); font-weight: 800; letter-spacing: -0.025em; }
  h2 { font-size: var(--text-h2); font-weight: 700; letter-spacing: -0.02em; }
  h3 { font-size: var(--text-h3); font-weight: 700; }
  h4 { font-size: var(--text-h4); font-weight: 600; }

  p {
    margin-top: 0;
    margin-bottom: var(--space-4);
  }

  p:last-child {
    margin-bottom: 0;
  }

  a {
    color: inherit;
    text-decoration: none;
    transition: var(--transition);
  }

  img, svg, video {
    display: block;
    max-width: 100%;
    height: auto;
  }

  /* Reset outer margins on first/last children inside sections */
  :where(section > .container > * > :first-child),
  :where(section > * > :first-child) {
    margin-top: 0;
  }

  :where(section > .container > * > :last-child),
  :where(section > * > :last-child) {
    margin-bottom: 0;
  }
}

/* ==========================================================================
   LAYER: LAYOUT
   ========================================================================== */
@layer layout {
  /* Unified Container System */
  .container,
  .nx-container,
  div[class*="container"]:not(.sub-menu):not(.form-container):not(.nexx-header-inner):not(.nexx-mobile-header-inner),
  section > .nx-row,
  section > .nexx-faq-list,
  section > .nexx-grid-2cols,
  section > .nexx-grid-3cols,
  section > .nexx-grid-4cols,
  .case-studies-container,
  .services-container {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--gutter);
    box-sizing: border-box;
  }

  /* Remove negative row margins when nx-row is a direct child of a containerless section */
  section > .nx-row {
    margin-left: auto;
    margin-right: auto;
  }

  /* Section Vertical Rhythm (Uniform across every page) */
  section,
  .landing_section,
  .nexx-workflow-section,
  .nexx-cta-section,
  .who-we-serve,
  .services-directory,
  .nexx-homepage-services-section,
  .nexx-ai-benefits-section {
    padding-block: var(--section-pad-y);
    margin-block: 0;
    position: relative;
    width: 100%;
    box-sizing: border-box;
  }

  /* Documented Section Padding Variants */
  section.section--tight {
    padding-block: var(--section-pad-y-tight);
  }

  section.section--loose {
    padding-block: var(--section-pad-y-loose);
  }

  /* Grid System (Strict equal columns, stretch, and gap scale) */
  .grid,
  .nexx-workflow-grid,
  .nexx-grid-4cols {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-5);
    align-items: stretch;
    width: 100%;
  }

  .nexx-grid-3cols {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-5);
    align-items: stretch;
    width: 100%;
  }

  .nexx-grid-2cols,
  .case-studies-grid,
  .nx-srv-single .nx-prob-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
    align-items: stretch;
    width: 100%;
  }

  .nx-tools-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
    align-items: stretch;
    width: 100%;
  }

  /* Responsive Grid Breakpoints */
  @media (max-width: 1099px) {
    .grid,
    .nexx-workflow-grid,
    .nexx-grid-4cols {
      grid-template-columns: repeat(2, 1fr);
      gap: var(--space-4);
    }

    .nexx-grid-3cols {
      grid-template-columns: repeat(2, 1fr);
      gap: var(--space-4);
    }

    .nx-tools-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: var(--space-3);
    }
  }

  @media (max-width: 767px) {
    .grid,
    .nexx-workflow-grid,
    .nexx-grid-4cols,
    .nexx-grid-3cols,
    .nexx-grid-2cols,
    .case-studies-grid,
    .nx-srv-single .nx-prob-grid,
    .nx-tools-grid {
      grid-template-columns: 1fr;
      gap: var(--space-4);
    }
  }

  /* Neutralize all Odd/Even zigzag layout traps */
  .circuit-item,
  .circuit-item:nth-child(even),
  .circuit-item:nth-child(odd),
  .timeline-item,
  .timeline-item:nth-child(even),
  .timeline-item:nth-child(odd),
  .solutions-item:nth-child(even),
  .solutions-item:nth-child(odd),
  .nx-row:nth-child(even),
  .nx-row:nth-child(odd) {
    margin-top: 0;
    margin-left: 0;
    margin-right: 0;
    transform: none;
    flex-direction: row;
    align-self: auto;
  }

  /* Mobile Stack Order Standardization */
  @media (max-width: 767px) {
    .nx-row,
    .row,
    [class*="row-reverse"],
    .flex-row {
      flex-direction: column;
    }

    .split--reverse {
      flex-direction: column;
    }
  }
}

/* ==========================================================================
   LAYER: COMPONENTS
   ========================================================================== */
@layer components {
  /* Navigation Bar System */
  header,
  #nexx-header,
  .nexx-header {
    height: var(--header-height);
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(28, 32, 49, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--nx-card-border);
    display: flex;
    align-items: center;
  }

  header .container,
  #nexx-header .container,
  .nexx-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    width: 100%;
  }

  /* Desktop Header (>= 1100px) */
  @media (min-width: 1100px) {
    .nexx-header-inner {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
    }

    .nexx-mobile-header-inner {
      display: none;
    }

    .nexx-nav,
    nav.nexx-nav {
      display: flex;
      align-items: center;
      gap: var(--nav-gap);
    }

    .nexx-nav .main-menu {
      display: flex;
      align-items: center;
      gap: var(--nav-gap);
      list-style: none;
      margin: 0;
      padding: 0;
    }

    .nexx-nav .main-menu > li {
      position: relative;
      display: flex;
      align-items: center;
      height: var(--header-height);
    }

    .nexx-nav .main-menu > li > a {
      color: #E2E8F0;
      font-size: var(--nav-font-size);
      font-weight: 500;
      white-space: nowrap;
      padding: var(--space-2) var(--space-1);
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    .nexx-nav .main-menu > li:hover > a,
    .nexx-nav .main-menu > li:focus-within > a,
    .nexx-nav .main-menu > li.current-menu-item > a,
    .nexx-nav .main-menu > li.current_page_item > a,
    .nexx-nav .main-menu > li.current-menu-ancestor > a {
      color: var(--nx-lime);
    }

    /* Standard Mega Menu / Dropdown */
    .nexx-nav .main-menu > li.menu-item-has-children > .sub-menu {
      position: absolute;
      top: 100%;
      left: 50%;
      transform: translateX(-50%) translateY(8px);
      background: var(--nx-bg-alt);
      border: 1px solid var(--nx-card-border);
      border-radius: var(--radius);
      box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: var(--transition);
      z-index: 1010;
    }

    .nexx-nav .main-menu > li.menu-item-has-children:hover > .sub-menu,
    .nexx-nav .main-menu > li.menu-item-has-children:focus-within > .sub-menu {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
      transform: translateX(-50%) translateY(0);
    }

    .nexx-nav .main-menu > li#menu-item-2168 > .sub-menu {
      width: 860px;
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: var(--space-5);
      padding: var(--space-6);
    }

    .nexx-nav .main-menu > li:not(#menu-item-2168) > .sub-menu {
      min-width: 220px;
      display: flex;
      flex-direction: column;
      gap: 4px;
      padding: var(--space-3);
    }
  }

  /* Tablet & Mobile Nav (< 1100px) */
  @media (max-width: 1099px) {
    .nexx-header-inner {
      display: none;
    }

    .nexx-mobile-header-inner {
      display: flex;
      min-height: 44px;
      justify-content: space-between;
      align-items: center;
      width: 100%;
    }

    .nexx-mobile-menu-toggler {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 44px;
      height: 44px;
      background: transparent;
      border: 1px solid var(--nx-card-border);
      border-radius: var(--radius);
      color: var(--nx-text);
      cursor: pointer;
    }
  }

  /* Button System (Strict 6px radius, no pill buttons, 44px touch target) */
  .nx-btn-primary,
  .nexx-button:not(.is-secondary),
  .btn-primary,
  a.nx-btn-primary,
  button.nx-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--nx-lime);
    color: #11141D;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1;
    padding: 13px 26px;
    border-radius: var(--radius);
    min-height: 44px;
    height: 44px;
    border: 1px solid var(--nx-lime);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
    transition: var(--transition);
  }

  .nx-btn-primary:hover,
  .nexx-button:not(.is-secondary):hover,
  .btn-primary:hover {
    background-color: var(--nx-lime-hover);
    border-color: var(--nx-lime-hover);
    color: #000000;
    transform: translateY(-1px);
  }

  .nx-btn-secondary,
  .nexx-button.is-secondary,
  .btn-secondary,
  a.nx-btn-secondary,
  button.nx-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    color: var(--nx-text);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1;
    padding: 13px 24px;
    border-radius: var(--radius);
    min-height: 44px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
    transition: var(--transition);
  }

  .nx-btn-secondary:hover,
  .nexx-button.is-secondary:hover,
  .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    color: #FFFFFF;
    transform: translateY(-1px);
  }

  /* Cards in a Row (Equal height, padding, and inner stretch) */
  .nexx-block,
  .nexx-workflow-step,
  .nexx-benefit-card,
  .nx-tool-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--nx-card-bg);
    border: 1px solid var(--nx-card-border);
    border-radius: var(--radius-card);
    padding: var(--space-6) var(--space-5);
    box-sizing: border-box;
    margin: 0;
    transition: var(--transition);
  }

  .nexx-block:hover,
  .nexx-workflow-step:hover,
  .nx-tool-card:hover {
    border-color: var(--nx-card-hover-border);
    transform: translateY(-2px);
  }

  /* Process Cards Inner Alignment */
  .nw-step-inner {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    flex: 1 1 auto;
  }

  .nw-step-content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
  }

  .nw-desc {
    flex-grow: 1;
    margin: 0;
  }

  /* Final CTA Block (Strict Centering & Zero Horizontal Overlap) */
  .nexx-cta-section .nexx-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: clamp(2.5rem, 6vw, 4.5rem) clamp(1.5rem, 5vw, 4rem);
  }

  .nexx-cta-section .nexx-label {
    display: block;
    width: 100%;
    color: var(--nx-lime);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    margin-bottom: var(--space-4);
    text-align: center;
  }

  .nexx-cta-section h2 {
    width: 100%;
    max-width: 860px;
    margin-inline: auto;
    margin-bottom: var(--space-4);
    text-align: center;
  }

  .nexx-cta-section p {
    width: 100%;
    max-width: 680px;
    margin-inline: auto;
    margin-bottom: var(--space-6);
    font-size: var(--text-body-large);
    text-align: center;
  }
}

/* ==========================================================================
   LAYER: UTILITIES
   ========================================================================== */
@layer utilities {
  .align-center, .text-center { text-align: center; }
  .align-left, .text-left { text-align: left; }
  .align-right, .text-right { text-align: right; }

  /* Accessibility Exceptions (Allowed) */
  .sr-only,
  .visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }

  @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;
    }
  }
}


/* ==========================================================================
   UNLAYERED ARCHITECTURAL ENFORCEMENTS (High Specificity - ZERO !important)
   ========================================================================== */

/* 1. Navigation Breakpoint: Desktop >= 1100px; Mobile/Burger < 1100px */
@media (min-width: 1100px) {
  html body #nexx-header .nexx-header-inner,
  html body .nexx-header-inner {
    display: flex;
  }
  html body #nexx-header .nexx-mobile-header-inner,
  html body .nexx-mobile-header-inner {
    display: none;
  }
}

@media (max-width: 1099px) {
  html body #nexx-header .nexx-header-inner,
  html body .nexx-header-inner {
    display: none;
  }
  html body #nexx-header .nexx-mobile-header-inner,
  html body .nexx-mobile-header-inner {
    display: flex;
    min-height: 44px;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }
  html body .nexx-mobile-menu-toggler {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: 1px solid var(--nx-card-border);
    border-radius: var(--radius);
    color: var(--nx-text);
    cursor: pointer;
  }
}

/* 2. Button System Enforcements: Strict 6px Radius, 44px Touch Target */
html body .nx-srv-wrap .nx-btn,
html body .nx-btn,
html body .nx-btn-primary,
html body .nx-btn-secondary,
html body .nexx-button,
html body .btn-primary,
html body .btn-secondary,
html body input[type="submit"].nexx-button,
html body input[type="submit"].wpcf7-submit,
html body input.wpcf7-submit,
html body button.wpcf7-submit,
html body a.nx-btn,
html body a.nexx-button {
  border-radius: var(--radius);
  min-height: 44px;
  height: 44px;
  box-sizing: border-box;
}
