// Hawaiian Style — FAQ page components.
// Customer-service hub. Index-card / library register: typewriter labels,
// hand-numbered questions, mascot helpers. Reuses Primitives + Nav + Footer.
// Source data is verbatim from the brand's official customer-question doc
// (FAQ.xlsx). Citations like "(American Academy of Dermatology)" are split
// out at render time and rendered as a small source footnote.

// ---- helpers --------------------------------------------------------------

// Pull a trailing "( ... )" attribution off an answer (if present) and
// return { body, source }. The source string drops the parens.
const splitSource = (text) => {
  const m = text.match(/\s*\(([^()]+)\)\s*$/);
  if (!m) return { body: text, source: null };
  return { body: text.slice(0, m.index).trim(), source: m[1].trim() };
};

// ---- data -----------------------------------------------------------------

const FAQ_DATA = [
  {
    id: 'sun',
    label: 'Sun & SPF',
    eyebrow: 'Class 01 · Protection',
    title: 'Sun & SPF',
    script: 'the basics.',
    blurb: 'Everything about sun protection — what SPF means, how often to reapply, who can use it, and where to keep the bottle when you\u2019re not.',
    mascot: 'assets/mascots/kona-lotion-sunblock.png',
    accent: 'var(--blue)',
    pillBg: 'var(--blue)',
    pillFg: 'var(--paper)',
    items: [
      { q: 'What does SPF mean?',
        a: 'SPF mainly refers to protection against UVB rays, which are the rays strongly linked with sunburn. SPF 15 filters about 93% of UVB rays, SPF 30 about 97%, and SPF 50 about 98%, when used correctly. (The Skin Cancer Foundation)' },
      { q: 'Is SPF50 much stronger than SPF30?',
        a: 'SPF50 blocks slightly more UVB than SPF30, but the key is applying enough and reapplying regularly. Higher SPF does not mean you can stay in the sun all day without reapplying. AAD states SPF30 blocks 97% of UVB rays, higher SPFs block slightly more, and no sunscreen blocks 100%. (American Academy of Dermatology)' },
      { q: 'How often should I reapply sunscreen?',
        a: 'Reapply sunscreen about every 2 hours when outdoors, and immediately after swimming or sweating. AAD recommends reapplying every two hours and immediately after swimming or sweating. (American Academy of Dermatology)' },
      { q: 'How much sunscreen should I apply?',
        a: 'For most adults, AAD recommends about 1 ounce for exposed body skin, roughly a shot-glass amount. For the face, use at least 1 teaspoon or about two-finger length. (American Academy of Dermatology)' },
      { q: 'Should I apply sunscreen before going outside?',
        a: 'Yes. Apply sunscreen to dry skin before sun exposure. AAD recommends applying sunscreen to dry skin 15 minutes before going outdoors. (American Academy of Dermatology)' },
      { q: 'Does sunscreen protect from UVA and UVB?',
        a: 'Broad-spectrum sunscreen protects against both UVA and UVB. UVA is linked with premature skin aging, while UVB is the primary cause of sunburn. (American Academy of Dermatology)' },
      { q: 'Is Hawaiian Style sunscreen waterproof?',
        a: 'No sunscreen should be described as fully \u201Cwaterproof.\u201D Sunscreens may be water-resistant for a stated time if the product label supports it. AAD notes that no sunscreen is \u201Cwaterproof\u201D or \u201Csweatproof.\u201D (American Academy of Dermatology)' },
      { q: 'Is Hawaiian Style Sunblock suitable for face and body?',
        a: 'For Hawaiian Style Sunblock products, the brand\u2019s product direction is face and body use. Please check the specific label direction before use.' },
      { q: 'Is it suitable for all skin types?',
        a: 'Our sunblock products are designed for general use, but skin reaction can vary by person. If you have sensitive skin, allergies, or a medical skin condition, please check the ingredient list and do a patch test first.' },
      { q: 'Can children use it?',
        a: 'Please check the product label and use as directed. For babies under 6 months, AAD says sunscreen should ideally be avoided unless shade and protective clothing are not available; parents should ask a doctor. (American Academy of Dermatology)' },
      { q: 'Can pregnant women use it?',
        a: 'Please check the ingredient list with your doctor or pharmacist before use, especially during pregnancy or breastfeeding.' },
      { q: 'Can I use it around the eyes?',
        a: 'Avoid direct contact with eyes. If product gets into the eyes, rinse thoroughly with clean water.' },
      { q: 'Does sunscreen expire?',
        a: 'Please check the expiry date printed on the product. AAD notes the FDA requires sunscreens to retain original strength for at least three years, and any obvious change in color or consistency means the product should be replaced.' },
      { q: 'How should I store sunscreen?',
        a: 'Store in a cool, dry place and avoid direct sunlight or high heat. AAD notes that leaving sunscreen in direct sunlight or hot environments, such as inside a car, can speed up ingredient breakdown. (American Academy of Dermatology)' },
    ],
  },
  {
    id: 'tan',
    label: 'Tanning Oil & Glow',
    eyebrow: 'Class 02 · The Soul',
    title: 'Tanning oil & glow',
    script: 'golden hour.',
    blurb: 'The brand soul. How tanning oil works, how to pair it with SPF, when to come back inside, and which oil suits which mood.',
    mascot: 'assets/mascots/kona-lotion-tanning.png',
    accent: 'var(--orange)',
    pillBg: 'var(--orange)',
    pillFg: 'var(--paper)',
    items: [
      { q: 'What is tanning oil for?',
        a: 'Tanning oil is designed to help create a glowing, sun-kissed tanning experience when used during sun exposure.' },
      { q: 'Does tanning oil make skin tan instantly?',
        a: 'No. Hawaiian Style tanning oil is not an instant self-tanner. It is used while sunbathing to support a golden tan from sun exposure.' },
      { q: 'Can I use tanning oil instead of sunscreen?',
        a: 'We do not recommend replacing sunscreen with tanning oil if your goal is sun protection. Tanning oil is for tanning/glow experience; sunscreen is for UV protection.' },
      { q: 'Can I apply SPF50 first, then tanning oil?',
        a: 'Yes, you may apply sunscreen first for protection, let it absorb, then apply tanning oil on top. However, sunscreen may slow tanning because it reduces UV exposure. Reapply sunscreen regularly as directed.' },
      { q: 'Will sunscreen make me unable to tan?',
        a: 'Sunscreen reduces UV exposure, so tanning may happen more slowly. It does not create a total UV block because no sunscreen blocks 100% of UV rays. AAD states no sunscreen blocks 100% of UVB rays. (American Academy of Dermatology)' },
      { q: 'How long should I sunbathe?',
        a: 'We cannot recommend a fixed tanning time because it depends on UV index, skin type, location, time of day, and product use. Start carefully, avoid intense midday sun, and stop if skin turns red or uncomfortable.' },
      { q: 'Is tanning safe?',
        a: 'UV tanning is a sign of skin reacting to UV radiation. AAD states there is no safe way to tan and that every tan damages skin. (American Academy of Dermatology)' },
      { q: 'Can I use tanning oil on my face?',
        a: 'Please check the product label. If you have acne-prone, sensitive, or oily skin, avoid using oil on the face or patch test first.' },
      { q: 'Will tanning oil stain clothes?',
        a: 'Oil products may transfer to fabric. Allow the product to absorb and avoid direct contact with light-colored clothing or towels.' },
      { q: 'Does Coconut Tanning Oil smell like coconut?',
        a: 'The product direction includes coconut-themed scent/experience. For exact scent notes, check the current product label or product page.' },
      { q: 'What is the difference between Coconut Tanning Oil and Classic Tanning Oil?',
        a: 'Coconut Tanning Oil focuses on a coconut-style tanning experience, while Classic Tanning Oil gives a more classic tanning oil experience. For exact scent, ingredient, and texture differences, please check the latest product label or catalog.' },
    ],
  },
  {
    id: 'shop',
    label: 'Buying & Shipping',
    eyebrow: 'Class 03 · Where to find us',
    title: 'Buying & shipping',
    script: 'we ship.',
    blurb: 'Where to grab a bottle locally, what we can do internationally, and what to do if your parcel shows up a little worse for wear.',
    mascot: 'assets/mascots/kona-run.png',
    accent: 'var(--aloha)',
    pillBg: 'var(--aloha)',
    pillFg: 'var(--paper)',
    items: [
      { q: 'Where can I buy Hawaiian Style?',
        a: 'You can buy from our official online channels and selected retail stores. Current retail channels include 7-Eleven, Tops, Central, Gourmet Market, Foodland, and local drug stores.' },
      { q: 'Is it available in every 7-Eleven?',
        a: 'Availability may vary by branch and area. Please share your location or preferred branch, and we will help check if possible.' },
      { q: 'Do you have retailers in UAE / Malaysia / Singapore / Philippines?',
        a: 'Retail availability depends on country. Please tell us your country and we will check the latest available channel or official online store for you.' },
      { q: 'Can you ship internationally?',
        a: 'We may be able to arrange international shipping depending on destination, courier availability, and shipping cost. Please share your country, product quantity, and address area so we can check.' },
      { q: 'Why is international shipping expensive?',
        a: 'International shipping cost depends on destination, parcel weight, courier, fuel surcharge, and customs process. We can check the most suitable option for you.' },
      { q: 'How long does delivery take?',
        a: 'Delivery time depends on destination and courier. Please share your order location so we can check the estimated delivery time.' },
      { q: 'Can I return or exchange the product?',
        a: 'Return/exchange depends on where you purchased the product and the condition of the item. Please send your order details, purchase channel, receipt, photos, and issue description so we can check.' },
      { q: 'Product arrived damaged. What should I do?',
        a: 'Please send clear photos/videos of the parcel box, product condition, shipping label, order number, and purchase channel. Our team will check and support according to the case.' },
    ],
  },
];

