// Guestmaker · Voice Agent, Distribution & Routing section
const { useState: useStateR, useEffect: useEffectR, useRef: useRefR, useMemo: useMemoR } = React;

const RT_FUCHSIA = "#ED4D86";
const RT_FUCHSIA_DEEP = "#B8336A";
const RT_PINK_SOFT = "#F2C4D8";
const RT_INK = "#1a1a1a";
const RT_DIM = "#6e6363";
const RT_FAINT = "#a99fa3";
const RT_RULE = "#e3ddcf";
const RT_PAPER = "#fbfaf6";
const RT_CREAM = "#f6f4ef";
const RT_TEAL = "#08CDC8";

const MARKETS = [
  { iso: "ES", code: "+34",  number: "+34 91 020 00 11",  country: "Spain",        city: "Madrid",      lang: "Spanish",         voice: "Sof\u00eda",  hours: "24/7", calls: 482, status: "live",          dest: "Marbella",   region: "Costa del Sol",   headline: "Tu escapada de verano",       price: "€189", per: "/noche", scene: "sunset" },
  { iso: "GB", code: "+44",  number: "+44 20 7946 0044",  country: "United Kingdom",city: "London",      lang: "English",         voice: "Liam",        hours: "24/7", calls: 318, status: "live",          dest: "Tenerife",   region: "Canary Islands",  headline: "Plan your summer escape",       price: "£165", per: "/night", scene: "volcanic" },
  { iso: "FR", code: "+33",  number: "+33 1 70 70 30 33", country: "France",       city: "Paris",       lang: "French",          voice: "Camille",     hours: "24/7", calls: 207, status: "live",          dest: "Mallorca",   region: "Îles Baléares",   headline: "Votre évasion estivale",        price: "€199", per: "/nuit",  scene: "cove" },
  { iso: "DE", code: "+49",  number: "+49 30 568 405 49", country: "Germany",      city: "Berlin",      lang: "German",          voice: "Hannah",      hours: "24/7", calls: 144, status: "live",          dest: "Ibiza",      region: "Balearen",        headline: "Ihre Sommerauszeit",            price: "€209", per: "/Nacht", scene: "village" },
  { iso: "IT", code: "+39",  number: "+39 02 4953 7039",  country: "Italy",        city: "Milan",       lang: "Italian",         voice: "Giulia",      hours: "24/7", calls: 132, status: "live",          dest: "Sardegna",   region: "Costa Smeralda",  headline: "La tua fuga estiva",            price: "€219", per: "/notte", scene: "cove" },
  { iso: "PT", code: "+351", number: "+351 21 005 0351",  country: "Portugal",     city: "Lisbon",      lang: "Portuguese",      voice: "Tiago",       hours: "24/7", calls: 76,  status: "live",          dest: "Algarve",    region: "Costa Vicentina", headline: "A sua escapada de verão",       price: "€175", per: "/noite", scene: "cliffs" },
  { iso: "NL", code: "+31",  number: "+31 20 808 0031",   country: "Netherlands",  city: "Amsterdam",   lang: "Dutch",           voice: "Sanne",       hours: "24/7", calls: 64,  status: "live",          dest: "Costa Brava",region: "Catalunya",       headline: "Plan jouw zomervakantie",       price: "€189", per: "/nacht", scene: "cove" },
  { iso: "US", code: "+1",   number: "+1 (212) 555 0134", country: "United States",city: "New York",    lang: "English",         voice: "Eva",        hours: "24/7", calls: 401, status: "live",          dest: "Mediterranean",region: "Spain & Italy", headline: "Your summer abroad",            price: "$229", per: "/night", scene: "sunset" },
  { iso: "AE", code: "+971", number: "+971 4 557 0971",   country: "UAE",          city: "Dubai",       lang: "Arabic / EN",     voice: "Layla",       hours: "24/7", calls: 58,  status: "live",          dest: "Marbella",   region: "Costa del Sol",   headline: "Your Mediterranean retreat",    price: "AED 990", per: "/night", scene: "sunset" },
  { iso: "JP", code: "+81",  number: "+81 3 4577 0081",   country: "Japan",        city: "Tokyo",       lang: "Japanese",        voice: "Yui",         hours: "24/7", calls: 22,  status: "provisioning",  dest: "Okinawa",    region: "Kerama Islands",  headline: "夏のリトリート",                 price: "¥28,900", per: "/泊",   scene: "tropical" },
];

const THEMES = [
  { id: "groups",   name: "Group bookings",       sub: "10+ rooms",        route: "Reservations · Group desk", target: "+34 91 020 0011" },
  { id: "mice",     name: "MICE & events",        sub: "weddings · meetings", route: "Events team",             target: "+34 91 020 0022" },
  { id: "vip",      name: "VIP & loyalty",        sub: "Orchid & Onyx",    route: "VIP concierge",              target: "Direct · Olea Cliffside" },
  { id: "modify",   name: "Booking modification", sub: "change · cancel",  route: "Hotel of stay",              target: "Routes per booking" },
  { id: "special",  name: "Special requests",     sub: "diet · access",    route: "Hotel of stay",              target: "Routes per booking" },
  { id: "complaint",name: "Complaints",           sub: "service · room",   route: "Guest relations",            target: "+34 91 020 0044" },
  { id: "billing",  name: "Billing & invoices",   sub: "payment issues",   route: "Finance team",               target: "finance@olea.com" },
  { id: "loyalty",  name: "Loyalty enrolment",    sub: "points · status",  route: "Loyalty desk",               target: "+34 91 020 0055" },
  { id: "press",    name: "Press & PR",           sub: "media requests",   route: "Communications",             target: "+34 91 020 0066" },
  { id: "careers",  name: "Careers",              sub: "applications",     route: "HR team",                    target: "careers@olea.com" },
  { id: "supplier", name: "Supplier inquiries",   sub: "vendors · b2b",    route: "Procurement",                target: "supplies@olea.com" },
  { id: "lost",     name: "Lost & found",         sub: "items · luggage",  route: "Hotel of stay",              target: "Routes per booking" },
];

const HOTELS_FAN = [
  { id: "cc",    name: "Call center",      loc: "Group ops · MICE / cancellations / groups", phone: "Human team", color: RT_INK,          isHuman: true, rules: ["Group ≥ 8 rooms", "MICE / events", "Cancellations"] },
  { id: "cliff", name: "Olea Cliffside",   loc: "Tenerife",      phone: "+34 922 010 010", color: RT_FUCHSIA },
  { id: "marina",name: "Zafira Marina",    loc: "Lanzarote",     phone: "+34 928 020 020", color: "#9B3F70" },
  { id: "sunset",name: "Sunset Beach",     loc: "Fuerteventura", phone: "+34 928 030 030", color: "#C45481" },
  { id: "verde", name: "Verde Wellness",   loc: "Mallorca",      phone: "+34 971 040 040", color: RT_FUCHSIA_DEEP },
  { id: "rosa",  name: "Casa Rosa",        loc: "Marbella",      phone: "+34 952 050 050", color: "#D67BA0" },
  { id: "lago",  name: "Lago Suites",      loc: "Como",          phone: "+39 031 060 060", color: "#B96A8A" },
];

