// Agentic Title — Homepage shell parts (self-contained; no bundle dependency)

// ============================================================
// ROUTING DESTINATIONS — where CTA / form submissions are sent.
// DEFAULT: closings@agentictitletx.com (Thai's team's monitored inbox).
// The site owner (build team) controls these values; Thai's team just
// receives what comes through. To re-point anything (e.g. to a CRM
// intake address or a different inbox), change the addresses here —
// this is the ONE place order/contact/notify routing is defined.
// ============================================================
window.AT_ROUTING = window.AT_ROUTING || {
  orderEmail: 'closings@agentictitletx.com',
  contactEmail: 'closings@agentictitletx.com',
  notifyEmail: 'closings@agentictitletx.com',
};
window.ATMailto = function (email, subject, body) {
  let u = 'mailto:' + email;
  const q = [];
  if (subject) q.push('subject=' + encodeURIComponent(subject));
  if (body) q.push('body=' + encodeURIComponent(body));
  if (q.length) u += '?' + q.join('&');
  return u;
};
// "New Conversation": clear the thread AND return the visitor to Home, so the
// button always visibly does something (not a no-op on an empty Home thread).
window.ATNewConversation = function () {
  window.dispatchEvent(new CustomEvent('at-new-conversation'));
  if (window.__goToPage) {
    window.__goToPage('Home');
  } else if (window.location.pathname !== '/') {
    window.location.href = '/';
    return;
  }
  const t = document.querySelector('.at-thread');
  if (t) t.scrollTop = 0;
};
// Sends a form straight to an inbox — no email app needed on the visitor's device.
// Uses FormSubmit (formsubmit.co). The FIRST submission to a new address triggers a
// one-time activation email to that inbox; someone must click it before mail flows.
// Until then, forms show a fallback with the email + phone instead of failing silently.
window.ATSubmit = async function (to, subject, fields) {
  try {
    const res = await fetch('https://formsubmit.co/ajax/' + to, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
      body: JSON.stringify(Object.assign({ _subject: subject, _template: 'table', _captcha: 'false' }, fields)),
    });
    const data = await res.json().catch(() => ({}));
    return { ok: res.ok && String(data.success) === 'true' };
  } catch (e) {
    return { ok: false };
  }
};
window.ATOpenOrder = function () {
  window.dispatchEvent(new CustomEvent('at-open-order'));
};


// ---- Mobile layer (≤900px): one stylesheet shared by every page ----
(function injectMobileCSS() {
  if (document.getElementById('at-mobile-css')) return;
  const css = `
  .at-mobile-bar, .at-drawer-backdrop { display: none; }
  @media (max-width: 900px) {
    html, body { overflow: hidden; }
    #root > div { flex-direction: column !important; }
    .at-mobile-bar { display: flex !important; }
    .at-topbar { display: none !important; }
    .at-watermark { display: none !important; }
    .at-home-sidebar { display: none !important; }
    .at-home-sidebar.at-drawer-open { display: flex !important; position: fixed !important; top: 0; left: 0; bottom: 0; width: min(86vw, 320px) !important; height: auto !important; z-index: 1001; overflow-y: auto; box-shadow: 0 0 40px rgba(0,0,0,0.35); }
    .at-drawer-backdrop.at-open { display: block !important; }
    .at-thread { padding: 22px 0 196px !important; overflow-x: hidden; }
    .at-thread > div { padding: 0 16px !important; gap: 26px !important; }
    .at-thread section { min-width: 0; }
    .at-thread section > div { min-width: 0; }
    .at-thread section[style*="padding-left: 62px"] { padding-left: 0 !important; }
    .at-thread [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
    .at-thread [style*="padding: 2"], .at-thread [style*="padding: 3"], .at-thread [style*="padding: 4"] { padding: 20px 18px !important; }
    .at-thread h1 { overflow-wrap: anywhere; }
    .at-thread img { max-width: 100%; }
    .at-bottom { padding: 0 12px 10px !important; }
    .at-chips { flex-wrap: nowrap !important; overflow-x: auto; margin: 0 -12px 10px !important; padding: 2px 12px !important; gap: 8px !important; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .at-chips::-webkit-scrollbar { display: none; }
    .at-chips > button { flex: none !important; white-space: nowrap; padding: 9px 14px !important; font-size: 12px !important; }
    .at-composer { padding: 6px 6px 6px 14px !important; gap: 8px !important; }
    .at-composer img { display: none !important; }
    .at-order-grid { grid-template-columns: 1fr !important; }
    .at-composer input { font-size: 16px !important; padding: 11px 0 !important; min-width: 0; }
    .at-composer button { padding: 12px 16px !important; font-size: 12px !important; flex: none; }
    .at-bottom > div > div:last-child { font-size: 9px !important; letter-spacing: 0.08em !important; margin-top: 8px !important; line-height: 1.6; }
  }`;
  const el = document.createElement('style');
  el.id = 'at-mobile-css';
  el.textContent = css;
  document.head.appendChild(el);
})();

