// tokens.jsx — Design tokens, global CSS, and shared UI atoms

const SITE_TOKENS = {
  cream:    '#FBF7F0',
  cream2:   '#F4EEDE',
  paper:    '#FFFFFF',
  ink:      '#1F2A24',
  ink2:     '#3A4641',
  muted:    '#6B7268',
  line:     '#E5DCC9',
  coral:    '#E8825A',
  forest:   '#2D5F4E',
  forestDk: '#1A3D32',
  sky:      '#7BAEC8',
  sun:      '#E8B84A',
};

function SiteStyles() {
  return (
    <style>{`
      *, *::before, *::after { box-sizing: border-box; }
      html { scroll-behavior: smooth; }
      [id] { scroll-margin-top: 78px; }
      body {
        margin: 0; padding: 0;
        font-family: 'Manrope', system-ui, sans-serif;
        color: #1F2A24; background: #FBF7F0;
        line-height: 1.5; -webkit-font-smoothing: antialiased;
      }
      h1, h2, h3, h4 {
        font-family: 'Bricolage Grotesque', system-ui, sans-serif;
        font-weight: 600; letter-spacing: -0.02em;
        margin: 0; line-height: 1.05; color: #1F2A24;
      }
      p { margin: 0; }
      a { color: inherit; text-decoration: none; }
      button { font-family: inherit; cursor: pointer; border: 0; }
      .serif { font-family: 'Newsreader', Georgia, serif; font-style: italic; font-weight: 500; }
      .eyebrow {
        font-size: 12px; font-weight: 600; letter-spacing: 0.14em;
        text-transform: uppercase; color: #6B7268;
      }
      @keyframes site-marquee {
        from { transform: translateX(0); }
        to   { transform: translateX(-50%); }
      }
      .marquee-track {
        display: flex; gap: 48px;
        width: max-content;
        animation: site-marquee 90s linear infinite;
      }
      .marquee-mask {
        overflow: hidden;
        mask-image: linear-gradient(to right, transparent, black 8%, black 92%, transparent);
        -webkit-mask-image: linear-gradient(to right, transparent, black 8%, black 92%, transparent);
      }
      .btn {
        display: inline-flex; align-items: center; gap: 8px;
        padding: 14px 22px; border-radius: 999px;
        font-weight: 600; font-size: 15px; transition: transform .15s, box-shadow .15s;
        text-decoration: none; border: 0; cursor: pointer;
      }
      .btn-primary { background: #2D5F4E; color: #FBF7F0; }
      .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(45,95,78,0.25); }
      .btn-secondary { background: #FFFFFF; color: #1F2A24; box-shadow: inset 0 0 0 1.5px #E5DCC9; }
      .btn-secondary:hover { background: #F4EEDE; }
      .chip {
        display: inline-flex; align-items: center; gap: 6px;
        padding: 6px 12px; border-radius: 999px;
        font-size: 12px; font-weight: 600;
        background: #FFFFFF; color: #1F2A24;
        box-shadow: inset 0 0 0 1px #E5DCC9;
      }
      .chip-dot { width: 8px; height: 8px; border-radius: 50%; }
      .dark-field::placeholder { color: rgba(251,247,240,0.5); }
      .card {
        background: #FFFFFF; border-radius: 20px;
        box-shadow: 0 1px 0 #E5DCC9, 0 12px 32px rgba(31,42,36,0.04);
      }
      .partner-card {
        transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s ease;
        cursor: pointer;
      }
      .partner-card:hover {
        transform: translateY(-6px);
        box-shadow: 0 16px 36px rgba(31,42,36,0.13);
      }
      .event-row {
        transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
        cursor: pointer; border-radius: 12px;
      }
      .event-row:hover { transform: translateX(10px); }
      .event-badge {
        transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
        transform-origin: center;
      }
      .event-row:hover .event-badge { transform: scale(1.14) rotate(-6deg); }

      /* Illustration hover animations */
      .illu-anim { transform-box: fill-box; transform-origin: center; }
      @keyframes illu-pulse   { 0%,100%{transform:scale(1);opacity:.25;} 50%{transform:scale(1.18);opacity:.52;} }
      @keyframes illu-sway    { 0%,100%{transform:rotate(0deg);} 50%{transform:rotate(3deg);} }
      @keyframes illu-glow    { 0%,100%{opacity:.18;} 50%{opacity:.52;} }
      @keyframes illu-twinkle { 0%,100%{transform:scale(1);opacity:1;} 50%{transform:scale(.55);opacity:.15;} }
      @keyframes illu-float   { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-7px);} }
      @keyframes illu-swing   { 0%,100%{transform:rotate(-10deg);} 50%{transform:rotate(10deg);} }
      @keyframes illu-spark   { 0%,100%{transform:scale(1);opacity:1;} 50%{transform:scale(1.35);opacity:.4;} }
      @keyframes illu-discfly { 0%,100%{transform:translate(0,0) rotate(0deg);} 50%{transform:translate(14px,-11px) rotate(28deg);} }
      @keyframes illu-bloom   { 0%,100%{transform:rotate(0deg);} 50%{transform:rotate(9deg);} }
      @keyframes illu-pop     { 0%,100%{transform:translateY(0) scale(1);} 45%{transform:translateY(-8px) scale(1.07);} }
      @keyframes illu-hop     { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-5px);} }
      @keyframes illu-treesway{ 0%,100%{transform:rotate(0deg);} 50%{transform:rotate(4deg);} }

      .project-card:hover .illu-corona     { animation: illu-pulse   1.8s ease-in-out infinite; }
      .project-card:hover .illu-stall      { animation: illu-sway    2s   ease-in-out infinite; }
      .project-card:hover .illu-lamp-glow  { animation: illu-glow    1.4s ease-in-out infinite; }
      .project-card:hover .illu-xmas-lt    { animation: illu-twinkle 1.2s ease-in-out infinite; }
      .project-card:hover .illu-beach-sun  { animation: illu-float   2s   ease-in-out infinite; }
      .project-card:hover .illu-gym-ball   { animation: illu-swing   1.2s ease-in-out infinite; }
      .project-card:hover .illu-bolt       { animation: illu-spark   0.9s ease-in-out infinite; }
      .project-card:hover .illu-disc       { animation: illu-discfly 1.5s ease-in-out infinite; }
      .project-card:hover .illu-flower-a   { animation: illu-bloom   1.8s ease-in-out infinite; }
      .project-card:hover .illu-flower-b   { animation: illu-bloom   1.8s ease-in-out infinite 0.32s; }
      .project-card:hover .illu-flower-c   { animation: illu-bloom   1.8s ease-in-out infinite 0.64s; }
      .project-card:hover .illu-bubble     { animation: illu-pop     1.4s ease-in-out infinite; }
      .project-card:hover .illu-runner     { animation: illu-hop     1s   ease-in-out infinite; }
      .project-card:hover .illu-bench-tree { animation: illu-treesway 2.5s ease-in-out infinite; }
    `}</style>
  );
}

