/* ============================================================
 * 4. SYSTEM OVERVIEW, 3 PILLARS
 * ============================================================ */

/* Editorial illustrations for each pillar */
const PillarVizBrain = () => (
  <svg viewBox="0 0 240 160" fill="none" xmlns="http://www.w3.org/2000/svg" className="pillar-viz-svg">
    <defs>
      <radialGradient id="brainGlow" cx="50%" cy="50%" r="50%">
        <stop offset="0%" stopColor="var(--accent)" stopOpacity="0.4" />
        <stop offset="100%" stopColor="var(--accent)" stopOpacity="0" />
      </radialGradient>
    </defs>
    <circle cx="120" cy="80" r="70" fill="url(#brainGlow)" />
    {/* Knowledge nodes orbiting a core */}
    <circle cx="120" cy="80" r="22" fill="var(--bg)" stroke="var(--accent)" strokeWidth="1.5" />
    <circle cx="120" cy="80" r="44" stroke="var(--hairline-strong)" strokeWidth="1" strokeDasharray="2 4" fill="none" />
    <circle cx="120" cy="80" r="64" stroke="var(--hairline)" strokeWidth="1" strokeDasharray="2 4" fill="none" />
    {/* Inner pulse — held still until the pillar is hovered. It used to
        breathe permanently, so this illustration was never once at rest
        on the page. */}
    <circle className="pvbr-pulse" cx="120" cy="80" r="10" fill="var(--accent)" opacity="0.9" />
    {/* Knowledge chips on rings */}
    {[
      { x: 76, y: 80, label: "POL" },
      { x: 164, y: 80, label: "FAQ" },
      { x: 120, y: 36, label: "SOP" },
      { x: 120, y: 124, label: "MENU" },
      { x: 56, y: 80, label: "" },
      { x: 184, y: 80, label: "" },
      { x: 90, y: 134, label: "" },
      { x: 150, y: 26, label: "" },
    ].map((n, i) => (
      <g key={i} className="pvbr-chip" style={{ "--i": i, "--cx": `${n.x}px`, "--cy": `${n.y}px` }}>
        <circle cx={n.x} cy={n.y} r={n.label ? 12 : 4} fill="var(--bg-elev-1)" stroke="var(--accent)" strokeWidth="1" />
        {n.label && <text x={n.x} y={n.y + 3} textAnchor="middle" fontSize="7" fontFamily="var(--f-mono)" fill="var(--ink-2)" letterSpacing="0.05em">{n.label}</text>}
      </g>
    ))}
    {/* Center mark */}
    <text x="120" y="84" textAnchor="middle" fontSize="11" fontFamily="var(--f-display)" fill="var(--accent)" fontStyle="italic">Brain</text>
  </svg>
);

/* CHANNELS — ONE THREAD, MANY CHANNELS.
 *
 * This deliberately does NOT draw lanes converging on an inbox: the
 * Channels card two sections above already draws exactly that, and the
 * same diagram twice on one page reads as a template rather than an
 * argument. The pillar's claim is different — one agent, one memory, one
 * history — so it draws the THREAD: consecutive messages in a single
 * conversation, each arriving on a different channel.
 *
 * On hover the thread assembles in order, which is the point: they are
 * one conversation, not six.
 */
const PillarVizChannels = () => (
  <svg viewBox="0 0 240 160" fill="none" xmlns="http://www.w3.org/2000/svg" className="pillar-viz-svg pv-ch" aria-hidden="true">
    <line className="pvch-spine" x1="26" y1="18" x2="26" y2="146"
          stroke="var(--hairline-strong)" strokeWidth="1" strokeDasharray="130" strokeDashoffset="130" />
    {[
      { y: 20, c: "var(--c-web)", w: 118, side: 0, label: "WEB" },
      { y: 52, c: "var(--c-whatsapp)", w: 158, side: 1, label: "WHATSAPP" },
      { y: 84, c: "var(--c-voice)", w: 132, side: 0, label: "VOICE" },
      { y: 116, c: "var(--c-email)", w: 172, side: 1, label: "EMAIL" },
    ].map((m, i) => (
      <g key={m.label} className="pvch-msg" style={{ "--i": i }}>
        <circle cx="26" cy={m.y + 12} r="4.5" fill={m.c} />
        <rect x={m.side ? 56 : 42} y={m.y} width={m.w} height="24" rx="7"
              fill={m.side ? "var(--bg-elev-2)" : "var(--bg-elev-1)"}
              stroke="var(--hairline-strong)" strokeWidth="1" />
        <text x={(m.side ? 56 : 42) + 12} y={m.y + 15} fontSize="8"
              fontFamily="var(--f-mono)" fill="var(--ink-3)" letterSpacing="0.08em">{m.label}</text>
        {/* the message body, drawn as weight not words */}
        <line x1={(m.side ? 56 : 42) + 12} y1={m.y + 19.5}
              x2={(m.side ? 56 : 42) + m.w - 14} y2={m.y + 19.5}
              stroke="var(--hairline)" strokeWidth="2" strokeLinecap="round" />
      </g>
    ))}
    {/* one history, one agent — stated once, at the foot of the thread */}
    <g className="pvch-seal">
      <rect x="42" y="146" width="96" height="12" rx="6" fill="var(--accent)" opacity="0.1" />
      <text x="54" y="155" fontSize="7.5" fontFamily="var(--f-mono)"
            fill="var(--accent)" letterSpacing="0.1em">ONE CONVERSATION</text>
    </g>
  </svg>
);

