// Work page — 4 invented-but-believable case studies
// Mid-market clients across the industries the user specified
// Layout: short narrative (challenge / approach / what's next) + metrics strip
// Imagery: abstract editorial marks rendered in SVG, one per study

const Work = () => {
  const studies = [
    {
      n: '01',
      industry: 'B2B SaaS · 80 employees',
      title: 'A 47-person CS team that finally sleeps on weekends.',
      service: 'Custom Agents · Training',
      timeline: '8 weeks · ongoing partnership',
      challenge: "An infrastructure-monitoring SaaS was drowning in tier-1 support tickets — repetitive questions about thresholds, integrations, and billing. The CS team was burning out and senior engineers were getting pulled in nightly to firefight issues a thoughtful first-line response could have caught.",
      approach: [
        "We sat in on a week of support shifts before writing a line of anything.",
        "Built a triage agent that handles tier-1 questions, escalates real issues to engineers with full context attached, and learns from every resolution.",
        "Trained the CS team to refine the agent's playbooks themselves — no developer needed for tweaks.",
      ],
      next: "We're now expanding the agent into proactive customer health monitoring — flagging churn risk before customers churn.",
      quote: "They spent the first week just listening. By the time they proposed anything, they understood our product better than half our PMs.",
      quoteWho: "VP Customer Success",
      metrics: [
        { label: 'tickets auto-resolved', value: '64%', unit: '' },
        { label: 'response time', value: '12×', unit: 'faster' },
        { label: 'weekend escalations', value: '−83', unit: '%' },
        { label: 'CSAT', value: '+18', unit: 'pts' },
      ],
      mark: 'pulse',
      tint: '#c8542a',
    },
    {
      n: '02',
      industry: 'Professional services · Law firm · 32 attorneys',
      title: '4,000 hours back. Same team. Same caseload.',
      service: 'AI Opportunity Audit · Custom Agents',
      timeline: '12 weeks · monthly retainer',
      challenge: "A regional litigation firm was losing senior-attorney time to discovery review and case-history searches. Junior associates were spending 60% of their week on document combing — work clients hated paying for and the firm hated billing.",
      approach: [
        "Three-week audit shadowing senior partners, paralegals, and associates across two practice groups.",
        "Built a private document-aware research assistant trained only on the firm's matter history — citations always link back to the source.",
        "Workshopped the rollout with every group; partners now sign off on every output, with the heavy lifting done.",
      ],
      next: "Phase two is intake automation — qualifying inbound matters and drafting initial conflict checks before a partner ever opens the file.",
      quote: "Two other firms pitched us platforms. Leviyet pitched us a question first: do you actually need one? We didn't. We needed this.",
      quoteWho: "Managing Partner",
      metrics: [
        { label: 'hours saved', value: '4,000', unit: '/yr' },
        { label: 'discovery review', value: '6×', unit: 'faster' },
        { label: 'realization rate', value: '+11', unit: '%' },
        { label: 'attorneys onboarded', value: '32 of 32', unit: '' },
      ],
      mark: 'arc',
      tint: '#c8542a',
    },
    {
      n: '03',
      industry: 'Healthcare · Multi-site clinic · 140 staff',
      title: 'No-shows down by half. Front desk gets to be human again.',
      service: 'Custom Agents · AI Marketing',
      timeline: '10 weeks · ongoing',
      challenge: "A multi-location wellness clinic was losing serious revenue to no-shows and last-minute cancellations. Front desk staff spent half their day on the phone confirming appointments instead of welcoming people walking in.",
      approach: [
        "Mapped every patient touchpoint from booking to follow-up across all six locations.",
        "Built a friendly outbound assistant that handles confirmations, rebooks, and post-visit check-ins by SMS — written in the clinic's actual voice.",
        "Set up a content engine: weekly wellness emails written by AI, edited by humans, segmented by patient interest.",
      ],
      next: "We're piloting an intake summarizer that turns long-form patient notes into a structured pre-visit briefing for the practitioner.",
      quote: "It sounds like us, not a robot. Patients reply to the texts thinking they're talking to Sarah at the front desk.",
      quoteWho: "Clinic Director",
      metrics: [
        { label: 'no-show rate', value: '−52', unit: '%' },
        { label: 'rebooked appts', value: '$340k', unit: '/yr' },
        { label: 'newsletter open rate', value: '38', unit: '%' },
        { label: 'front-desk hours freed', value: '24', unit: 'hrs/wk' },
      ],
      mark: 'cells',
      tint: '#c8542a',
    },
    {
      n: '04',
      industry: 'Manufacturing · 110 employees',
      title: "An engineering team's institutional memory, finally searchable.",
      service: 'AI Opportunity Audit · Custom Agents · Training',
      timeline: '14 weeks · quarterly partnership',
      challenge: "A precision-parts manufacturer had 30 years of engineering specs, change orders, and supplier correspondence — most of it locked in PDFs, scanned drawings, and one retired engineer's brain. Every new RFQ meant reinventing answers the company already knew.",
      approach: [
        "Six weeks digitizing and indexing the archive. Drawings, specs, change orders, every email thread.",
        "Built a private engineering-knowledge agent. Engineers query in plain language; the agent returns answers with the original document attached.",
        "Trained the team — including the shop floor — on prompting, edge cases, and how to feed it new knowledge as the business grows.",
      ],
      next: "Next quarter: connecting the agent to live ERP data so quote turnaround can include real-time material costs and lead times.",
      quote: "We were quoting from memory and email threads. Now a new engineer is productive in their first week. That's the part I didn't believe until it happened.",
      quoteWho: "Director of Engineering",
      metrics: [
        { label: 'RFQ turnaround', value: '4 days', unit: '→ 6 hrs' },
        { label: 'documents indexed', value: '180k+', unit: '' },
        { label: 'engineering capacity', value: '+22', unit: '%' },
        { label: 'win rate on quotes', value: '+9', unit: 'pts' },
      ],
      mark: 'grid',
      tint: '#c8542a',
    },
  ];

  const css = `
    .work-h1 { font-family: 'Instrument Serif', serif; font-size: 124px; line-height: 0.95; letter-spacing: -0.025em; font-weight: 400; margin: 0 0 36px; max-width: 1280px; }
    .work-h1 em { color: #c8542a; font-style: italic; }

    .work-list { padding: 40px 56px 0; max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 0; }
    .work-card { display: grid; grid-template-columns: 1fr 1.3fr; gap: 80px; padding: 96px 0; border-top: 1px solid rgba(26,22,18,0.12); align-items: start; position: relative; }
    .work-card:last-child { border-bottom: 1px solid rgba(26,22,18,0.12); }
    .work-card .work-mark-wrap { position: sticky; top: 110px; align-self: start; aspect-ratio: 1; max-width: 480px; }
    .work-mark { width: 100%; aspect-ratio: 1; background: #ede5d6; border-radius: 18px; overflow: hidden; position: relative; display: flex; align-items: center; justify-content: center; }
    .work-mark svg { width: 100%; height: 100%; display: block; }

    .work-num { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #c8542a; letter-spacing: 0.15em; margin-bottom: 18px; display: flex; align-items: center; gap: 12px; }
    .work-num-line { width: 28px; height: 1px; background: #c8542a; }

    .work-industry { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: #6b5d4d; text-transform: uppercase; letter-spacing: 0.15em; margin-bottom: 22px; }
    .work-title { font-family: 'Instrument Serif', serif; font-size: 56px; line-height: 1.02; letter-spacing: -0.025em; font-weight: 400; margin: 0 0 36px; }
    .work-title em { color: #c8542a; font-style: italic; }

    .work-block { margin-bottom: 28px; }
    .work-block h4 { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: #c8542a; text-transform: uppercase; letter-spacing: 0.15em; margin: 0 0 12px; font-weight: 500; }
    .work-block p { font-size: 16px; line-height: 1.6; color: #4a3f33; margin: 0 0 8px; }
    .work-block ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
    .work-block li { font-size: 15px; line-height: 1.55; color: #4a3f33; padding-left: 22px; position: relative; }
    .work-block li::before { content: '→'; color: #c8542a; position: absolute; left: 0; top: 1px; font-family: 'Instrument Serif', serif; font-style: italic; }

    .work-meta { display: flex; gap: 24px; flex-wrap: wrap; padding-top: 4px; padding-bottom: 28px; border-bottom: 1px dashed rgba(26,22,18,0.18); margin-bottom: 28px; }
    .work-meta-item { display: flex; flex-direction: column; gap: 4px; }
    .work-meta-l { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: #6b5d4d; text-transform: uppercase; letter-spacing: 0.12em; }
    .work-meta-v { font-size: 14px; color: #1a1612; }

    .work-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; padding: 28px 0 0; border-top: 1px solid rgba(26,22,18,0.12); }

    .work-quote { margin: 32px 0 28px; padding: 28px 32px; background: #ede5d6; border-radius: 14px; border-left: 3px solid #c8542a; }
    .work-quote blockquote { font-family: 'Instrument Serif', serif; font-size: 24px; line-height: 1.35; letter-spacing: -0.01em; color: #1a1612; margin: 0 0 14px; font-style: italic; text-wrap: pretty; }
    .work-quote figcaption { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: #6b5d4d; text-transform: uppercase; letter-spacing: 0.12em; }

    .work-principle { padding: 100px 56px 0; max-width: 1100px; margin: 60px auto 0; text-align: center; }
    .work-principle-eyebrow { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #c8542a; letter-spacing: 0.15em; text-transform: uppercase; margin-bottom: 22px; }
    .work-principle h2 { font-family: 'Instrument Serif', serif; font-size: 56px; line-height: 1.05; letter-spacing: -0.02em; font-weight: 400; margin: 0 auto 20px; max-width: 880px; text-wrap: balance; }
    .work-principle h2 em { color: #c8542a; font-style: italic; }
    .work-principle p { font-size: 17px; line-height: 1.6; color: #4a3f33; max-width: 640px; margin: 0 auto; }

    @media (max-width: 720px) {
      .work-quote { padding: 22px 22px; margin: 24px 0 20px; }
      .work-quote blockquote { font-size: 18px; }
      .work-principle { padding: 56px 20px 0; }
      .work-principle h2 { font-size: 32px; }
      .work-principle p { font-size: 15px; }
    }
    .work-metric { padding: 4px 18px 4px 0; border-right: 1px solid rgba(26,22,18,0.12); }
    .work-metric:last-child { border-right: 0; padding-right: 0; }
    .work-metric-l { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: #6b5d4d; text-transform: uppercase; letter-spacing: 0.15em; margin-bottom: 12px; line-height: 1.3; min-height: 26px; }
    .work-metric-v { font-family: 'Instrument Serif', serif; font-size: 48px; line-height: 1; letter-spacing: -0.02em; color: #1a1612; }
    .work-metric-v em { color: #c8542a; font-style: italic; }
    .work-metric-u { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #6b5d4d; margin-top: 6px; }

    .work-cta { padding: 100px 56px 0; max-width: 1400px; margin: 60px auto 0; }
    .work-cta-card { background: #1a1612; color: #f4efe6; border-radius: 24px; padding: 80px 56px; display: grid; grid-template-columns: 1.4fr 1fr; gap: 60px; align-items: center; position: relative; overflow: hidden; }
    .work-cta-card::before { content: ''; position: absolute; top: -250px; right: -200px; width: 500px; height: 500px; background: radial-gradient(circle, rgba(232,167,127,0.25) 0%, transparent 70%); border-radius: 50%; }
    .work-cta-h { font-family: 'Instrument Serif', serif; font-size: 64px; line-height: 0.98; letter-spacing: -0.025em; margin: 0 0 16px; position: relative; }
    .work-cta-h em { font-style: italic; color: #e8a77f; }
    .work-cta-p { font-size: 17px; line-height: 1.5; color: rgba(244,239,230,0.7); margin: 0; max-width: 480px; position: relative; }
    .work-cta-btn { font-size: 16px; padding: 18px 32px; background: #e8a77f; color: #1a1612; border-radius: 999px; font-weight: 500; display: inline-flex; align-items: center; gap: 10px; align-self: center; justify-self: end; position: relative; transition: transform 0.3s, background 0.3s; }
    .work-cta-btn:hover { transform: translateY(-3px); background: #f4efe6; }

    @media (max-width: 1024px) {
      .work-h1 { font-size: 92px; }
      .work-list { padding: 32px 32px 0; }
      .work-card { grid-template-columns: 1fr; gap: 36px; padding: 72px 0; }
      .work-card .work-mark-wrap { position: static; max-width: 320px; }
      .work-title { font-size: 44px; }
      .work-metrics { grid-template-columns: repeat(2, 1fr); gap: 24px 24px; }
      .work-metric { border-right: 0; padding-right: 0; }
      .work-metric-v { font-size: 40px; }
      .work-cta { padding: 64px 32px 0; }
      .work-cta-card { padding: 56px 40px; gap: 32px; grid-template-columns: 1fr; }
      .work-cta-h { font-size: 48px; }
      .work-cta-btn { justify-self: start; }
    }
    @media (max-width: 720px) {
      .work-h1 { font-size: 56px; line-height: 0.96; margin: 0 0 24px; }
      .work-h1 br { display: none; }
      .work-list { padding: 16px 20px 0; }
      .work-card { gap: 28px; padding: 48px 0; }
      .work-card .work-mark-wrap { max-width: 100%; }
      .work-title { font-size: 32px; margin-bottom: 24px; }
      .work-block p { font-size: 15px; }
      .work-block li { font-size: 14px; }
      .work-metrics { grid-template-columns: 1fr 1fr; gap: 20px 16px; padding-top: 20px; }
      .work-metric-v { font-size: 32px; }
      .work-metric-l { min-height: auto; }
      .work-cta { padding: 40px 20px 0; margin-top: 32px; }
      .work-cta-card { padding: 40px 28px; border-radius: 18px; }
      .work-cta-h { font-size: 32px; }
      .work-cta-p { font-size: 15px; }
      .work-cta-btn { padding: 14px 22px; font-size: 14px; }
    }
  `;

  return (
    <>
      <window.WeNav active="work" />
      <window.WeSEO page="work" />
      <style>{css}</style>

      <section className="we-page-hero">
        <div className="we-shead"><div className="we-shead-line"></div>Selected work</div>
        <h1 className="work-h1">A few <em>partnerships</em><br />we're proud of.</h1>
        <p className="we-page-sub">Names are anonymized. Numbers are real, rounded honest. Each one started with a conversation, a notebook, and a few weeks of listening before we wrote a line of anything.</p>
      </section>

      <div className="work-list">
        {studies.map(s => (
          <article className="work-card" key={s.n}>
            <div className="work-mark-wrap">
              <div className="work-mark"><Mark kind={s.mark} tint={s.tint} /></div>
            </div>
            <div>
              <div className="work-num"><span className="work-num-line"></span>case {s.n}</div>
              <div className="work-industry">{s.industry}</div>
              <h2 className="work-title">{s.title}</h2>

              <div className="work-meta">
                <div className="work-meta-item">
                  <div className="work-meta-l">Service</div>
                  <div className="work-meta-v">{s.service}</div>
                </div>
                <div className="work-meta-item">
                  <div className="work-meta-l">Timeline</div>
                  <div className="work-meta-v">{s.timeline}</div>
                </div>
              </div>

              <div className="work-block">
                <h4>The challenge</h4>
                <p>{s.challenge}</p>
              </div>

              <div className="work-block">
                <h4>Our approach</h4>
                <ul>{s.approach.map(a => <li key={a}>{a}</li>)}</ul>
              </div>

              <div className="work-block">
                <h4>What's next</h4>
                <p>{s.next}</p>
              </div>

              {s.quote && (
                <figure className="work-quote">
                  <blockquote>"{s.quote}"</blockquote>
                  <figcaption>— {s.quoteWho}, {s.industry.split(' · ')[0]}</figcaption>
                </figure>
              )}

              <div className="work-metrics">
                {s.metrics.map(m => (
                  <div className="work-metric" key={m.label}>
                    <div className="work-metric-l">{m.label}</div>
                    <div className="work-metric-v">{m.value.startsWith('+') || m.value.startsWith('−') ? <em>{m.value}</em> : m.value}</div>
                    {m.unit && <div className="work-metric-u">{m.unit}</div>}
                  </div>
                ))}
              </div>
            </div>
          </article>
        ))}
      </div>

      <section className="work-principle">
        <div className="work-principle-eyebrow">// a note on what we don't show</div>
        <h2>For every project here, there's one we <em>turned down</em> — because AI wasn't the answer.</h2>
        <p>Sometimes the right move is a clearer process, a one-page dashboard, or hiring one more person. We'd rather lose the engagement than build the wrong thing. That's the part that doesn't make a case study.</p>
      </section>

      <section className="work-cta">
        <div className="work-cta-card">
          <div>
            <h2 className="work-cta-h">Got a corner of your <em>business</em> in mind?</h2>
            <p className="work-cta-p">30 minutes, no deck. Tell us what's slow, what's expensive, what wakes you up at 3am — and we'll tell you honestly whether we can help.</p>
          </div>
          <a className="work-cta-btn" href="Leviyet Contact.html">Book the call →</a>
        </div>
      </section>

      <window.WeFooter />
    </>
  );
};