function Logo({ size = 32 }) {
  return (
    <svg viewBox="0 0 64 64" width={size} height={size} style={{ display: 'block' }}>
      <circle cx="20" cy="20" r="10" fill={SITE_TOKENS.forest}/>
      <circle cx="44" cy="32" r="10" fill={SITE_TOKENS.coral}/>
      <circle cx="20" cy="44" r="10" fill={SITE_TOKENS.sun}/>
      <path d="M28 20 Q34 24 38 28" stroke={SITE_TOKENS.forest} strokeWidth="3" fill="none" strokeLinecap="round"/>
      <path d="M38 36 Q32 40 28 44" stroke={SITE_TOKENS.coral} strokeWidth="3" fill="none" strokeLinecap="round"/>
    </svg>
  );
}

function Wordmark({ size = 32, dark = false }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
      <Logo size={size}/>
      <div style={{ display: 'flex', flexDirection: 'column', lineHeight: 1 }}>
        <span style={{
          fontFamily: 'Bricolage Grotesque, sans-serif', fontWeight: 700,
          fontSize: size * 0.56, letterSpacing: '-0.02em',
          color: dark ? SITE_TOKENS.cream : SITE_TOKENS.ink,
        }}>Sandared</span>
        <span style={{
          fontFamily: 'Manrope, sans-serif', fontWeight: 500,
          fontSize: size * 0.32, letterSpacing: '0.08em', textTransform: 'uppercase',
          color: dark ? SITE_TOKENS.cream + 'bb' : SITE_TOKENS.muted,
          marginTop: 2,
        }}>Intresseförening</span>
      </div>
    </div>
  );
}