// ---- HERO -----------------------------------------------------------------

const FAQHero = ({ totalQs, onJump }) => (
  <header style={{ position: 'relative', maxWidth: 1320, margin: '0 auto', padding: '64px 36px 24px' }}>
    <div style={{ display: 'grid', gridTemplateColumns: '1.1fr 0.9fr', gap: 48, alignItems: 'center' }}>
      {/* LEFT TEXT */}
      <div>
        <Eyebrow>Customer Service · Honest Answers · est. 1995</Eyebrow>
        <h1 style={{
          fontFamily: 'var(--font-display)', fontWeight: 400,
          fontSize: 'clamp(56px, 7.5vw, 128px)', lineHeight: 0.92,
          letterSpacing: '0.005em', textTransform: 'uppercase',
          color: 'var(--brown)', margin: '20px 0 0',
        }}>
          Got <span style={{ color: 'var(--orange)' }}>questions</span>?<br/>
          <span style={{
            fontFamily: 'var(--font-script)', textTransform: 'none',
            color: 'var(--orange)', fontSize: '0.78em',
            transform: 'rotate(-4deg) translateY(-0.08em)',
            display: 'inline-block', lineHeight: 0.9,
          }}>we got you.</span>
        </h1>
        <p style={{ fontSize: 18, color: 'var(--brown-soft)', maxWidth: 520, marginTop: 28, lineHeight: 1.55 }}>
          Thirty-three plain-English answers about sunscreen, tanning oil, and how to get a bottle to your door — written by the same people who answer Hawaiian Style{'\u2019'}s DMs at 11 PM.
        </p>
        <p style={{ fontFamily: 'var(--font-thai)', fontSize: 14, color: 'var(--brown-soft)', marginTop: 12, opacity: 0.75 }}>
          คำถามที่พบบ่อย เรื่องครีมกันแดด น้ำมันมะพร้าวอาบแดด และการจัดส่ง
        </p>
        <div style={{ display: 'flex', gap: 14, flexWrap: 'wrap', marginTop: 32 }}>
          <Pill variant="sun" onClick={(e) => { e.preventDefault(); onJump('sun'); }} href="#sun">Sun & SPF</Pill>
          <Pill variant="ghost" onClick={(e) => { e.preventDefault(); onJump('tan'); }} href="#tan">Tanning oil</Pill>
          <Pill variant="ghost" onClick={(e) => { e.preventDefault(); onJump('shop'); }} href="#shop">Buying & shipping</Pill>
        </div>
        <div style={{
          display: 'flex', gap: 28, marginTop: 40,
          borderTop: '2px solid rgba(61, 47, 35, 0.18)', paddingTop: 22,
        }}>
          {[
            { num: totalQs,  lbl: 'Questions answered' },
            { num: '3',      lbl: 'Categories · all bilingual' },
            { num: '< 24h',  lbl: 'Reply time on DMs' },
          ].map(m => (
            <div key={m.lbl}>
              <div style={{ fontFamily: 'var(--font-display)', fontSize: 32, color: 'var(--orange)', lineHeight: 1 }}>{m.num}</div>
              <div style={{ fontSize: 11, color: 'var(--brown-soft)', marginTop: 6, maxWidth: 160, textTransform: 'uppercase', letterSpacing: '0.06em', fontWeight: 600 }}>{m.lbl}</div>
            </div>
          ))}
        </div>
      </div>

      {/* RIGHT VISUAL: index-card stack on warm sun panel */}
      <div style={{
        position: 'relative', borderRadius: 28, overflow: 'hidden',
        background: 'radial-gradient(120% 80% at 25% 30%, var(--paper-soft) 0%, var(--beige) 50%, var(--beige-deep) 100%)',
        boxShadow: 'var(--shadow-lg)', minHeight: 520,
      }}>
        <div style={{ position: 'absolute', inset: 0,
          backgroundImage: 'repeating-linear-gradient(0deg, rgba(61,47,35,0.04) 0 1px, transparent 1px 5px)',
          pointerEvents: 'none' }} />
        <div style={{ position: 'absolute', top: 28, right: 28, zIndex: 8 }}>
          <VintageStamp year="FAQ" label="ask anything" script="we answer" rotate={-8} size={120} />
        </div>
        <div style={{ position: 'absolute', top: 60, left: -10 }}>
          <Doodle.Sun size={100} color="var(--orange)" opacity={0.35} spin />
        </div>
        <div style={{ position: 'absolute', bottom: 28, right: 28, opacity: 0.35 }}>
          <Doodle.Waves width={140} color="var(--brown)" opacity={0.5} />
        </div>

        {/* The stacked index cards */}
        {[
          { rot: -7, top: 60,  left: 60,  bg: 'var(--paper)',     q: 'How often do I reapply?',         a: 'Every 2 hrs, friend.' },
          { rot: 4,  top: 170, left: 130, bg: 'var(--sun)',       q: 'Can I tan with SPF on?',          a: 'Yes — just slower.' },
          { rot: -3, top: 290, left: 50,  bg: 'var(--paper-soft)',q: 'Do you ship to Manila?',          a: 'Tell us your zip.' },
        ].map((c, i) => (
          <div key={i} style={{
            position: 'absolute', top: c.top, left: c.left, zIndex: 5 + i,
            background: c.bg, padding: '18px 22px', borderRadius: 12,
            border: '2px solid var(--brown)', boxShadow: '0 6px 0 var(--brown)',
            transform: `rotate(${c.rot}deg)`, width: 240,
          }}>
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
              <span style={{ fontFamily: 'var(--font-mono)', fontSize: 9.5, letterSpacing: '0.18em', color: 'var(--brown-soft)', textTransform: 'uppercase' }}>Q · {String(i + 1).padStart(2, '0')}</span>
              <span style={{ fontFamily: 'var(--font-display)', fontSize: 18, color: 'var(--orange)' }}>?</span>
            </div>
            <div style={{ fontFamily: 'var(--font-display)', fontSize: 18, lineHeight: 1.05, marginTop: 8, color: 'var(--brown)', letterSpacing: '0.02em', textTransform: 'uppercase' }}>{c.q}</div>
            <div style={{
              marginTop: 10, paddingTop: 10,
              borderTop: '1.5px dashed rgba(61,47,35,0.35)',
              fontFamily: 'var(--font-script)', color: 'var(--orange)',
              fontSize: 22, lineHeight: 1,
            }}>{c.a}</div>
          </div>
        ))}

        {/* Coco bottom-right peeking */}
        <img src="assets/mascots/coco-look.png" alt="Coco"
          style={{
            position: 'absolute', bottom: -10, right: 30, width: 180, height: 'auto',
            filter: 'drop-shadow(0 18px 22px rgba(0,0,0,0.35))',
            zIndex: 9,
          }} />
      </div>
    </div>
  </header>
);