// ---- Brand monogram: architectural orange blocks ----
function Monogram({ s = 30 }) {
  const u = s / 30;
  return (
    <span style={{ display: 'inline-block', width: s, height: s, position: 'relative' }}>
      {/* left vertical bar */}
      <span style={{ position: 'absolute', left: 2 * u, top: 2 * u, width: 8 * u, height: 26 * u, background: 'var(--at-hermes)', borderRadius: 2 * u }} />
      {/* top-right wide bar */}
      <span style={{ position: 'absolute', left: 12 * u, top: 2 * u, width: 16 * u, height: 8 * u, background: 'var(--at-hermes)', borderRadius: 2 * u }} />
      {/* mid-right bar */}
      <span style={{ position: 'absolute', left: 12 * u, top: 12 * u, width: 11 * u, height: 7 * u, background: 'var(--at-hermes)', borderRadius: 2 * u }} />
    </span>
  );
}

// ---- Tiny icon set for the nav (16px, 1.7 stroke) ----
const NavSvg = (children) => ({ size = 17 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">{children}</svg>
);
const HomeI = NavSvg(<><path d="m3 10 9-7 9 7v9a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z"/></>);
const AboutI = NavSvg(<><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="2.5"/></>);
const ServicesI = NavSvg(<><path d="M12 3 21 12 12 21 3 12z"/></>);
const HowI = NavSvg(<><path d="M5 12h14"/><path d="m13 6 6 6-6 6"/></>);
const TeamI = NavSvg(<><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="4" fill="currentColor" stroke="none"/></>);
const AreasI = NavSvg(<><circle cx="12" cy="12" r="9"/><path d="M12 3v18M3 12h18"/></>);
const ContactI = NavSvg(<><rect x="3" y="5" width="18" height="14" rx="1.5"/><path d="m3 7 9 6 9-6"/></>);
const PlusI = NavSvg(<><path d="M12 5v14M5 12h14"/></>);
const ArrowI = NavSvg(<><path d="M5 12h14"/><path d="m13 6 6 6-6 6"/></>);

const NAV = [
  { label: 'Home', I: HomeI, active: true },
  { label: 'Services', I: ServicesI },
  { label: 'How It Works', I: HowI },
  { label: 'Team', I: TeamI },
  { label: 'Service Areas', I: AreasI },
  { label: 'FAQ', I: '?' },
  { label: 'Contact', I: ContactI },
];

function SidebarPanel({ active, setActive, mobileOpen = false, setMobileOpen = () => {} }) {
  const ROUTES = { Home: '/', Services: '/services', 'How It Works': '/how-it-works', Team: '/team', 'Service Areas': '/service-areas', FAQ: '/faq', Contact: '/contact' };
  const navGo = (label) => { setMobileOpen(false); if (ROUTES[label] && active !== label) window.location.href = ROUTES[label]; else setActive(label); };
  const [collapsed, setCollapsed] = React.useState(() => { try { return localStorage.getItem('at-sidebar-collapsed') === '1'; } catch (e) { return false; } });
  const setCol = (v) => { setCollapsed(v); try { localStorage.setItem('at-sidebar-collapsed', v ? '1' : '0'); } catch (e) {} };

  if (collapsed && !mobileOpen) {
    return (
      <aside style={{
        width: 72, flex: 'none', background: '#0E0D0C', color: 'var(--at-cream)',
        display: 'flex', flexDirection: 'column', alignItems: 'center', height: '100%',
        borderRight: '1px solid rgba(255,255,255,0.06)', padding: '22px 0 18px',
      }} className={'at-home-sidebar' + (mobileOpen ? ' at-drawer-open' : '')}>
        <button onClick={() => setCol(false)} title="Expand menu" style={{ border: 'none', background: 'transparent', cursor: 'pointer', padding: 6, display: 'flex' }}>
          <img src="/assets/mark-cream.png" alt="Expand menu" style={{ width: 30, height: 'auto', display: 'block' }} />
        </button>
        <nav style={{ display: 'flex', flexDirection: 'column', gap: 4, marginTop: 28 }}>
          {NAV.map((n) => {
            const on = active === n.label;
            return (
              <button key={n.label} onClick={() => navGo(n.label)} title={n.label} style={{
                width: 44, height: 44, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
                border: 'none', borderRadius: 'var(--radius-sm)', cursor: 'pointer',
                background: on ? 'rgba(224,114,40,0.12)' : 'transparent',
                color: on ? 'var(--at-hermes)' : 'rgba(237,235,231,0.62)',
                transition: 'background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard)',
              }}
              onMouseEnter={(e) => { if (!on) { e.currentTarget.style.background = 'rgba(255,255,255,0.04)'; e.currentTarget.style.color = 'var(--at-cream)'; } }}
              onMouseLeave={(e) => { if (!on) { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.color = 'rgba(237,235,231,0.62)'; } }}>
                {n.I === '?' ? <span style={{ fontFamily: 'var(--font-mono)', fontSize: 16 }}>?</span> : <n.I size={19} />}
              </button>
            );
          })}
        </nav>
        <div style={{ flex: 1 }} />
        <button title="Open an Order" onClick={() => window.ATOpenOrder()} style={{
          width: 46, height: 46, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
          border: 'none', borderRadius: 'var(--radius-md)', cursor: 'pointer', background: 'var(--at-hermes)',
          color: '#1c0d04', boxShadow: '0 6px 18px rgba(224,114,40,0.30)', transition: 'background var(--dur-fast)',
        }}
        onMouseEnter={(e) => e.currentTarget.style.background = 'var(--at-hermes-deep)'}
        onMouseLeave={(e) => e.currentTarget.style.background = 'var(--at-hermes)'}>
          <ArrowI size={20} />
        </button>
      </aside>
    );
  }

  return (
    <aside style={{
      width: 300, flex: 'none', background: '#0E0D0C', color: 'var(--at-cream)',
      display: 'flex', flexDirection: 'column', height: '100%',
      borderRight: '1px solid rgba(255,255,255,0.06)',
    }} className={'at-home-sidebar' + (mobileOpen ? ' at-drawer-open' : '')}>
      {/* Logo */}
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '24px 22px 20px' }}>
        <button onClick={() => setCol(false)} title="Expand menu" style={{ border: 'none', background: 'transparent', cursor: 'pointer', padding: 0, display: 'flex' }}>
          <img src="/assets/logo-horizontal-cream.png" alt="Agentic Title" style={{ height: 26, width: 'auto', display: 'block' }} />
        </button>
        <button onClick={() => (mobileOpen ? setMobileOpen(false) : setCol(true))} title="Collapse menu" aria-label="Collapse menu" style={{
          border: 'none', background: 'transparent', cursor: 'pointer', color: 'rgba(237,235,231,0.5)',
          fontSize: 12, flex: 'none', marginLeft: 10, padding: '4px 6px', borderRadius: 'var(--radius-xs)',
          transition: 'color var(--dur-fast), background var(--dur-fast)',
        }}
        onMouseEnter={(e) => { e.currentTarget.style.color = 'var(--at-cream)'; e.currentTarget.style.background = 'rgba(255,255,255,0.06)'; }}
        onMouseLeave={(e) => { e.currentTarget.style.color = 'rgba(237,235,231,0.5)'; e.currentTarget.style.background = 'transparent'; }}>◁</button>
      </div>

      {/* New conversation */}
      <div style={{ padding: '0 16px' }}>
        <button onClick={() => window.ATNewConversation()} style={{
          width: '100%', display: 'flex', alignItems: 'center', gap: 10,
          padding: '14px 16px', background: 'transparent', cursor: 'pointer',
          border: '1px solid rgba(255,255,255,0.14)', borderRadius: 'var(--radius-md)',
          color: 'var(--at-cream)', fontFamily: 'var(--font-mono)', fontSize: 12.5,
          letterSpacing: '0.12em', textTransform: 'uppercase',
        }}><PlusI size={15} /> New Conversation</button>
      </div>

      {/* Nav */}
      <div style={{ padding: '24px 16px 0' }}>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10.5, letterSpacing: '0.2em', color: 'rgba(237,235,231,0.4)', padding: '0 4px 12px' }}>NAVIGATION</div>
        <nav style={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
          {NAV.map((n) => {
            const on = active === n.label;
            const go = () => navGo(n.label);
            return (
              <button key={n.label} onClick={go} style={{
                display: 'flex', alignItems: 'center', gap: 12, width: '100%',
                padding: '11px 12px', cursor: 'pointer', textAlign: 'left',
                border: 'none', borderRadius: 'var(--radius-sm)',
                background: on ? 'rgba(224,114,40,0.10)' : 'transparent',
                color: on ? 'var(--at-hermes)' : 'rgba(237,235,231,0.62)',
                fontFamily: 'var(--font-mono)', fontSize: 13.5, letterSpacing: '0.04em',
                transition: 'background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard)',
              }}
              onMouseEnter={(e) => { if (!on) { e.currentTarget.style.background = 'rgba(255,255,255,0.04)'; e.currentTarget.style.color = 'var(--at-cream)'; } }}
              onMouseLeave={(e) => { if (!on) { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.color = 'rgba(237,235,231,0.62)'; } }}>
                <span style={{ width: 18, display: 'inline-flex', justifyContent: 'center' }}>
                  {n.I === '?' ? <span style={{ fontFamily: 'var(--font-mono)', fontSize: 15 }}>?</span> : <n.I size={17} />}
                </span>
                {n.label}
              </button>
            );
          })}
        </nav>
      </div>

      <div style={{ flex: 1 }} />

      {/* Open an order */}
      <div style={{ padding: '16px 16px 12px' }}>
        <button onClick={() => window.ATOpenOrder()} style={{
          width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
          padding: '18px 16px', cursor: 'pointer', border: 'none',
          background: 'var(--at-hermes)', borderRadius: 'var(--radius-md)',
          color: '#1c0d04', fontFamily: 'var(--font-mono)', fontWeight: 500, fontSize: 13.5,
          letterSpacing: '0.12em', textTransform: 'uppercase', boxShadow: '0 6px 18px rgba(224,114,40,0.30)',
          transition: 'background var(--dur-fast) var(--ease-standard)',
        }}
        onMouseEnter={(e) => e.currentTarget.style.background = 'var(--at-hermes-deep)'}
        onMouseLeave={(e) => e.currentTarget.style.background = 'var(--at-hermes)'}>
          Open an Order →
        </button>
      </div>
      <div style={{ padding: '0 16px 18px', textAlign: 'center', fontFamily: 'var(--font-mono)', fontSize: 9.5, letterSpacing: '0.16em', color: 'rgba(237,235,231,0.3)' }}>
        LICENSED · INSURED · AI-POWERED
      </div>
    </aside>
  );
}

