// c-shell.jsx — shared chrome for the C direction across pages.
// Provides CGlobalStyles, CNav, CFooter — used by the homepage and the
// About / Leadership / Contact pages.

function CGlobalStyles() {
  return (
    <style>{`
      @keyframes c-orbFloat {
        0%   { transform: translate(0,0)        scale(1);    }
        50%  { transform: translate(20px,-18px) scale(1.04); }
        100% { transform: translate(0,0)        scale(1);    }
      }
      @keyframes c-orbHue {
        0%   { filter: hue-rotate(0deg)   blur(60px); }
        100% { filter: hue-rotate(360deg) blur(60px); }
      }
      @keyframes c-ringSpin {
        from { transform: translate(-50%,-50%) rotate(0deg);   }
        to   { transform: translate(-50%,-50%) rotate(360deg); }
      }
      @keyframes c-tickerSlide {
        0%   { transform: translateY(0);       }
        20%  { transform: translateY(0);       }
        25%  { transform: translateY(-1.2em);  }
        45%  { transform: translateY(-1.2em);  }
        50%  { transform: translateY(-2.4em);  }
        70%  { transform: translateY(-2.4em);  }
        75%  { transform: translateY(-3.6em);  }
        95%  { transform: translateY(-3.6em);  }
        100% { transform: translateY(-4.8em);  }
      }
      @keyframes c-pulse {
        0%, 100% { opacity: .8;  transform: scale(1);   }
        50%      { opacity: .35; transform: scale(1.6); }
      }
      .c-card { transition: transform .4s cubic-bezier(.2,.7,.3,1), border-color .25s; }
      .c-card:hover { transform: translateY(-4px); }
      .c-cta:hover .c-cta-arrow { transform: translateX(4px); }
      .c-link { transition: color .2s; position: relative; }
      .c-link::after {
        content: ''; position: absolute; left: 0; right: 0; bottom: -4px;
        height: 1px; background: currentColor; transform: scaleX(0);
        transform-origin: left; transition: transform .25s;
      }
      .c-link:hover::after { transform: scaleX(1); }
      /* Centered content canvas (max 1440) sitting inside full-bleed sections.
         Sections keep their orb/gradient decorations outside .c-content so
         those bleed to viewport edges; text and cards stay in the design
         canvas. */
      .c-content { max-width: 1440px; margin: 0 auto; position: relative; }

      /* Mobile nav defaults: hamburger hidden on desktop. */
      .c-nav-burger { display: none; }

      /* ── Tablet: 600–1023px ─────────────────────────────────────────── */
      @media (max-width: 1023px) {
        .c-content       { padding: 0 32px; }
        .c-section-pad   { padding-left: 32px !important; padding-right: 32px !important; }
        .c-headline-mega { font-size: 84px !important; letter-spacing: -2.4px !important; }
        .c-headline-big  { font-size: 64px !important; letter-spacing: -2px !important; }
        .c-headline-mid  { font-size: 48px !important; letter-spacing: -1.2px !important; }
        .c-headline-sml  { font-size: 40px !important; letter-spacing: -1px !important; }
        .c-headline-statement { font-size: 32px !important; letter-spacing: -0.6px !important; }
        .c-grid-4        { grid-template-columns: repeat(2, 1fr) !important; }
        .c-grid-3        { grid-template-columns: repeat(2, 1fr) !important; }
        .c-grid-stack-md { grid-template-columns: 1fr !important; gap: 32px !important; }
      }

      /* ── Phone: ≤ 599px ─────────────────────────────────────────────── */
      @media (max-width: 599px) {
        .c-content        { padding: 0 20px; }
        .c-section-pad    { padding-left: 20px !important; padding-right: 20px !important; }
        .c-section-pad-y  { padding-top: 56px !important; padding-bottom: 56px !important; }
        .c-hero-pad       { padding-top: 32px !important; padding-bottom: 72px !important; }
        .c-headline-mega  { font-size: 52px !important; letter-spacing: -1.4px !important; line-height: 1 !important; }
        .c-headline-big   { font-size: 40px !important; letter-spacing: -1px !important; }
        .c-headline-mid   { font-size: 32px !important; letter-spacing: -0.8px !important; }
        .c-headline-sml   { font-size: 28px !important; letter-spacing: -0.6px !important; }
        .c-headline-statement { font-size: 22px !important; letter-spacing: -0.3px !important; line-height: 1.3 !important; }
        .c-body-lg        { font-size: 16px !important; line-height: 1.55 !important; }
        .c-grid-4         { grid-template-columns: 1fr !important; gap: 16px !important; }
        .c-grid-3         { grid-template-columns: 1fr !important; gap: 16px !important; }
        .c-grid-2         { grid-template-columns: 1fr !important; gap: 16px !important; }
        .c-stats-4        { grid-template-columns: 1fr 1fr !important; }
        .c-stats-4 > div  { border-right: none !important; border-bottom: 1px solid rgba(244,241,255,0.08) !important; padding: 18px 16px !important; }
        .c-stats-4 > div:nth-last-child(-n+2) { border-bottom: none !important; }
        .c-stats-4 .c-stat-val { font-size: 24px !important; }
        .c-grid-stack-md  { grid-template-columns: 1fr !important; gap: 24px !important; }
        .c-flex-stack     { flex-direction: column !important; align-items: flex-start !important; gap: 20px !important; }
        .c-card-pad       { padding: 24px 22px 26px !important; }
        .c-orb            { transform: scale(0.55) !important; opacity: 0.42 !important; }
        .c-ring           { display: none !important; }
        .c-nav-pills, .c-nav-cta { display: none !important; }
        .c-nav-burger     { display: inline-flex !important; }
        .c-nav-bar        { grid-template-columns: 1fr auto !important; }
        .c-footer-wm      { font-size: 56px !important; letter-spacing: -1.6px !important; }
        .c-footer-wm-rule { height: 44px !important; }
        .c-leadrow        { grid-template-columns: 1fr !important; gap: 24px !important; padding: 32px 0 !important; }
        .c-leadrow-photo  { width: 100% !important; height: 320px !important; max-width: 360px !important; }
        .c-pcard-h        { font-size: 28px !important; }
        .c-section-h-row  { flex-direction: column !important; align-items: flex-start !important; gap: 16px !important; }
      }

      /* Hamburger drawer */
      .c-drawer-open { overflow: hidden; }
      .c-drawer {
        position: fixed; inset: 0; z-index: 1000;
        background: #08050f;
        display: flex; flex-direction: column;
        padding: 24px 20px 32px;
        transform: translateX(100%);
        transition: transform .3s cubic-bezier(.2,.7,.3,1);
      }
      .c-drawer.open { transform: translateX(0); }
    `}</style>
  );
}