// ---- SEARCH BAR -----------------------------------------------------------

const FAQSearch = ({ query, onChange, resultCount, totalCount }) => (
  <section style={{ maxWidth: 1320, margin: '0 auto', padding: '32px 36px 0' }}>
    <div style={{
      background: 'var(--paper-soft)', border: '2px solid var(--brown)',
      borderRadius: 18, padding: '6px 6px 6px 22px',
      display: 'flex', alignItems: 'center', gap: 14,
      boxShadow: '0 4px 0 var(--brown)',
    }}>
      <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--brown)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" style={{ flexShrink: 0 }}>
        <circle cx="11" cy="11" r="7"/><line x1="20" y1="20" x2="17" y2="17"/>
      </svg>
      <input
        value={query}
        onChange={(e) => onChange(e.target.value)}
        placeholder={'Search the FAQ \u2014 try \u201CSPF\u201D, \u201Cwaterproof\u201D, \u201Cship to Manila\u201D\u2026'}
        style={{
          flex: 1, padding: '14px 0', border: 'none', outline: 'none',
          background: 'transparent', fontFamily: 'var(--font-body)',
          fontSize: 16, color: 'var(--brown)', minWidth: 0,
        }}
      />
      {query && (
        <button onClick={() => onChange('')} aria-label="Clear"
          style={{
            background: 'transparent', border: 'none', cursor: 'pointer',
            color: 'var(--brown-soft)', fontSize: 13, fontWeight: 700,
            fontFamily: 'var(--font-body)', letterSpacing: '0.1em', textTransform: 'uppercase',
            padding: '6px 10px',
          }}>
          Clear
        </button>
      )}
      <span style={{
        fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.16em',
        textTransform: 'uppercase', color: 'var(--brown-soft)',
        background: 'var(--paper)', borderRadius: 999, padding: '8px 14px',
        border: '1.5px solid rgba(61,47,35,0.18)', whiteSpace: 'nowrap',
      }}>
        {query ? `${resultCount} / ${totalCount}` : `${totalCount} total`}
      </span>
    </div>
  </section>
);

