(function () {
  'use strict';
  var root = document.documentElement;
  var motion = window.matchMedia('(prefers-reduced-motion: reduce)');
  var finePointer = window.matchMedia('(hover: hover) and (pointer: fine)');
  var content = JSON.parse(document.getElementById('site-content').textContent);
  var $ = function (selector) { return document.querySelector(selector); };
  var $$ = function (selector) { return Array.prototype.slice.call(document.querySelectorAll(selector)); };
  var solutions = [
    { name: 'Sales & CRM', label: 'RELATIONSHIPS, CONNECTED', title: ['Turn enquiries', 'into opportunities.'], description: 'Keep leads, follow-ups, quotations, and sales orders in one place. Give every customer conversation a clear next step.', tags: ['CRM', 'Quotations', 'Sales orders'], cta: 'Explore sales & CRM', board: 'Your sales workflow', steps: [["Enquiry", "Keep customer information together"], ["Follow up", "Track conversations and the next action"], ["Quotation", "Give every opportunity a next step"], ["Order", "Connect commitments to operations"]], short: 'Keep every enquiry, follow-up and sales order in one place.', flow: ['Enquiry', 'Quotation', 'Order'] },
    { name: 'Production', label: 'OPERATIONS, CONNECTED', title: ['Bring clarity', 'to your shop floor.'], description: 'Connect bills of materials, work orders, job cards, and production progress. Keep delivery commitments visible to your team.', tags: ['BOM', 'Job cards', 'Work orders'], cta: 'Explore manufacturing ERP', board: 'Your production workflow', steps: [["BOM", "Connect products and material requirements"], ["Material planning", "Plan the materials needed for production"], ["Work order", "Keep production priorities clear"], ["Job card", "Track activity on your shop floor"]], short: 'Connect bills of materials, work orders and production progress.', flow: ['BOM', 'Work order', 'Job card'] },
    { name: 'Inventory', label: 'SUPPLY CHAIN, CONNECTED', title: ['The right stock.', 'At the right time.'], description: 'Track purchases, goods received, batches, reservations, and dispatches. Connect material requirements with stock availability.', tags: ['Purchasing', 'Stock', 'Dispatch'], cta: 'Explore inventory management', board: 'Your inventory workflow', steps: [["Stock", "View stock availability and balances"], ["Receive", "Record purchases, goods received and batches"], ["Reserve", "Align material requirements with stock"], ["Dispatch", "Keep stock movements connected"]], short: 'Connect purchases, batches, stock reservations and dispatch.', flow: ['Receive', 'Reserve', 'Dispatch'] },
    { name: 'Finance', label: 'VISIBILITY, CONNECTED', title: ['See the details.', 'Know the bigger picture.'], description: 'Bring invoicing, ledgers, business reports, and management dashboards together for a clearer view of daily operations.', tags: ['Finance', 'Reporting', 'Dashboards'], cta: 'Explore finance & reporting', board: 'Your financial workflow', steps: [["Invoice", "Keep business transactions connected"], ["Eway bill", "Connect goods movement with transport details"], ["Ledger", "Bring financial records together"], ["Report", "See a clearer picture of your business"]], short: 'Bring invoices, ledgers and business reports into one view.', flow: ['Invoice', 'Ledger', 'Report'] }
    ,{ name: 'Purchasing', label: 'PROCUREMENT, CONNECTED', title: ['From requirement', 'to goods received.'], description: 'Connect purchase requests, supplier quotations, purchase orders, approvals and goods received. Keep procurement aligned with your material requirements.', tags: ['Purchase requests', 'Purchase orders', 'GRN'], cta: 'Explore purchasing', board: 'Your purchasing workflow', steps: [["Indent", "Plan the materials your teams need"], ["Purchase quotation", "Review supplier quotations"], ["Purchase order", "Connect supplier details and approvals"], ["GRN", "Record inward materials and quality checks"]] }
    ,{ name: 'HRMS & payroll', label: 'PEOPLE, CONNECTED', title: ['Your people.', 'Your processes, together.'], description: 'Bring employee records, attendance, shifts, leave and payroll together. Manage salary structures and salary slips alongside your daily people operations.', tags: ['Attendance', 'Leave & shifts', 'Payroll'], cta: 'Explore HRMS & payroll', board: 'Your employee workflow', steps: [['Employee', 'Organise records and onboarding'], ['Attendance & leave', 'Connect shifts, attendance and leave'], ['Payroll', 'Manage salary structures and salary slips']] }
    ,{ name: 'Service management', label: 'CUSTOMER CARE, CONNECTED', title: ['Keep every service', 'request in view.'], description: 'Record customer complaints, assign work to employees and track service status and history. Keep customer, product and problem details together.', tags: ['Complaints', 'Assignments', 'Service history'], cta: 'Explore service management', board: 'Your service workflow', steps: [['Complaint', 'Capture the customer and reported problem'], ['Assignment', 'Connect the request with your service team'], ['Service history', 'Track status and previous service activity']] }
    ,{ name: 'Maintenance', label: 'EQUIPMENT CARE, CONNECTED', title: ['Organised maintenance.', 'Clearer follow-through.'], description: 'Maintain equipment maintenance and calibration records, including due dates and reminder dates. Keep planned activities and tracking in one workspace.', tags: ['Maintenance', 'Calibration', 'Due dates'], cta: 'Explore maintenance', board: 'Your maintenance workflow', steps: [['Record', 'Maintain equipment activity details'], ['Plan', 'Set calibration due and reminder dates'], ['Track', 'Review maintenance and calibration records']] }

  ];
  function animate(element) {
    if (motion.matches) { return; }
    element.classList.remove('panel-enter');
    void element.offsetWidth;
    element.classList.add('panel-enter');
  }
  function replaceTextChildren(element, items, tag) {
    element.textContent = '';
    items.forEach(function (text, index) {
      if (tag === 'flow' && index > 0) { element.appendChild(document.createElement('i')); }
      var child = document.createElement(tag === 'flow' ? 'span' : tag);
      child.textContent = text;
      element.appendChild(child);
    });
  }
  function tabs(selector, onSelect) {
    var buttons = $$(selector);
    function select(button) {
      buttons.forEach(function (b) { b.setAttribute('aria-selected', String(b === button)); b.tabIndex = b === button ? 0 : -1; });
      onSelect(button, buttons.indexOf(button));
    }
    buttons.forEach(function (button, index) {
      button.addEventListener('click', function () { select(button); });
      button.addEventListener('keydown', function (event) {
        var next = index;
        if (event.key === 'ArrowRight') { next = (index + 1) % buttons.length; }
        else if (event.key === 'ArrowLeft') { next = (index + buttons.length - 1) % buttons.length; }
        else if (event.key === 'Home') { next = 0; }
        else if (event.key === 'End') { next = buttons.length - 1; }
        else { return; }
        event.preventDefault(); buttons[next].focus(); select(buttons[next]);
      });
    });
  }
  var heroWorkflows = [
    { name: 'Sales & CRM', short: solutions[0].short, flow: ['Enquiry', 'Follow up', 'Quotation', 'Order'] },
    { name: 'Production', short: solutions[1].short, flow: ['BOM', 'Material planning', 'Work order', 'Job card'] },
    { name: 'Purchase', short: 'Connect indents, supplier quotations, purchase orders and inward GRN.', flow: ['Indent', 'Purchase quotation', 'Purchase order', 'GRN'] },
    { name: 'Inventory', short: solutions[2].short, flow: ['Stock', 'Receive', 'Reserve', 'Dispatch'] },
    { name: 'Finance', short: solutions[3].short, flow: ['Invoice', 'Eway bill', 'Ledger', 'Report'] }
  ];
  tabs('[data-hero]', function (button, index) {
    var item = heroWorkflows[index];
    $('#hero-module-name').textContent = item.name;
    $('#hero-module-copy').textContent = item.short;
    replaceTextChildren($('#hero-module-flow'), item.flow, 'flow');
    $('#hero-module-flow').scrollLeft = 0;
    $('#hero-module').setAttribute('aria-labelledby', button.id);
    animate($('#hero-module'));
  });
  tabs('[data-solution]', function (button, index) {
    var item = solutions[index];
    $('#solution-label').textContent = item.label;
    var title = $('#solution-title'); title.textContent = item.title[0];
    title.appendChild(document.createElement('br')); title.appendChild(document.createTextNode(item.title[1]));
    $('#solution-description').textContent = item.description;
    replaceTextChildren($('#solution-tags'), item.tags, 'span');
    $('#solution-cta').textContent = item.cta;
    $('#board-title').textContent = item.board;
    var steps = $('#process-steps'); steps.textContent = '';
    item.steps.forEach(function (step, i) {
      var row = document.createElement('div'), number = document.createElement('span'), section = document.createElement('section'), title = document.createElement('h4'), description = document.createElement('p'), mark = document.createElement('span');
      number.className = 'process-number'; number.textContent = '0' + (i + 1);
      title.textContent = step[0]; description.textContent = step[1]; section.appendChild(title); section.appendChild(description);
      mark.className = 'process-mark'; mark.textContent = '+'; mark.setAttribute('aria-hidden', 'true');
      row.appendChild(number); row.appendChild(section); row.appendChild(mark); steps.appendChild(row);
    });
    $('#solution-panel').setAttribute('aria-labelledby', button.id);
    animate($('.solution-copy')); animate($('.process-board'));
  });
  var industryIndex = 0, industryTimer = 0;
  function showIndustry(index) {
    if (index === industryIndex) { return; }
    industryIndex = index;
    var item = content.industries[index];
    $$('[data-industry]').forEach(function (button, i) { button.classList.toggle('selected', i === index); button.setAttribute('aria-pressed', String(i === index)); });
    var img = $('#industry-image');
    img.src = 'assets/images/' + item[1] + '.webp'; img.alt = item[0] + ' operations';
    $('#industry-title').textContent = item[0]; $('#industry-description').textContent = item[2];
    $('#industry-counter').textContent = '0' + (index + 1) + ' / 08';
    $('#industry-cta').textContent = 'Discuss ' + item[3].charAt(0).toLowerCase() + item[3].slice(1);
    animate($('.industry-stage-copy'));
  }
  $$('[data-industry]').forEach(function (button, index) {
    button.addEventListener('click', function () { window.clearTimeout(industryTimer); showIndustry(index); });
    button.addEventListener('pointerenter', function () {
      if (!finePointer.matches) { return; }
      window.clearTimeout(industryTimer); industryTimer = window.setTimeout(function () { showIndustry(index); }, 140);
    });
    button.addEventListener('pointerleave', function () { window.clearTimeout(industryTimer); });
  });
  var clientButtons = $$('[data-client]'), clientProfile = $('#client-profile'), activeClient = null;
  function closeProfile() {
    clientProfile.hidden = true;
    clientButtons.forEach(function (button) { button.setAttribute('aria-expanded', 'false'); });
    if (activeClient) { activeClient.focus({ preventScroll: true }); }
    activeClient = null;
  }
  clientButtons.forEach(function (button, index) {
    button.addEventListener('click', function () {
      if (activeClient === button) { closeProfile(); return; }
      var item = content.clients[index]; activeClient = button;
      clientButtons.forEach(function (other) { other.setAttribute('aria-expanded', String(other === button)); });
      $('#client-name').textContent = item[0]; $('#client-sector').textContent = item[1]; $('#client-description').textContent = item[3]; $('#client-category').textContent = item[4];
      clientProfile.hidden = false; clientProfile.setAttribute('role', 'region'); clientProfile.setAttribute('aria-labelledby', 'client-name'); animate(clientProfile);
    });
  });
  $('.close-profile').addEventListener('click', closeProfile);
  var themeButton = $('.theme-toggle');
  function themeLabel() {
    var dark = root.dataset.theme === 'dark';
    themeButton.setAttribute('aria-label', dark ? 'Switch to light mode' : 'Switch to dark mode');
    themeButton.title = dark ? 'Switch to light mode' : 'Switch to dark mode';
    $('meta[name="theme-color"]').content = dark ? '#101311' : '#f5f7f1';
  }
  themeLabel();
  themeButton.addEventListener('click', function () {
    document.body.classList.add('theme-changing');
    root.dataset.theme = root.dataset.theme === 'dark' ? 'light' : 'dark';
    try { localStorage.setItem('techunity2-theme', root.dataset.theme); } catch (error) {}
    themeLabel(); window.setTimeout(function () { document.body.classList.remove('theme-changing'); }, 400);
  });
  var menuButton = $('.menu-toggle'), menu = $('#navigation');
  var menuScrim = $('.menu-scrim');
  function setMenuState(open) {
    document.body.classList.toggle('menu-open', open);
    menu.inert = !open;
    $('#main').inert = open; $('.site-footer').inert = open;
  }
  setMenuState(false);
  function closeMenu(returnFocus) {
    setMenuState(false); menu.classList.remove('open'); menuButton.setAttribute('aria-expanded', 'false'); menuButton.setAttribute('aria-label', 'Open menu');
    if (returnFocus) { menuButton.focus(); }
  }
  menuButton.addEventListener('click', function () {
    var open = !menu.classList.contains('open'); menu.classList.toggle('open', open); setMenuState(open);
    menuButton.setAttribute('aria-expanded', String(open)); menuButton.setAttribute('aria-label', open ? 'Close menu' : 'Open menu');
  });
  $$('#navigation a').forEach(function (link) { link.addEventListener('click', function () { closeMenu(false); }); });
  document.addEventListener('keydown', function (event) { if (event.key === 'Escape') { if (menu.classList.contains('open')) { closeMenu(true); } else if (!clientProfile.hidden) { closeProfile(); } } });
  document.addEventListener('click', function (event) { if (!event.target.closest('.site-header')) { closeMenu(false); } });
  menuScrim.addEventListener('click', function () { closeMenu(true); });
  $$('[data-open-solution]').forEach(function (link) { link.addEventListener('click', function () { var tab = $('[data-solution="' + link.dataset.openSolution + '"]'); if (tab) { tab.click(); } }); });
  document.addEventListener('keydown', function (event) {
    if (event.key !== 'Tab' || !menu.classList.contains('open')) { return; }
    var controls = $$('.site-header a[href], .site-header button').filter(function (el) { return el.getClientRects().length > 0 && !el.closest('[inert]'); });
    var first = controls[0], last = controls[controls.length - 1];
    if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
    else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
  });
  // Repeatable entrances and exits in either scroll direction.
  $$('.hero-heading, .hero-visual, .module-ribbon, .clients-heading, .client-grid, .footer-top, .footer-wordmark').forEach(function (el) { el.classList.add('reveal'); });
  var reveals = $$('.reveal'), revealObserver;
  function revealAll() {
    root.classList.remove('motion');
    reveals.forEach(function (el) { el.classList.add('visible'); el.classList.remove('above-viewport'); });
    if (revealObserver) { revealObserver.disconnect(); }
  }
  function startReveals() {
    if (revealObserver) { revealObserver.disconnect(); }
    if (motion.matches || !('IntersectionObserver' in window)) { revealAll(); return; }
    try {
      revealObserver = new IntersectionObserver(function (entries) {
        entries.forEach(function (entry) {
          var el = entry.target;
          var isAbove = entry.boundingClientRect.bottom <= (entry.rootBounds ? entry.rootBounds.top : 115);
          el.classList.toggle('above-viewport', isAbove);
          el.classList.toggle('visible', entry.isIntersecting || el.contains(document.activeElement));
        });
      }, { threshold: 0, rootMargin: '-115px 0px -35px 0px' });
      root.classList.add('motion');
      reveals.forEach(function (el) { el.style.setProperty('--delay', '0ms'); revealObserver.observe(el); });
    } catch (error) { revealAll(); }
  }
  startReveals();
  document.addEventListener('focusin', function (event) {
    var reveal = event.target.closest('.reveal');
    if (reveal) { reveal.classList.add('visible'); }
  });
  function motionChanged() { startReveals(); if (motion.matches) { $('.hero-photo').style.transform = ''; } }
  if (motion.addEventListener) { motion.addEventListener('change', motionChanged); } else if (motion.addListener) { motion.addListener(motionChanged); }
  window.addEventListener('beforeprint', revealAll);
  window.addEventListener('afterprint', startReveals);
  window.addEventListener('pageshow', function (event) { if (event.persisted) { startReveals(); } });
  var scrollFrame = 0, heroPhoto = $('.hero-photo'), heroVisual = $('.hero-visual'), progress = $('.scroll-progress');
  var sectionNames = { main: 'Welcome', clients: 'Our clients', about: 'Working as one', solutions: 'Solutions', industries: 'Industries', platform: 'The platform', approach: 'Our approach', workflow: 'CRM in motion', faq: 'Your questions', contact: 'Let’s connect' };
  var sections = $$('main > section[id]');
  function updateScroll() {
    scrollFrame = 0;
    var height = root.scrollHeight - window.innerHeight;
    progress.style.transform = 'scaleX(' + (height > 0 ? Math.min(1, Math.max(0, window.scrollY / height)) : 0) + ')';
    if (!motion.matches && window.innerWidth > 760) {
      var rect = heroVisual.getBoundingClientRect();
      if (rect.bottom > 0 && rect.top < window.innerHeight) { heroPhoto.style.transform = 'translateY(' + Math.max(-9, Math.min(12, -rect.top * 0.022)) + 'px)'; }
    }
    var current = 'main';
    sections.forEach(function (section) { if (section.getBoundingClientRect().top < window.innerHeight * .38) { current = section.id; } });
    $('#reading-section').textContent = sectionNames[current] || 'TechUnity';
    $$('#navigation a').forEach(function (link) { var active = link.getAttribute('href') === '#' + current; link.classList.toggle('active', active); if (active) { link.setAttribute('aria-current', 'location'); } else { link.removeAttribute('aria-current'); } });
  }
  window.addEventListener('scroll', function () { if (!scrollFrame) { scrollFrame = window.requestAnimationFrame(updateScroll); } }, { passive: true });
  window.addEventListener('resize', function () { if (!scrollFrame) { scrollFrame = window.requestAnimationFrame(updateScroll); } }, { passive: true });
  updateScroll();
  var form = $('#demo-form');
  form.addEventListener('submit', function (event) {
    if (form.dataset.mode !== 'preview') { return; }
    event.preventDefault();
    if (!form.reportValidity()) { return; }
    var data = new FormData(form);
    var message = String(data.get('message') || '').trim();
    if (message.length < 10) { $('#form-status').textContent = 'Please add at least 10 characters about your requirements.'; $('#message').focus(); return; }
    var text = 'TECHUNITY — ERP DEMO REQUEST\n\n' + ['name', 'company', 'email', 'phone', 'message'].map(function (key) { return key.charAt(0).toUpperCase() + key.slice(1) + ': ' + String(data.get(key) || '').trim(); }).join('\n\n');
    var blob = new Blob([text], { type: 'text/plain;charset=utf-8' }), url = URL.createObjectURL(blob), link = document.createElement('a');
    link.href = url; link.download = 'TechUnity-Demo-Request.txt'; document.body.appendChild(link); link.click(); link.remove();
    window.setTimeout(function () { URL.revokeObjectURL(url); }, 10000);
    $('#form-status').textContent = 'Your demo request is ready to download. Share the file with TechUnity; no email has been sent.';
  });
  // Fine-pointer polish only. The system cursor and touch interactions remain usable.
  var halo = $('.cursor-halo'), pointerFrame = 0, px = -100, py = -100, hx = -100, hy = -100, pointerKnown = false, hoveredCard = null;
  function cursorAllowed() { return finePointer.matches && !motion.matches; }
  function stopCursor() {
    root.classList.remove('custom-cursor-active');
    halo.classList.remove('is-visible', 'is-action'); pointerKnown = false;
    if (pointerFrame) { window.cancelAnimationFrame(pointerFrame); pointerFrame = 0; }
    if (hoveredCard) { hoveredCard.classList.remove('pointer-over'); hoveredCard.style.setProperty('--tilt-x', '0deg'); hoveredCard.style.setProperty('--tilt-y', '0deg'); hoveredCard = null; }
  }
  function paintPointer() {
    pointerFrame = 0;
    if (!cursorAllowed() || !pointerKnown) { return; }
    hx = px; hy = py;
    halo.style.transform = 'translate3d(' + hx + 'px,' + hy + 'px,0)';
    if (hoveredCard) {
      var box = hoveredCard.getBoundingClientRect();
      hoveredCard.style.setProperty('--pointer-x', (px - box.left) + 'px');
      hoveredCard.style.setProperty('--pointer-y', (py - box.top) + 'px');
      hoveredCard.style.setProperty('--tilt-x', ((.5 - (py - box.top) / box.height) * 6).toFixed(2) + 'deg');
      hoveredCard.style.setProperty('--tilt-y', (((px - box.left) / box.width - .5) * 6).toFixed(2) + 'deg');
    }
  }
  document.addEventListener('pointermove', function (event) {
    if (!cursorAllowed() || event.pointerType === 'touch') { stopCursor(); return; }
    if (event.target.closest('input, textarea, select')) { stopCursor(); return; }
    px = event.clientX; py = event.clientY;
    if (!pointerKnown) { hx = px; hy = py; pointerKnown = true; }
    halo.classList.add('is-visible');
    root.classList.add('custom-cursor-active');
    halo.classList.toggle('is-action', !!event.target.closest('a, button, summary'));
    var card = event.target.closest('.client-logo');
    if (card !== hoveredCard) {
      if (hoveredCard) { hoveredCard.classList.remove('pointer-over'); hoveredCard.style.setProperty('--tilt-x', '0deg'); hoveredCard.style.setProperty('--tilt-y', '0deg'); }
      hoveredCard = card; if (card) { card.classList.add('pointer-over'); }
    }
    if (!pointerFrame) { pointerFrame = window.requestAnimationFrame(paintPointer); }
  }, { passive: true });
  document.documentElement.addEventListener('pointerleave', stopCursor);
  window.addEventListener('blur', stopCursor);
  document.addEventListener('visibilitychange', function () { if (document.hidden) { stopCursor(); } });
  document.addEventListener('keydown', function (event) { if (event.key === 'Tab') { stopCursor(); } });
  [motion, finePointer].forEach(function (query) { if (query.addEventListener) { query.addEventListener('change', function () { if (!cursorAllowed()) { stopCursor(); } }); } });
  var film = $('#crm-film'), filmButton = $('#film-toggle'), filmVisible = false, filmUserPaused = false;
  function syncFilm() { filmButton.textContent = film.paused ? 'Play workflow' : 'Pause workflow'; filmButton.setAttribute('aria-label', film.paused ? 'Play CRM workflow animation' : 'Pause CRM workflow animation'); }
  function playFilm() { var attempt = film.play(); if (attempt && attempt.catch) { attempt.catch(function () { syncFilm(); }); } }
  function autoFilm() { if (filmVisible && !filmUserPaused && !motion.matches && !document.hidden) { playFilm(); } else { film.pause(); } }
  filmButton.addEventListener('click', function () { if (film.paused) { filmUserPaused = false; playFilm(); } else { filmUserPaused = true; film.pause(); } });
  film.addEventListener('play', syncFilm); film.addEventListener('pause', syncFilm);
  film.addEventListener('error', function () { filmButton.hidden = true; $('#film-caption').textContent = 'Animation unavailable. Workflow: enquiry, quotation, sales order, then dispatch.'; });
  if ('IntersectionObserver' in window) { new IntersectionObserver(function (entries) { filmVisible = entries[0].isIntersecting; autoFilm(); }, { threshold: .15 }).observe(film); }
  if (motion.addEventListener) { motion.addEventListener('change', autoFilm); }
  document.addEventListener('visibilitychange', autoFilm);
  syncFilm();
  $('#copyright-year').textContent = String(new Date().getFullYear());
}());