function Squiggle({ color, width = 200 }) {
  return (
    <svg viewBox="0 0 200 14" width={width} height={width * 0.07} style={{ display: 'block' }}>
      <path d="M2 9 Q40 2 80 8 T160 8 T198 6" stroke={color} strokeWidth="4" fill="none" strokeLinecap="round"/>
    </svg>
  );
}

function SectionHead({ eyebrow, title, subtitle, align = 'left', maxWidth = 640, titleSize = 56, color }) {
  return (
    <div style={{ textAlign: align, maxWidth, margin: align === 'center' ? '0 auto' : undefined }}>
      {eyebrow && <div className="eyebrow" style={{ color: color || SITE_TOKENS.muted, marginBottom: 14 }}>{eyebrow}</div>}
      <h2 style={{ fontSize: titleSize, color: color || SITE_TOKENS.ink, textWrap: 'balance' }}>{title}</h2>
      {subtitle && <p style={{ fontSize: 18, color: SITE_TOKENS.ink2, marginTop: 18, lineHeight: 1.55, textWrap: 'pretty' }}>{subtitle}</p>}
    </div>
  );
}

// ─── Kalenderverktyg ──────────────────────────────────────────────────────────
const CalendarUtils = (function () {
  function pad2(n) { return String(n).padStart(2, '0'); }
  function fmt(dateStr, timeStr, addHours) {
    const p = String(dateStr || '').split('-').map(Number);
    let hh = 9, mm = 0;
    if (timeStr && /\d{1,2}:\d{2}/.test(timeStr)) { const t = timeStr.split(':'); hh = +t[0]; mm = +t[1]; }
    const dt = new Date(p[0] || 1970, (p[1] || 1) - 1, p[2] || 1, hh, mm, 0);
    if (addHours) dt.setHours(dt.getHours() + addHours);
    return dt.getFullYear() + pad2(dt.getMonth() + 1) + pad2(dt.getDate()) + 'T' + pad2(dt.getHours()) + pad2(dt.getMinutes()) + '00';
  }
  function esc(s) { return String(s || '').replace(/\\/g, '\\\\').replace(/;/g, '\\;').replace(/,/g, '\\,').replace(/\n/g, '\\n'); }
  function slug(s) { return String(s || 'event').toLowerCase().replace(/[åä]/g, 'a').replace(/ö/g, 'o').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40); }

  function buildICS(ev) {
    return [
      'BEGIN:VCALENDAR', 'VERSION:2.0', 'PRODID:-//Sandared//Kalender//SV', 'CALSCALE:GREGORIAN',
      'BEGIN:VEVENT',
      'UID:' + slug(ev.title) + '-' + (ev.date || '') + '@sandared.se',
      'DTSTART:' + fmt(ev.date, ev.time, 0),
      'DTEND:' + fmt(ev.date, ev.time, 2),
      'SUMMARY:' + esc(ev.title),
      ev.place ? 'LOCATION:' + esc(ev.place) : '',
      'END:VEVENT', 'END:VCALENDAR',
    ].filter(Boolean).join('\r\n');
  }

  function downloadICS(ev) {
    const blob = new Blob([buildICS(ev)], { type: 'text/calendar;charset=utf-8' });
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url; a.download = slug(ev.title) + '.ics';
    document.body.appendChild(a); a.click(); document.body.removeChild(a);
    setTimeout(function () { URL.revokeObjectURL(url); }, 2000);
  }

  function googleUrl(ev) {
    const dates = fmt(ev.date, ev.time, 0) + '/' + fmt(ev.date, ev.time, 2);
    let u = 'https://calendar.google.com/calendar/render?action=TEMPLATE'
      + '&text=' + encodeURIComponent(ev.title || '')
      + '&dates=' + dates + '&ctz=Europe/Stockholm';
    if (ev.place) u += '&location=' + encodeURIComponent(ev.place);
    return u;
  }

  function isoLocal(ev, addH) {
    const f = fmt(ev.date, ev.time, addH); // YYYYMMDDTHHMMSS
    return f.slice(0, 4) + '-' + f.slice(4, 6) + '-' + f.slice(6, 8) + 'T' + f.slice(9, 11) + ':' + f.slice(11, 13) + ':' + f.slice(13, 15);
  }
  function outlookEventUrl(ev) {
    let u = 'https://outlook.live.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent';
    u += '&subject=' + encodeURIComponent(ev.title || '');
    u += '&startdt=' + encodeURIComponent(isoLocal(ev, 0)) + '&enddt=' + encodeURIComponent(isoLocal(ev, 2));
    if (ev.place) u += '&location=' + encodeURIComponent(ev.place);
    return u;
  }

  function addToCalendar(ev) {
    // Dator: öppna Google Kalender i ny flik (kalendern öppnas direkt).
    // Mobil: ladda ner .ics som öppnar enhetens kalenderapp.
    if (window.innerWidth >= 768) {
      window.open(googleUrl(ev), '_blank', 'noopener');
    } else {
      downloadICS(ev);
    }
  }

  // webcal:// öppnar kalender-appen för prenumeration
  function subscribeUrl() { return 'webcal://' + window.location.host + '/api/ics'; }
  function feedUrl() { return window.location.origin + '/api/ics'; }

  function subscribe() {
    // Mobil: webcal öppnar kalenderappen direkt och lägger till prenumerationen.
    if (window.innerWidth < 768) {
      window.location.href = subscribeUrl();
      return;
    }
    // Dator: kopiera den fullständiga https-länken (webcal:// fungerar dåligt
    // i bl.a. Outlook på dator). Användaren klistrar in den under
    // "Prenumerera på kalender / Lägg till från webben".
    const url = feedUrl();
    const help = 'Lägg till den i din kalender via "Prenumerera på kalender" / "Lägg till från webben" (Google, Apple eller Outlook).';
    if (navigator.clipboard && navigator.clipboard.writeText) {
      navigator.clipboard.writeText(url).then(
        function () { window.alert('✓ Kalenderlänk kopierad:\n\n' + url + '\n\n' + help); },
        function () { window.prompt(help, url); }
      );
    } else {
      window.prompt(help, url);
    }
  }

  return { addToCalendar, downloadICS, googleUrl, outlookEventUrl, subscribeUrl, feedUrl, subscribe };
})();