// ---- CATEGORY GROUP + ACCORDION ------------------------------------------

const FAQItem = ({ index, q, a, accent, defaultOpen }) => {
  const { useState } = React;
  const [open, setOpen] = useState(!!defaultOpen);
  const { body, source } = splitSource(a);
  return (
    <div style={{
      borderBottom: '1.5px solid rgba(61,47,35,0.14)',
      background: open ? 'var(--paper-soft)' : 'transparent',
      transition: 'background .25s',
    }}>
      <button
        onClick={() => setOpen(!open)}
        aria-expanded={open}
        style={{
          width: '100%', display: 'grid',
          gridTemplateColumns: '64px 1fr 40px', gap: 20,
          alignItems: 'center', padding: '24px 28px',
          background: 'transparent', border: 'none', cursor: 'pointer',
          textAlign: 'left', color: 'var(--brown)',
        }}>
        <span style={{
          fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.18em',
          textTransform: 'uppercase', color: 'var(--brown-soft)',
        }}>Q · {String(index).padStart(2, '0')}</span>
        <span style={{
          fontFamily: 'var(--font-display)', fontSize: 'clamp(20px, 2.1vw, 26px)',
          letterSpacing: '0.02em', textTransform: 'uppercase',
          lineHeight: 1.15, color: open ? accent : 'var(--brown)',
          transition: 'color .25s',
        }}>{q}</span>
        <span style={{
          width: 36, height: 36, borderRadius: '50%',
          border: `2px solid ${open ? accent : 'var(--brown)'}`,
          background: open ? accent : 'transparent',
          color: open ? 'var(--paper)' : 'var(--brown)',
          display: 'grid', placeItems: 'center',
          transition: 'transform .25s, background .25s, color .25s, border-color .25s',
          transform: open ? 'rotate(45deg)' : 'rotate(0deg)',
          justifySelf: 'end', flexShrink: 0,
        }}>
          <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round">
            <line x1="7" y1="2" x2="7" y2="12"/><line x1="2" y1="7" x2="12" y2="7"/>
          </svg>
        </span>
      </button>
      <div style={{
        display: 'grid',
        gridTemplateRows: open ? '1fr' : '0fr',
        transition: 'grid-template-rows .3s var(--ease-out)',
      }}>
        <div style={{ overflow: 'hidden' }}>
          <div style={{ padding: '0 28px 28px', display: 'grid', gridTemplateColumns: '64px 1fr 40px', gap: 20 }}>
            <span style={{
              fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.18em',
              textTransform: 'uppercase', color: accent,
            }}>A</span>
            <div>
              <p style={{
                fontSize: 16, lineHeight: 1.65, color: 'var(--brown-soft)',
                margin: 0, maxWidth: 720,
              }}>{body}</p>
              {source && (
                <div style={{
                  marginTop: 14, display: 'inline-flex', alignItems: 'center', gap: 8,
                  fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.16em',
                  textTransform: 'uppercase', color: 'var(--brown-soft)',
                  background: 'var(--paper)', borderRadius: 999, padding: '6px 12px',
                  border: '1.5px solid rgba(61,47,35,0.18)',
                }}>
                  <span style={{
                    width: 6, height: 6, borderRadius: '50%', background: accent,
                  }} />
                  Source · {source}
                </div>
              )}
            </div>
            <span />
          </div>
        </div>
      </div>
    </div>
  );
};