const atFieldStyle = { width: '100%', boxSizing: 'border-box', border: '1px solid var(--border-default)', background: 'var(--surface-raised)', borderRadius: 'var(--radius-sm)', padding: '12px 14px', fontFamily: 'var(--font-serif)', fontSize: 16, color: 'var(--text-primary)', outline: 'none' };
const atLabelStyle = { display: 'block', fontFamily: 'var(--font-mono)', fontSize: 10.5, letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--text-secondary)', marginBottom: 6 };

function OrderModal() {
  const [open, setOpen] = React.useState(false);
  const [status, setStatus] = React.useState('idle'); // idle | sending | sent | error
  const [copied, setCopied] = React.useState(false);
  const firstRef = React.useRef(null);
  React.useEffect(() => {
    const onOpen = () => { setStatus('idle'); setCopied(false); setOpen(true); };
    const onKey = (e) => { if (e.key === 'Escape') setOpen(false); };
    window.addEventListener('at-open-order', onOpen);
    window.addEventListener('keydown', onKey);
    return () => { window.removeEventListener('at-open-order', onOpen); window.removeEventListener('keydown', onKey); };
  }, []);
  React.useEffect(() => { if (open && status === 'idle' && firstRef.current) firstRef.current.focus(); }, [open, status]);
  if (!open) return null;
  const email = window.AT_ROUTING.orderEmail;

  const submit = async (e) => {
    e.preventDefault();
    const f = e.currentTarget;
    const v = (n) => ((f.elements[n] && f.elements[n].value) || '').trim();
    setStatus('sending');
    const r = await window.ATSubmit(email, 'New Order Request — ' + (v('property') || 'Agentic Title'), {
      'Name': v('name'), 'Email': v('email'), 'Phone': v('phone'), 'I am a': v('role'),
      'Property address': v('property'), 'Buyer(s)': v('buyer'), 'Seller(s)': v('seller'),
      'Lender': v('lender'), 'Notes': v('notes'), _replyto: v('email'),
    });
    setStatus(r.ok ? 'sent' : 'error');
  };
  const copy = () => { try { navigator.clipboard.writeText(email); setCopied(true); } catch (err) {} };
  const btn = { cursor: 'pointer', border: 'none', background: 'var(--at-hermes)', color: '#1c0d04', borderRadius: 'var(--radius-md)', padding: '15px 26px', fontFamily: 'var(--font-mono)', fontWeight: 500, fontSize: 12.5, letterSpacing: '0.12em', textTransform: 'uppercase' };
  const ghost = { ...btn, background: 'transparent', color: 'var(--text-primary)', border: '1px solid var(--border-strong)' };

  return (
    <div role="dialog" aria-modal="true" aria-label="Open an Order" onMouseDown={(e) => { if (e.target === e.currentTarget) setOpen(false); }} style={{
      position: 'fixed', inset: 0, zIndex: 2000, background: 'rgba(14,13,12,0.5)',
      display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 12,
    }}>
      <div style={{
        width: 'min(600px, 100%)', maxHeight: 'calc(100vh - 24px)', overflowY: 'auto',
        background: 'var(--at-cream)', borderRadius: 'var(--radius-lg)', boxShadow: 'var(--shadow-xl)', padding: '28px 30px',
      }}>
        <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 16, marginBottom: 18 }}>
          <div>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: 11.5, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--at-hermes)', marginBottom: 8 }}>Open an Order</div>
            <div style={{ fontFamily: 'var(--font-serif)', fontStyle: 'italic', fontWeight: 500, fontSize: 28, lineHeight: 1.15, color: 'var(--text-primary)' }}>{status === 'sent' ? 'Order request received.' : 'Tell us about the transaction.'}</div>
          </div>
          <button onClick={() => setOpen(false)} aria-label="Close" style={{ flex: 'none', width: 40, height: 40, border: 'none', background: 'transparent', cursor: 'pointer', fontSize: 22, color: 'var(--text-secondary)' }}>×</button>
        </div>

        {status === 'sent' && (
          <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
            <p style={{ fontFamily: 'var(--font-serif)', fontSize: 18, lineHeight: 1.5, color: 'var(--text-primary)', margin: 0 }}>Thank you — your order request is with our team, and we'll be in touch during business hours (Mon–Fri, 9am–5pm CT).</p>
            <p style={{ fontFamily: 'var(--font-serif)', fontSize: 18, lineHeight: 1.5, color: 'var(--text-primary)', margin: 0 }}>If you have the executed contract, please email it to <a href={'mailto:' + email}>{email}</a> so we can match it to your order.</p>
            <div><button onClick={() => setOpen(false)} style={btn}>Done</button></div>
          </div>
        )}

        {status === 'error' && (
          <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
            <p style={{ fontFamily: 'var(--font-serif)', fontSize: 18, lineHeight: 1.5, color: 'var(--text-primary)', margin: 0 }}>We couldn't send that just now. You can reach our team directly:</p>
            <div style={{ background: '#FBFAF8', border: '1px solid var(--border-hairline)', borderRadius: 'var(--radius-md)', padding: '16px 18px', fontFamily: 'var(--font-mono)', fontSize: 14, lineHeight: 1.9, color: 'var(--text-primary)' }}>
              <div>{email}</div>
              <div>(832) 615-2588</div>
            </div>
            <div style={{ display: 'flex', gap: 10, flexWrap: 'wrap' }}>
              <button onClick={copy} style={btn}>{copied ? 'Email copied' : 'Copy email'}</button>
              <a href="tel:+18326152588" style={{ ...ghost, textDecoration: 'none', display: 'inline-flex', alignItems: 'center' }}>Call us</a>
              <button onClick={() => setStatus('idle')} style={ghost}>Try again</button>
            </div>
          </div>
        )}

        {(status === 'idle' || status === 'sending') && (
          <form onSubmit={submit} style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
            <div className="at-order-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
              <div><label style={atLabelStyle}>Your name *</label><input ref={firstRef} name="name" required style={atFieldStyle} autoComplete="name" /></div>
              <div><label style={atLabelStyle}>Email *</label><input name="email" type="email" required style={atFieldStyle} autoComplete="email" /></div>
              <div><label style={atLabelStyle}>Phone</label><input name="phone" type="tel" style={atFieldStyle} autoComplete="tel" /></div>
              <div><label style={atLabelStyle}>I am a</label>
                <select name="role" defaultValue="" style={{ ...atFieldStyle, cursor: 'pointer' }}>
                  <option value="">Select...</option><option>Buyer / Seller</option><option>Realtor / Agent</option><option>Lender</option><option>Attorney</option><option>Other</option>
                </select>
              </div>
            </div>
            <div><label style={atLabelStyle}>Property address *</label><input name="property" required style={atFieldStyle} autoComplete="street-address" /></div>
            <div className="at-order-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
              <div><label style={atLabelStyle}>Buyer(s)</label><input name="buyer" style={atFieldStyle} /></div>
              <div><label style={atLabelStyle}>Seller(s)</label><input name="seller" style={atFieldStyle} /></div>
            </div>
            <div><label style={atLabelStyle}>Lender (if any)</label><input name="lender" style={atFieldStyle} /></div>
            <div><label style={atLabelStyle}>Anything else we should know?</label><textarea name="notes" rows="3" style={{ ...atFieldStyle, resize: 'vertical', lineHeight: 1.5 }}></textarea></div>
            <p style={{ fontFamily: 'var(--font-serif)', fontSize: 15.5, lineHeight: 1.45, color: 'var(--text-secondary)', margin: 0 }}>Have the executed contract? After submitting, email it to {email} and we'll match it to your order.</p>
            <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
              <button type="submit" disabled={status === 'sending'} style={{ ...btn, opacity: status === 'sending' ? 0.6 : 1 }}>{status === 'sending' ? 'Sending…' : 'Submit Order →'}</button>
            </div>
          </form>
        )}
      </div>
    </div>
  );
}