// Swish-betalningslänk — öppnar Swish-appen (mobil) / Swish web (dator)
// med förifyllt nummer och belopp. Meddelandet går att redigera.
function swishUrl(amount, message) {
  let u = 'https://app.swish.nu/1/p/sw/?sw=1230223628&cur=SEK&edit=msg';
  if (amount) u += '&amt=' + encodeURIComponent(amount);
  if (message) u += '&msg=' + encodeURIComponent(message);
  return u;
}

// ─── Info-anmälan (nyhetsbrev/informationsregister) ──────────────────────────
function InfoSignup({ dark }) {
  const T = SITE_TOKENS;
  const [email, setEmail] = React.useState('');
  const [done, setDone] = React.useState(false);
  const submit = async (e) => {
    e.preventDefault();
    if (!email.trim()) return;
    try { await window.API.post('subscribers', { email: email.trim() }); } catch (err) {}
    setDone(true);
  };
  if (done) {
    return (
      <div style={{ fontSize: 13, color: dark ? T.cream + 'cc' : T.ink2, display: 'flex', alignItems: 'center', gap: 8 }}>
        <svg width="16" height="16" viewBox="0 0 24 24"><path d="M5 13 L10 18 L20 7" stroke={dark ? T.sun : T.forest} strokeWidth="2.5" fill="none" strokeLinecap="round"/></svg>
        Tack! Du får nu information från oss.
      </div>
    );
  }
  return (
    <form onSubmit={submit} style={{ display: 'flex', gap: 8, maxWidth: 360 }}>
      <input
        type="email" required value={email} onChange={e => setEmail(e.target.value)}
        placeholder="din@epost.se" aria-label="E-postadress"
        className={dark ? 'dark-field' : ''}
        style={{ flex: 1, padding: '12px 14px', borderRadius: 10, border: 0, fontSize: 14, fontFamily: 'inherit', outline: 'none', background: dark ? 'rgba(255,255,255,0.1)' : T.paper, color: dark ? T.cream : T.ink, boxShadow: dark ? `inset 0 0 0 1.5px ${T.cream}33` : `inset 0 0 0 1.5px ${T.line}`, boxSizing: 'border-box' }}
      />
      <button type="submit" className="btn btn-primary" style={{ background: T.coral, color: '#fff', padding: '0 18px', fontSize: 14, flexShrink: 0 }}>Anmäl →</button>
    </form>
  );
}