const FAQGroup = ({ group, query }) => {
  const items = group.items;
  return (
    <section id={group.id} style={{ maxWidth: 1320, margin: '0 auto', padding: '88px 36px 0', scrollMarginTop: 100 }}>
      {/* Section head */}
      <div style={{
        display: 'grid', gridTemplateColumns: '1.4fr 0.9fr', gap: 40,
        alignItems: 'end', marginBottom: 32,
      }}>
        <div>
          <Eyebrow color="var(--brown-soft)">{group.eyebrow}</Eyebrow>
          <h2 style={{
            fontFamily: 'var(--font-display)', fontWeight: 400,
            fontSize: 'clamp(48px, 6vw, 96px)', lineHeight: 0.94,
            letterSpacing: '0.005em', textTransform: 'uppercase',
            color: 'var(--brown)', margin: '18px 0 0',
          }}>
            {group.title} <span style={{
              fontFamily: 'var(--font-script)', textTransform: 'none',
              color: group.accent, fontSize: '0.62em', display: 'inline-block',
              transform: 'rotate(-3deg) translateY(-0.05em)',
            }}>{group.script}</span>
          </h2>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 14, textAlign: 'right' }}>
          <p style={{ fontSize: 15, color: 'var(--brown-soft)', lineHeight: 1.55, maxWidth: 360, margin: 0 }}>{group.blurb}</p>
          <span style={{
            fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em',
            textTransform: 'uppercase', color: 'var(--paper)',
            background: group.accent, borderRadius: 999, padding: '6px 14px',
          }}>{items.length} question{items.length === 1 ? '' : 's'}</span>
        </div>
      </div>

      {/* Accordion list — wrapped in a "ledger" card */}
      <div style={{
        background: 'var(--paper)',
        border: '2px solid var(--brown)', borderRadius: 24,
        boxShadow: '0 6px 0 var(--brown)', overflow: 'hidden',
      }}>
        {/* Top "ledger" header row */}
        <div style={{
          display: 'grid', gridTemplateColumns: '64px 1fr 40px', gap: 20,
          padding: '16px 28px', background: group.accent, color: 'var(--paper)',
          alignItems: 'center',
        }}>
          <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', opacity: 0.85 }}>No.</span>
          <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', opacity: 0.85 }}>Customer Question</span>
          <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', opacity: 0.85, textAlign: 'right' }}>Open</span>
        </div>

        {items.length === 0 ? (
          <div style={{ padding: '48px 28px', textAlign: 'center', color: 'var(--brown-soft)', fontStyle: 'italic' }}>
            No matches in this section.
          </div>
        ) : items.map((it, i) => (
          <FAQItem
            key={it.q}
            index={i + 1}
            q={it.q}
            a={it.a}
            accent={group.accent}
            defaultOpen={!!query && i === 0}
          />
        ))}
      </div>
    </section>
  );
};