// ────────────────────────────────────────────────────────────
//  Local numbers · realistic dashboard + browser preview
// ────────────────────────────────────────────────────────────
function HeroScene({ scene }) {
  // Editorial, photographic-feel SVG hero per market.
  // All scenes within fuchsia / coral / plum / cream palette.
  // Each scene has its own architectural focal element + atmospheric depth.

  const ID = `rt-${scene}`;

  const SCENES = {
    // Spain · Marbella sunset, infinity pool clifftop villa
    sunset: {
      sky: ["#FFE4D2", "#F5B0B8", "#D86592", "#9B3F70"],
      sea: ["#7A2A4E", "#3A1530"],
      sun: { x: 240, y: 92, r: 22, glow: ["#FFE9C2", "#FFB388"] },
      hazeY: 132,
    },
    // UK -> Tenerife, volcanic dawn, basalt headland
    volcanic: {
      sky: ["#FFD0BE", "#E07298", "#9B3F70", "#3A1530"],
      sea: ["#5C2244", "#2A0E22"],
      sun: { x: 90, y: 78, r: 18, glow: ["#FFD9A0", "#E08AA0"] },
      hazeY: 130,
    },
    // France -> Mallorca cove, limestone outcrop
    cove: {
      sky: ["#FFE9D6", "#F5B5B8", "#ED4D86", "#7A2A4E"],
      sea: ["#7A2A4E", "#3A1530"],
      sun: { x: 220, y: 102, r: 18, glow: ["#FFEDC2", "#FFC58E"] },
      hazeY: 134,
    },
    // Germany -> Ibiza, white village on hill
    village: {
      sky: ["#FFEAD6", "#F4A8B5", "#ED4D86", "#7A2A4E"],
      sea: ["#5C2244", "#2A0E22"],
      sun: { x: 70, y: 60, r: 14, glow: ["#FFF3D8", "#FFD89A"] },
      hazeY: 138,
    },
    // Italy/Portugal -> Algarve cliffs with arch
    cliffs: {
      sky: ["#FFE3C0", "#F09478", "#ED4D86", "#7A2A4E"],
      sea: ["#7A2A4E", "#3A1530"],
      sun: { x: 240, y: 96, r: 20, glow: ["#FFE9C2", "#F09478"] },
      hazeY: 132,
    },
    // Japan -> Okinawa, twin palms over coral lagoon
    tropical: {
      sky: ["#FFE0E8", "#F4A8B5", "#ED4D86", "#7A2A4E"],
      sea: ["#7A2A4E", "#3A1530"],
      sun: { x: 170, y: 64, r: 14, glow: ["#FFF0DC", "#FFC58E"] },
      hazeY: 136,
    },
  };

  const s = SCENES[scene] || SCENES.sunset;

  return (
    <svg viewBox="0 0 320 220" preserveAspectRatio="xMidYMid slice"
      style={{ position: "absolute", inset: 0, width: "100%", height: "100%" }}>
      <defs>
        {/* atmospheric sky with 4 stops for real haze */}
        <linearGradient id={`${ID}-sky`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0"    stopColor={s.sky[0]} />
          <stop offset="0.35" stopColor={s.sky[1]} />
          <stop offset="0.72" stopColor={s.sky[2]} />
          <stop offset="1"    stopColor={s.sky[3]} />
        </linearGradient>
        <linearGradient id={`${ID}-sea`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor={s.sea[0]} />
          <stop offset="1" stopColor={s.sea[1]} />
        </linearGradient>
        <radialGradient id={`${ID}-sun`} cx="0.5" cy="0.5" r="0.5">
          <stop offset="0"   stopColor={s.sun.glow[0]} />
          <stop offset="0.55" stopColor={s.sun.glow[1]} />
          <stop offset="1"   stopColor={s.sun.glow[1]} stopOpacity="0" />
        </radialGradient>
        <linearGradient id={`${ID}-haze`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor={s.sky[1]} stopOpacity="0" />
          <stop offset="1" stopColor={s.sky[2]} stopOpacity="0.55" />
        </linearGradient>
        <linearGradient id={`${ID}-sea-spec`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor={s.sun.glow[0]} stopOpacity="0.65" />
          <stop offset="1" stopColor={s.sun.glow[0]} stopOpacity="0" />
        </linearGradient>
        <radialGradient id={`${ID}-vignette`} cx="0.5" cy="0.55" r="0.75">
          <stop offset="0.55" stopColor="#000" stopOpacity="0" />
          <stop offset="1"    stopColor="#000" stopOpacity="0.32" />
        </radialGradient>
      </defs>

      {/* sky */}
      <rect x="0" y="0" width="320" height={s.hazeY + 6} fill={`url(#${ID}-sky)`} />

      {/* soft cloud bands */}
      <ellipse cx="56"  cy="34" rx="44" ry="3.5" fill="#fff" opacity="0.32" />
      <ellipse cx="120" cy="22" rx="30" ry="2.5" fill="#fff" opacity="0.28" />
      <ellipse cx="270" cy="44" rx="38" ry="3"   fill="#fff" opacity="0.22" />

      {/* sun glow + disc */}
      <circle cx={s.sun.x} cy={s.sun.y} r="78" fill={`url(#${ID}-sun)`} />
      <circle cx={s.sun.x} cy={s.sun.y} r={s.sun.r} fill={s.sun.glow[0]} opacity="0.95" />
      <circle cx={s.sun.x} cy={s.sun.y} r={s.sun.r * 0.55} fill="#FFF3DA" />

      {/* horizon haze band */}
      <rect x="0" y={s.hazeY - 10} width="320" height="20" fill={`url(#${ID}-haze)`} />

      {/* sea */}
      <rect x="0" y={s.hazeY} width="320" height={220 - s.hazeY} fill={`url(#${ID}-sea)`} />

      {/* sun column reflection on water */}
      <ellipse cx={s.sun.x} cy={s.hazeY + 4}  rx="58" ry="6"   fill={s.sun.glow[0]} opacity="0.55" />
      <ellipse cx={s.sun.x} cy={s.hazeY + 14} rx="46" ry="3.5" fill={s.sun.glow[0]} opacity="0.4" />
      <ellipse cx={s.sun.x} cy={s.hazeY + 22} rx="32" ry="2.5" fill={s.sun.glow[0]} opacity="0.28" />
      <ellipse cx={s.sun.x} cy={s.hazeY + 30} rx="20" ry="1.8" fill={s.sun.glow[0]} opacity="0.18" />

      {/* faint horizontal wave striations */}
      {[0,1,2,3,4,5].map(i => (
        <line key={i} x1="0" x2="320"
          y1={s.hazeY + 8 + i * 7} y2={s.hazeY + 8 + i * 7}
          stroke={s.sun.glow[0]} strokeOpacity={0.08 - i * 0.01} strokeWidth="0.6" />
      ))}

      {/* SCENE-SPECIFIC FOREGROUND */}
      {scene === "sunset" && (
        <g>
          {/* far headland silhouette */}
          <path d={`M0,${s.hazeY-2} Q60,${s.hazeY-12} 110,${s.hazeY-6} L110,${s.hazeY+2} L0,${s.hazeY+2} Z`}
            fill="#3A1530" opacity="0.55" />
          {/* near clifftop villa terrace, right */}
          <g>
            {/* cliff mass */}
            <path d="M210,148 Q235,132 268,138 L320,142 L320,220 L210,220 Z" fill="#3A1530" />
            <path d="M210,148 Q235,132 268,138 L320,142 L320,160 L210,165 Z" fill="#5C2244" opacity="0.6" />
            {/* infinity pool ledge */}
            <rect x="220" y="146" width="100" height="6" fill="#FFE9C2" opacity="0.85" />
            <rect x="220" y="152" width="100" height="2" fill="#fff" opacity="0.55" />
            {/* villa block, low slung */}
            <rect x="232" y="128" width="58" height="20" fill="#FAF3E6" />
            <rect x="232" y="128" width="58" height="3"  fill="#E8DCC4" />
            {/* archway windows */}
            {[236, 250, 264, 278].map((x,i) => (
              <path key={i} d={`M${x},148 L${x},138 Q${x+4},132 ${x+8},138 L${x+8},148 Z`} fill="#3A1530" opacity="0.85" />
            ))}
            {/* warm interior glow on one window */}
            <path d="M250,148 L250,138 Q254,132 258,138 L258,148 Z" fill="#FFD89A" opacity="0.7" />
            {/* parasol on terrace */}
            <line x1="226" y1="146" x2="226" y2="135" stroke="#3A1530" strokeWidth="1" />
            <path d="M218,135 Q226,128 234,135 Z" fill="#ED4D86" />
            <path d="M218,135 Q226,131 234,135" stroke="#fff" strokeWidth="0.4" opacity="0.6" fill="none" />
            {/* cypress accent */}
            <ellipse cx="216" cy="138" rx="3.5" ry="9" fill="#2A0E22" />
            <ellipse cx="298" cy="142" rx="2.5" ry="7" fill="#2A0E22" />
          </g>
          {/* tiny sailboat, far out */}
          <g opacity="0.7">
            <path d="M64,140 L64,128 L72,140 Z" fill="#2A0E22" />
            <path d="M62,140 L74,140 L72,143 L64,143 Z" fill="#2A0E22" />
            <line x1="64" y1="143" x2="64" y2="146" stroke={s.sun.glow[0]} strokeOpacity="0.4" />
          </g>
          {/* foreground rocky shoreline left, low */}
          <path d="M0,200 Q30,190 60,200 L60,220 L0,220 Z" fill="#2A0E22" opacity="0.55" />
        </g>
      )}

      {scene === "volcanic" && (
        <g>
          {/* far volcano cone */}
          <path d="M120,135 L185,52 L218,82 L255,135 Z" fill="#1A0820" />
          <path d="M170,72 L185,52 L201,68 L191,80 L182,76 Z" fill="#fff" opacity="0.85" />
          {/* lava chimney smoke */}
          <ellipse cx="186" cy="44" rx="7" ry="3"  fill="#fff" opacity="0.4" />
          <ellipse cx="190" cy="36" rx="5" ry="2.2" fill="#fff" opacity="0.3" />
          {/* near basalt headland with cliff hotel */}
          <path d="M0,150 L70,118 L130,128 L130,220 L0,220 Z" fill="#2A0E22" />
          <path d="M0,150 L70,118 L130,128 L130,140 L0,160 Z" fill="#3A1530" opacity="0.7" />
          {/* terraced villa cluster */}
          <rect x="40"  y="116" width="22" height="12" fill="#F4ECDC" />
          <rect x="62"  y="120" width="18" height="10" fill="#EFE3CB" />
          <rect x="80"  y="124" width="20" height="8"  fill="#F4ECDC" />
          {/* warm windows */}
          <rect x="48"  y="120" width="3" height="4" fill="#FFD89A" />
          <rect x="68"  y="123" width="3" height="3" fill="#FFD89A" />
          <rect x="86"  y="126" width="3" height="3" fill="#FFD89A" />
          {/* foreground: black sand beach curve */}
          <path d="M0,200 Q80,196 160,202 Q240,206 320,200 L320,220 L0,220 Z" fill="#1A0820" />
          <path d="M0,206 Q80,202 160,208 Q240,212 320,206 L320,220 L0,220 Z" fill="#0A0410" opacity="0.7" />
        </g>
      )}

      {scene === "cove" && (
        <g>
          {/* limestone outcrop right */}
          <path d="M232,140 Q258,108 282,118 Q306,124 320,138 L320,220 L232,220 Z" fill="#7A2A4E" />
          <path d="M232,140 Q258,108 282,118 L282,134 L232,154 Z" fill="#9B3F70" opacity="0.55" />
          {/* hilltop chapel + cypresses */}
          <rect x="266" y="100" width="14" height="14" fill="#FAF3E6" />
          <path d="M266,100 L273,92 L280,100 Z" fill="#ED4D86" />
          <rect x="270" y="106" width="2" height="4" fill="#3A1530" />
          <ellipse cx="258" cy="108" rx="2.8" ry="7" fill="#2A0E22" />
          <ellipse cx="288" cy="112" rx="2.5" ry="6" fill="#2A0E22" />
          {/* wooden swim platform jutting from cove */}
          <rect x="232" y="148" width="44" height="3" fill="#7A4A2E" />
          <rect x="232" y="151" width="44" height="1" fill="#5A3520" />
          <line x1="240" y1="151" x2="240" y2="170" stroke="#5A3520" strokeWidth="0.8" />
          <line x1="260" y1="151" x2="260" y2="170" stroke="#5A3520" strokeWidth="0.8" />
          {/* yacht in foreground */}
          <g>
            <path d="M58,168 Q68,164 90,164 Q102,164 108,168 Q102,176 70,176 Q60,176 58,168 Z" fill="#FAF3E6" />
            <rect x="74" y="160" width="14" height="4" fill="#FAF3E6" />
            <rect x="74" y="156" width="14" height="4" fill="#3A1530" opacity="0.4" />
            <line x1="81" y1="146" x2="81" y2="160" stroke="#2A0E22" strokeWidth="0.8" />
          </g>
          {/* far village on left coast */}
          <path d="M0,148 Q24,140 60,144 L60,156 L0,156 Z" fill="#5C2244" opacity="0.65" />
          {[10, 24, 38, 50].map((x,i) => (
            <rect key={i} x={x} y={141 + (i%2)*2} width="6" height="6" fill="#F4ECDC" opacity="0.85" />
          ))}
        </g>
      )}

      {scene === "village" && (
        <g>
          {/* tiered hillside */}
          <path d="M0,165 Q80,140 200,148 L320,158 L320,220 L0,220 Z" fill="#7A2A4E" />
          <path d="M0,170 Q80,150 200,156 L320,164 L320,180 L0,180 Z" fill="#5C2244" opacity="0.6" />
          {/* white cubic houses, three rows */}
          {[
            { y: 140, items: [[18,16,18],[42,12,16],[64,16,14],[84,14,18],[108,18,16],[130,14,18],[154,16,16],[176,12,18]] },
            { y: 152, items: [[10,14,16],[30,18,14],[52,12,18],[74,16,16],[96,14,18],[120,18,16],[148,14,18]] },
            { y: 164, items: [[6,16,14],[26,14,18],[50,18,16],[76,14,18],[102,16,16],[128,12,20]] },
          ].map((row,r) => (
            <g key={r}>
              {row.items.map(([x,h,w],i) => (
                <g key={i}>
                  <rect x={x} y={row.y - h} width={w} height={h} fill="#FAF3E6" />
                  <rect x={x} y={row.y - h} width={w} height="2" fill="#E8DCC4" />
                  {/* tiny roof shadow */}
                  <rect x={x} y={row.y - h + h - 2} width={w} height="1" fill="#D8C8A8" opacity="0.5" />
                  {/* warm windows */}
                  <rect x={x + 3} y={row.y - h + 4} width="2" height="2.5" fill="#FFD89A" />
                  {w > 14 && <rect x={x + w - 5} y={row.y - h + 4} width="2" height="2.5" fill="#FFD89A" />}
                </g>
              ))}
            </g>
          ))}
          {/* whitewashed church/dome on crest */}
          <rect x="68" y="118" width="20" height="20" fill="#FAF3E6" />
          <ellipse cx="78" cy="118" rx="10" ry="8" fill="#FAF3E6" />
          <rect x="76" y="106" width="4" height="6" fill="#FAF3E6" />
          {/* bougainvillea spill on terraces */}
          <ellipse cx="40"  cy="170" rx="14" ry="4" fill="#ED4D86" opacity="0.55" />
          <ellipse cx="178" cy="172" rx="12" ry="3.5" fill="#ED4D86" opacity="0.5" />
          {/* harbour ledge with two boats */}
          <rect x="0" y="178" width="320" height="4" fill="#3A1530" />
          <ellipse cx="220" cy="184" rx="14" ry="2.5" fill="#FAF3E6" />
          <ellipse cx="270" cy="186" rx="12" ry="2"   fill="#FAF3E6" opacity="0.85" />
        </g>
      )}

      {scene === "cliffs" && (
        <g>
          {/* far cliff right */}
          <path d="M236,140 L284,108 L320,118 L320,220 L236,220 Z" fill="#7A2A4E" />
          <path d="M236,140 L284,108 L320,118 L320,140 L236,160 Z" fill="#9B3F70" opacity="0.55" />
          {/* foreground arch cliff left */}
          <path d="M0,150 L70,90 L130,104 L130,220 L0,220 Z" fill="#9B3F70" />
          <path d="M0,150 L70,90 L130,104 L130,128 L0,168 Z" fill="#ED4D86" opacity="0.45" />
          {/* erosion striations */}
          <path d="M10,158 Q60,108 120,116" stroke="#3A1530" strokeWidth="0.6" fill="none" opacity="0.45" />
          <path d="M10,168 Q60,128 120,134" stroke="#3A1530" strokeWidth="0.6" fill="none" opacity="0.35" />
          {/* sea arch hole */}
          <path d="M86,150 Q98,128 110,146 Q104,154 96,156 Q88,156 86,150 Z" fill="#3A1530" />
          <path d="M88,148 Q99,131 108,146" stroke="#7A2A4E" strokeWidth="1" fill="none" opacity="0.7" />
          {/* lone clifftop chapel */}
          <rect x="64" y="84"  width="10" height="10" fill="#FAF3E6" />
          <path d="M64,84 L69,78 L74,84 Z" fill="#3A1530" />
          {/* paraglider in sky */}
          <g opacity="0.75">
            <path d="M180,52 Q190,46 200,52" stroke="#3A1530" strokeWidth="1.2" fill="none" />
            <line x1="186" y1="54" x2="190" y2="60" stroke="#3A1530" strokeWidth="0.6" />
            <line x1="194" y1="54" x2="190" y2="60" stroke="#3A1530" strokeWidth="0.6" />
            <circle cx="190" cy="62" r="1.4" fill="#3A1530" />
          </g>
          {/* small skiff in foreground sea */}
          <path d="M158,162 Q166,159 180,159 Q188,159 192,162 Q186,167 168,167 Q160,167 158,162 Z" fill="#FAF3E6" opacity="0.95" />
        </g>
      )}

      {scene === "tropical" && (
        <g>
          {/* lagoon pale shoal */}
          <ellipse cx="160" cy="156" rx="120" ry="14" fill="#FFE0E8" opacity="0.4" />
          <ellipse cx="160" cy="160" rx="90"  ry="9"  fill="#FFE0E8" opacity="0.5" />
          {/* small sand island */}
          <ellipse cx="160" cy="148" rx="42" ry="6" fill="#FAF3E6" />
          <ellipse cx="160" cy="146" rx="36" ry="4" fill="#FFEED4" />
          {/* over-water bungalow */}
          <g>
            <rect x="142" y="132" width="36" height="12" fill="#F4ECDC" />
            <path d="M142,132 L160,122 L178,132 Z" fill="#7A4A2E" />
            <rect x="148" y="136" width="3" height="4" fill="#FFD89A" />
            <rect x="158" y="136" width="3" height="4" fill="#FFD89A" />
            <rect x="168" y="136" width="3" height="4" fill="#FFD89A" />
            {/* stilts */}
            <line x1="146" y1="144" x2="146" y2="158" stroke="#3A1530" strokeWidth="0.8" />
            <line x1="160" y1="144" x2="160" y2="158" stroke="#3A1530" strokeWidth="0.8" />
            <line x1="174" y1="144" x2="174" y2="158" stroke="#3A1530" strokeWidth="0.8" />
            {/* boardwalk to shore */}
            <rect x="160" y="144" width="60" height="2" fill="#7A4A2E" />
          </g>
          {/* twin palms framing */}
          {[34, 286].map((x, i) => (
            <g key={i} transform={`translate(${x}, 200)`}>
              <path d="M0,0 Q-3,-40 -6,-78" stroke="#2A0E22" strokeWidth="3" fill="none" strokeLinecap="round" />
              <g transform="translate(-6,-78)">
                <path d="M0,0 Q-16,-10 -30,-6 Q-18,-3 -2,3 Z" fill="#3A1530" />
                <path d="M0,0 Q16,-10 30,-6 Q18,-3 2,3 Z" fill="#3A1530" />
                <path d="M0,0 Q-12,-22 -26,-26 Q-14,-14 -2,-2 Z" fill="#5C2244" />
                <path d="M0,0 Q12,-22 26,-26 Q14,-14 2,-2 Z" fill="#5C2244" />
                <path d="M0,0 Q-2,-26 0,-40 Q3,-26 2,-2 Z" fill="#7A2A4E" />
                {/* coconuts */}
                <circle cx="-1" cy="2" r="2" fill="#2A0E22" />
                <circle cx="3"  cy="3" r="2" fill="#2A0E22" />
              </g>
            </g>
          ))}
        </g>
      )}

      {/* foreground sea ripples */}
      <path d="M0,200 Q40,194 80,200 T160,200 T240,200 T320,200 L320,220 L0,220 Z" fill="#fff" fillOpacity="0.18" />
      <path d="M0,210 Q40,205 80,210 T160,210 T240,210 T320,210 L320,220 L0,220 Z" fill="#fff" fillOpacity="0.3" />

      {/* film-grade vignette */}
      <rect x="0" y="0" width="320" height="220" fill={`url(#${ID}-vignette)`} />
    </svg>
  );
}

function FlagBadge({ iso, size = 22 }) {
  // Tiny stylised flag tile, abstract but recognisable colour palette per ISO
  const palettes = {
    ES: ["#AA151B", "#F1BF00", "#AA151B"],
    GB: ["#012169", "#fff", "#C8102E"],
    FR: ["#0055A4", "#fff", "#EF4135"],
    DE: ["#000", "#DD0000", "#FFCE00"],
    IT: ["#008C45", "#fff", "#CD212A"],
    PT: ["#006600", "#006600", "#FF0000"],
    NL: ["#AE1C28", "#fff", "#21468B"],
    US: ["#B22234", "#fff", "#3C3B6E"],
    AE: ["#00732F", "#fff", "#000"],
    JP: ["#fff", "#BC002D", "#fff"],
  };
  const p = palettes[iso] || ["#999", "#bbb", "#777"];
  return (
    <div style={{
      width: size, height: size * 0.7, borderRadius: 3,
      overflow: "hidden", display: "flex", flexDirection: "column",
      border: "1px solid rgba(0,0,0,0.08)",
      flexShrink: 0,
    }}>
      <div style={{ flex: 1, background: p[0] }} />
      <div style={{ flex: 1, background: p[1] }} />
      <div style={{ flex: 1, background: p[2] }} />
    </div>
  );
}

function LocalNumbersDashboard() {
  const [active, setActive] = useStateR(0);
  useEffectR(() => {
    const id = setInterval(() => setActive(a => (a + 1) % MARKETS.length), 2600);
    return () => clearInterval(id);
  }, []);
  const cur = MARKETS[active];

  return (
    <div style={{
      display: "grid", gridTemplateColumns: "1.45fr 1fr",
      gap: 18, alignItems: "stretch",
    }}>
      {/* LEFT, Dashboard panel */}
      <div style={{
        background: "#fff",
        border: `1px solid ${RT_RULE}`,
        borderRadius: 18,
        overflow: "hidden",
        display: "flex", flexDirection: "column",
      }}>
        {/* panel header */}
        <div style={{
          display: "flex", alignItems: "center", gap: 12,
          padding: "16px 20px",
          borderBottom: `1px solid ${RT_RULE}`,
        }}>
          <div style={{
            width: 28, height: 28, borderRadius: 7,
            background: "#1a1a1a",
            display: "flex", alignItems: "center", justifyContent: "center",
          }}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
              <path d="M6.6 10.8a15.6 15.6 0 0 0 6.6 6.6l2.2-2.2a1 1 0 0 1 1-.25 11.4 11.4 0 0 0 3.6.6 1 1 0 0 1 1 1V20a1 1 0 0 1-1 1A17 17 0 0 1 3 4a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1 1 11.4 11.4 0 0 0 .6 3.6 1 1 0 0 1-.25 1z"/>
            </svg>
          </div>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{
              fontFamily: "'Inter', system-ui, sans-serif",
              fontSize: 14, color: RT_INK, fontWeight: 600,
            }}>Phone numbers</div>
            <div style={{
              fontFamily: "'JetBrains Mono', ui-monospace, monospace",
              fontSize: 10, color: RT_DIM, letterSpacing: "0.06em",
            }}>SETTINGS · {MARKETS.length} ACTIVE</div>
          </div>
          <button style={{
            background: RT_FUCHSIA, color: "#fff", border: "none",
            borderRadius: 8, padding: "7px 12px",
            fontFamily: "'Inter', system-ui, sans-serif",
            fontSize: 12, fontWeight: 600, cursor: "pointer",
            display: "flex", alignItems: "center", gap: 6,
          }}>
            <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 5v14M5 12h14"/></svg>
            Buy a number
          </button>
        </div>

        {/* table head */}
        <div style={{
          display: "grid",
          gridTemplateColumns: "minmax(160px, 1.5fr) 1.2fr 0.9fr 0.8fr 78px",
          padding: "10px 20px",
          borderBottom: `1px solid ${RT_RULE}`,
          background: RT_PAPER,
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 9, color: RT_FAINT,
          letterSpacing: "0.14em", textTransform: "uppercase", fontWeight: 600,
        }}>
          <span>Number</span>
          <span>IVR language</span>
          <span>Voice</span>
          <span>Calls today</span>
          <span style={{ textAlign: "right" }}>Status</span>
        </div>

        {/* rows */}
        <div style={{ flex: 1 }}>
          {MARKETS.map((m, i) => {
            const isActive = i === active;
            return (
              <div key={i}
                onMouseEnter={() => setActive(i)}
                style={{
                  display: "grid",
                  gridTemplateColumns: "minmax(160px, 1.5fr) 1.2fr 0.9fr 0.8fr 78px",
                  alignItems: "center", gap: 0,
                  padding: "11px 20px",
                  borderBottom: i === MARKETS.length - 1 ? "none" : `1px solid ${RT_RULE}`,
                  background: isActive ? `${RT_FUCHSIA}08` : "#fff",
                  borderLeft: `3px solid ${isActive ? RT_FUCHSIA : "transparent"}`,
                  paddingLeft: isActive ? 17 : 20,
                  transition: "background 0.2s ease, border 0.2s ease",
                  cursor: "pointer",
                }}>
                <div style={{ display: "flex", alignItems: "center", gap: 10, minWidth: 0 }}>
                  <FlagBadge iso={m.iso} />
                  <div style={{ minWidth: 0 }}>
                    <div style={{
                      fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                      fontSize: 12, color: isActive ? RT_FUCHSIA : RT_INK,
                      fontWeight: 600, letterSpacing: "0.01em",
                      whiteSpace: "nowrap",
                    }}>{m.number}</div>
                    <div style={{
                      fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                      fontSize: 11, color: RT_DIM, fontStyle: "italic",
                    }}>{m.country}</div>
                  </div>
                </div>
                <span style={{
                  fontSize: 12.5, color: RT_INK,
                }}>{m.lang}</span>
                <span style={{
                  fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                  fontSize: 13, color: RT_INK, fontStyle: "italic",
                }}>{m.voice}</span>
                <span style={{
                  fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                  fontSize: 12, color: RT_INK, fontWeight: 500,
                }}>{m.calls}</span>
                <span style={{ textAlign: "right" }}>
                  <span style={{
                    display: "inline-flex", alignItems: "center", gap: 5,
                    fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                    fontSize: 9, fontWeight: 600,
                    letterSpacing: "0.1em", textTransform: "uppercase",
                    color: m.status === "live" ? "#3FA88E" : "#D38247",
                    background: m.status === "live" ? "#3FA88E12" : "#D3824712",
                    padding: "3px 7px", borderRadius: 999,
                  }}>
                    <span style={{
                      width: 5, height: 5, borderRadius: "50%",
                      background: m.status === "live" ? "#3FA88E" : "#D38247",
                    }} />
                    {m.status === "live" ? "Live" : "Setup"}
                  </span>
                </span>
              </div>
            );
          })}
        </div>

        {/* footer */}
        <div style={{
          padding: "10px 20px",
          borderTop: `1px solid ${RT_RULE}`,
          background: RT_PAPER,
          display: "flex", justifyContent: "space-between", alignItems: "center",
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 10, color: RT_DIM, letterSpacing: "0.04em",
        }}>
          <span>Coverage in {MARKETS.length}+ countries · numbers provisioned in minutes</span>
          <span style={{ color: RT_FUCHSIA, fontWeight: 600 }}>Manage IVR &rarr;</span>
        </div>
      </div>

      {/* RIGHT, Browser preview */}
      <div style={{
        background: "#fff",
        border: `1px solid ${RT_RULE}`,
        borderRadius: 18, padding: 16,
        display: "flex", flexDirection: "column", gap: 12,
      }}>
        <div style={{
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 10, color: RT_FUCHSIA, letterSpacing: "0.18em",
          textTransform: "uppercase", fontWeight: 600,
          display: "flex", alignItems: "center", gap: 8,
        }}>
          <span>What the visitor sees</span>
          <span style={{ flex: 1, height: 1, background: RT_RULE }} />
          <span style={{ color: RT_FAINT, letterSpacing: "0.1em" }}>LIVE</span>
        </div>

        {/* fake browser */}
        <div style={{
          flex: 1,
          background: RT_PAPER,
          borderRadius: 12,
          border: `1px solid ${RT_RULE}`,
          overflow: "hidden",
          display: "flex", flexDirection: "column",
        }}>
          {/* chrome */}
          <div style={{
            padding: "8px 12px",
            borderBottom: `1px solid ${RT_RULE}`,
            background: "#fff",
            display: "flex", alignItems: "center", gap: 8,
          }}>
            <span style={{ display: "flex", gap: 4 }}>
              {["#FF5F57", "#FEBC2E", "#28C840"].map((c, i) => (
                <span key={i} style={{ width: 8, height: 8, borderRadius: "50%", background: c }} />
              ))}
            </span>
            <div style={{
              flex: 1, height: 20, borderRadius: 6,
              background: RT_PAPER, border: `1px solid ${RT_RULE}`,
              display: "flex", alignItems: "center", padding: "0 8px", gap: 6,
              fontFamily: "'JetBrains Mono', ui-monospace, monospace",
              fontSize: 9.5, color: RT_DIM,
            }}>
              <svg width="9" height="9" viewBox="0 0 24 24" fill="none" stroke={RT_DIM} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                <rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/>
              </svg>
              <span>olea-hotels.com</span>
            </div>
          </div>

          {/* hotel website mock */}
          <div style={{
            flex: 1, position: "relative",
            background: `linear-gradient(180deg, #ffffff 0%, ${RT_PAPER} 100%)`,
            padding: "14px 14px",
            display: "flex", flexDirection: "column", gap: 12,
          }}>
            {/* nav with phone link */}
            <div style={{
              display: "flex", alignItems: "center", justifyContent: "space-between",
              padding: "8px 12px",
              background: "#fff",
              border: `1px solid ${RT_RULE}`,
              borderRadius: 8,
            }}>
              <span style={{
                fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                fontSize: 16, fontWeight: 400, fontStyle: "italic",
                color: RT_INK, letterSpacing: "-0.02em",
              }}>olea</span>
              <div style={{
                display: "flex", alignItems: "center", gap: 6,
                padding: "5px 10px",
                background: `${RT_FUCHSIA}10`,
                border: `1px solid ${RT_FUCHSIA}40`,
                borderRadius: 999,
                animation: "gm-fadein 0.45s ease",
              }} key={cur.iso}>
                <svg width="11" height="11" viewBox="0 0 24 24" fill={RT_FUCHSIA}>
                  <path d="M6.6 10.8a15.6 15.6 0 0 0 6.6 6.6l2.2-2.2a1 1 0 0 1 1-.25 11.4 11.4 0 0 0 3.6.6 1 1 0 0 1 1 1V20a1 1 0 0 1-1 1A17 17 0 0 1 3 4a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1 1 11.4 11.4 0 0 0 .6 3.6 1 1 0 0 1-.25 1z"/>
                </svg>
                <span style={{
                  fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                  fontSize: 11, color: RT_FUCHSIA, fontWeight: 600,
                  whiteSpace: "nowrap",
                }}>{cur.number}</span>
              </div>
            </div>

            {/* hero, stylised seaside illustration */}
            <div style={{
              flex: 1, position: "relative",
              borderRadius: 8,
              overflow: "hidden",
              display: "flex", flexDirection: "column",
            }}>
              {/* sky/sea SVG illustration */}
              <HeroScene scene={cur.scene} />

              {/* darken overlay bottom for text legibility */}
              <div style={{
                position: "absolute", inset: 0,
                background: "linear-gradient(180deg, transparent 40%, rgba(0,0,0,0.4) 100%)",
              }} />

              {/* geo pill top-left */}
              <div style={{
                position: "absolute", top: 8, left: 10,
                display: "flex", alignItems: "center", gap: 6,
                background: "rgba(255,255,255,0.92)",
                backdropFilter: "blur(6px)",
                padding: "4px 8px", borderRadius: 999,
                animation: "gm-fadein 0.45s ease",
                boxShadow: "0 4px 10px -4px rgba(0,0,0,0.25)",
              }} key={"geo-"+cur.iso}>
                <FlagBadge iso={cur.iso} size={14} />
                <span style={{
                  fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                  fontSize: 9, color: RT_INK, fontWeight: 600,
                  letterSpacing: "0.08em",
                }}>VISITING FROM {cur.country.toUpperCase()}</span>
              </div>

              {/* rating chip top-right */}
              <div style={{
                position: "absolute", top: 8, right: 10,
                display: "flex", alignItems: "center", gap: 5,
                background: "rgba(255,255,255,0.92)",
                padding: "3px 7px", borderRadius: 999,
                fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                fontSize: 9, color: RT_INK, fontWeight: 600,
                letterSpacing: "0.08em",
              }}>
                <svg width="9" height="9" viewBox="0 0 24 24" fill="#E0A23A">
                  <path d="M12 2 14.5 8.5 21 9 16 13.5 17.5 20 12 16.5 6.5 20 8 13.5 3 9 9.5 8.5z"/>
                </svg>
                4.9 · BEACHFRONT
              </div>

              {/* content bottom */}
              <div style={{
                position: "absolute", left: 12, right: 12, bottom: 12,
                display: "flex", alignItems: "flex-end", justifyContent: "space-between",
                gap: 10,
              }}>
                <div style={{ minWidth: 0 }}>
                  <div style={{
                    fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                    fontSize: 9, color: "#fff", opacity: 0.85,
                    letterSpacing: "0.16em", textTransform: "uppercase",
                    marginBottom: 3,
                  }}>{cur.dest} · {cur.region}</div>
                  <div style={{
                    fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                    fontSize: 19, color: "#fff", fontWeight: 400,
                    lineHeight: 1.05, letterSpacing: "-0.015em",
                    textShadow: "0 2px 10px rgba(0,0,0,0.5)",
                  }}>{cur.headline}</div>
                </div>
                <div style={{
                  flexShrink: 0,
                  background: "rgba(255,255,255,0.95)",
                  borderRadius: 8,
                  padding: "5px 10px",
                  textAlign: "right",
                  boxShadow: "0 6px 14px -6px rgba(0,0,0,0.35)",
                }}>
                  <div style={{
                    fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                    fontSize: 8, color: RT_DIM,
                    letterSpacing: "0.12em", textTransform: "uppercase",
                  }}>From</div>
                  <div style={{
                    fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                    fontSize: 14, color: RT_FUCHSIA, fontWeight: 400,
                    fontStyle: "italic", lineHeight: 1,
                  }}>{cur.price}<span style={{ fontSize: 9, color: RT_DIM, fontStyle: "normal", fontWeight: 400 }}> {cur.per}</span></div>
                </div>
              </div>
            </div>

            {/* book strip */}
            <div style={{
              padding: "8px 10px",
              background: "#fff",
              border: `1px solid ${RT_RULE}`,
              borderRadius: 8,
              display: "flex", alignItems: "center", gap: 8,
              fontSize: 10, color: RT_DIM,
            }}>
              <span>Hotels</span>
              <span style={{ flex: 1, height: 1, background: RT_RULE }} />
              <span>Dates</span>
              <span style={{ flex: 1, height: 1, background: RT_RULE }} />
              <span>Guests</span>
              <button style={{
                background: RT_FUCHSIA, color: "#fff", border: "none",
                borderRadius: 6, padding: "4px 10px",
                fontFamily: "'Inter', system-ui, sans-serif",
                fontSize: 10, fontWeight: 600, cursor: "pointer",
              }}>Book</button>
            </div>
          </div>
        </div>

        <div style={{
          fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
          fontSize: 12, color: RT_DIM, fontStyle: "italic",
          textAlign: "center",
          lineHeight: 1.45,
        }}>
          Geo-detected. The number on your site, the IVR voice, and the language all
          adapt to where the visitor is calling from.
        </div>
      </div>
    </div>
  );
}

// ────────────────────────────────────────────────────────────
//  Themes · 12 escalation routes
// ────────────────────────────────────────────────────────────
function ThemesGrid() {
  const [active, setActive] = useStateR("groups");
  const cur = THEMES.find(t => t.id === active);

  return (
    <ScaleFrame nativeWidth={1216} style={{ maxWidth: 1216, margin: "0 auto" }}>
    <div style={{
      display: "grid", gridTemplateColumns: "1.05fr 0.95fr",
      gap: 18, alignItems: "stretch",
    }}>
      {/* LEFT, chip grid */}
      <div style={{
        background: "#fff",
        border: `1px solid ${RT_RULE}`,
        borderRadius: 18, padding: 18,
      }}>
        <div style={{
          display: "flex", alignItems: "center", gap: 10, marginBottom: 14,
        }}>
          <span style={{
            fontFamily: "'JetBrains Mono', ui-monospace, monospace",
            fontSize: 10, color: RT_FUCHSIA, letterSpacing: "0.18em",
            textTransform: "uppercase", fontWeight: 600,
          }}>12 escalation themes</span>
          <span style={{ flex: 1, height: 1, background: RT_RULE }} />
          <span style={{
            fontFamily: "'JetBrains Mono', ui-monospace, monospace",
            fontSize: 9.5, color: RT_FAINT, letterSpacing: "0.1em",
          }}>Click to inspect</span>
        </div>
        <div style={{
          display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 8,
        }}>
          {THEMES.map(t => {
            const isActive = t.id === active;
            return (
              <button key={t.id}
                onClick={() => setActive(t.id)}
                onMouseEnter={() => setActive(t.id)}
                style={{
                  background: isActive ? RT_FUCHSIA : "#fff",
                  border: `1px solid ${isActive ? RT_FUCHSIA : RT_RULE}`,
                  color: isActive ? "#fff" : RT_INK,
                  borderRadius: 10, cursor: "pointer",
                  padding: "10px 12px", textAlign: "left",
                  transition: "background 0.2s ease, border 0.2s ease, color 0.2s ease",
                  boxShadow: isActive ? `0 8px 18px -10px ${RT_FUCHSIA}AA` : "none",
                }}>
                <div style={{
                  fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                  fontSize: 13, fontWeight: 400,
                  fontStyle: isActive ? "italic" : "normal",
                  letterSpacing: "-0.005em",
                  marginBottom: 2,
                  whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis",
                }}>{t.name}</div>
                <div style={{
                  fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                  fontSize: 9, opacity: isActive ? 0.85 : 0.55,
                  letterSpacing: "0.08em", textTransform: "uppercase",
                  whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis",
                }}>{t.sub}</div>
              </button>
            );
          })}
        </div>
        <div style={{
          marginTop: 14,
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 10, color: RT_DIM,
          letterSpacing: "0.04em",
          display: "flex", alignItems: "center", gap: 6,
        }}>
          <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke={RT_FUCHSIA} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 5v14M5 12h14"/></svg>
          Add a custom theme, your hotel group decides the rules.
        </div>
      </div>

      {/* RIGHT, routing inspector */}
      <RoutingInspector theme={cur} />
    </div>
    </ScaleFrame>
  );
}

function RoutingInspector({ theme }) {
  const [time, setTime] = useStateR(0);
  useEffectR(() => {
    let raf, last = performance.now();
    const tick = (now) => { setTime(t => t + (now - last) / 1000); last = now; raf = requestAnimationFrame(tick); };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, []);

  const isPerHotel = theme.target.startsWith("Routes per booking") || theme.target.startsWith("Direct ·");
  return (
    <div style={{
      background: "#fff", border: `1px solid ${RT_RULE}`,
      borderRadius: 18, padding: 18,
      display: "flex", flexDirection: "column",
    }}>
      <div style={{
        display: "flex", alignItems: "center", gap: 10, marginBottom: 14,
      }}>
        <span style={{
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 10, color: RT_FUCHSIA, letterSpacing: "0.18em",
          textTransform: "uppercase", fontWeight: 600,
        }}>Routing rule</span>
        <span style={{ flex: 1, height: 1, background: RT_RULE }} />
        <span style={{
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 9, color: RT_FAINT, letterSpacing: "0.1em",
          padding: "2px 7px", border: `1px solid ${RT_RULE}`, borderRadius: 999,
        }}>EDITABLE</span>
      </div>

      <div style={{
        fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
        fontSize: 22, fontWeight: 400, color: RT_INK,
        letterSpacing: "-0.015em", lineHeight: 1.15,
        marginBottom: 4,
      }}>
        {theme.name}{" "}
        <span style={{ color: RT_FUCHSIA, fontStyle: "italic" }}>{theme.sub}</span>
      </div>
      <div style={{
        fontSize: 12.5, color: RT_DIM, marginBottom: 18,
      }}>When the caller's intent matches, the voice agent escalates automatically.</div>

      {/* Flow visual */}
      <div style={{
        position: "relative",
        background: RT_PAPER, border: `1px dashed ${RT_FUCHSIA}40`,
        borderRadius: 12, padding: "16px 14px",
        display: "grid", gridTemplateColumns: "1fr auto 1fr auto 1fr",
        alignItems: "center", gap: 10,
        marginBottom: 14,
      }}>
        <FlowNode title="Caller" sub={`Intent · ${theme.name}`} icon="phone" />
        <FlowArrow time={time} delay={0} />
        <FlowNode title="the voice agent" sub="classifies + escalates" icon="agent" accent />
        <FlowArrow time={time} delay={0.5} />
        <FlowNode title={isPerHotel ? "Hotel of stay" : theme.route} sub={theme.target} icon="dest" />
      </div>

      {/* Behaviour list */}
      <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
        <BehaviourRow label="Match" value={`Caller intent · ${theme.name.toLowerCase()}`} />
        <BehaviourRow label="Try" value={theme.target} />
        <BehaviourRow label="Fallback" value="If no answer in 25s · recover & email + ticket" />
        <BehaviourRow label="Notify" value="Reservations · property GM · CRM" />
      </div>
    </div>
  );
}

function FlowNode({ title, sub, icon, accent }) {
  const Icon = () => {
    if (icon === "phone") return (
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={accent ? "#fff" : RT_FUCHSIA} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
        <path d="M6.6 10.8a15.6 15.6 0 0 0 6.6 6.6l2.2-2.2a1 1 0 0 1 1-.25 11.4 11.4 0 0 0 3.6.6 1 1 0 0 1 1 1V20a1 1 0 0 1-1 1A17 17 0 0 1 3 4a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1 1 11.4 11.4 0 0 0 .6 3.6 1 1 0 0 1-.25 1z"/>
      </svg>
    );
    if (icon === "agent") return (
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
        <circle cx="12" cy="9" r="3.5"/>
        <path d="M5 20a7 7 0 0 1 14 0"/>
      </svg>
    );
    return (
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={RT_FUCHSIA} strokeWidth="1.8" strokeLinejoin="round">
        <polygon points="12,3 21,12 12,21 3,12"/>
      </svg>
    );
  };
  return (
    <div style={{
      display: "flex", flexDirection: "column", alignItems: "center", gap: 6,
      minWidth: 0,
    }}>
      <div style={{
        width: 36, height: 36, borderRadius: "50%",
        background: accent ? RT_FUCHSIA : "#fff",
        border: `1.5px solid ${RT_FUCHSIA}`,
        display: "flex", alignItems: "center", justifyContent: "center",
        boxShadow: accent ? `0 8px 16px -6px ${RT_FUCHSIA}88` : "none",
      }}>
        <Icon />
      </div>
      <div style={{
        fontFamily: "'JetBrains Mono', ui-monospace, monospace",
        fontSize: 9.5, color: RT_FUCHSIA, fontWeight: 600,
        letterSpacing: "0.14em", textTransform: "uppercase",
      }}>{title}</div>
      <div style={{
        fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
        fontSize: 11, color: RT_INK, fontStyle: "italic",
        textAlign: "center", lineHeight: 1.2,
        maxWidth: 130,
        whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis",
      }}>{sub}</div>
    </div>
  );
}

function FlowArrow({ time, delay }) {
  const phase = ((time * 0.7 + delay) % 2) / 2;
  return (
    <div style={{
      position: "relative",
      width: 60, height: 1.5,
      background: `linear-gradient(90deg, ${RT_FUCHSIA}40, ${RT_FUCHSIA})`,
    }}>
      {/* travelling dot */}
      <span style={{
        position: "absolute", top: -2.5, left: `${phase * 100}%`,
        width: 6, height: 6, borderRadius: "50%",
        background: RT_FUCHSIA, transform: "translateX(-50%)",
        boxShadow: `0 0 0 3px ${RT_FUCHSIA}30`,
      }} />
    </div>
  );
}

function BehaviourRow({ label, value }) {
  return (
    <div style={{
      display: "grid", gridTemplateColumns: "78px 1fr",
      alignItems: "baseline", gap: 12,
      paddingBottom: 8, borderBottom: `1px solid ${RT_RULE}`,
    }}>
      <span style={{
        fontFamily: "'JetBrains Mono', ui-monospace, monospace",
        fontSize: 9, color: RT_FAINT, letterSpacing: "0.14em",
        textTransform: "uppercase", fontWeight: 600,
      }}>{label}</span>
      <span style={{
        fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
        fontSize: 13.5, color: RT_INK, letterSpacing: "-0.005em",
      }}>{value}</span>
    </div>
  );
}

// ────────────────────────────────────────────────────────────
//  Hotel fan-out · animated routing per property
// ────────────────────────────────────────────────────────────
function HotelFanOut() {
  const [time, setTime] = useStateR(0);
  const [activeIdx, setActiveIdx] = useStateR(0);
  useEffectR(() => {
    let raf, last = performance.now();
    const tick = (now) => { setTime(t => t + (now - last) / 1000); last = now; raf = requestAnimationFrame(tick); };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, []);
  useEffectR(() => {
    const id = setInterval(() => setActiveIdx(i => (i + 1) % HOTELS_FAN.length), 2200);
    return () => clearInterval(id);
  }, []);

  const W = 720, H = 440;
  const hubX = 90, hubY = H / 2;
  const positions = HOTELS_FAN.map((_, i) => {
    const yStep = (H - 60) / (HOTELS_FAN.length - 1);
    return { x: W - 230, y: 30 + i * yStep };
  });

  return (
    <div style={{
      background: "#fff", border: `1px solid ${RT_RULE}`,
      borderRadius: 18, padding: 18,
    }}>
      <div style={{
        display: "flex", alignItems: "center", gap: 10, marginBottom: 14,
      }}>
        <span style={{
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 10, color: RT_FUCHSIA, letterSpacing: "0.18em",
          textTransform: "uppercase", fontWeight: 600,
        }}>Hotel-aware routing</span>
        <span style={{ flex: 1, height: 1, background: RT_RULE }} />
        <span style={{
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 9, color: RT_FAINT, letterSpacing: "0.1em",
        }}>6 HOTELS · 1 CALL CENTER · 1 NUMBER</span>
      </div>

      <div style={{ position: "relative", width: "100%", aspectRatio: `${W}/${H}` }}>
        <svg viewBox={`0 0 ${W} ${H}`} style={{ position: "absolute", inset: 0, width: "100%", height: "100%" }}>
          {/* faint grid */}
          <g stroke={RT_RULE} strokeOpacity="0.5" strokeWidth="0.6">
            <line x1="0" y1={hubY} x2={W} y2={hubY} strokeDasharray="3 6" />
          </g>
          {/* connection lines */}
          {positions.map((p, i) => {
            const isActive = i === activeIdx;
            const midX = (hubX + p.x) / 2;
            return (
              <g key={i}>
                <path d={`M ${hubX + 30} ${hubY} C ${midX} ${hubY}, ${midX} ${p.y + 18}, ${p.x} ${p.y + 18}`}
                  fill="none" stroke={RT_FUCHSIA}
                  strokeOpacity={isActive ? 0.9 : 0.18}
                  strokeWidth={isActive ? 1.8 : 1}
                  strokeDasharray={isActive ? "none" : "4 6"}
                />
                {/* travelling dot */}
                {isActive && (() => {
                  const phase = (time * 0.8) % 1;
                  // sample bezier
                  const t = phase;
                  const mt = 1 - t;
                  const x = mt*mt*mt*(hubX+30) + 3*mt*mt*t*midX + 3*mt*t*t*midX + t*t*t*p.x;
                  const y = mt*mt*mt*hubY + 3*mt*mt*t*hubY + 3*mt*t*t*(p.y+18) + t*t*t*(p.y+18);
                  return <circle cx={x} cy={y} r="4" fill={RT_FUCHSIA} />;
                })()}
              </g>
            );
          })}
          {/* HUB */}
          <g>
            {[0, 1, 2].map(k => {
              const breath = (Math.sin(time * 1.4 + k * 1.2) * 0.5 + 0.5);
              return (
                <circle key={k} cx={hubX} cy={hubY} r={28 + k * 12 + breath * 4}
                  fill="none" stroke={RT_FUCHSIA}
                  strokeOpacity={0.18 - k * 0.04}
                  strokeWidth={1} />
              );
            })}
            <circle cx={hubX} cy={hubY} r="22" fill={RT_FUCHSIA} />
            <path
              transform={`translate(${hubX-7}, ${hubY-7})`}
              d="M3.6 7.8a15.6 15.6 0 0 0 6.6 6.6l2.2-2.2a1 1 0 0 1 1-.25 11.4 11.4 0 0 0 3.6.6 1 1 0 0 1 1 1V17a1 1 0 0 1-1 1A17 17 0 0 1 0 1a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1 1 11.4 11.4 0 0 0 .6 3.6 1 1 0 0 1-.25 1z"
              fill="#fff"
            />
          </g>
        </svg>

        {/* Hub label */}
        <div style={{
          position: "absolute",
          left: hubX, top: hubY + 36,
          transform: "translateX(-50%)",
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 9.5, color: RT_FUCHSIA, fontWeight: 600,
          letterSpacing: "0.18em", textTransform: "uppercase",
          whiteSpace: "nowrap",
        }}>+34 91 020 0000</div>
        <div style={{
          position: "absolute",
          left: hubX, top: hubY + 52,
          transform: "translateX(-50%)",
          fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
          fontSize: 12, color: RT_DIM, fontStyle: "italic",
          whiteSpace: "nowrap",
        }}>Group hotline</div>

        {/* Destination cards (call center + hotels) */}
        {HOTELS_FAN.map((h, i) => {
          const p = positions[i];
          const isActive = i === activeIdx;
          return (
            <div key={h.id} style={{
              position: "absolute",
              left: `${(p.x / W) * 100}%`,
              top: `${(p.y / H) * 100}%`,
              width: 220,
              background: "#fff",
              border: `1px solid ${isActive ? h.color : RT_RULE}`,
              borderRadius: 10,
              padding: "8px 10px",
              boxShadow: isActive ? `0 12px 22px -14px ${h.color}AA` : "none",
              transition: "border 0.3s ease, box-shadow 0.3s ease",
              display: "flex", alignItems: "center", gap: 10,
            }}>
              <div style={{
                width: 28, height: 28, borderRadius: 6,
                background: h.color,
                color: "#fff",
                display: "flex", alignItems: "center", justifyContent: "center",
                fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                fontSize: 14, fontStyle: "italic", fontWeight: 400,
                flexShrink: 0,
              }}>
                {h.isHuman ? (
                  <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                    <path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>
                  </svg>
                ) : h.name[0]}
              </div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{
                  fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                  fontSize: 12.5, color: RT_INK, fontWeight: 400,
                  letterSpacing: "-0.005em",
                  whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis",
                }}>{h.name}</div>
                <div style={{
                  fontFamily: h.isHuman ? "'Instrument Serif', 'Source Serif 4', Georgia, serif" : "'JetBrains Mono', ui-monospace, monospace",
                  fontSize: h.isHuman ? 10.5 : 9,
                  color: isActive ? h.color : RT_FAINT,
                  fontStyle: h.isHuman ? "italic" : "normal",
                  letterSpacing: h.isHuman ? "0" : "0.04em",
                  whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis",
                }}>{h.isHuman ? "groups · MICE · cancellations" : h.phone}</div>
              </div>
              {isActive && (
                <div style={{ display: "flex", flexDirection: "column", gap: 1.5 }}>
                  {[0, 1, 2].map(k => (
                    <span key={k} style={{
                      width: 6, height: 1.5, background: h.color, borderRadius: 1,
                      animation: `gm-bar 0.9s ease-in-out ${k * 0.12}s infinite`,
                      transformOrigin: "left",
                    }} />
                  ))}
                </div>
              )}
            </div>
          );
        })}
      </div>

      <div style={{
        marginTop: 14,
        fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
        fontSize: 14, color: RT_DIM, fontStyle: "italic",
        lineHeight: 1.45, textAlign: "center",
      }}>
        One number for the group, the voice agent reads the booking and routes the caller to the right front desk, or escalates to the human call-center team for groups, MICE and cancellations.
      </div>
    </div>
  );
}

// ────────────────────────────────────────────────────────────
//  Recovery flow · missed call → email + ticket
// ────────────────────────────────────────────────────────────
function RecoveryFlow() {
  const [time, setTime] = useStateR(0);
  useEffectR(() => {
    let raf, last = performance.now();
    const tick = (now) => { setTime(t => (t + (now - last) / 1000) % 12); last = now; raf = requestAnimationFrame(tick); };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, []);

  // Phases: 0 ringing 0–3, 1 no answer 3–4.5, 2 recover offer 4.5–7, 3 email sent 7–9, 4 ticket created 9–12
  const stage = time < 3 ? 0 : time < 4.5 ? 1 : time < 7 ? 2 : time < 9 ? 3 : 4;

  const STAGES = [
    { label: "Hotel rings",          sub: "no answer in 25s",     color: RT_FUCHSIA },
    { label: "Recovered by the voice agent",    sub: "agent steps back in",  color: RT_FUCHSIA_DEEP },
    { label: "Caller offered email", sub: "\u201cMay I email you?\u201d", color: "#7B5BC8" },
    { label: "Email sent",           sub: "draft + booking link", color: "#3FA88E" },
    { label: "Ticket opened",        sub: "for hotel team",       color: "#D38247" },
  ];

  return (
    <div style={{
      background: "#fff", border: `1px solid ${RT_RULE}`,
      borderRadius: 18, padding: 18,
    }}>
      <div style={{
        display: "flex", alignItems: "center", gap: 10, marginBottom: 14,
      }}>
        <span style={{
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 10, color: RT_FUCHSIA, letterSpacing: "0.18em",
          textTransform: "uppercase", fontWeight: 600,
        }}>Nothing falls through</span>
        <span style={{ flex: 1, height: 1, background: RT_RULE }} />
        <span style={{
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 9, color: RT_FAINT, letterSpacing: "0.1em",
        }}>RECOVERY FLOW</span>
      </div>

      {/* Track */}
      <div style={{
        position: "relative",
        display: "grid", gridTemplateColumns: "repeat(5, 1fr)",
        gap: 0, alignItems: "flex-start",
        padding: "10px 0 0",
      }}>
        {/* track line */}
        <div style={{
          position: "absolute", left: "10%", right: "10%", top: 28,
          height: 2, background: RT_RULE, borderRadius: 1,
        }} />
        <div style={{
          position: "absolute", left: "10%", top: 28,
          width: `${Math.min(80, (stage / 4) * 80)}%`,
          height: 2, background: RT_FUCHSIA, borderRadius: 1,
          transition: "width 0.6s ease",
        }} />

        {STAGES.map((s, i) => {
          const isActive = stage === i;
          const isPast = stage > i;
          const c = isActive || isPast ? s.color : RT_FAINT;
          return (
            <div key={i} style={{
              display: "flex", flexDirection: "column", alignItems: "center",
              gap: 8, position: "relative",
            }}>
              <div style={{
                width: 22, height: 22, borderRadius: "50%",
                background: isActive ? c : isPast ? c : "#fff",
                border: `2px solid ${c}`,
                display: "flex", alignItems: "center", justifyContent: "center",
                boxShadow: isActive ? `0 0 0 6px ${c}22` : "none",
                transition: "all 0.3s ease",
                zIndex: 1,
              }}>
                {isPast && (
                  <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
                    <polyline points="4,12 10,18 20,6" />
                  </svg>
                )}
                {isActive && (
                  <span style={{ width: 8, height: 8, borderRadius: "50%", background: "#fff" }} />
                )}
              </div>
              <div style={{ textAlign: "center", maxWidth: 140 }}>
                <div style={{
                  fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                  fontSize: 13.5, color: isActive ? RT_INK : RT_DIM,
                  fontWeight: 400, fontStyle: isActive ? "italic" : "normal",
                  letterSpacing: "-0.005em",
                  transition: "color 0.3s ease",
                }}>{s.label}</div>
                <div style={{
                  fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                  fontSize: 9, color: isActive ? c : RT_FAINT,
                  letterSpacing: "0.08em", textTransform: "uppercase",
                  marginTop: 2,
                }}>{s.sub}</div>
              </div>
            </div>
          );
        })}
      </div>

      {/* live caption */}
      <div style={{
        marginTop: 18,
        background: RT_PAPER, border: `1px dashed ${STAGES[stage].color}55`,
        borderRadius: 10, padding: "12px 14px",
        display: "flex", alignItems: "center", gap: 10,
        animation: "gm-fadein 0.4s ease",
      }} key={stage}>
        <span style={{
          width: 8, height: 8, borderRadius: "50%",
          background: STAGES[stage].color,
          animation: "gm-dot-pulse 1.2s ease-in-out infinite",
        }} />
        <span style={{
          fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
          fontSize: 14.5, color: RT_INK, fontStyle: "italic",
        }}>
          {stage === 0 && "Hotel front desk is ringing, caller is waiting."}
          {stage === 1 && "Front desk didn't pick up. the voice agent steps back into the call."}
          {stage === 2 && "\u201cI'll have your booking details emailed and our team will follow up.\u201d"}
          {stage === 3 && "Email delivered with the booking link, vegan menu and spa availability."}
          {stage === 4 && "Ticket #4823 opened for Olea Cliffside, assigned to GM, due in 2h."}
        </span>
      </div>
    </div>
  );
}

// ────────────────────────────────────────────────────────────
//  Web call · widgets gallery
// ────────────────────────────────────────────────────────────
function WebWidgets() {
  return (
    <div style={{
      display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 18,
    }}>
      <WidgetCase
        title="Bubble button"
        subtitle="Lives in the corner"
        body={<BubbleMock />}
      />
      <WidgetCase
        title="Voice-first widget"
        subtitle="Standalone, voice only"
        body={<VoiceOnlyMock />}
      />
      <WidgetCase
        title="Voice + chat combined"
        subtitle="Speak or type"
        body={<CombinedMock />}
      />
    </div>
  );
}

function WidgetCase({ title, subtitle, body }) {
  return (
    <div style={{
      background: "#fff", border: `1px solid ${RT_RULE}`,
      borderRadius: 18, padding: 16,
      display: "flex", flexDirection: "column", gap: 10,
    }}>
      <div>
        <div style={{
          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
          fontSize: 10, color: RT_FUCHSIA, letterSpacing: "0.18em",
          textTransform: "uppercase", fontWeight: 600, marginBottom: 4,
        }}>{title}</div>
        <div style={{
          fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
          fontSize: 13, color: RT_DIM, fontStyle: "italic",
        }}>{subtitle}</div>
      </div>
      <div style={{
        position: "relative",
        background: `linear-gradient(135deg, ${RT_FUCHSIA}10, ${RT_FUCHSIA_DEEP}06)`,
        border: `1px solid ${RT_RULE}`,
        borderRadius: 12,
        height: 360,
        overflow: "hidden",
      }}>
        {/* fake browser bg */}
        <div style={{
          position: "absolute", inset: 0,
          background: "url('data:image/svg+xml;utf8,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 200 100%22><rect width=%22200%22 height=%22100%22 fill=%22%23f6f4ef%22/><circle cx=%2240%22 cy=%2240%22 r=%2228%22 fill=%22%23ce518820%22/><rect x=%2280%22 y=%2270%22 width=%22100%22 height=%2210%22 fill=%22%23ce518815%22 rx=%225%22/></svg>') center/cover",
          opacity: 0.6,
        }} />
        {body}
      </div>
    </div>
  );
}

// ────────────────────────────────────────────────────────────
//  Bubble button, auto-plays scenario: idle → click → expand → live transcript
// ────────────────────────────────────────────────────────────
const BUBBLE_TRANSCRIPT = [
  { who: "guest", t: 3.2, text: "Hi, I left my passport in the room, checked out this morning." },
  { who: "aria",  t: 5.4, text: "I see your stay at Olea Cliffside ended at 11:00. Connecting you to the front desk now." },
  { who: "guest", t: 8.0, text: "Thanks, can they ship it to Madrid?" },
  { who: "aria",  t: 9.6, text: "Yes, courier on us. You'll receive a tracking link by email." },
];
function BubbleMock() {
  const [time, setTime] = useStateR(0);
  useEffectR(() => {
    let raf, last = performance.now();
    const tick = (now) => {
      setTime(t => (t + (now - last) / 1000) % 14);
      last = now; raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, []);

  // 0–2.0 idle bubble · 2.0–2.6 click pulse · 2.6+ expanded panel
  const stage = time < 2.0 ? "idle" : time < 2.6 ? "click" : "open";
  const openT = Math.max(0, time - 2.6);
  const visibleLines = BUBBLE_TRANSCRIPT.filter(l => time > l.t);

  return (
    <>
      {/* the bubble */}
      <div style={{
        position: "absolute", right: 16, bottom: 16,
        display: "flex", alignItems: "center", gap: 10,
        background: "#fff",
        border: `1px solid ${RT_FUCHSIA}30`,
        borderRadius: 999,
        padding: "8px 16px 8px 8px",
        boxShadow: `0 14px 30px -14px ${RT_FUCHSIA}AA`,
        opacity: stage === "open" ? 0 : 1,
        transform: stage === "click" ? `scale(${1 + (time - 2.0) * 0.4})` : "scale(1)",
        transition: "opacity 0.25s ease",
      }}>
        <div style={{
          position: "relative",
          width: 36, height: 36, borderRadius: "50%",
          background: RT_FUCHSIA,
          display: "flex", alignItems: "center", justifyContent: "center",
        }}>
          {[0, 1].map(k => {
            const phase = ((time * 0.7 + k * 0.5) % 1);
            return (
              <span key={k} style={{
                position: "absolute", inset: 0, borderRadius: "50%",
                border: `1.5px solid ${RT_FUCHSIA}`,
                transform: `scale(${1 + phase * 0.7})`,
                opacity: (1 - phase) * 0.6,
              }} />
            );
          })}
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
            <path d="M6.6 10.8a15.6 15.6 0 0 0 6.6 6.6l2.2-2.2a1 1 0 0 1 1-.25 11.4 11.4 0 0 0 3.6.6 1 1 0 0 1 1 1V20a1 1 0 0 1-1 1A17 17 0 0 1 3 4a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1 1 11.4 11.4 0 0 0 .6 3.6 1 1 0 0 1-.25 1z"/>
          </svg>
        </div>
        <div>
          <div style={{
            fontFamily: "'Inter', system-ui, sans-serif",
            fontSize: 12, color: RT_INK, fontWeight: 600,
          }}>Call us</div>
          <div style={{ fontSize: 9.5, color: RT_DIM }}>Speak instantly with our team</div>
        </div>
        {stage === "click" && (
          <span style={{
            position: "absolute", inset: -4, borderRadius: 999,
            border: `2px solid ${RT_FUCHSIA}`,
            opacity: 1 - (time - 2.0) / 0.6,
          }} />
        )}
      </div>

      {/* expanded panel */}
      <div style={{
        position: "absolute", right: 12, bottom: 12,
        width: 250,
        background: "#fff",
        border: `1px solid ${RT_FUCHSIA}30`,
        borderRadius: 14,
        boxShadow: `0 18px 40px -18px ${RT_FUCHSIA}AA`,
        opacity: stage === "open" ? 1 : 0,
        transform: stage === "open" ? "translateY(0)" : "translateY(8px)",
        transition: "opacity 0.3s ease, transform 0.3s ease",
        overflow: "hidden",
      }}>
        <div style={{
          display: "flex", alignItems: "center", gap: 8,
          padding: "10px 12px", borderBottom: `1px solid ${RT_RULE}`,
        }}>
          <div style={{
            position: "relative",
            width: 24, height: 24, borderRadius: "50%",
            background: RT_FUCHSIA,
            display: "flex", alignItems: "center", justifyContent: "center",
          }}>
            {[0, 1].map(k => (
              <span key={k} style={{
                position: "absolute", inset: 0, borderRadius: "50%",
                border: `1.2px solid ${RT_FUCHSIA}`,
                transform: `scale(${1 + (((time * 1.1 + k * 0.5) % 1)) * 0.6})`,
                opacity: (1 - ((time * 1.1 + k * 0.5) % 1)) * 0.55,
              }} />
            ))}
            <svg width="11" height="11" viewBox="0 0 24 24" fill="#fff">
              <path d="M6.6 10.8a15.6 15.6 0 0 0 6.6 6.6l2.2-2.2a1 1 0 0 1 1-.25 11.4 11.4 0 0 0 3.6.6 1 1 0 0 1 1 1V20a1 1 0 0 1-1 1A17 17 0 0 1 3 4a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1 1 11.4 11.4 0 0 0 .6 3.6 1 1 0 0 1-.25 1z"/>
            </svg>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 11, fontWeight: 600, color: RT_INK }}>the voice agent · Olea Hotels</div>
            <div style={{
              fontFamily: "'JetBrains Mono', ui-monospace, monospace",
              fontSize: 8.5, color: RT_FUCHSIA, letterSpacing: "0.14em",
            }}>● LIVE · {String(Math.floor(openT)).padStart(2,"0")}:{String(Math.floor((openT*1)%60)).padStart(2,"0")}</div>
          </div>
        </div>
        <div style={{
          padding: "10px 12px", display: "flex", flexDirection: "column", gap: 6,
          minHeight: 132, maxHeight: 200, overflow: "hidden",
        }}>
          {visibleLines.map((l, i) => (
            <div key={i} style={{
              alignSelf: l.who === "guest" ? "flex-start" : "flex-end",
              maxWidth: "85%",
              background: l.who === "guest" ? "#fff" : `${RT_FUCHSIA}12`,
              border: l.who === "guest" ? `1px solid ${RT_RULE}` : `1px solid ${RT_FUCHSIA}30`,
              borderRadius: 8, padding: "5px 8px",
              fontSize: 10.5, color: RT_INK, lineHeight: 1.4,
              fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
              animation: i === visibleLines.length - 1 ? "gm-fadein 0.4s ease" : "none",
            }}>
              <div style={{
                fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                fontSize: 7.5, color: l.who === "guest" ? RT_FAINT : RT_FUCHSIA,
                letterSpacing: "0.1em", marginBottom: 1, fontWeight: 600,
              }}>{l.who === "guest" ? "GUEST" : "AGENT"}</div>
              {l.text}
            </div>
          ))}
        </div>
        <div style={{
          padding: "8px 12px", borderTop: `1px solid ${RT_RULE}`,
          display: "flex", alignItems: "center", gap: 6,
          background: "#FAF8F4",
        }}>
          {/* live waveform */}
          <div style={{ flex: 1, display: "flex", alignItems: "center", gap: 2, height: 14 }}>
            {Array.from({ length: 22 }).map((_, k) => {
              const h = 3 + Math.abs(Math.sin(time * 4 + k * 0.6)) * 9;
              return <span key={k} style={{
                width: 2, height: h, background: RT_FUCHSIA, borderRadius: 1, opacity: 0.7,
              }} />;
            })}
          </div>
          <button style={{
            width: 22, height: 22, borderRadius: "50%",
            background: "#E04E4E", border: "none",
            display: "flex", alignItems: "center", justifyContent: "center",
          }}>
            <svg width="9" height="9" viewBox="0 0 24 24" fill="#fff">
              <path d="M19.7 14.6 17 11.7a1 1 0 0 0-1.5 0c-1 1-2.4 1-3.4 0-1-1-1-2.4 0-3.4a1 1 0 0 0 0-1.5L9.3 4a1 1 0 0 0-1.5 0L4.5 7.3c-2 2-2 5.3 0 7.4l4.8 4.8c2 2 5.3 2 7.4 0l3.3-3.3a1 1 0 0 0-.3-1.6z"/>
            </svg>
          </button>
        </div>
      </div>
    </>
  );
}

// ────────────────────────────────────────────────────────────
//  Voice-first widget, full call timeline scenario
// ────────────────────────────────────────────────────────────
const VOICE_PHASES = [
  { from: 0,   to: 1.2, key: "ringing",   label: "Ringing",       sub: "Connecting you to the voice agent",          who: null },
  { from: 1.2, to: 4.8, key: "aria1",     label: "the voice agent speaking", sub: "Welcome to Olea Hotels",          who: "aria",
    line: "Welcome to Olea Hotels, I can see you're on our Mallorca page. How can I help?" },
  { from: 4.8, to: 8.4, key: "guest1",    label: "Listening",     sub: "Caller speaking",                 who: "guest",
    line: "Looking for a sea-view suite for two nights, July 14–16." },
  { from: 8.4, to: 12.6, key: "aria2",    label: "the voice agent speaking", sub: "Checking availability",           who: "aria",
    line: "I have a Deluxe Sea View at €419/night, breakfast included. Shall I hold it for you?" },
  { from: 12.6, to: 15.2, key: "guest2",  label: "Listening",     sub: "Caller speaking",                 who: "guest",
    line: "Yes please, and email me the link." },
  { from: 15.2, to: 18.0, key: "wrap",    label: "Confirming",    sub: "Sending email · booking on hold", who: "aria",
    line: "Held on booking #A4127. You'll receive the link in 30 seconds." },
];
function VoiceOnlyMock() {
  const [time, setTime] = useStateR(0);
  useEffectR(() => {
    let raf, last = performance.now();
    const tick = (now) => {
      setTime(t => (t + (now - last) / 1000) % 19);
      last = now; raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, []);
  const phase = VOICE_PHASES.find(p => time >= p.from && time < p.to) || VOICE_PHASES[0];
  const isAriaTurn = phase.who === "aria";
  const isGuestTurn = phase.who === "guest";
  const isRinging = phase.key === "ringing";
  const callT = Math.max(0, time - 1.2);
  const mm = String(Math.floor(callT / 60)).padStart(2, "0");
  const ss = String(Math.floor(callT % 60)).padStart(2, "0");

  return (
    <div style={{
      position: "absolute", inset: 0,
      display: "flex", alignItems: "center", justifyContent: "center",
      padding: 14,
    }}>
      <div style={{
        width: "92%",
        background: "#fff",
        border: `1px solid ${RT_RULE}`,
        borderRadius: 14, padding: "14px 14px 12px",
        boxShadow: "0 18px 36px -18px rgba(0,0,0,0.3)",
        display: "flex", flexDirection: "column", gap: 10,
      }}>
        {/* header */}
        <div style={{
          display: "flex", alignItems: "center", gap: 8,
        }}>
          <div style={{ flex: 1 }}>
            <div style={{
              fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
              fontSize: 12.5, color: RT_INK, fontWeight: 400,
            }}>Olea Hotels · Voice concierge</div>
            <div style={{
              fontFamily: "'JetBrains Mono', ui-monospace, monospace",
              fontSize: 9, color: RT_FUCHSIA, letterSpacing: "0.14em",
            }}>● {phase.label.toUpperCase()} · {mm}:{ss}</div>
          </div>
          <span style={{
            fontFamily: "'JetBrains Mono', ui-monospace, monospace",
            fontSize: 8, color: RT_FAINT, letterSpacing: "0.1em",
          }}>EN · ES</span>
        </div>

        {/* big orb + waveform */}
        <div style={{
          position: "relative", height: 86,
          display: "flex", alignItems: "center", justifyContent: "center",
        }}>
          {/* orb */}
          <div style={{ position: "relative", width: 76, height: 76 }}>
            {[0, 1, 2].map(k => {
              const breath = (Math.sin(time * (isAriaTurn ? 2.4 : 1.6) + k * 1.0) * 0.5 + 0.5);
              return (
                <span key={k} style={{
                  position: "absolute", inset: -k * 7,
                  borderRadius: "50%",
                  background: isGuestTurn ? RT_INK : RT_FUCHSIA,
                  opacity: (isRinging ? 0.1 : 0.22) - k * 0.06,
                  transform: `scale(${1 + breath * (isAriaTurn ? 0.18 : 0.08)})`,
                  transition: "background 0.3s ease",
                }} />
              );
            })}
            <span style={{
              position: "absolute", inset: 14,
              borderRadius: "50%",
              background: isGuestTurn ? RT_INK : RT_FUCHSIA,
              transition: "background 0.3s ease",
            }} />
            {isGuestTurn && (
              <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="2"
                style={{ position: "absolute", inset: 0, margin: "auto" }}>
                <rect x="9" y="3" width="6" height="12" rx="3" fill="#fff" stroke="none" />
                <path d="M5 11a7 7 0 0 0 14 0" /><line x1="12" y1="18" x2="12" y2="22" />
              </svg>
            )}
          </div>
          {/* waveform fanning out from orb */}
          <div style={{
            position: "absolute", left: "50%", top: "50%",
            transform: "translate(-50%, -50%)", display: "flex", alignItems: "center", gap: 2,
            width: "92%", justifyContent: "space-between", pointerEvents: "none",
          }}>
            {Array.from({ length: 28 }).map((_, k) => {
              const dist = Math.abs(k - 13.5);
              const fade = Math.max(0, 1 - dist / 14);
              const speed = isAriaTurn ? 6 : isGuestTurn ? 4 : 1.2;
              const amp = isRinging ? 4 : (isAriaTurn ? 14 : isGuestTurn ? 10 : 4);
              const h = 3 + Math.abs(Math.sin(time * speed + k * 0.55)) * amp * fade;
              return <span key={k} style={{
                width: 2, height: h,
                background: isGuestTurn ? RT_INK : RT_FUCHSIA,
                borderRadius: 1, opacity: 0.55 + fade * 0.35,
              }} />;
            })}
          </div>
        </div>

        {/* live caption */}
        <div style={{
          minHeight: 56,
          background: isGuestTurn ? `${RT_INK}06` : `${RT_FUCHSIA}08`,
          border: `1px solid ${isGuestTurn ? RT_RULE : `${RT_FUCHSIA}30`}`,
          borderRadius: 8, padding: "8px 10px",
          fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
          fontSize: 11.5, color: RT_INK, lineHeight: 1.45,
          transition: "background 0.3s, border 0.3s",
        }}>
          <div style={{
            fontFamily: "'JetBrains Mono', ui-monospace, monospace",
            fontSize: 8, color: isGuestTurn ? RT_DIM : RT_FUCHSIA,
            letterSpacing: "0.14em", marginBottom: 2, fontWeight: 600,
          }}>{isRinging ? "STATUS" : isGuestTurn ? "GUEST" : "AGENT"}</div>
          {isRinging ? <span style={{ color: RT_DIM, fontStyle: "italic" }}>Connecting…</span> : phase.line}
        </div>

        {/* controls */}
        <div style={{ display: "flex", gap: 8, justifyContent: "center" }}>
          <button style={{
            width: 30, height: 30, borderRadius: "50%",
            background: "#fff", border: `1px solid ${RT_RULE}`,
            display: "flex", alignItems: "center", justifyContent: "center",
          }}>
            <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke={RT_INK} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
              <rect x="9" y="3" width="6" height="12" rx="3" fill={RT_INK} stroke="none" />
              <path d="M5 11a7 7 0 0 0 14 0" /><line x1="12" y1="18" x2="12" y2="22" />
            </svg>
          </button>
          <button style={{
            width: 30, height: 30, borderRadius: "50%",
            background: "#fff", border: `1px solid ${RT_RULE}`,
            display: "flex", alignItems: "center", justifyContent: "center",
          }}>
            <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke={RT_INK} strokeWidth="1.8">
              <rect x="6" y="6" width="3" height="12" /><rect x="15" y="6" width="3" height="12" />
            </svg>
          </button>
          <button style={{
            width: 30, height: 30, borderRadius: "50%",
            background: "#E04E4E", border: "none",
            display: "flex", alignItems: "center", justifyContent: "center",
          }}>
            <svg width="12" height="12" viewBox="0 0 24 24" fill="#fff">
              <path d="M19.7 14.6 17 11.7a1 1 0 0 0-1.5 0c-1 1-2.4 1-3.4 0-1-1-1-2.4 0-3.4a1 1 0 0 0 0-1.5L9.3 4a1 1 0 0 0-1.5 0L4.5 7.3c-2 2-2 5.3 0 7.4l4.8 4.8c2 2 5.3 2 7.4 0l3.3-3.3a1 1 0 0 0-.3-1.6z"/>
            </svg>
          </button>
        </div>
      </div>
    </div>
  );
}

// ────────────────────────────────────────────────────────────
//  Voice + chat combined, picker → personalized assistance flow → chat
// ────────────────────────────────────────────────────────────
function CombinedMock() {
  const [time, setTime] = useStateR(0);
  useEffectR(() => {
    let raf, last = performance.now();
    const tick = (now) => {
      setTime(t => (t + (now - last) / 1000) % 22);
      last = now; raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, []);

  // 0–3.2 picker (highlight Get personalized → click)
  // 3.2–7.2 form fill (name, party, time)
  // 7.2–11.0 confirmation (the voice agent will call you in 0:14…)
  // 11.0–14.5 chat path: user types
  // 14.5–22  chat reply + follow-up
  let stage = "picker";
  if (time >= 3.2 && time < 7.2) stage = "form";
  else if (time >= 7.2 && time < 11.0) stage = "confirm";
  else if (time >= 11.0) stage = "chat";

  const stageT = stage === "picker" ? time
    : stage === "form" ? time - 3.2
    : stage === "confirm" ? time - 7.2
    : time - 11.0;

  // form text reveals
  const NAME = "Léa Martin";
  const nameLen = stage === "form" ? Math.min(NAME.length, Math.floor(stageT * 7)) : (stage === "confirm" ? NAME.length : 0);
  const namePart = NAME.slice(0, nameLen);

  // chat
  const CHAT_Q = "What time is breakfast?";
  const qLen = stage === "chat" ? Math.min(CHAT_Q.length, Math.floor(stageT * 12)) : 0;
  const qShown = CHAT_Q.slice(0, qLen);
  const qDone = qLen >= CHAT_Q.length;
  const ariaTyping = stage === "chat" && qDone && stageT < 4.0;
  const ariaShown = stage === "chat" && stageT >= 4.0;

  return (
    <div style={{
      position: "absolute", inset: 0,
      display: "flex", alignItems: "center", justifyContent: "center",
      padding: 12,
    }}>
      <div style={{
        width: "92%",
        background: "#fff",
        border: `1px solid ${RT_RULE}`,
        borderRadius: 14, overflow: "hidden",
        boxShadow: "0 18px 36px -18px rgba(0,0,0,0.3)",
        display: "flex", flexDirection: "column",
      }}>
        {/* header */}
        <div style={{
          display: "flex", alignItems: "center", gap: 8,
          padding: "10px 12px", borderBottom: `1px solid ${RT_RULE}`,
        }}>
          <div style={{
            width: 22, height: 22, borderRadius: "50%",
            background: RT_FUCHSIA,
            display: "flex", alignItems: "center", justifyContent: "center",
          }}>
            <svg width="10" height="10" viewBox="0 0 24 24" fill="#fff">
              <circle cx="12" cy="12" r="10" />
              <text x="12" y="16" textAnchor="middle" fill={RT_FUCHSIA} fontSize="14" fontWeight="700" fontFamily="serif" fontStyle="italic">A</text>
            </svg>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 11, fontWeight: 600, color: RT_INK }}>Olea Hotels</div>
            <div style={{
              fontFamily: "'JetBrains Mono', ui-monospace, monospace",
              fontSize: 8, color: RT_DIM, letterSpacing: "0.06em",
            }}>YOUR AI CONCIERGE</div>
          </div>
          <div style={{ display: "flex", gap: 4 }}>
            {["picker","form","confirm","chat"].map(s => (
              <span key={s} style={{
                width: 5, height: 5, borderRadius: "50%",
                background: s === stage ? RT_FUCHSIA : `${RT_FUCHSIA}25`,
              }} />
            ))}
          </div>
        </div>

        <div style={{ padding: "10px 12px", minHeight: 230 }}>
          {stage === "picker" && (
            <>
              <div style={{
                fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                fontSize: 11.5, color: RT_DIM, fontStyle: "italic",
                textAlign: "center", marginBottom: 10,
              }}>How would you like to continue?</div>
              <div style={{ display: "flex", flexDirection: "column", gap: 7 }}>
                {[
                  { ic: "phone",   label: "Call now",                  sub: "Immediate · no details needed", on: false },
                  { ic: "star",    label: "Get personalized assistance",sub: "Tailored call · email confirmation", on: true, recommended: true },
                  { ic: "chat",    label: "Chat with us",              sub: "Type your question",            on: false },
                ].map((b, i) => {
                  const hovered = b.on && time > 1.4;
                  const clicked = b.on && time > 2.6;
                  return (
                    <button key={i} style={{
                      position: "relative",
                      display: "flex", alignItems: "center", gap: 9,
                      background: hovered ? `${RT_FUCHSIA}10` : (b.on ? `${RT_FUCHSIA}06` : "#fff"),
                      border: `1px solid ${hovered ? RT_FUCHSIA : (b.on ? `${RT_FUCHSIA}55` : RT_RULE)}`,
                      borderRadius: 10, padding: "8px 10px",
                      textAlign: "left",
                      transform: clicked ? "scale(0.98)" : "scale(1)",
                      transition: "all 0.2s ease",
                    }}>
                      <div style={{
                        width: 24, height: 24, borderRadius: "50%",
                        background: hovered ? RT_FUCHSIA : (b.on ? RT_FUCHSIA : `${RT_FUCHSIA}10`),
                        display: "flex", alignItems: "center", justifyContent: "center",
                      }}>
                        {b.ic === "phone" && (
                          <svg width="11" height="11" viewBox="0 0 24 24" fill="none"
                            stroke={hovered || b.on ? "#fff" : RT_FUCHSIA} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
                            <path d="M6.6 10.8a15.6 15.6 0 0 0 6.6 6.6l2.2-2.2a1 1 0 0 1 1-.25 11.4 11.4 0 0 0 3.6.6 1 1 0 0 1 1 1V20a1 1 0 0 1-1 1A17 17 0 0 1 3 4a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1 1 11.4 11.4 0 0 0 .6 3.6 1 1 0 0 1-.25 1z"/>
                          </svg>
                        )}
                        {b.ic === "star" && (
                          <svg width="11" height="11" viewBox="0 0 24 24" fill="#fff">
                            <path d="M12 2 14.5 8.5 21 9 16 13.5 17.5 20 12 16.5 6.5 20 8 13.5 3 9 9.5 8.5z"/>
                          </svg>
                        )}
                        {b.ic === "chat" && (
                          <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke={RT_INK} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
                            <path d="M21 15a3 3 0 0 1-3 3H7l-4 4V6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3z"/>
                          </svg>
                        )}
                      </div>
                      <div style={{ flex: 1 }}>
                        <div style={{ fontSize: 11, fontWeight: 600, color: hovered ? RT_FUCHSIA : (b.on ? RT_FUCHSIA : RT_INK) }}>{b.label}</div>
                        <div style={{ fontSize: 9, color: RT_DIM }}>{b.sub}</div>
                      </div>
                      {b.recommended && (
                        <span style={{
                          position: "absolute", top: -8, right: 8,
                          padding: "1.5px 7px", borderRadius: 999,
                          background: RT_FUCHSIA, color: "#fff",
                          fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                          fontSize: 7.5, letterSpacing: "0.1em", fontWeight: 600,
                        }}>RECOMMENDED</span>
                      )}
                      {clicked && b.on && (
                        <span style={{
                          position: "absolute", inset: 0, borderRadius: 10,
                          border: `2px solid ${RT_FUCHSIA}`, opacity: 1 - (time - 2.6) / 0.6, pointerEvents: "none",
                        }} />
                      )}
                    </button>
                  );
                })}
              </div>
            </>
          )}

          {stage === "form" && (
            <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
              <div style={{
                fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                fontSize: 12, color: RT_INK, fontWeight: 400,
              }}>Tell the voice agent a few quick details.</div>
              <div>
                <div style={{ fontSize: 8.5, color: RT_DIM, letterSpacing: "0.1em", marginBottom: 3, fontFamily: "'JetBrains Mono', ui-monospace, monospace" }}>YOUR NAME</div>
                <div style={{
                  border: `1px solid ${RT_RULE}`, borderRadius: 8,
                  padding: "7px 9px", fontSize: 11, color: RT_INK, background: "#fff",
                  display: "flex", alignItems: "center",
                }}>
                  {namePart}
                  {namePart.length < NAME.length && (
                    <span style={{ width: 1.5, height: 12, background: RT_FUCHSIA, marginLeft: 1, animation: "gm-blink 1s steps(2) infinite" }} />
                  )}
                </div>
              </div>
              <div>
                <div style={{ fontSize: 8.5, color: RT_DIM, letterSpacing: "0.1em", marginBottom: 3, fontFamily: "'JetBrains Mono', ui-monospace, monospace" }}>WHEN SHOULD WE CALL?</div>
                <div style={{ display: "flex", gap: 4 }}>
                  {["Now", "In 5 min", "In 30 min"].map((opt, i) => {
                    const sel = (stageT > 2.6 && i === 1);
                    return <span key={i} style={{
                      flex: 1, textAlign: "center",
                      padding: "6px 4px", borderRadius: 6,
                      border: `1px solid ${sel ? RT_FUCHSIA : RT_RULE}`,
                      background: sel ? `${RT_FUCHSIA}10` : "#fff",
                      fontSize: 10, color: sel ? RT_FUCHSIA : RT_INK,
                      fontWeight: sel ? 600 : 400,
                      transition: "all 0.3s ease",
                    }}>{opt}</span>;
                  })}
                </div>
              </div>
              <div>
                <div style={{ fontSize: 8.5, color: RT_DIM, letterSpacing: "0.1em", marginBottom: 3, fontFamily: "'JetBrains Mono', ui-monospace, monospace" }}>PARTY</div>
                <div style={{ display: "flex", gap: 4 }}>
                  {["1", "2", "3", "4+"].map((opt, i) => {
                    const sel = (stageT > 3.4 && i === 1);
                    return <span key={i} style={{
                      flex: 1, textAlign: "center",
                      padding: "6px 4px", borderRadius: 6,
                      border: `1px solid ${sel ? RT_FUCHSIA : RT_RULE}`,
                      background: sel ? `${RT_FUCHSIA}10` : "#fff",
                      fontSize: 10, color: sel ? RT_FUCHSIA : RT_INK,
                      fontWeight: sel ? 600 : 400,
                      transition: "all 0.3s ease",
                    }}>{opt}</span>;
                  })}
                </div>
              </div>
            </div>
          )}

          {stage === "confirm" && (
            <div style={{
              display: "flex", flexDirection: "column", alignItems: "center", gap: 10,
              padding: "16px 8px",
            }}>
              <div style={{
                position: "relative", width: 60, height: 60, borderRadius: "50%",
                background: RT_FUCHSIA,
                display: "flex", alignItems: "center", justifyContent: "center",
              }}>
                {[0, 1].map(k => (
                  <span key={k} style={{
                    position: "absolute", inset: 0, borderRadius: "50%",
                    border: `2px solid ${RT_FUCHSIA}`,
                    transform: `scale(${1 + (((time * 1.0 + k * 0.5) % 1)) * 0.7})`,
                    opacity: (1 - ((time * 1.0 + k * 0.5) % 1)) * 0.6,
                  }} />
                ))}
                <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
                  <path d="M6.6 10.8a15.6 15.6 0 0 0 6.6 6.6l2.2-2.2a1 1 0 0 1 1-.25 11.4 11.4 0 0 0 3.6.6 1 1 0 0 1 1 1V20a1 1 0 0 1-1 1A17 17 0 0 1 3 4a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1 1 11.4 11.4 0 0 0 .6 3.6 1 1 0 0 1-.25 1z"/>
                </svg>
              </div>
              <div style={{
                fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                fontSize: 13, color: RT_INK, fontWeight: 400, textAlign: "center",
              }}>the voice agent will call you in <span style={{ color: RT_FUCHSIA }}>{Math.max(0, Math.ceil(5 - stageT * 1.3))} min</span>.</div>
              <div style={{
                fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                fontSize: 11, color: RT_DIM, fontStyle: "italic", textAlign: "center", lineHeight: 1.4,
              }}>{NAME} · party of 2 · in 5 min<br/>Confirmation sent to your inbox.</div>
              <div style={{
                fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                fontSize: 8.5, color: RT_FUCHSIA, letterSpacing: "0.16em",
              }}>● TICKET #C-4127</div>
            </div>
          )}

          {stage === "chat" && (
            <div style={{ display: "flex", flexDirection: "column", gap: 6, minHeight: 210 }}>
              <div style={{
                alignSelf: "flex-end", maxWidth: "85%",
                background: `${RT_FUCHSIA}12`, border: `1px solid ${RT_FUCHSIA}30`,
                borderRadius: 8, padding: "5px 8px",
                fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                fontSize: 11, color: RT_INK, lineHeight: 1.4,
              }}>
                <div style={{
                  fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                  fontSize: 7.5, color: RT_FUCHSIA, letterSpacing: "0.1em", fontWeight: 600, marginBottom: 1,
                }}>YOU</div>
                {qShown}{!qDone && <span style={{ display: "inline-block", width: 1.5, height: 11, background: RT_FUCHSIA, marginLeft: 1, animation: "gm-blink 1s steps(2) infinite", verticalAlign: "middle" }} />}
              </div>
              {ariaTyping && (
                <div style={{
                  alignSelf: "flex-start", padding: "6px 9px",
                  background: "#fff", border: `1px solid ${RT_RULE}`,
                  borderRadius: 8, display: "flex", gap: 3,
                }}>
                  {[0, 1, 2].map(k => (
                    <span key={k} style={{
                      width: 4, height: 4, borderRadius: "50%", background: RT_FUCHSIA,
                      opacity: 0.4 + Math.abs(Math.sin(time * 5 + k * 0.7)) * 0.6,
                    }} />
                  ))}
                </div>
              )}
              {ariaShown && (
                <div style={{
                  alignSelf: "flex-start", maxWidth: "85%",
                  background: "#fff", border: `1px solid ${RT_RULE}`,
                  borderRadius: 8, padding: "5px 8px",
                  fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
                  fontSize: 11, color: RT_INK, lineHeight: 1.4,
                  animation: "gm-fadein 0.4s ease",
                }}>
                  <div style={{
                    fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                    fontSize: 7.5, color: RT_FAINT, letterSpacing: "0.1em", fontWeight: 600, marginBottom: 1,
                  }}>ARIA</div>
                  Breakfast is served from <strong>7:00 to 11:00</strong> in the Sea Garden, would you like me to reserve a table?
                </div>
              )}
              {ariaShown && stageT > 6.0 && (
                <div style={{ display: "flex", gap: 4, marginTop: 4, animation: "gm-fadein 0.4s ease" }}>
                  {["Yes, 8:30", "9:00 please", "No thanks"].map((opt, i) => (
                    <span key={i} style={{
                      padding: "5px 9px", borderRadius: 999,
                      border: `1px solid ${i === 0 ? RT_FUCHSIA : RT_RULE}`,
                      background: i === 0 ? `${RT_FUCHSIA}10` : "#fff",
                      fontSize: 10, color: i === 0 ? RT_FUCHSIA : RT_INK,
                      fontWeight: i === 0 ? 600 : 400,
                    }}>{opt}</span>
                  ))}
                </div>
              )}
              <div style={{ flex: 1 }} />
              <div style={{
                marginTop: 4, padding: "6px 8px",
                border: `1px solid ${RT_RULE}`, borderRadius: 8,
                display: "flex", alignItems: "center", gap: 6,
                background: "#FAF8F4",
              }}>
                <span style={{ fontSize: 10, color: RT_FAINT, flex: 1 }}>Ask anything…</span>
                <svg width="11" height="11" viewBox="0 0 24 24" fill={RT_FUCHSIA}>
                  <path d="M22 2 11 13M22 2l-7 20-4-9-9-4z" stroke={RT_FUCHSIA} strokeWidth="1.5" fill="none" strokeLinejoin="round"/>
                </svg>
              </div>
            </div>
          )}
        </div>
      </div>
    </div>
  );
}

// ────────────────────────────────────────────────────────────
//  Whole section
// ────────────────────────────────────────────────────────────
function VoiceRouting() {
  return (
    <section data-screen-label="Voice Agent · Routing" style={{
      background: RT_CREAM,
      padding: "72px 32px 88px",
      position: "relative",
      borderTop: `1px solid ${RT_RULE}`,
      fontFamily: "'Inter', system-ui, sans-serif",
      color: RT_INK,
    }}>
      <div style={{ maxWidth: 1320, margin: "0 auto" }}>
        {/* Section eyebrow + headline */}
        <div style={{ textAlign: "center", marginBottom: 56 }}>
          <div style={{
            display: "inline-flex", alignItems: "center", gap: 10, marginBottom: 18,
          }}>
            <span style={{ width: 16, height: 1.5, background: RT_FUCHSIA }} />
            <span style={{
              fontFamily: "'JetBrains Mono', ui-monospace, monospace",
              fontSize: 11, color: RT_FUCHSIA, letterSpacing: "0.22em",
              textTransform: "uppercase", fontWeight: 500,
            }}>Distribution & Routing</span>
            <span style={{ width: 16, height: 1.5, background: RT_FUCHSIA }} />
          </div>
          <h2 style={{
            fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
            fontWeight: 400, fontSize: "clamp(30px, 4vw, 56px)", letterSpacing: "-0.025em",
            lineHeight: 1.05, margin: 0,
            maxWidth: 920, marginInline: "auto",
          }}>
            Reach your guests where they are.{" "}
            <span style={{ fontStyle: "italic", color: RT_FUCHSIA, display: "block" }}>
              Route every call to the right team.
            </span>
          </h2>
          <p style={{
            fontSize: 15, color: RT_DIM, lineHeight: 1.65,
            maxWidth: 640, margin: "20px auto 0",
          }}>
            A local number in every market, smart escalation across twelve themes,
            seamless hand-off to the right hotel, and recovery built in for the calls
            that don't get picked up.
          </p>
        </div>

        {/* 1, Local numbers */}
        <SectionBlock
          eyebrow="01 · Local presence"
          title="A local number"
          italic="for every market."
          body="Spain dials +34. The UK dials +44. the voice agent's number adapts to the visitor's geography so every call feels native, IVR language, voice, opening hours and routing all configurable per number from your dashboard."
        >
          <LocalNumbersDashboard />
        </SectionBlock>

        {/* 2, Themes */}
        <SectionBlock
          eyebrow="02 · Smart routing"
          title="Twelve themes"
          italic="for every kind of call."
          body="the voice agent classifies the caller's intent in real time and escalates against your rules. Each theme can route to a phone number, an email inbox, or directly to the relevant hotel, and you can add as many custom themes as your group needs."
        >
          <ThemesGrid />
        </SectionBlock>

        {/* 3, Hotel fan-out */}
        <SectionBlock
          eyebrow="03 · Hotel-aware"
          title="One number,"
          italic="every hotel reachable."
          body="Configure a phone for each property and link the rooms-of-stay. Booking modifications, special requests and lost-and-found get routed straight to the right front desk, no menu trees, no transfers."
        >
          <HotelFanOut />
        </SectionBlock>

        {/* 4, Recovery */}
        <SectionBlock
          eyebrow="04 · Recovery"
          title="When the hotel"
          italic="can't pick up."
          body="If the front desk doesn't answer in 25 seconds, the voice agent steps back into the call, offers an email follow-up and opens a ticket for the hotel team, no missed bookings, no lost intent."
        >
          <RecoveryFlow />
        </SectionBlock>

        {/* 5, Web */}
        <SectionBlock
          eyebrow="05 · On the website"
          title="Voice on every page,"
          italic="however your guests prefer it."
          body="Drop the widget on your hotel website and the voice agent becomes one click away. Standalone voice, a corner bubble, or combined with the chatbot, same agent, same memory, same routing."
        >
          <WebWidgets />
        </SectionBlock>
      </div>
    </section>
  );
}

function SectionBlock({ eyebrow, title, italic, body, children }) {
  return (
    <div style={{ marginBottom: 72 }}>
      <div style={{
        display: "grid", gridTemplateColumns: "1fr 1.2fr",
        gap: 48, alignItems: "end", marginBottom: 28,
      }}>
        <div>
          <div style={{
            fontFamily: "'JetBrains Mono', ui-monospace, monospace",
            fontSize: 10.5, color: RT_FUCHSIA, letterSpacing: "0.22em",
            textTransform: "uppercase", fontWeight: 600, marginBottom: 14,
          }}>{eyebrow}</div>
          <h3 style={{
            fontFamily: "'Instrument Serif', 'Source Serif 4', Georgia, serif",
            fontWeight: 400, fontSize: 38, letterSpacing: "-0.022em",
            lineHeight: 1.08, margin: 0,
          }}>
            {title}{" "}
            <span style={{ fontStyle: "italic", color: RT_FUCHSIA }}>{italic}</span>
          </h3>
        </div>
        <p style={{
          fontSize: 15, color: RT_DIM, lineHeight: 1.6, margin: 0,
        }}>{body}</p>
      </div>
      {children}
    </div>
  );
}

window.VoiceRouting = VoiceRouting;