// ─── Modal: lägg till kalendern (Outlook / Google / Apple) ───────────────────
function CalSubscribeModal({ onClose }) {
  const T = SITE_TOKENS;
  const feed = CalendarUtils.feedUrl();          // https://.../api/ics
  const webcal = CalendarUtils.subscribeUrl();   // webcal://.../api/ics
  const NAME = 'Sandareds Intresseförening';
  const googleHref  = 'https://calendar.google.com/calendar/render?cid=' + encodeURIComponent(webcal);
  const outlookHref = 'https://outlook.live.com/calendar/0/addfromweb?url=' + encodeURIComponent(feed) + '&name=' + encodeURIComponent(NAME);
  const [copied, setCopied] = React.useState(false);

  const copy = () => {
    if (navigator.clipboard && navigator.clipboard.writeText) {
      navigator.clipboard.writeText(feed).then(() => setCopied(true), () => window.prompt('Kopiera länken:', feed));
    } else { window.prompt('Kopiera länken:', feed); }
  };

  const calIcon = (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke={T.forest} strokeWidth="2" strokeLinecap="round"><rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 9 H21 M8 3 V7 M16 3 V7"/></svg>
  );
  const Row = ({ href, onClick, title, sub }) => (
    <a href={href || '#'} target={href ? '_blank' : undefined} rel="noopener"
      onClick={(e) => { if (onClick) { e.preventDefault(); onClick(); } else { onClose && setTimeout(onClose, 50); } }}
      style={{ display: 'flex', alignItems: 'center', gap: 14, padding: '14px 16px', borderRadius: 14, background: T.cream, boxShadow: `inset 0 0 0 1.5px ${T.line}`, textDecoration: 'none', color: T.ink, cursor: 'pointer' }}>
      <div style={{ width: 40, height: 40, borderRadius: 10, background: T.forest + '14', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>{calIcon}</div>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ fontWeight: 600, fontSize: 15 }}>{title}</div>
        <div style={{ fontSize: 12.5, color: T.muted, marginTop: 1 }}>{sub}</div>
      </div>
      <span style={{ color: T.muted, fontSize: 18, flexShrink: 0 }}>→</span>
    </a>
  );

  return (
    <div onClick={onClose} style={{ position: 'fixed', inset: 0, background: 'rgba(31,42,36,0.6)', backdropFilter: 'blur(4px)', WebkitBackdropFilter: 'blur(4px)', zIndex: 6000, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 18 }}>
      <div onClick={e => e.stopPropagation()} style={{ background: T.paper, borderRadius: 24, padding: 28, width: '100%', maxWidth: 460, maxHeight: '90vh', overflowY: 'auto', boxShadow: '0 30px 80px rgba(0,0,0,0.32)' }}>
        <h3 style={{ fontSize: 24, marginBottom: 6 }}>Lägg till vår kalender</h3>
        <p style={{ fontSize: 14, color: T.ink2, marginBottom: 18, lineHeight: 1.5 }}>Välj din kalender — alla event uppdateras automatiskt när vi lägger till nya.</p>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
          <Row href={googleHref} title="Google Kalender (Gmail)" sub="Öppnas i Google Kalender"/>
          <Row href={webcal} title="Apple Kalender" sub="Öppnas i Kalender på Mac/iPhone"/>
          <Row href={outlookHref} title="Outlook" sub="Öppnas i Outlook på webben"/>
          <Row onClick={copy} title={copied ? 'Länk kopierad ✓' : 'Kopiera länk'} sub={copied ? feed : 'För Outlook (dator) m.fl. — klistra in i "Lägg till från webben"'}/>
        </div>
        <button onClick={onClose} className="btn btn-secondary" style={{ width: '100%', justifyContent: 'center', marginTop: 18 }}>Stäng</button>
      </div>
    </div>
  );
}