// ---- CONTACT CTA ----------------------------------------------------------

const FAQContact = () => (
  <section style={{ maxWidth: 1320, margin: '0 auto', padding: '96px 36px 0' }}>
    <div style={{
      background: 'var(--brown)', borderRadius: 32, color: 'var(--paper)',
      padding: '64px 56px', position: 'relative', overflow: 'hidden',
      display: 'grid', gridTemplateColumns: '1.2fr 1fr', gap: 56, alignItems: 'center',
    }}>
      <div style={{ position: 'absolute', bottom: -90, right: -90, width: 300, height: 300, borderRadius: '50%',
        background: 'radial-gradient(circle, rgba(247, 223, 77, 0.32) 0%, transparent 70%)' }} />
      <div style={{ position: 'absolute', top: 30, right: 36, opacity: 0.18 }}>
        <Doodle.Palm size={120} color="var(--paper)" opacity={1} />
      </div>

      <div style={{ position: 'relative' }}>
        <Eyebrow color="rgba(252, 213, 182, 0.85)">Still curious? · We reply by hand</Eyebrow>
        <h3 style={{
          fontFamily: 'var(--font-display)', fontWeight: 400,
          fontSize: 'clamp(40px, 5vw, 80px)', lineHeight: 0.94,
          letterSpacing: '0.005em', textTransform: 'uppercase',
          margin: '14px 0 0', color: 'var(--paper)',
        }}>
          Didn{'\u2019'}t find <span style={{
            fontFamily: 'var(--font-script)', textTransform: 'none',
            color: 'var(--sun)', fontSize: '0.7em', display: 'inline-block',
            transform: 'rotate(-3deg)',
          }}>your</span><br/>
          answer?
        </h3>
        <p style={{ fontSize: 16, opacity: 0.85, marginTop: 18, lineHeight: 1.6, maxWidth: 440 }}>
          Slide into our DMs, ping us on LINE, or send a postcard-length email. Real humans, usually back within a day, Bangkok time.
        </p>

        <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, marginTop: 28 }}>
          <Pill variant="yellow" href="mailto:contact@sahatavesin.co.th">Email contact@</Pill>
          <Pill variant="ghost-paper" href="https://www.instagram.com/hawaiianstyleofficial/">DM on Instagram</Pill>
          <Pill variant="ghost-paper" href="https://www.facebook.com/hawaiianstyleshop">Message on Facebook</Pill>
        </div>

        <div style={{
          marginTop: 36, paddingTop: 24, borderTop: '1.5px solid rgba(252, 213, 182, 0.2)',
          display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 24,
        }}>
          {[
            { lbl: 'Office hours', val: 'Mon \u2013 Fri · 9 \u2013 6 ICT' },
            { lbl: 'Reply time',   val: 'Under 24 hrs · usually' },
            { lbl: 'Wholesale',    val: ['sahatavesin@hotmail.com', 'setawut@sahatavesin.co.th'] },
          ].map(c => (
            <div key={c.lbl}>
              <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.16em', textTransform: 'uppercase', opacity: 0.6 }}>{c.lbl}</div>
              <div style={{ fontFamily: 'var(--font-display)', fontSize: Array.isArray(c.val) ? 14 : 18, color: 'var(--sun)', letterSpacing: '0.02em', marginTop: 4, textTransform: 'uppercase', lineHeight: 1.25 }}>
                {Array.isArray(c.val)
                  ? c.val.map((v, i) => <div key={i}>{v}</div>)
                  : c.val}
              </div>
            </div>
          ))}
        </div>
      </div>

      {/* Right: Kona with phone-mascot vibe */}
      <div style={{ position: 'relative', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
        <div style={{
          position: 'absolute', top: 0, right: 20,
          background: 'var(--sun)', color: 'var(--brown)',
          padding: '12px 18px', borderRadius: 14,
          border: '2px solid var(--brown)', boxShadow: '0 4px 0 var(--brown)',
          transform: 'rotate(6deg)', maxWidth: 220, zIndex: 4,
        }}>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 9.5, letterSpacing: '0.14em', color: 'var(--brown-soft)', textTransform: 'uppercase' }}>DM \u00B7 just now</div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 16, marginTop: 4, color: 'var(--brown)', letterSpacing: '0.02em', textTransform: 'uppercase', lineHeight: 1.1 }}>Hey, can you ship to Cebu?</div>
        </div>
        <div style={{
          position: 'absolute', bottom: 18, left: 24,
          background: 'var(--paper)', color: 'var(--brown)',
          padding: '12px 18px', borderRadius: 14,
          border: '2px solid var(--brown)', boxShadow: '0 4px 0 var(--brown)',
          transform: 'rotate(-5deg)', maxWidth: 220, zIndex: 4,
        }}>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 9.5, letterSpacing: '0.14em', color: 'var(--brown-soft)', textTransform: 'uppercase' }}>Kona \u00B7 reply</div>
          <div style={{ fontFamily: 'var(--font-script)', fontSize: 22, marginTop: 2, color: 'var(--orange)', lineHeight: 1 }}>yes, we got you.</div>
        </div>
        <img src="assets/mascots/kona-hug.png" alt="Kona"
          style={{
            width: 280, height: 'auto', position: 'relative', zIndex: 3,
            filter: 'drop-shadow(0 18px 22px rgba(0,0,0,0.4))',
          }} />
      </div>
    </div>
  </section>
);