const PillarVizEngine = () => (
  <svg viewBox="0 0 240 160" fill="none" xmlns="http://www.w3.org/2000/svg" className="pillar-viz-svg">
    {/* Stacked data layers feeding a revenue spike */}
    {/* Bottom: data layer */}
    <g>
      <rect x="20" y="116" width="200" height="20" rx="3" fill="var(--bg-elev-1)" stroke="var(--hairline-strong)" />
      <text x="28" y="130" fontSize="9" fontFamily="var(--f-mono)" fill="var(--ink-3)" letterSpacing="0.06em">PROFILES · CDP · BOOKINGS</text>
      <circle cx="200" cy="126" r="3" fill="var(--accent)" />
    </g>
    {/* Middle: automation layer */}
    <g>
      <rect x="20" y="92" width="200" height="20" rx="3" fill="var(--bg-elev-1)" stroke="var(--hairline-strong)" />
      <text x="28" y="106" fontSize="9" fontFamily="var(--f-mono)" fill="var(--ink-3)" letterSpacing="0.06em">JOURNEYS · CAMPAIGNS · LOYALTY</text>
      <circle cx="200" cy="102" r="3" fill="var(--accent)" />
    </g>
    {/* Top: outcome chart */}
    <g>
      <rect x="20" y="16" width="200" height="68" rx="3" fill="var(--bg)" stroke="var(--hairline)" />
      {/* Grid */}
      <line x1="20" y1="32" x2="220" y2="32" stroke="var(--hairline)" strokeWidth="0.5" />
      <line x1="20" y1="48" x2="220" y2="48" stroke="var(--hairline)" strokeWidth="0.5" />
      <line x1="20" y1="64" x2="220" y2="64" stroke="var(--hairline)" strokeWidth="0.5" />
      {/* Bars */}
      {[
        { x: 36, h: 14 },
        { x: 60, h: 22 },
        { x: 84, h: 18 },
        { x: 108, h: 32 },
        { x: 132, h: 28 },
        { x: 156, h: 44 },
        { x: 180, h: 52 },
        { x: 204, h: 60 },
      ].map((b, i) => (
        <rect key={i} className="pven-bar" style={{ "--i": i }}
              x={b.x} y={80 - b.h} width="12" height={b.h}
              fill={i >= 5 ? "var(--accent)" : "var(--ink-4)"} opacity={i >= 5 ? 1 : 0.5} />
      ))}
      {/* Trend line */}
      <path className="pven-trend" d="M 42 66 L 66 58 L 90 62 L 114 48 L 138 52 L 162 36 L 186 28 L 210 20" stroke="var(--accent)" strokeWidth="1.5" fill="none" />
      <text x="28" y="26" fontSize="8" fontFamily="var(--f-mono)" fill="var(--ink-3)" letterSpacing="0.06em">DIRECT REVENUE</text>
    </g>
    {/* Connection ticks between layers */}
    <line x1="120" y1="84" x2="120" y2="92" stroke="var(--accent)" strokeWidth="1" />
    <line x1="120" y1="112" x2="120" y2="116" stroke="var(--accent)" strokeWidth="1" />
  </svg>
);

const pillarVizMap = { brain: PillarVizBrain, channels: PillarVizChannels, engine: PillarVizEngine };

/* Each point is a TERM plus what it means, not a sentence with a tick in
   front of it. Four near-identical sentences per pillar, three pillars
   across, gave three columns of interchangeable grey text — nothing to
   scan, nothing to land on. A short term carries the idea and the line
   underneath earns its length, so the lengths vary because the content
   does rather than because they were padded to match. */