// ─── Modal: lägg till ett enskilt event (Outlook / Google / Apple) ───────────
function CalAddModal({ ev, onClose }) {
  const T = SITE_TOKENS;
  const calIcon = (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke={T.forest} strokeWidth="2" strokeLinecap="round"><rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 9 H21 M8 3 V7 M16 3 V7"/></svg>
  );
  const Row = ({ href, onClick, title, sub }) => (
    <a href={href || '#'} target={href ? '_blank' : undefined} rel="noopener"
      onClick={(e) => { if (onClick) { e.preventDefault(); onClick(); } if (onClose) setTimeout(onClose, 50); }}
      style={{ display: 'flex', alignItems: 'center', gap: 14, padding: '14px 16px', borderRadius: 14, background: T.cream, boxShadow: `inset 0 0 0 1.5px ${T.line}`, textDecoration: 'none', color: T.ink, cursor: 'pointer' }}>
      <div style={{ width: 40, height: 40, borderRadius: 10, background: T.forest + '14', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>{calIcon}</div>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ fontWeight: 600, fontSize: 15 }}>{title}</div>
        <div style={{ fontSize: 12.5, color: T.muted, marginTop: 1 }}>{sub}</div>
      </div>
      <span style={{ color: T.muted, fontSize: 18, flexShrink: 0 }}>→</span>
    </a>
  );
  return (
    <div onClick={onClose} style={{ position: 'fixed', inset: 0, background: 'rgba(31,42,36,0.6)', backdropFilter: 'blur(4px)', WebkitBackdropFilter: 'blur(4px)', zIndex: 6000, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 18 }}>
      <div onClick={e => e.stopPropagation()} style={{ background: T.paper, borderRadius: 24, padding: 28, width: '100%', maxWidth: 460, maxHeight: '90vh', overflowY: 'auto', boxShadow: '0 30px 80px rgba(0,0,0,0.32)' }}>
        <h3 style={{ fontSize: 23, marginBottom: 4 }}>Lägg till i kalendern</h3>
        <p style={{ fontSize: 14, color: T.ink2, marginBottom: 18, lineHeight: 1.5 }}><strong>{ev.title}</strong>{ev.date ? ' · ' + ev.date : ''}</p>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
          <Row href={CalendarUtils.googleUrl(ev)} title="Google Kalender (Gmail)" sub="Öppnas i Google Kalender"/>
          <Row href={CalendarUtils.outlookEventUrl(ev)} title="Outlook" sub="Öppnas i Outlook på webben"/>
          <Row onClick={() => CalendarUtils.downloadICS(ev)} title="Apple Kalender" sub="Öppnar Kalender på Mac/iPhone (.ics)"/>
          <Row onClick={() => CalendarUtils.downloadICS(ev)} title="Ladda ner (.ics)" sub="För Outlook på dator m.fl."/>
        </div>
        <button onClick={onClose} className="btn btn-secondary" style={{ width: '100%', justifyContent: 'center', marginTop: 18 }}>Stäng</button>
      </div>
    </div>
  );
}