// ── Nav ─────────────────────────────────────────────────────────
function CNav({ active = 'Home' }) {
  // Pretty URLs — CloudFront Function rewrites /about → /about.html at the edge.
  const items = [
    ['Home',       '/'],
    ['About',      '/about'],
    ['Leadership', '/leadership'],
    ['Contact',    '/contact'],
  ];
  const [open, setOpen] = React.useState(false);
  React.useEffect(() => {
    document.body.classList.toggle('c-drawer-open', open);
    return () => document.body.classList.remove('c-drawer-open');
  }, [open]);
  return (
    <header style={{
      padding: '24px 56px',
      position: 'relative', zIndex: 10,
    }} className="c-section-pad">
      <div className="c-content c-nav-bar" style={{
        display: 'grid', gridTemplateColumns: '1fr auto 1fr',
        alignItems: 'center',
      }}>
      <a href="/" style={{
        display: 'flex', alignItems: 'center', gap: 18,
        textDecoration: 'none', color: 'inherit',
      }}>
        {/* Mark 03 · Lockup */}
        <span style={{
          fontWeight: 500, fontSize: 26, letterSpacing: -0.7, lineHeight: 1,
        }}>1686</span>
        <span style={{ width: 1, height: 26, background: P1686.lineHi }} />
        <span style={{
          display: 'inline-flex', flexDirection: 'column', gap: 2,
          fontFamily: '"JetBrains Mono", monospace', fontSize: 10.5,
          letterSpacing: 0.18, textTransform: 'uppercase', color: P1686.muted, lineHeight: 1.35,
        }}>
          <span>Holdings</span>
          <span>Company</span>
        </span>
        <span style={{
          marginLeft: 4,
          width: 7, height: 7, borderRadius: 99, background: P1686.violet,
          boxShadow: `0 0 12px ${P1686.violet}`, animation: 'c-pulse 2.4s ease-in-out infinite',
        }} />
      </a>
      <nav className="c-nav-pills" style={{
        display: 'flex', gap: 4,
        padding: 4, borderRadius: 999,
        background: 'rgba(255,255,255,0.03)', border: `1px solid ${P1686.line}`,
        backdropFilter: 'blur(8px)',
      }}>
        {items.map(([label, href]) => {
          const isActive = label === active;
          return (
            <a key={label} href={href} style={{
              padding: '8px 16px', borderRadius: 999,
              fontSize: 13, color: isActive ? P1686.text : P1686.muted,
              textDecoration: 'none', background: isActive ? 'rgba(255,255,255,0.06)' : 'transparent',
              transition: 'all .15s',
            }}>{label}</a>
          );
        })}
      </nav>
      <div className="c-nav-cta" style={{ justifySelf: 'end' }}>
        <a href="/contact" className="c-cta" style={{
          display: 'inline-flex', alignItems: 'center', gap: 10,
          padding: '10px 18px 10px 22px', borderRadius: 999,
          background: P1686.text, color: P1686.bg, textDecoration: 'none',
          fontSize: 13, fontWeight: 500,
        }}>
          Get in touch
          <span className="c-cta-arrow" style={{
            display: 'inline-flex', transition: 'transform .25s',
          }}><Arrow size={13} color={P1686.bg} /></span>
        </a>
      </div>
      <button
        type="button"
        onClick={() => setOpen(true)}
        aria-label="Open menu"
        className="c-nav-burger"
        style={{
          justifySelf: 'end',
          background: 'transparent', border: `1px solid ${P1686.lineHi}`,
          width: 44, height: 44, borderRadius: 12, padding: 0,
          color: P1686.text, cursor: 'pointer',
          alignItems: 'center', justifyContent: 'center',
        }}>
        <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round">
          <path d="M3 6h14M3 10h14M3 14h14" />
        </svg>
      </button>
      </div>

      {/* Mobile drawer */}
      <div className={`c-drawer${open ? ' open' : ''}`} aria-hidden={!open}>
        <div style={{
          display: 'flex', justifyContent: 'space-between', alignItems: 'center',
          marginBottom: 56,
        }}>
          <span style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
            <span style={{ fontWeight: 500, fontSize: 24, letterSpacing: -0.6, lineHeight: 1 }}>1686</span>
            <span style={{ width: 1, height: 22, background: P1686.lineHi }} />
            <span style={{
              display: 'inline-flex', flexDirection: 'column', gap: 2,
              fontFamily: '"JetBrains Mono", monospace', fontSize: 10,
              letterSpacing: 0.18, textTransform: 'uppercase', color: P1686.muted, lineHeight: 1.35,
            }}>
              <span>Holdings</span>
              <span>Company</span>
            </span>
          </span>
          <button
            type="button"
            onClick={() => setOpen(false)}
            aria-label="Close menu"
            style={{
              background: 'transparent', border: `1px solid ${P1686.lineHi}`,
              width: 44, height: 44, borderRadius: 12, padding: 0,
              color: P1686.text, cursor: 'pointer',
              display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
            }}>
            <svg width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round">
              <path d="M4 4l12 12M16 4L4 16" />
            </svg>
          </button>
        </div>
        <nav style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
          {items.map(([label, href]) => {
            const isActive = label === active;
            return (
              <a key={label} href={href} style={{
                display: 'flex', justifyContent: 'space-between', alignItems: 'center',
                padding: '20px 4px',
                borderBottom: `1px solid ${P1686.line}`,
                textDecoration: 'none',
                fontSize: 28, fontWeight: 500, letterSpacing: -0.6,
                color: isActive ? P1686.violetHi : P1686.text,
              }}>
                {label}
                <Arrow size={14} color={isActive ? P1686.violetHi : P1686.muted} />
              </a>
            );
          })}
        </nav>
        <div style={{ marginTop: 'auto', paddingTop: 32 }}>
          <a href="/contact" className="c-cta" style={{
            display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 12,
            padding: '18px 24px', borderRadius: 999,
            background: P1686.text, color: P1686.bg, textDecoration: 'none',
            fontSize: 16, fontWeight: 500,
          }}>
            Get in touch
            <Arrow size={14} color={P1686.bg} />
          </a>
          <div style={{
            marginTop: 24, fontSize: 11, color: P1686.mute2,
            fontFamily: '"JetBrains Mono", monospace', letterSpacing: 0.15,
            textTransform: 'uppercase', textAlign: 'center',
          }}>
            contact@1686holdings.com
          </div>
        </div>
      </div>
    </header>
  );
}