// ===========================
// ABSTRACT MARKS
// ===========================
const Mark = ({ kind, tint }) => {
  if (kind === 'pulse') {
    // Concentric arcs — soft pulse, suggests rhythm + scale
    return (
      <svg viewBox="0 0 400 400" preserveAspectRatio="xMidYMid meet">
        <rect width="400" height="400" fill="#ede5d6" />
        {[...Array(7)].map((_, i) => (
          <circle key={i} cx="200" cy="200" r={40 + i * 30}
            fill="none" stroke={tint} strokeWidth={i === 6 ? 1 : 1.4}
            strokeDasharray={i === 0 ? "0" : `${4 + i} ${6 + i * 2}`}
            opacity={0.85 - i * 0.1} />
        ))}
        <circle cx="200" cy="200" r="22" fill={tint} />
        <text x="200" y="384" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="11" fill="#6b5d4d" letterSpacing="2">// pulse 01</text>
      </svg>
    );
  }
  if (kind === 'arc') {
    // Bridging arcs — connecting two sides, suggests partnership
    return (
      <svg viewBox="0 0 400 400" preserveAspectRatio="xMidYMid meet">
        <rect width="400" height="400" fill="#ede5d6" />
        {[...Array(8)].map((_, i) => (
          <path key={i}
            d={`M ${50} ${130 + i * 22} Q 200 ${30 + i * 8} ${350} ${130 + i * 22}`}
            fill="none" stroke={tint} strokeWidth="1.2" opacity={0.85 - i * 0.08} />
        ))}
        <line x1="50" y1="306" x2="350" y2="306" stroke="#1a1612" strokeWidth="1.2" />
        <circle cx="50" cy="306" r="6" fill="#1a1612" />
        <circle cx="350" cy="306" r="6" fill={tint} />
        <text x="200" y="384" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="11" fill="#6b5d4d" letterSpacing="2">// arc 02</text>
      </svg>
    );
  }
  if (kind === 'cells') {
    // Soft grid of dots fading inwards — system of touchpoints
    return (
      <svg viewBox="0 0 400 400" preserveAspectRatio="xMidYMid meet">
        <rect width="400" height="400" fill="#ede5d6" />
        {[...Array(12)].map((_, r) =>
          [...Array(12)].map((__, c) => {
            const cx = 50 + c * 28;
            const cy = 50 + r * 28;
            const dx = cx - 200; const dy = cy - 200;
            const dist = Math.sqrt(dx * dx + dy * dy);
            const t = Math.max(0, 1 - dist / 180);
            return <circle key={`${r}-${c}`} cx={cx} cy={cy} r={1.2 + t * 5}
              fill={t > 0.4 ? tint : '#1a1612'} opacity={0.2 + t * 0.7} />;
          })
        )}
        <text x="200" y="384" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="11" fill="#6b5d4d" letterSpacing="2">// cells 03</text>
      </svg>
    );
  }
  if (kind === 'grid') {
    // Stacked rectangles + index lines — archive / structure
    return (
      <svg viewBox="0 0 400 400" preserveAspectRatio="xMidYMid meet">
        <rect width="400" height="400" fill="#ede5d6" />
        {[...Array(11)].map((_, i) => (
          <line key={`h${i}`} x1="40" y1={70 + i * 24} x2={300 + (i % 3) * 20} y2={70 + i * 24}
            stroke="#1a1612" strokeWidth="1" opacity={0.55 - i * 0.03} />
        ))}
        <rect x="60" y="180" width="180" height="40" fill={tint} opacity="0.85" />
        <rect x="80" y="230" width="120" height="14" fill="#1a1612" opacity="0.8" />
        <rect x="80" y="250" width="160" height="6" fill="#1a1612" opacity="0.4" />
        <circle cx="320" cy="120" r="34" fill="none" stroke={tint} strokeWidth="1.5" />
        <circle cx="320" cy="120" r="22" fill="none" stroke={tint} strokeWidth="1" strokeDasharray="2 4" />
        <circle cx="320" cy="120" r="6" fill={tint} />
        <text x="200" y="384" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="11" fill="#6b5d4d" letterSpacing="2">// grid 04</text>
      </svg>
    );
  }
  return null;
};

window.Work = Work;