// Phone header + slide-out drawer around the desktop sidebar.
function Sidebar(props) {
  const [mobileOpen, setMobileOpen] = React.useState(false);
  const lines = [0, 1, 2];
  return (
    <React.Fragment>
      <div className="at-mobile-bar" style={{
        height: 56, flex: 'none', alignItems: 'center', justifyContent: 'space-between',
        padding: '0 8px 0 18px', background: '#0E0D0C', borderBottom: '1px solid rgba(255,255,255,0.06)',
      }}>
        <img src="/assets/logo-horizontal-cream.png" alt="Agentic Title" style={{ height: 20, width: 'auto', display: 'block' }} />
        <button onClick={() => setMobileOpen(true)} aria-label="Open menu" style={{
          width: 44, height: 44, border: 'none', background: 'transparent', cursor: 'pointer',
          display: 'inline-flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 5,
        }}>
          {lines.map((i) => <span key={i} style={{ width: 20, height: 1.6, background: 'var(--at-cream)', borderRadius: 2 }}></span>)}
        </button>
      </div>
      <div className={'at-drawer-backdrop' + (mobileOpen ? ' at-open' : '')} onClick={() => setMobileOpen(false)} style={{
        position: 'fixed', inset: 0, background: 'rgba(14,13,12,0.45)', zIndex: 1000,
      }}></div>
      <SidebarPanel {...props} mobileOpen={mobileOpen} setMobileOpen={setMobileOpen} />
      <OrderModal />
    </React.Fragment>
  );
}

function TopBar({ title = 'ASK ATHENA', subtitle = 'Title Intelligence, Built In' }) {
  return (
    <div className="at-topbar" style={{
      height: 60, flex: 'none', display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      padding: '0 36px', borderBottom: '1px solid var(--border-hairline)', background: 'rgba(247,245,242,0.7)',
      backdropFilter: 'blur(8px)',
    }}>
      <div style={{ fontFamily: 'var(--font-mono)', fontSize: 13, letterSpacing: '0.1em' }}>
        <span style={{ color: 'var(--at-hermes)', fontWeight: 500 }}>{title}</span>
        <span style={{ color: 'var(--text-muted)' }}>&nbsp;&nbsp;·&nbsp;&nbsp;{subtitle}</span>
      </div>
    </div>
  );
}

Object.assign(window, { Monogram, Sidebar, TopBar, HomeNavIcons: { ArrowI } });