const pillars = [
  {
    key: "channels",
    icon: IconChannels,
    name: "The Channels",
    promise: "Every guest conversation, on every channel, in one shared inbox.",
    points: [
      { term: "Six channels", body: "WhatsApp, Meta Socials, Web Chatbot, Voice, and email inbound and outbound." },
      { term: "One agent behind all of them", body: "The same logic, the same memory, the same guest history." },
      { term: "Escalation that knows who", body: "HQ, property or department, chosen from the conversation itself." },
      { term: "Live availability", body: "Real rates and one-tap booking links, from any channel." },
    ],
  },
  {
    key: "brain",
    icon: IconBrain,
    name: "The Brain",
    promise: "AI knowledge that learns your hotel and powers every guest interaction.",
    points: [
      { term: "Trained on your hotel", body: "SOPs, services, policies and rates, per property and per group." },
      { term: "Any language, in seconds", body: "The guest writes how they speak; the answer comes back the same way." },
      { term: "Knows where the guest is", body: "Pre-stay, in-stay and post-stay are different conversations." },
      { term: "Gets better on its own", body: "Every conversation feeds the next one." },
    ],
  },
  {
    key: "engine",
    icon: IconEngine,
    name: "The Engine",
    promise: "The data and automation layer that turns conversations into revenue.",
    points: [
      { term: "Booking-first CRM", body: "Profiles anchored to real reservations, not to email addresses." },
      { term: "CDP", body: "Deduplicates across PMS silos automatically." },
      { term: "Omnichannel journeys", body: "Triggered by real booking data, across the whole stay." },
      { term: "Campaigns and loyalty", body: "Email, WhatsApp, and tier rules complex enough for a group." },
    ],
  },
];