// ── Footer ──────────────────────────────────────────────────────
function CFooter() {
  return (
    <footer style={{
      padding: '56px 56px 40px',
      borderTop: `1px solid ${P1686.line}`,
    }} className="c-section-pad">
      <div className="c-content">
      <div className="c-flex-stack" style={{
        display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end',
        paddingBottom: 40, borderBottom: `1px solid ${P1686.line}`,
        gap: 32,
      }}>
        <div style={{ display: 'flex', alignItems: 'baseline', gap: 22 }}>
          <span className="c-footer-wm" style={{ fontWeight: 500, fontSize: 88, letterSpacing: -2.8, lineHeight: 0.9 }}>1686</span>
          <span className="c-footer-wm-rule" style={{ width: 1, height: 68, background: P1686.lineHi, alignSelf: 'center' }} />
          <span style={{
            display: 'inline-flex', flexDirection: 'column', gap: 4,
            fontFamily: '"JetBrains Mono", monospace', fontSize: 12,
            letterSpacing: 0.2, textTransform: 'uppercase', color: P1686.muted, lineHeight: 1.45,
          }}>
            <span>Holdings</span>
            <span>Company</span>
          </span>
        </div>
        <div style={{
          display: 'flex', gap: 56, fontSize: 13, flexWrap: 'wrap',
        }}>
          {[
            ['Site',     [['Home', '/'], ['About', '/about'], ['Leadership', '/leadership'], ['Contact', '/contact']]],
            ['Companies', HOLDINGS.map((h) => [h.name, h.href])],
          ].map(([title, links]) => (
            <div key={title}>
              <MonoLabel>{title}</MonoLabel>
              <ul style={{ margin: '14px 0 0', padding: 0, listStyle: 'none' }}>
                {links.map(([label, href]) => {
                  const live = href && href !== '#';
                  return (
                    <li key={label} style={{ marginBottom: 8 }}>
                      {live
                        ? <a href={href} style={{ color: P1686.text, textDecoration: 'none' }}>{label}</a>
                        : <span style={{ color: P1686.mute2 }}>{label}</span>}
                    </li>
                  );
                })}
              </ul>
            </div>
          ))}
        </div>
      </div>
      <div className="c-flex-stack" style={{
        marginTop: 24,
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        gap: 12,
      }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, fontSize: 12, color: P1686.mute2 }}>
          <span style={{
            width: 6, height: 6, borderRadius: 99, background: P1686.violet,
            boxShadow: `0 0 10px ${P1686.violet}`,
          }} />
          1686 Holdings Co., LLC
        </div>
        <div style={{ fontSize: 12, color: P1686.mute2 }}>© 2026 — All rights reserved</div>
      </div>
      </div>
    </footer>
  );
}

// ── Page-frame helper ───────────────────────────────────────────
// Page fills the viewport; each section keeps its content centered in a
// 1440 design canvas via the c-content wrapper class. Decorations (orbs,
// gradients) live outside that wrapper so they bleed to viewport edges.
function CPage({ active, children }) {
  return (
    <div style={{
      width: '100%',
      background: P1686.bg,
      color: P1686.text,
      fontFamily: '"Archivo", "Geist", ui-sans-serif, system-ui, sans-serif',
      overflow: 'hidden', position: 'relative',
    }}>
      <CGlobalStyles />
      <CNav active={active} />
      {children}
      <CFooter />
    </div>
  );
}

Object.assign(window, { CGlobalStyles, CNav, CFooter, CPage });