// ---- TOP-LEVEL PAGE -------------------------------------------------------

const FAQPage = () => {
  const { useState, useMemo } = React;
  const [query, setQuery] = useState('');

  const total = useMemo(() => FAQ_DATA.reduce((s, g) => s + g.items.length, 0), []);

  const filtered = useMemo(() => {
    const q = query.trim().toLowerCase();
    if (!q) return FAQ_DATA;
    return FAQ_DATA.map(g => ({
      ...g,
      items: g.items.filter(it =>
        it.q.toLowerCase().includes(q) || it.a.toLowerCase().includes(q)
      ),
    }));
  }, [query]);

  const resultCount = filtered.reduce((s, g) => s + g.items.length, 0);

  const handleJump = (id) => {
    const el = document.getElementById(id);
    if (!el) return;
    const top = el.getBoundingClientRect().top + window.pageYOffset - 80;
    window.scrollTo({ top, behavior: 'smooth' });
  };

  return (
    <>
      <FAQHero totalQs={total} onJump={handleJump} />
      <FAQSearch
        query={query}
        onChange={setQuery}
        resultCount={resultCount}
        totalCount={total}
      />
      {filtered.map(g => (
        <FAQGroup key={g.id} group={g} query={query} />
      ))}
      <FAQContact />
    </>
  );
};

Object.assign(window, { FAQPage });