const SectionPillars = () => (
  <section className="section-pad pillars" id="system">
    <div className="container">
      <div style={{ marginBottom: 80, maxWidth: 720 }}>
        <Reveal><div className="eyebrow">The system</div></Reveal>
        <Reveal delay={120}>
          <h2 className="h-1" style={{ marginTop: 24 }}>
            A complete guest engagement system.<br />
            <span className="italic-accent">Not a collection of tools.</span>
          </h2>
        </Reveal>
      </div>

      <div className="pillars-grid">
        {pillars.map((p, i) => {
          const Ic = p.icon;
          const Viz = pillarVizMap[p.key];
          return (
            <Reveal key={p.key} delay={i * 100}>
              <article className="pillar">
                <div className="pillar-viz">
                  <Viz />
                </div>
                <div className="pillar-head">
                  <div className="pillar-mark"><Ic size={20} stroke={1.6} /></div>
                  <div className="pillar-num">0{i + 1} / {p.key.toUpperCase()}</div>
                </div>
                <h3 className="h-3 serif" style={{ fontSize: 28, fontFamily: "var(--f-display)", letterSpacing: "-0.01em" }}>{p.name}</h3>
                <p className="pillar-promise">{p.promise}</p>
                <ul className="pillar-bullets">
                  {p.points.map((pt, j) => (
                    <li key={j} style={{ "--j": j }}>
                      <span className="pillar-rule" aria-hidden="true" />
                      <span>
                        <strong className="pillar-term">{pt.term}</strong>
                        <span className="pillar-body">{pt.body}</span>
                      </span>
                    </li>
                  ))}
                </ul>
              </article>
            </Reveal>
          );
        })}
      </div>
    </div>

    <style>{`
      .pillars-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0;
        border-top: 1px solid var(--hairline);
      }
      .pillar {
        padding: 32px 40px 48px 0;
        border-right: 1px solid var(--hairline);
        position: relative;
      }
      .pillar:last-child { border-right: 0; }
      .pillar:not(:first-child) { padding-left: 40px; }
      .pillar-viz {
        background: var(--bg-elev-1);
        border: 1px solid var(--hairline);
        border-radius: 12px;
        padding: 12px;
        margin-bottom: 28px;
        aspect-ratio: 240 / 160;
        overflow: hidden;
      }
      .pillar-viz-svg { width: 100%; height: 100%; display: block; }
      .pillar-head {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 16px;
      }
      .pillar-mark {
        width: 36px; height: 36px;
        border-radius: 10px;
        background: color-mix(in srgb, var(--accent) 14%, var(--bg-elev-1));
        color: var(--accent);
        display: grid; place-items: center;
        flex-shrink: 0;
      }
      .pillar-num {
        font-family: var(--f-mono);
        font-size: 10px;
        color: var(--ink-4);
        letter-spacing: 0.12em;
      }
      .pillar-promise {
        margin: 12px 0 24px;
        font-size: 17px;
        color: var(--ink-2);
        line-height: 1.4;
      }
      /* Term above, meaning below — two weights instead of one flat run of
         grey. The hairline replaces the tick: a check mark on a feature
         list is decoration pretending to be information, and four of them
         stacked is the template look we are getting away from. */
      .pillar-bullets {
        list-style: none; margin: 0; padding: 0;
        display: flex; flex-direction: column;
        gap: 18px;
      }
      .pillar-bullets li {
        display: flex; gap: 14px;
        line-height: 1.5;
      }
      .pillar-rule {
        flex: 0 0 auto; width: 14px; height: 1px; margin-top: 11px;
        background: var(--accent); opacity: 0.5;
        transition: width .38s cubic-bezier(0.22, 1, 0.36, 1), opacity .38s ease;
        transition-delay: calc(var(--j) * 60ms);
      }
      .pillar:hover .pillar-rule,
      .pillar:focus-within .pillar-rule { width: 24px; opacity: 1; }
      .pillar-term {
        display: block;
        font-size: 14px; font-weight: 600; color: var(--ink);
        letter-spacing: -0.005em;
      }
      .pillar-body {
        display: block; margin-top: 3px;
        font-size: 13.5px; color: var(--ink-3);
        max-width: 34ch;
      }
      /* ============================================================
       * ILLUSTRATION MOTION — same rule as the platform cards above:
       * completely still until the pillar is hovered, and still again
       * after. Everything here is a transition, so unhover simply
       * reverses and no frame is ever caught half-played.
       * ============================================================ */
      .pillars { --e: cubic-bezier(0.22, 1, 0.36, 1); }

      /* Brain: the knowledge chips settle onto their rings, then the core
         takes one breath. */
      .pv-br .pvbr-chip, .pillar-viz-svg .pvbr-chip {
        opacity: 0.45; transform-box: fill-box; transform-origin: center;
        transform: scale(0.82);
        transition: opacity .45s ease, transform .55s var(--e);
        transition-delay: calc(var(--i) * 55ms);
      }
      .pillar:hover .pvbr-chip,
      .pillar:focus-within .pvbr-chip { opacity: 1; transform: scale(1); }
      .pvbr-pulse {
        transform-box: fill-box; transform-origin: center;
        transform: scale(0.72); opacity: 0.55;
        transition: transform .6s var(--e) .18s, opacity .6s ease .18s;
      }
      .pillar:hover .pvbr-pulse,
      .pillar:focus-within .pvbr-pulse { transform: scale(1.25); opacity: 0.95; }

      /* IMPORTANT: rest is QUIET, never EMPTY. The first cut started the
         thread and the bars from opacity/scale 0, so at rest those two
         panels were blank rectangles — which reads as a broken image, not
         as calm. Every drawing is complete before you touch it; hover
         raises it to full strength and adds the one element that resolves
         the idea (the seal, the trend line). */

      /* Channels: the thread is there, muted; hover brings it forward in
         order and states what it adds up to. */
      .pvch-spine { stroke-dashoffset: 0; }
      .pvch-msg {
        opacity: 0.45;
        transition: opacity .4s ease, transform .48s var(--e);
        transition-delay: calc(var(--i) * 100ms);
      }
      .pillar:hover .pvch-msg,
      .pillar:focus-within .pvch-msg { opacity: 1; transform: translateX(4px); }
      .pvch-seal { opacity: 0; transition: opacity .45s ease .48s; }
      .pillar:hover .pvch-seal,
      .pillar:focus-within .pvch-seal { opacity: 1; }

      /* Engine: the bars stand at rest, dimmed; hover lifts them and the
         trend draws across — the layers turning into revenue. */
      .pven-bar {
        opacity: 0.35; transform-box: fill-box; transform-origin: bottom;
        transform: scaleY(0.82);
        transition: transform .5s var(--e), opacity .4s ease;
        transition-delay: calc(var(--i) * 55ms);
      }
      .pillar:hover .pven-bar,
      .pillar:focus-within .pven-bar { transform: scaleY(1); opacity: 1; }
      .pven-trend {
        stroke-dasharray: 200; stroke-dashoffset: 200; opacity: 0;
        transition: stroke-dashoffset .9s var(--e) .3s, opacity .3s ease .3s;
      }
      .pillar:hover .pven-trend,
      .pillar:focus-within .pven-trend { stroke-dashoffset: 0; opacity: 1; }

      @media (prefers-reduced-motion: reduce) {
        .pillar-viz-svg *, .pillar-rule { transition: none !important; animation: none !important; }
        .pvbr-chip { opacity: 1; transform: none; }
        .pvch-msg { opacity: 1; transform: none; }
        .pvch-seal { opacity: 1; }
        .pven-bar { transform: none; opacity: 1; }
        .pven-trend { stroke-dashoffset: 0; opacity: 1; }
      }

      @media (max-width: 900px) {
        .pillars-grid { grid-template-columns: 1fr; }
        .pillar { border-right: 0; border-bottom: 1px solid var(--hairline); padding: 40px 0; }
        .pillar:not(:first-child) { padding-left: 0; }
        .pillar-body { max-width: none; }
      }
    `}</style>
  </section>
);

window.SectionPillars = SectionPillars;