// ─── Integritetspolicy & cookies (modal) ────────────────────────────────────
function PolicyModal({ onClose }) {
  const T = SITE_TOKENS;
  React.useEffect(() => {
    const h = (e) => { if (e.key === 'Escape') onClose(); };
    window.addEventListener('keydown', h);
    return () => window.removeEventListener('keydown', h);
  }, [onClose]);

  const H = ({ children }) => <h3 style={{ fontSize: 19, marginTop: 22, marginBottom: 8 }}>{children}</h3>;
  const P = ({ children }) => <p style={{ fontSize: 14, color: T.ink2, lineHeight: 1.6, margin: '0 0 10px' }}>{children}</p>;

  return (
    <div onClick={onClose} style={{ position: 'fixed', inset: 0, background: 'rgba(31,42,36,0.6)', backdropFilter: 'blur(5px)', WebkitBackdropFilter: 'blur(5px)', zIndex: 6500, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 18 }}>
      <div onClick={e => e.stopPropagation()} style={{ background: T.paper, borderRadius: 22, padding: '30px 32px', width: '100%', maxWidth: 620, maxHeight: '88vh', overflowY: 'auto', boxShadow: '0 30px 80px rgba(0,0,0,0.32)', position: 'relative' }}>
        <button onClick={onClose} aria-label="Stäng" style={{ position: 'absolute', top: 16, right: 16, width: 34, height: 34, borderRadius: '50%', background: T.cream2, border: 0, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <svg width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M1 1 L11 11 M11 1 L1 11" stroke={T.ink2} strokeWidth="2" strokeLinecap="round"/></svg>
        </button>

        <div className="eyebrow" style={{ marginBottom: 8 }}>Integritet</div>
        <h2 style={{ fontSize: 28 }}>Integritetspolicy &amp; cookies</h2>

        <H>Personuppgiftsansvarig</H>
        <P>Sandareds Intresseförening (org.nr 802431-1857) ansvarar för de personuppgifter du lämnar via sandared.se. Du når oss på <a href="mailto:info@sandared.se" style={{ color: T.forest }}>info@sandared.se</a>.</P>

        <H>Vilka uppgifter vi samlar in</H>
        <P>Namn, adress, e-postadress och telefonnummer — de uppgifter du själv anger när du blir medlem, anmäler dig eller ditt företag till ett evenemang, föreslår ett projekt eller anmäler dig till vårt informationsutskick.</P>

        <H>Varför och med vilken laglig grund</H>
        <P>Vi behandlar uppgifterna för att administrera medlemskap, hantera anmälningar till evenemang, skicka information och kontakta dig i föreningsärenden. Laglig grund är fullgörande av medlemsavtal, samtycke (informationsutskick) samt berättigat intresse (evenemang och föreningskommunikation).</P>

        <H>Var och hur länge uppgifterna lagras</H>
        <P>Uppgifterna lagras säkert hos Microsoft Azure inom EU. De sparas så länge du är medlem eller tills du ber oss ta bort dem. Anmälningar och projektförslag gallras när de inte längre behövs.</P>

        <H>Delning med andra</H>
        <P>Vi säljer eller delar aldrig dina uppgifter med tredje part i marknadsförings­syfte. Uppgifterna behandlas av föreningen och av vår tekniska leverantör (Microsoft Azure) som personuppgiftsbiträde.</P>

        <H>Dina rättigheter</H>
        <P>Du har rätt att begära tillgång till, rättelse eller radering av dina uppgifter, samt att invända mot eller begränsa behandlingen. Kontakta <a href="mailto:info@sandared.se" style={{ color: T.forest }}>info@sandared.se</a>. Du kan även lämna klagomål till Integritetsskyddsmyndigheten (IMY).</P>

        <H>Cookies</H>
        <P>sandared.se använder <strong>inga cookies för spårning, analys eller marknadsföring</strong>. För inloggning i föreningens admin-panel används webbläsarens <em>sessionStorage</em> för att hålla styrelsen inloggad — den informationen ligger kvar tills fliken stängs och delas inte med någon. Typsnitt laddas från Google Fonts, vilket innebär att Google kan ta emot din IP-adress vid sidladdning. Eftersom vi inte använder spårningscookies behövs inget samtycke.</P>

        <div style={{ marginTop: 24 }}>
          <button onClick={onClose} className="btn btn-primary">Jag förstår</button>
        </div>
      </div>
    </div>
  );
}

function openPolicy() { window.dispatchEvent(new CustomEvent('sint-open-policy')); }

Object.assign(window, { SITE_TOKENS, SiteStyles, Logo, Wordmark, Squiggle, SectionHead, CalendarUtils, InfoSignup, swishUrl, CalSubscribeModal, CalAddModal, PolicyModal, openPolicy });
