// screens2.jsx — Stamp pass, Reservation, Rooms, Beer, Info

// ─────────────────────────────────────────────────────────────
// Default editable app data (passed down from App via appData prop)
// ─────────────────────────────────────────────────────────────
const DEFAULT_APP_DATA = {
  hours: [
  { day: 'Do – Sa', times: ['17:00 – 21:30'], closed: false },
  { day: 'Sonntag', times: ['11:30 – 14:30', '17:00 – 21:00'], closed: false },
  { day: 'Mo – Mi', times: ['Ruhetag'], closed: true }],

  contact: {
    address: 'Kirchplatz 2 · 97292 Uettingen',
    phone: '09369 - 8221',
    email: 'kontakt@alte-brauerei.de',
    whatsapp: 'https://wa.me/4993698221',
    ebike: '6 kostenfreie Stationen am Hof',
    wall: '2 Wallboxen · je 11 kW'
  },
  home: {
    name: 'Brauerei Zapf',
    tagline: 'Familiengeführt seit 1883.\nFrisch g\'zapft, frisch g\'kocht.'
  },
  news: {
    icon: 'bike',
    text: 'Sechs E-Bike-Ladestationen',
    sub: 'Kostenfrei am Hof — Kabel bitte mitbringen.'
  },
  platzampel: {
    schichten: [
    { label: 'Do Abend', status: 'grün' },
    { label: 'Fr Abend', status: 'grün' },
    { label: 'Sa Abend', status: 'grün' },
    { label: 'So Mittag', status: 'grün' },
    { label: 'So Abend', status: 'grün' }]

  },
  wochenkarte: {
    kw: '21',
    do: [
    { name: 'Frühlings-„Brizza"', desc: 'Brezelteig-Pizza · Knoblauchschmand, Feta, grüner Spargel, Paprika, Zucchini, rote Zwiebelringe', price: '16,50' },
    { name: 'Paniertes Jägerschnitzel', desc: 'mit Rahmpilzen, Wedges und Beilagensalat', price: '19,90' }],

    fr: [
    { name: 'Frühlings-„Brizza"', desc: 'Brezelteig-Pizza · Knoblauchschmand, Feta, grüner Spargel, Paprika, Zucchini, rote Zwiebelringe', price: '16,50' },
    { name: 'Paniertes Jägerschnitzel', desc: 'mit Rahmpilzen, Wedges und Beilagensalat', price: '19,90' }],

    sa: [
    { name: 'Pikanter Schaschliktopf', desc: 'o. Innereien · mit Pommes frites und Beilagensalat', price: '18,50' },
    { name: 'Rinderbraten', desc: 'mit Burgundersauce, Kartoffelklößen und Salat oder Wirsing', price: '22,50' }],

    so: [
    { name: 'Pikanter Schaschliktopf', desc: 'o. Innereien · mit Pommes frites und Beilagensalat', price: '18,50' },
    { name: 'Rinderbraten', desc: 'mit Burgundersauce, Kartoffelklößen und Salat oder Wirsing', price: '22,50' }],

    bild: ''
  },
  sonderbier: {
    name: 'Vaters Freude',
    desc: 'Dunkel, herb, obergärig, leichte Trübung',
    price: '3,50'
  },
  sonderzeiten: {
    betriebsruhe: [
    { von: '02.07.26', bis: '05.07.26' },
    { von: '27.08.26', bis: '13.09.26' },
    { von: '05.11.26', bis: '08.11.26' },
    { von: '24.12.26', bis: '06.01.27' }],

    feiertage: [
    { datum: '01.05.2026', name: 'Tag der Arbeit (Fr)', zeit: 'ab 17:00' },
    { datum: '14.05.2026', name: 'Christi Himmelfahrt (Do)', zeit: 'ab 17:00' },
    { datum: '25.05.2026', name: 'Pfingstmontag (Mo)', zeit: 'ab 11:30' },
    { datum: '04.06.2026', name: 'Fronleichnam (Do)', zeit: 'ab 17:00' },
    { datum: '15.08.2026', name: 'Mariä Himmelfahrt (Sa)', zeit: 'ab 17:00' },
    { datum: '03.10.2026', name: 'Tag der dt. Einheit (Sa)', zeit: 'ab 17:00' },
    { datum: '01.11.2026', name: 'Allerheiligen (So)', zeit: 'ab 11:30' },
    { datum: '25.12.2026', name: 'Weihnachten (Fr)', zeit: 'geschlossen' },
    { datum: '26.12.2026', name: 'Weihnachten (Sa)', zeit: 'geschlossen' }]

  }
};

// ─────────────────────────────────────────────────────────────
// STEMPELPASS — hero feature
// ─────────────────────────────────────────────────────────────
const MILESTONES = [
{ at: 5, label: 'Ein Hausbier', sub: 'aufs Haus', icon: 'beer', earned: 5 },
{ at: 10, label: 'Cocktail nach Wahl', sub: 'aufs Haus', icon: 'sparkle', earned: 10 },
{ at: 20, label: 'Günstigstes Gericht frei', sub: 'von allen bestellten Speisen des Abends', icon: 'heart', earned: 20 }];


const STAMP_PHRASE = "PROST AUF UETTINGEN!";

const StampPassScreen = ({ palette, tweaks, stamps, setStamps, openQR, guestId, restoreByGuestId, stampsLoading }) => {
  const style = tweaks.stampStyle || 'bierdeckel';
  const next = MILESTONES.find((m) => stamps < m.at) || MILESTONES[2];
  const remaining = Math.max(0, next.at - stamps);
  const [showRestore, setShowRestore] = React.useState(false);
  const [restoreInput, setRestoreInput] = React.useState('');
  const [restoreMsg, setRestoreMsg] = React.useState('');

  const doRestore = async () => {
    if (restoreInput.length < 5) { setRestoreMsg('Bitte vollständige ID eingeben (z.B. ZB-4A2F)'); return; }
    const ok = await restoreByGuestId(restoreInput);
    setRestoreMsg(ok ? '✓ Stempel wiederhergestellt!' : '✗ ID nicht gefunden.');
    if (ok) setTimeout(() => setShowRestore(false), 1500);
  };

  return (
    <PaperBg palette={palette}>
      <div style={{ padding: '22px 22px 6px' }}>
        <SectionLabel palette={palette}>Wirtshaus-Pass</SectionLabel>
        <H1 palette={palette} style={{ fontSize: 30, marginTop: 6 }}>
          Deine <i style={{ color: palette.accent }}>Stempelkarte</i>
        </H1>
        <div style={{ fontSize: 13, color: palette.muted, marginTop: 6, lineHeight: 1.45 }}>
          Für jeden Besuch ein Stempel — Code beim Personal erfragen.
        </div>
      </div>

      {/* The card itself */}
      <div style={{ padding: '18px 22px 6px' }}>
        {style === 'bierdeckel' && <BierdeckelCard palette={palette} stamps={stamps} />}
        {style === 'klassisch' && <ClassicCard palette={palette} stamps={stamps} />}
        {style === 'krug' && <KrugCard palette={palette} stamps={stamps} />}
      </div>

      {/* Action buttons */}
      <div style={{ padding: '14px 22px 4px' }}>
        <button onClick={openQR} style={{
          width: '100%', background: palette.green, color: palette.cream,
          border: 'none', borderRadius: 12, padding: '14px',
          fontFamily: 'Manrope, sans-serif', fontWeight: 700, fontSize: 14,
          display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, cursor: 'pointer',
          boxShadow: `0 6px 14px ${palette.green}44`
        }}>
          <Icon name="plus" size={18} /> Stempel erhalten / Einlösen
        </button>
      </div>
      {/* Next milestone hint OR congratulations */}
      <div style={{ padding: '14px 22px 4px' }}>
        {stamps >= 20 ?
        <div style={{
          padding: 16, borderRadius: 14,
          background: `linear-gradient(135deg, ${palette.accent}, ${palette.accentDark})`,
          color: palette.cream, textAlign: 'center',
          boxShadow: `0 6px 20px ${palette.accent}44`
        }}>
            <div style={{ fontSize: 28, marginBottom: 6 }}>🎉</div>
            <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 20, lineHeight: 1.1, marginBottom: 6 }}>
              Herzlichen Glückwunsch!
            </div>
            <div style={{ fontSize: 12.5, opacity: 0.9, lineHeight: 1.5 }}>
              Du hast alle 20 Stempel gesammelt. Vielen Dank für deine Treue — zeige diese Karte beim Personal zum Einlösen.
            </div>
          </div> :

        <div style={{
          padding: 14, borderRadius: 14,
          background: palette.green, color: palette.cream,
          display: 'flex', alignItems: 'center', gap: 12
        }}>
            <div style={{ width: 38, height: 38, borderRadius: 19, background: palette.accent, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
              <Icon name={next.icon} size={20} color={palette.cream} />
            </div>
            <div style={{ flex: 1, fontSize: 13, lineHeight: 1.35 }}>
              <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 15, marginBottom: 2 }}>
                Noch <span style={{ color: palette.accent }}>{remaining || 1}</span> Stempel bis <i>{next.label}</i>
              </div>
              <div style={{ opacity: 0.8 }}>{next.sub}</div>
            </div>
          </div>
        }
      </div>

      {/* Google-Bewertung = Stempel */}
      <div style={{ padding: '14px 22px 28px' }}>
        <div style={{
          borderRadius: 16, overflow: 'hidden',
          border: `1px solid ${palette.green}20`
        }}>
          <div style={{ background: palette.green, padding: '12px 16px', display: 'flex', alignItems: 'center', gap: 10 }}>
            <span style={{ fontSize: 20 }}>⭐</span>
            <div style={{ flex: 1 }}>
              <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 16, color: palette.cream, lineHeight: 1.1 }}>Bewertung = Stempel</div>
              <div style={{ fontSize: 11.5, color: palette.cream, opacity: 0.8, marginTop: 2 }}>Google-Bewertung abgeben → +1 Stempel extra</div>
            </div>
          </div>
          <div style={{ background: palette.paper, padding: 14 }}>
            <div style={{ fontSize: 12.5, color: palette.ink, lineHeight: 1.5, marginBottom: 12 }}>
              Hinterlasse uns eine Google-Bewertung und zeige sie dem Personal. Du bekommst dafür einen <b>Bonus-Stempel</b>!
            </div>
            <a href="https://g.page/brauereizapf/review?rc" target="_blank" rel="noreferrer" style={{
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
              padding: '11px', borderRadius: 10, textDecoration: 'none',
              background: '#4285F4', color: '#fff',
              fontFamily: 'Manrope', fontWeight: 700, fontSize: 13,
              marginBottom: 10
            }}>
              <svg width="16" height="16" viewBox="0 0 24 24" fill="white"><path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm0 18a8 8 0 110-16 8 8 0 010 16zm-1-8v-4h2v4h4v2h-4v4h-2v-4H7v-2h4z" /></svg>
              Jetzt bei Google bewerten
            </a>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '8px 12px', borderRadius: 8, background: palette.green + '10', border: `1px solid ${palette.green}15` }}>
              <div style={{ fontSize: 11.5, color: palette.muted, fontFamily: 'Manrope' }}>Code vom Personal erfragen</div>
              <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 14, color: palette.muted }}>_ _ _ _</div>
            </div>
            <div style={{ fontSize: 10.5, color: palette.muted, marginTop: 6, textAlign: 'center', lineHeight: 1.4 }}>
              Bewertung zeigen → Personal gibt dir einen Code → +1 Stempel
            </div>
          </div>
        </div>
      </div>

      {/* Belohnungen */}
      <div style={{ padding: '22px 22px 28px' }}>
        <SectionLabel palette={palette}>Was du bekommst</SectionLabel>
        <div style={{ marginTop: 12, display: 'flex', flexDirection: 'column', gap: 10 }}>
          {MILESTONES.map((m) => {
            const got = stamps >= m.at;
            return (
              <div key={m.at} style={{
                display: 'flex', alignItems: 'center', gap: 14,
                padding: 14, borderRadius: 14,
                background: got ? palette.accent + '14' : palette.paper,
                border: `1px solid ${got ? palette.accent + '50' : palette.green + '15'}`,
                position: 'relative', overflow: 'hidden'
              }}>
                {/* Big number */}
                <div style={{
                  width: 48, height: 48, borderRadius: 24,
                  background: got ? palette.accent : palette.green + '14',
                  color: got ? palette.cream : palette.green,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  fontFamily: '"DM Serif Display", serif', fontSize: 22, flexShrink: 0
                }}>{m.at}</div>
                <div style={{ flex: 1 }}>
                  <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 17, color: palette.ink, lineHeight: 1.15 }}>{m.label}</div>
                  <div style={{ fontSize: 12, color: palette.muted, marginTop: 2 }}>{m.sub}</div>
                </div>
                {got ?
                <div style={{ display: 'flex', alignItems: 'center', gap: 4, color: palette.accentDark, fontSize: 11, fontWeight: 700, fontFamily: 'JetBrains Mono, monospace', textTransform: 'uppercase', letterSpacing: 0.2 }}><Icon name="check" size={14} /> Erreicht</div> :
                <div style={{ fontSize: 11, color: palette.muted, fontFamily: 'JetBrains Mono, monospace' }}>{m.at - stamps} fehlen</div>}
              </div>);

          })}
        </div>
      </div>

      {/* Guest ID + Restore */}
      <div style={{ padding:'0 22px 28px' }}>
        {stampsLoading ? (
          <div style={{ textAlign:'center', color:palette.muted, fontSize:12, padding:'8px 0' }}>Lade Stempel…</div>
        ) : (
          <div style={{
            padding:'12px 14px', borderRadius:12,
            background:palette.paper, border:`1px solid ${palette.green}15`,
          }}>
            <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between' }}>
              <div>
                <div style={{ fontFamily:'JetBrains Mono, monospace', fontSize:9.5, letterSpacing:'0.14em', textTransform:'uppercase', color:palette.muted }}>Deine Karten-ID</div>
                <div style={{ fontFamily:'"DM Serif Display", serif', fontSize:18, color:palette.green, letterSpacing:4, marginTop:2 }}>{guestId || '…'}</div>
                <div style={{ fontSize:10.5, color:palette.muted, marginTop:2 }}>Screenshot machen — zum Wiederherstellen</div>
              </div>
              <button onClick={() => setShowRestore(v => !v)} style={{
                padding:'6px 10px', borderRadius:8, border:`1px solid ${palette.green}25`,
                background:'transparent', cursor:'pointer', fontFamily:'Manrope', fontSize:11, color:palette.muted,
              }}>Restore</button>
            </div>
            {showRestore && (
              <div style={{ marginTop:12, display:'flex', flexDirection:'column', gap:8 }}>
                <div style={{ fontFamily:'JetBrains Mono, monospace', fontSize:10, color:palette.muted, letterSpacing:'0.1em', textTransform:'uppercase' }}>Alte ID eingeben</div>
                <div style={{ display:'flex', gap:6 }}>
                  <input
                    value={restoreInput}
                    onChange={e => { setRestoreInput(e.target.value.toUpperCase()); setRestoreMsg(''); }}
                    placeholder="ZB-XXXX"
                    style={{
                      flex:1, padding:'9px 12px', background:palette.cream,
                      border:`1px solid ${palette.green}25`, borderRadius:8,
                      fontFamily:'JetBrains Mono, monospace', fontSize:14, color:palette.ink,
                      letterSpacing:2, outline:'none', textTransform:'uppercase',
                    }}
                  />
                  <button onClick={doRestore} style={{
                    padding:'9px 14px', borderRadius:8, border:'none', cursor:'pointer',
                    background:palette.green, color:palette.cream, fontFamily:'Manrope', fontWeight:700, fontSize:13,
                  }}>OK</button>
                </div>
                {restoreMsg && <div style={{ fontSize:12, color: restoreMsg.startsWith('✓') ? palette.green : '#ef4444', fontFamily:'Manrope' }}>{restoreMsg}</div>}
              </div>
            )}
          </div>
        )}
      </div>
    </PaperBg>);

};

const BierdeckelCard = ({ palette, stamps }) =>
<div style={{
  width: '100%', borderRadius: 18,
  background: palette.cream,
  boxShadow: `0 12px 32px ${palette.ink}25, 0 0 0 1px ${palette.green}10`,
  padding: '14px 14px 40px', position: 'relative', overflow: 'hidden',
  backgroundImage: `radial-gradient(circle at 50% 50%, ${palette.cream} 0%, ${palette.cream} 92%, ${palette.green}15 100%)`
}}>
    {/* Outer & inner rings */}
    <div style={{ position: 'absolute', inset: 8, borderRadius: 14, border: `2px solid ${palette.green}`, pointerEvents: 'none' }} />
    <div style={{ position: 'absolute', inset: 14, borderRadius: 12, border: `1px dashed ${palette.green}50`, pointerEvents: 'none' }} />

    {/* Header */}
    <div style={{ textAlign: 'center', paddingTop: 16, paddingBottom: 4 }}>
      <HopGlyph size={28} color={palette.accent} />
      <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 18, color: palette.green, letterSpacing: '0.06em', marginTop: 4 }}>BRAUEREI ZAPF</div>
      <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9, letterSpacing: '0.22em', color: palette.muted, textTransform: 'uppercase' }}>Wirtshaus-Pass · seit 1883</div>
    </div>

    {/* 5×4 stamp grid — fixed size cells so all 20 fit */}
    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gap: 6, padding: '16px 18px 8px' }}>
      {Array.from({ length: 20 }).map((_, i) => {
      const filled = i < stamps;
      const isMilestone = [4, 9, 19].includes(i);
      return (
        <div key={i} style={{
          aspectRatio: '1/1', borderRadius: '50%',
          border: `1.5px ${filled ? 'solid' : 'dashed'} ${filled ? palette.accent : palette.green + '40'}`,
          background: filled ? palette.accent : 'transparent',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          position: 'relative',
          transform: filled ? `rotate(${i * 37 % 30 - 15}deg)` : 'none',
          transition: 'all 0.4s cubic-bezier(.5,1.6,.4,1)'
        }}>
            {filled &&
          <span style={{ fontFamily: '"DM Serif Display", serif', fontSize: 12, fontWeight: 700, color: palette.cream, lineHeight: 1, userSelect: 'none' }}>
                {STAMP_PHRASE[i]}
              </span>
          }
            {isMilestone &&
          <span style={{
            position: 'absolute', top: -5, right: -2, fontSize: 7.5,
            background: filled ? palette.accentDark : palette.green,
            color: palette.cream, padding: '1px 3px',
            borderRadius: 4, fontFamily: 'JetBrains Mono, monospace', lineHeight: 1.4
          }}>{i + 1}</span>
          }
          </div>);

    })}
    </div>

    {/* footer */}
    <div style={{
    position: 'absolute', bottom: 14, left: 0, right: 0, textAlign: 'center',
    fontFamily: 'JetBrains Mono, monospace', fontSize: 9, color: palette.muted,
    letterSpacing: '0.18em', textTransform: 'uppercase'
  }}>
      {stamps} / 20 · Kirchplatz 2 · Uettingen
    </div>
  </div>;


// Card style 2: Classic gastronomy stamp card — rectangular
const ClassicCard = ({ palette, stamps }) =>
<div style={{
  width: '100%', borderRadius: 16, background: palette.paper,
  boxShadow: `0 12px 32px ${palette.ink}20`,
  overflow: 'hidden', position: 'relative'
}}>
    {/* Top strip */}
    <div style={{
    background: palette.green, color: palette.cream, padding: '14px 18px',
    display: 'flex', alignItems: 'center', justifyContent: 'space-between'
  }}>
      <div>
        <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9.5, letterSpacing: '0.2em', opacity: 0.7 }}>SEIT 1883</div>
        <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, lineHeight: 1 }}>Stempelkarte</div>
      </div>
      <HopGlyph size={36} color={palette.accent} />
    </div>

    {/* Stamp grid 5x4 */}
    <div style={{ padding: 16, display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gap: 6 }}>
      {Array.from({ length: 20 }).map((_, i) => {
      const filled = i < stamps;
      return (
        <div key={i} style={{
          aspectRatio: '1/1', borderRadius: 8,
          border: `1.5px ${filled ? 'solid' : 'dashed'} ${filled ? palette.green : palette.green + '30'}`,
          background: filled ? palette.green : palette.cream,
          color: filled ? palette.accent : palette.green + '30',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          fontFamily: '"DM Serif Display", serif', fontSize: 12, fontWeight: 700,
          transform: filled ? `rotate(${i * 23 % 24 - 12}deg)` : 'none',
          transition: 'all 0.3s'
        }}>
            {filled ? STAMP_PHRASE[i] : i + 1}
          </div>);

    })}
    </div>

    {/* Footer with name */}
    <div style={{
    borderTop: `1px dashed ${palette.green}30`, padding: '10px 18px',
    display: 'flex', justifyContent: 'space-between', alignItems: 'center',
    fontFamily: 'JetBrains Mono, monospace', fontSize: 10, color: palette.muted
  }}>
      <span>NAME: M. WEBER</span>
      <span>{stamps}/20</span>
    </div>
  </div>;


// Card style 3: Krug-Sammlung — 20 mugs that fill up
const KrugCard = ({ palette, stamps }) =>
<div style={{
  width: '100%', borderRadius: 16, padding: 18,
  background: `linear-gradient(160deg, ${palette.greenDark} 0%, ${palette.green} 100%)`,
  color: palette.cream, position: 'relative', overflow: 'hidden',
  boxShadow: `0 12px 32px ${palette.ink}30`
}}>
    <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
      <div>
        <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9.5, letterSpacing: '0.2em', opacity: 0.7 }}>KRUG-SAMMLUNG</div>
        <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 24, lineHeight: 1 }}>Prost!</div>
      </div>
      <div style={{ textAlign: 'right' }}>
        <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 32, color: palette.accent, lineHeight: 1 }}>{stamps}</div>
        <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9, opacity: 0.7, letterSpacing: '0.15em' }}>/20</div>
      </div>
    </div>

    {/* Mug grid 5x4 */}
    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gap: 10, marginTop: 18 }}>
      {Array.from({ length: 20 }).map((_, i) => {
      const filled = i < stamps;
      const fillPct = filled ? 0.85 : 0;
      return (
        <svg key={i} viewBox="0 0 24 32" style={{ width: '100%', display: 'block' }}>
            {/* mug body */}
            <path d="M5 6 h12 v22 a2 2 0 0 1 -2 2 h-8 a2 2 0 0 1 -2 -2 z"
          fill={palette.cream + '15'} stroke={palette.cream + '70'} strokeWidth="1" />
            {/* handle */}
            <path d="M17 12 q5 0 5 6 t-5 6" fill="none" stroke={palette.cream + '70'} strokeWidth="1" />
            {/* beer fill */}
            {filled &&
          <rect x="6.5" y={8 + (1 - fillPct) * 20} width="9" height={fillPct * 20} fill={palette.accent} opacity="0.95" />
          }
            {/* foam */}
            {filled &&
          <ellipse cx="11" cy={9 + (1 - fillPct) * 20} rx="5" ry="1.5" fill={palette.cream} />
          }
          </svg>);

    })}
    </div>

    {/* Foot */}
    <div style={{
    marginTop: 16, paddingTop: 12, borderTop: `1px dashed ${palette.cream}30`,
    fontFamily: 'JetBrains Mono, monospace', fontSize: 10, opacity: 0.65,
    textAlign: 'center', letterSpacing: '0.18em'
  }}>
      ZAPFBRÄU · KIRCHPLATZ 2 · UETTINGEN
    </div>
  </div>;


// ─────────────────────────────────────────────────────────────
// CODE MODAL — customer enters daily PIN to receive stamp
// ─────────────────────────────────────────────────────────────
const CodeModal = ({ palette, onClose, onStamp }) => {
  const [code, setCode] = React.useState('');
  const [error, setError] = React.useState('');
  const [success, setSuccess] = React.useState(null); // null | 'add' | number(subtract)
  const daily = getDailyStampCode();

  const verify = () => {
    if (code.trim() === daily) {
      setSuccess('add');
      setTimeout(() => {onStamp(1);onClose();}, 1200);
      return;
    }
    // Review bonus code
    if (typeof getReviewCode === 'function' && code.trim() === getReviewCode()) {
      setSuccess('add');
      setTimeout(() => {onStamp(1);onClose();}, 1200);
      return;
    }
    for (const n of [5, 10, 20]) {
      if (code.trim() === getRedemptionCode(n)) {
        setSuccess(n);
        setTimeout(() => {onStamp(-n);onClose();}, 1500);
        return;
      }
    }
    setError('Falscher Code — bitte Personal fragen.');
    setCode('');
  };

  return (
    <div onClick={onClose} style={{
      position: 'absolute', inset: 0, background: `${palette.ink}cc`, backdropFilter: 'blur(8px)',
      zIndex: 30, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 22,
      animation: 'fadeIn 0.25s'
    }}>
      <div onClick={(e) => e.stopPropagation()} style={{
        background: palette.cream, borderRadius: 22, padding: 24, width: '100%',
        boxShadow: `0 24px 60px ${palette.ink}60`,
        display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 14
      }}>
        {success ?
        <>
            <div style={{ width: 64, height: 64, borderRadius: 32, background: success === 'add' ? palette.accent : palette.green, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
              <Icon name="check" size={36} color={palette.cream} stroke={2.4} />
            </div>
            <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, color: palette.ink, textAlign: 'center' }}>
              {success === 'add' ? 'Stempel erhalten!' : `${success} Stempel eingelöst!`}
            </div>
          </> :

        <>
            <SectionLabel palette={palette}>Stempel erhalten</SectionLabel>
            <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 20, color: palette.ink, textAlign: 'center', lineHeight: 1.1 }}>
              Tages-Code vom<br /><i style={{ color: palette.accent }}>Personal eingeben</i>
            </div>
            <input
            value={code}
            onChange={(e) => {setCode(e.target.value.replace(/\D/g, ''));setError('');}}
            maxLength={4}
            placeholder="_ _ _ _"
            inputMode="numeric"
            style={{
              width: '100%', textAlign: 'center', fontSize: 36, letterSpacing: 14, fontFamily: '"DM Serif Display", serif',
              padding: '14px 0', background: palette.paper, border: `2px solid ${error ? '#ef4444' : palette.green}`,
              borderRadius: 14, color: palette.ink, outline: 'none'
            }} />
          
            {error && <div style={{ fontSize: 12, color: '#ef4444', fontFamily: 'Manrope', textAlign: 'center' }}>{error}</div>}
            <button onClick={verify} disabled={code.length !== 4} style={{
            width: '100%', padding: '13px', borderRadius: 12, border: 'none', cursor: code.length === 4 ? 'pointer' : 'not-allowed',
            background: code.length === 4 ? palette.green : palette.muted + '40',
            color: palette.cream, fontFamily: 'Manrope', fontWeight: 700, fontSize: 14
          }}>Code bestätigen</button>
            <div style={{ fontSize: 11, color: palette.muted, textAlign: 'center', lineHeight: 1.4 }}>
              Den Tages-Code erhältst du vom Personal beim Bezahlen.
            </div>
            <button onClick={onClose} style={{
            background: 'transparent', border: 'none', cursor: 'pointer',
            fontFamily: 'Manrope', fontSize: 13, color: palette.muted
          }}>Abbrechen</button>
          </>
        }
      </div>
    </div>);

};

// ─────────────────────────────────────────────────────────────
// RESERVIEREN FLOW
// ─────────────────────────────────────────────────────────────
const BookScreen = ({ palette, onComplete }) => {
  const [step, setStep] = React.useState(0);
  const [data, setData] = React.useState({
    persons: 4, date: null, time: null, area: 'innen', name: '', tel: '', notes: ''
  });
  const update = (patch) => setData((d) => ({ ...d, ...patch }));
  const next = () => setStep((s) => s + 1);
  const back = () => setStep((s) => Math.max(0, s - 1));

  const stepLabels = ['Personen', 'Datum & Zeit', 'Bereich', 'Kontakt', 'Bestätigung'];

  return (
    <PaperBg palette={palette}>
      <div style={{ padding: '22px 22px 6px' }}>
        <SectionLabel palette={palette}>Tisch reservieren</SectionLabel>
        <H1 palette={palette} style={{ fontSize: 28, marginTop: 6 }}>
          {step < 4 ? <>Schritt {step + 1} <span style={{ color: palette.muted, fontSize: 18 }}>/ {stepLabels.length}</span></> : <>Geschafft!</>}
        </H1>
      </div>

      {/* Progress bar */}
      {step < 4 &&
      <div style={{ padding: '14px 22px 4px' }}>
          <div style={{ display: 'flex', gap: 4 }}>
            {stepLabels.map((_, i) =>
          <div key={i} style={{
            flex: 1, height: 4, borderRadius: 2,
            background: i <= step ? palette.accent : palette.green + '20',
            transition: 'all 0.3s'
          }} />
          )}
          </div>
          <div style={{ marginTop: 8, fontSize: 12, color: palette.muted, fontFamily: 'JetBrains Mono, monospace', letterSpacing: '0.1em' }}>
            {stepLabels[step].toUpperCase()}
          </div>
        </div>
      }

      <div style={{ padding: '8px 22px 24px' }}>
        {step === 0 && <StepPersons data={data} update={update} palette={palette} />}
        {step === 1 && <StepDate data={data} update={update} palette={palette} />}
        {step === 2 && <StepArea data={data} update={update} palette={palette} />}
        {step === 3 && <StepContact data={data} update={update} palette={palette} />}
        {step === 4 && <StepConfirm data={data} palette={palette} />}
      </div>

      {/* Footer buttons */}
      {step < 4 ?
      <div style={{
        position: 'sticky', bottom: 0, padding: '14px 22px 16px',
        background: `linear-gradient(180deg, transparent 0%, ${palette.cream} 30%)`,
        display: 'flex', gap: 10
      }}>
          {step > 0 &&
        <button onClick={back} style={{
          padding: '14px 18px', background: 'transparent', color: palette.green,
          border: `1px solid ${palette.green}40`, borderRadius: 12, cursor: 'pointer',
          fontFamily: 'Manrope', fontWeight: 600, display: 'flex', alignItems: 'center', gap: 6
        }}>
              <Icon name="arrowLeft" size={16} /> Zurück
            </button>
        }
          <button onClick={() => step === 3 ? next() : next()} disabled={!validateStep(step, data)} style={{
          flex: 1, padding: '14px', background: validateStep(step, data) ? palette.green : palette.muted + '40',
          color: palette.cream, border: 'none', borderRadius: 12, cursor: validateStep(step, data) ? 'pointer' : 'not-allowed',
          fontFamily: 'Manrope', fontWeight: 700, fontSize: 14,
          display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
          boxShadow: validateStep(step, data) ? `0 6px 14px ${palette.green}40` : 'none'
        }}>
            {step === 3 ? 'Reservierung absenden' : 'Weiter'}
            <Icon name="arrow" size={16} />
          </button>
        </div> :

      <div style={{ padding: '14px 22px 16px' }}>
          <button onClick={onComplete} style={{
          width: '100%', padding: '14px', background: palette.green, color: palette.cream,
          border: 'none', borderRadius: 12, cursor: 'pointer',
          fontFamily: 'Manrope', fontWeight: 700, fontSize: 14
        }}>Zurück zur Übersicht</button>
        </div>
      }
    </PaperBg>);

};

const validateStep = (step, d) => {
  if (step === 0) return d.persons > 0;
  if (step === 1) return d.date && d.time;
  if (step === 2) return !!d.area;
  if (step === 3) return d.name.length > 1 && d.tel.length > 5;
  return true;
};

const StepPersons = ({ data, update, palette }) =>
<div>
    <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, color: palette.ink, marginBottom: 20 }}>
      Wie <i style={{ color: palette.accent }}>viele</i> seid ihr?
    </div>
    <div style={{
    display: 'flex', alignItems: 'center', justifyContent: 'space-between',
    padding: '20px 8px', background: palette.paper, borderRadius: 16,
    border: `1px solid ${palette.green}18`
  }}>
      <button onClick={() => update({ persons: Math.max(1, data.persons - 1) })} style={{
      width: 52, height: 52, borderRadius: 26, background: palette.green + '10', border: 'none',
      color: palette.green, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center'
    }}><Icon name="minus" size={20} /></button>
      <div style={{ textAlign: 'center' }}>
        <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 56, color: palette.green, lineHeight: 1 }}>
          {data.persons}
        </div>
        <div style={{ fontSize: 12, color: palette.muted, marginTop: 4 }}>{data.persons === 1 ? 'Person' : 'Personen'}</div>
      </div>
      <button onClick={() => update({ persons: Math.min(20, data.persons + 1) })} style={{
      width: 52, height: 52, borderRadius: 26, background: palette.green, border: 'none',
      color: palette.cream, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center'
    }}><Icon name="plus" size={20} /></button>
    </div>
    {data.persons >= 7 &&
  <div style={{ marginTop: 14, padding: 12, borderRadius: 10, background: palette.accent + '14', fontSize: 12.5, color: palette.accentDark, lineHeight: 1.4 }}>
        Größere Gruppen sind herzlich willkommen — bis zu <b>25 Personen</b> kein Problem. Bitte ruf kurz an: <b>09369 8221</b>
      </div>
  }
  </div>;


const StepDate = ({ data, update, palette }) => {
  const today = new Date();
  const days = Array.from({ length: 14 }).map((_, i) => {
    const d = new Date(today);d.setDate(today.getDate() + i);return d;
  });
  const dayNames = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'];
  const months = ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'];

  // Only Thu(4), Fri(5), Sat(6), Sun(0) are open; disable others
  const isClosed = (d) => [1, 2, 3].includes(d.getDay());

  // Also disable today if no more slots (past 19:45)
  const isTodayFull = (d) => {
    const now = new Date();
    if (d.toDateString() !== now.toDateString()) return false;
    const hm = now.getHours() * 60 + now.getMinutes();
    return hm >= 19 * 60 + 46; // past last slot + 45min buffer
  };

  // Generate valid time slots for selected date
  const getSlots = (d) => {
    if (!d) return [];
    const dow = d.getDay();
    const now = new Date();
    const isToday = d.toDateString() === now.toDateString();
    const nowHm = isToday ? now.getHours() * 60 + now.getMinutes() : 0;
    const slots = [];
    // Sunday lunch: only 11:30 and 13:00
    if (dow === 0) {
      [691, 780].forEach((m) => {// 11:30=691, 13:00=780
        const h = Math.floor(m / 60),mn = m % 60;
        if (!isToday || nowHm + 45 <= m) {
          slots.push(`${h}:${String(mn).padStart(2, '0')}`);
        }
      });
    }
    // Evening slots 17:00–19:45 in 15-min steps (all open days)
    if ([0, 4, 5, 6].includes(dow)) {
      for (let m = 17 * 60; m <= 19 * 60 + 45; m += 15) {
        const h = Math.floor(m / 60),mn = m % 60;
        if (!isToday || nowHm + 45 <= m) {
          slots.push(`${h}:${String(mn).padStart(2, '0')}`);
        }
      }
    }
    return slots;
  };

  const selectedDate = data.date ? new Date(data.date) : null;
  const slots = getSlots(selectedDate);

  return (
    <div>
      <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, color: palette.ink, marginBottom: 16 }}>
        <i style={{ color: palette.accent }}>Wann</i> dürfen wir euch begrüßen?
      </div>

      {/* Date picker */}
      <div style={{ display: 'flex', gap: 8, overflowX: 'auto', padding: '4px 0 12px', marginRight: -22, paddingRight: 22 }}>
        {days.map((d, i) => {
          const closed = isClosed(d) || isTodayFull(d);
          const sel = selectedDate && d.toDateString() === selectedDate.toDateString();
          return (
            <button key={i} onClick={() => !closed && update({ date: d.toISOString(), time: null })} disabled={closed} style={{
              flexShrink: 0, width: 56, padding: '10px 0', borderRadius: 12,
              border: sel ? 'none' : `1px solid ${palette.green}25`,
              background: sel ? palette.green : palette.paper,
              color: sel ? palette.cream : closed ? palette.muted + '80' : palette.ink,
              fontFamily: 'Manrope', cursor: closed ? 'not-allowed' : 'pointer',
              opacity: closed ? 0.4 : 1
            }}>
              <div style={{ fontSize: 10, fontWeight: 600, opacity: 0.7 }}>{dayNames[d.getDay()]}</div>
              <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, lineHeight: 1.1, marginTop: 2 }}>{d.getDate()}</div>
              <div style={{ fontSize: 9, opacity: 0.6 }}>{months[d.getMonth()]}</div>
              {closed && [1, 2, 3].includes(d.getDay()) &&
              <div style={{ fontSize: 7.5, opacity: 0.7, marginTop: 1 }}>Ruhetag</div>
              }
            </button>);

        })}
      </div>

      {/* Time slots */}
      {selectedDate &&
      <>
          <div style={{ marginTop: 14, fontFamily: 'JetBrains Mono, monospace', fontSize: 11, color: palette.muted, letterSpacing: 0.1, marginBottom: 8 }}>
            UHRZEIT
          </div>
          {slots.length > 0 ?
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
              {slots.map((t) => {
            const sel = data.time === t;
            return (
              <button key={t} onClick={() => update({ time: t })} style={{
                padding: '12px 0', borderRadius: 10,
                border: sel ? 'none' : `1px solid ${palette.green}25`,
                background: sel ? palette.accent : palette.paper,
                color: sel ? palette.cream : palette.ink,
                fontFamily: '"DM Serif Display", serif', fontSize: 15, cursor: 'pointer'
              }}>{t}</button>);

          })}
            </div> :

        <div style={{ padding: 14, borderRadius: 12, background: palette.accent + '12', fontSize: 13, color: palette.accentDark, lineHeight: 1.5 }}>
              Für diesen Tag sind keine Zeiten mehr verfügbar. Bitte einen anderen Tag wählen.
            </div>
        }
          <div style={{ marginTop: 12, fontSize: 11.5, color: palette.muted, lineHeight: 1.5 }}>
            Letzter Buchungsslot um 19:45 Uhr.
          </div>
        </>
      }
    </div>);

};

const StepArea = ({ data, update, palette }) => {
  const areas = [
  { id: 'innen', name: 'Innenbereich', desc: 'Liebevoll eingerichtete Räume — gemütlich & traditionell', emoji: '🪑' },
  { id: 'aussen', name: 'Außenbereich', desc: 'Unterm alten Kühlschiff — Mai bis September', emoji: '🌳', seasonal: true }];

  return (
    <div>
      <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, color: palette.ink, marginBottom: 16 }}>
        Wo möchtet ihr <i style={{ color: palette.accent }}>sitzen</i>?
      </div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
        {areas.map((a) => {
          const sel = data.area === a.id;
          return (
            <button key={a.id} onClick={() => update({ area: a.id })} style={{
              display: 'flex', alignItems: 'center', gap: 14, padding: 16,
              borderRadius: 14, textAlign: 'left', cursor: 'pointer',
              background: sel ? palette.green : palette.paper,
              color: sel ? palette.cream : palette.ink,
              border: sel ? 'none' : `1px solid ${palette.green}18`,
              fontFamily: 'Manrope'
            }}>
              <div style={{
                width: 56, height: 56, borderRadius: 28, fontSize: 28,
                display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0,
                background: sel ? palette.accent : palette.green + '14'
              }}>{a.emoji}</div>
              <div style={{ flex: 1 }}>
                <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 18, lineHeight: 1.1 }}>{a.name}</div>
                <div style={{ fontSize: 12, opacity: sel ? 0.85 : 0.6, marginTop: 3, lineHeight: 1.4 }}>{a.desc}</div>
              </div>
              {sel && <Icon name="check" size={20} color={palette.cream} />}
            </button>);

        })}
      </div>
    </div>);

};

const ContactField = ({ palette, label, value, onChange, type = 'text', placeholder, hint }) =>
<div style={{ marginBottom: 14 }}>
    <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 10.5, color: palette.muted, letterSpacing: 0.2, textTransform: 'uppercase', marginBottom: 6 }}>
      {label}
    </div>
    <input type={type} value={value} onChange={(e) => onChange(e.target.value)} placeholder={placeholder} style={{
    width: '100%', padding: '14px 16px', background: palette.paper,
    border: `1px solid ${palette.green}25`, borderRadius: 12,
    fontFamily: 'Manrope', fontSize: 15, color: palette.ink, outline: 'none'
  }} />
    {hint && <div style={{ fontSize: 11, color: palette.muted, marginTop: 4 }}>{hint}</div>}
  </div>;


const StepContact = ({ data, update, palette }) =>
<div>
    <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, color: palette.ink, marginBottom: 16 }}>
      Wie heißt du, <i style={{ color: palette.accent }}>damit's klappt</i>?
    </div>
    <ContactField palette={palette} label="Name" value={data.name} onChange={(v) => update({ name: v })} placeholder="Maxi Mustermann" />
    <ContactField palette={palette} label="Telefon" value={data.tel} onChange={(v) => update({ tel: v })} type="tel" placeholder="+49 …" hint="Falls wir dich kurz erreichen müssen." />
    <ContactField palette={palette} label="Anmerkung (optional)" value={data.notes} onChange={(v) => update({ notes: v })} placeholder="Geburtstag, Allergien, …" />
  </div>;


const StepConfirm = ({ data, palette }) => {
  const date = data.date && new Date(data.date);
  const months = ['Jan', 'Feb', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'Sept', 'Okt', 'Nov', 'Dez'];
  const days = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
  const areaName = { innen: 'Innenbereich', aussen: 'Außenbereich' }[data.area] || data.area;

  const dateStr = date ? `${days[date.getDay()]}, ${date.getDate()}. ${months[date.getMonth()]} · ${data.time}` : '—';
  const waText = encodeURIComponent(
    `Hallo, ich möchte gerne einen Tisch reservieren:\n` +
    `📅 ${dateStr}\n👥 ${data.persons} ${data.persons === 1 ? 'Person' : 'Personen'}\n` +
    `📍 ${areaName}\n👤 ${data.name}` + (
    data.notes ? `\n📝 ${data.notes}` : '')
  );
  const waLink = `https://wa.me/4993698221?text=${waText}`;

  return (
    <div>
      <div style={{ textAlign: 'center', padding: '20px 0' }}>
        <div style={{
          width: 76, height: 76, borderRadius: 38, background: palette.accent,
          display: 'flex', alignItems: 'center', justifyContent: 'center', margin: '0 auto 16px',
          boxShadow: `0 8px 24px ${palette.accent}50`
        }}>
          <Icon name="check" size={40} color={palette.cream} stroke={2.4} />
        </div>
        <H1 palette={palette} style={{ fontSize: 28 }}>Wir freuen uns!</H1>
        <div style={{ fontSize: 13, color: palette.muted, marginTop: 8 }}>
          Schick uns jetzt deine Reservierung per WhatsApp — wir bestätigen sie persönlich.
        </div>
      </div>

      <div style={{ background: palette.paper, borderRadius: 16, padding: 18, border: `1px solid ${palette.green}15` }}>
        <Row palette={palette} k="Wann" v={dateStr} />
        <Row palette={palette} k="Personen" v={`${data.persons} ${data.persons === 1 ? 'Person' : 'Personen'}`} />
        <Row palette={palette} k="Bereich" v={areaName} />
        <Row palette={palette} k="Name" v={data.name} />
        {data.notes && <Row palette={palette} k="Notiz" v={data.notes} last />}
      </div>

      {/* Info boxes */}
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8, marginTop: 14 }}>
        {[
        '🕐 Dein Tisch wird 15 Minuten freigehalten.',
        '⏱ Standard-Sitzzeit: 90 Minuten — längerer Aufenthalt gerne auf Anfrage im Kommentarfeld.',
        '🐾 Im Innenbereich sind Haustiere leider nicht erlaubt.'].
        map((txt, i) =>
        <div key={i} style={{ padding: '10px 12px', borderRadius: 10, background: palette.green + '0c', fontSize: 12.5, color: palette.green, lineHeight: 1.5 }}>{txt}</div>
        )}
      </div>

      {/* WhatsApp CTA */}
      <a href={waLink} target="_blank" rel="noreferrer" style={{
        display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
        marginTop: 16, padding: '14px', borderRadius: 14, textDecoration: 'none',
        background: '#25D366', color: '#fff',
        fontFamily: 'Manrope', fontWeight: 700, fontSize: 15,
        boxShadow: '0 6px 20px rgba(37,211,102,0.35)'
      }}>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="white">
          <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347z" />
          <path d="M12 0C5.373 0 0 5.373 0 12c0 2.122.554 4.122 1.527 5.855L.057 23.1a.75.75 0 00.921.921l5.245-1.47A11.952 11.952 0 0012 24c6.627 0 12-5.373 12-12S18.627 0 12 0zm0 22a9.954 9.954 0 01-5.07-1.386l-.361-.215-3.762 1.054 1.054-3.762-.215-.361A9.954 9.954 0 012 12C2 6.486 6.486 2 12 2s10 4.486 10 10-4.486 10-10 10z" />
        </svg>
        Per WhatsApp reservieren
      </a>

      <div style={{ marginTop: 12, padding: 12, borderRadius: 10, background: palette.green + '10', fontSize: 12, color: palette.green, lineHeight: 1.5 }}>
        <b>Hinweis:</b> Haustiere sind im Innenbereich leider nicht erlaubt. Im Außenbereich gerne willkommen.
      </div>
    </div>);

};

const Row = ({ k, v, palette, last }) =>
<div style={{
  display: 'flex', justifyContent: 'space-between', gap: 14,
  padding: '10px 0', borderBottom: last ? 'none' : `1px dashed ${palette.green}20`
}}>
    <span style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 11, color: palette.muted, letterSpacing: 0.1, textTransform: 'uppercase', flexShrink: 0, minWidth: 70 }}>{k}</span>
    <span style={{ fontFamily: '"DM Serif Display", serif', fontSize: 15, color: palette.ink, textAlign: 'right' }}>{v}</span>
  </div>;


// ─────────────────────────────────────────────────────────────
// ROOMS / ZIMMER
// ─────────────────────────────────────────────────────────────
const ROOMS = [
{ type: 'Einzelzimmer', sleep: 1, ab: 78, count: 4, desc: 'Parkett, Schreibtisch, Balkon', img: 'einzelzimmer · parkett, balkon' },
{ type: 'Doppelzimmer', sleep: 2, ab: 110, count: 5, desc: 'Großes Bad, Sitzecke, schallisoliert', img: 'doppelzimmer · sitzecke' },
{ type: 'Familienzimmer', sleep: 4, ab: 145, count: 2, desc: 'Zwei Räume verbunden, ideal für Familien', img: 'familienzimmer · zwei räume' }];


const RoomsScreen = ({ palette }) => {
  const iframeRef = React.useRef();

  React.useEffect(() => {
    let loaded = false;
    const handle = (e) => {
      if (e.data?.action === 'RESIZE' && iframeRef.current) {
        iframeRef.current.style.height = e.data.height + 'px';
        if (loaded) {
          const top = iframeRef.current.parentElement?.scrollTop || 0;
          iframeRef.current.parentElement?.scrollTo?.(0, top);
        } else {loaded = true;}
      }
    };
    window.addEventListener('message', handle);
    return () => window.removeEventListener('message', handle);
  }, []);

  return (
    <PaperBg palette={palette}>
      <div style={{ padding: '22px 22px 6px' }}>
        <SectionLabel palette={palette}>Gästehaus</SectionLabel>
        <H1 palette={palette} style={{ fontSize: 30, marginTop: 6 }}>
          Elf gemütliche <i style={{ color: palette.accent }}>Gästezimmer</i>
        </H1>
      </div>

      {/* Foto-Slider Zimmer */}
      <div style={{ display: 'flex', gap: 10, overflowX: 'auto', padding: '8px 22px 14px' }}>
        {[
        { id: 'zapf-gaestehaus-blau', label: 'Gästehaus', src: 'uploads/IMG_20170120_131630.jpg' },
        { id: 'zapf-innenhof-nacht', label: 'Innenhof', src: 'uploads/20210715_215113.jpg' },
        { id: 'zapf-doppelzimmer', label: 'Doppelzimmer', src: 'uploads/Zapf_Uettingen_Zimmer-02084.jpg' },
        { id: 'zapf-familienzimmer', label: 'Familienzimmer', src: 'uploads/20210707_143453.jpg' },
        { id: 'zapf-fruehstueck', label: 'Frühstück', src: 'uploads/IMG_20260515_074715583.jpg' }].
        map(({ id, label, src }) =>
        <div key={id} style={{ flexShrink: 0, width: 160, borderRadius: 12, overflow: 'hidden', border: `1px solid ${palette.green}15` }}>
            {src ?
          <img src={src} alt={label} style={{ width: '100%', height: '100px', objectFit: 'cover', display: 'block' }} /> :

          <image-slot id={id} placeholder={label} shape="rect"
          style={{ width: '100%', height: '100px', display: 'block' }} />
          }
            <div style={{ background: palette.paper, padding: '6px 8px' }}>
              <div style={{ fontSize: 11.5, fontFamily: '"DM Serif Display", serif', color: palette.ink }}>{label}</div>
            </div>
          </div>
        )}
      </div>

      {/* Kompakt-Info */}
      <div style={{ padding: '0 22px 14px', display: 'flex', flexDirection: 'column', gap: 6 }}>
        {[
        '🔑 Check-in ab 14:00 · Check-out bis 10:00',
        '🍳 Frühstück 15 €/P · Do/Fr 7:30–10:00 · Sa/So 8:00–10:00 · Anmeldung bis 15:00 Uhr am Anreisetag',
        '🅿️ Kostenlos im abschließbaren Innenhof',
        '🐾 Haustiere leider nicht gestattet',
        '🚬 Nichtraucherzimmer · Rauchen im Hof erlaubt',
        '🔋 E-Auto laden: 2 × 11 kW · 0,40 €/kWh (Ladekarte von uns)'].
        map((txt, i) =>
        <div key={i} style={{ padding: '8px 12px', borderRadius: 10, background: palette.paper, border: `1px solid ${palette.green}10`, fontSize: 11.5, color: palette.ink, lineHeight: 1.4 }}>{txt}</div>
        )}
        <a href="https://www.alte-brauerei.de/zimmer/g%C3%A4stemappe/" target="_blank" rel="noreferrer"
        style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '10px 12px', borderRadius: 10, background: palette.accent + '12', border: `1px solid ${palette.accent}25`, textDecoration: 'none' }}>
          <span style={{ fontSize: 12, color: palette.accentDark, fontWeight: 600, fontFamily: 'Manrope' }}>📖 Digitale Gästemappe öffnen</span>
          <Icon name="chevron" size={15} color={palette.accent} />
        </a>
        {/* Längeraufenthalt */}
        <div style={{ padding: '12px 14px', borderRadius: 10, background: palette.paper, border: `1px solid ${palette.green}15` }}>
          <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9.5, letterSpacing: '0.14em', textTransform: 'uppercase', color: palette.muted, marginBottom: 6 }}>Längere Aufenthalte</div>
          <div style={{ fontSize: 12.5, color: palette.ink, lineHeight: 1.5 }}>Ab <b>3 Nächten</b> ab <b>45 €/Nacht</b> im Einzelzimmer. Buchung ab Montag. Doppel-, 3- und 4-Bett-Zimmer auf Anfrage auch als Einzelzimmer buchbar. </div>
          <a href="tel:093698221" style={{ display: 'inline-flex', alignItems: 'center', gap: 5, marginTop: 8, padding: '6px 12px', borderRadius: 16, background: palette.green, color: palette.cream, textDecoration: 'none', fontFamily: 'Manrope', fontWeight: 600, fontSize: 12 }}>
            <Icon name="phone" size={13} color={palette.cream} /> Anfrage: 09369 8221
          </a>
        </div>
      </div>

      {/* Resavio Booking */}
      <div style={{ padding: '0 22px 6px' }}>
        <SectionLabel palette={palette}>Verfügbarkeit & Buchung</SectionLabel>
      </div>
      <div style={{ overflow: 'auto' }}>
        <iframe
          ref={iframeRef}
          src="https://resavio.com/booking/de/771"
          id="resavio"
          style={{ width: '100%', height: 1400, border: 'none', background: 'transparent', display: 'block' }}
          title="Zimmer buchen" />
        
      </div>

      {/* Gästebewertungen */}
      <div style={{ padding: '22px 22px 6px' }}>
        <SectionLabel palette={palette}>Gästebewertungen</SectionLabel>
      </div>
      <div style={{ overflow: 'auto' }}>
        <iframe
          src="https://resavio.com/booking/de/771/reviews"
          style={{ width: '100%', height: 1000, border: 'none', background: 'transparent', display: 'block' }}
          title="Gästebewertungen" />
        
      </div>
    </PaperBg>);

};

// ─────────────────────────────────────────────────────────────
// INFO / HAUS
// ─────────────────────────────────────────────────────────────
const InfoScreen = ({ palette, appData, openInApp, goto }) => {
  const d = appData || DEFAULT_APP_DATA;
  const hours = d.hours || DEFAULT_APP_DATA.hours;
  const contact = d.contact || DEFAULT_APP_DATA.contact;
  return (
    <PaperBg palette={palette}>
    <div style={{ padding: '22px 22px 6px' }}>
      <SectionLabel palette={palette}>Über das Haus</SectionLabel>
      <H1 palette={palette} style={{ fontSize: 30, marginTop: 6 }}>
        Seit <i style={{ color: palette.accent }}>1883</i><br />im Familienbesitz
      </H1>

    </div>

    {/* Sketch image */}
    <div style={{ padding: '18px 22px 4px' }}>
      <div style={{
          background: palette.paper, borderRadius: 16, padding: 14,
          border: `1px solid ${palette.green}15`
        }}>
        <img src="uploads/20210712_125622.jpg" style={{ width: '100%', display: 'block', borderRadius: 4 }} />
      </div>
    </div>

    {/* Sonderzeiten */}
    {((d.sonderzeiten?.feiertage?.length || 0) > 0 || (d.sonderzeiten?.betriebsruhe?.length || 0) > 0) &&
      <div style={{ padding: '22px 22px 4px' }}>
        <SectionLabel palette={palette}>Sonderzeiten</SectionLabel>
        {(d.sonderzeiten?.betriebsruhe?.length || 0) > 0 &&
        <div style={{ marginTop: 10, background: palette.paper, borderRadius: 12, padding: '10px 14px', border: `1px solid ${palette.green}15`, marginBottom: 10 }}>
            <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9.5, letterSpacing: '0.14em', textTransform: 'uppercase', color: palette.muted, marginBottom: 8 }}>Betriebsruhe · Geschlossen</div>
            {d.sonderzeiten.betriebsruhe.map((b, i) =>
          <div key={i} style={{ display: 'flex', justifyContent: 'space-between', padding: '5px 0', borderBottom: i < d.sonderzeiten.betriebsruhe.length - 1 ? `1px dashed ${palette.green}15` : 'none' }}>
                <span style={{ fontFamily: 'Manrope', fontSize: 13, color: palette.ink }}>{b.von}</span>
                <span style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 11, color: palette.muted }}>bis {b.bis}</span>
              </div>
          )}
          </div>
        }
        {(d.sonderzeiten?.feiertage?.length || 0) > 0 &&
        <div style={{ background: palette.paper, borderRadius: 12, overflow: 'hidden', border: `1px solid ${palette.green}15` }}>
            <div style={{ padding: '10px 14px 4px', fontFamily: 'JetBrains Mono, monospace', fontSize: 9.5, letterSpacing: '0.14em', textTransform: 'uppercase', color: palette.muted }}>Feiertage</div>
            {d.sonderzeiten.feiertage.map((f, i) =>
          <div key={i} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '8px 14px', borderBottom: i < d.sonderzeiten.feiertage.length - 1 ? `1px dashed ${palette.green}15` : 'none' }}>
                <div>
                  <div style={{ fontFamily: 'Manrope', fontSize: 12.5, fontWeight: 600, color: palette.ink }}>{f.name}</div>
                  <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 10, color: palette.muted, marginTop: 1 }}>{f.datum}</div>
                </div>
                <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 14, color: f.zeit === 'geschlossen' ? palette.muted : palette.green, whiteSpace: 'nowrap' }}>{f.zeit}</div>
              </div>
          )}
          </div>
        }
      </div>
      }

    {/* Hours */}
    <div style={{ padding: '22px 22px 4px' }}>
      <SectionLabel palette={palette}>Öffnungszeiten</SectionLabel>
      <div style={{ marginTop: 12, background: palette.paper, borderRadius: 14, overflow: 'hidden', border: `1px solid ${palette.green}15` }}>
        {hours.map((h, i) =>
          <div key={i} style={{
            display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between',
            padding: '11px 14px', gap: 12,
            borderBottom: i < hours.length - 1 ? `1px dashed ${palette.green}18` : 'none'
          }}>
            <span style={{
              fontFamily: 'Manrope', fontSize: 13, fontWeight: 600, flexShrink: 0,
              color: h.closed ? palette.muted : palette.ink,
              whiteSpace: 'nowrap'
            }}>{h.day}</span>
            <div style={{ textAlign: 'right' }}>
              {h.times.map((t, ti) =>
              <div key={ti} style={{
                fontFamily: '"DM Serif Display", serif', fontSize: 14,
                color: h.closed ? palette.muted : palette.ink,
                lineHeight: 1.5, whiteSpace: 'nowrap'
              }}>{t}</div>
              )}
            </div>
          </div>
          )}
      </div>
    </div>

    {/* Contact rows */}
    <div style={{ padding: '22px 22px 4px' }}>
      <SectionLabel palette={palette}>Anfahrt & Kontakt</SectionLabel>
      <div style={{ marginTop: 12, display: 'flex', flexDirection: 'column', gap: 10 }}>
        <ContactRow palette={palette} icon="pin" k="Adresse" v={contact.address} link={`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(contact.address)}`} />
        <ContactRow palette={palette} icon="phone" k="Telefon" v={contact.phone} link={`tel:${contact.phone.replace(/[^0-9+]/g, '')}`} />
        {contact.whatsapp && <ContactRow palette={palette} icon="phone" k="WhatsApp" v="Reservierungen & Anfragen" link={contact.whatsapp} />}
        <ContactRow palette={palette} icon="info" k="E-Mail" v={contact.email} link={`mailto:${contact.email}`} />
        <ContactRow palette={palette} icon="bike" k="E-Bike Laden" v={contact.ebike} />
        <ContactRow palette={palette} icon="car" k="Auto laden" v={`${contact.wall} · 0,40€/kWh`} />
        <ContactRow palette={palette} icon="info" k="WLAN" v={'Kostenfreies WLAN — „ZapfWifi"'} />
        <ContactRow palette={palette} icon="users" k="Brauseminare" v="Tickets & Infos" link="https://www.eventim-light.com/de/a/68e7819487a05c16200ae183/iframe/e/68e78b1bd3b6dd78d7a8d20c/" onPress={openInApp ? () => openInApp('https://www.eventim-light.com/de/a/68e7819487a05c16200ae183/iframe/e/68e78b1bd3b6dd78d7a8d20c/', 'Brauseminare') : null} />
        <ContactRow palette={palette} icon="check" k="Barrierefreiheit" v="Rollstuhlgerechter Eingang · Rampe bei Bedarf" />
      </div>
    </div>

    {/* Website & Social */}
    <div style={{ padding: '22px 22px 4px' }}>
      <SectionLabel palette={palette}>Online</SectionLabel>
      <div style={{ marginTop: 12, display: 'flex', flexDirection: 'column', gap: 10 }}>
        <a href="https://www.alte-brauerei.de" target="_blank" rel="noreferrer" style={{ textDecoration: 'none' }}>
          <div style={{ background: palette.paper, borderRadius: 12, padding: '12px 14px', border: `1px solid ${palette.green}12`, display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
            <div>
              <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 10, color: palette.muted, textTransform: 'uppercase', letterSpacing: 0.15 }}>Website</div>
              <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 15, color: palette.accent, marginTop: 2 }}>www.alte-brauerei.de</div>
            </div>
            <Icon name="chevron" size={16} color={palette.muted} />
          </div>
        </a>
        <div style={{ background: palette.paper, borderRadius: 12, padding: '12px 14px', border: `1px solid ${palette.green}12` }}>
          <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 10, color: palette.muted, textTransform: 'uppercase', letterSpacing: 0.15, marginBottom: 6 }}>Social Media</div>
          <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 14, color: palette.ink }}>@altebrauereizapf</div>
          <div style={{ fontSize: 12, color: palette.muted, marginTop: 2 }}>Instagram · Facebook</div>
        </div>
      </div>
    </div>

    {/* Foto-Slider */}
    <GallerySlider palette={palette} />

    {/* Geschichte */}
    <div style={{ padding: '22px 22px 4px' }}>
      <SectionLabel palette={palette}>Unsere Geschichte</SectionLabel>
      <div style={{ marginTop: 12, position: 'relative' }}>
        {/* vertical line */}
        <div style={{ position: 'absolute', left: 18, top: 0, bottom: 0, width: 2, background: `${palette.green}20` }} />
        {[
          { year: '1883', icon: '🏠', title: 'Die Anfänge', text: 'Wilhelm Gottlieb Zapf erwirbt das Wirtshaus mit Brauerei. Er braut bis ca. 1918.' },
          { year: '1926', icon: '👩', title: 'Elsa & die Fernfahrer', text: 'Nach dem Unfalltod ihres Mannes Andreas führt Elsa Zapf das Gasthaus allein — und macht es zur bekannten Fernfahrerstation.' },
          { year: '1951', icon: '👨‍👩‍👧', title: 'Erich & Hanna', text: 'Erich Zapf kehrt aus der Kriegsgefangenschaft zurück und übernimmt 1951 gemeinsam mit Hanna das Wirtshaus.' },
          { year: '1982', icon: '🏨', title: 'Metzgerei & Gästehaus', text: 'Metzgerei ab 1982 (bis 2017). 1998 entsteht das Gästehaus mit sechs modernen Zimmern im Innenhof.' },
          { year: '2017', icon: '🍺', title: 'Heute · 5. Generation', text: 'Yvonne Mennig und Dr. Andreas Herr führen die Brauerei. Seit 2018 brauen sie wieder eigenes Zapfbräu.' }].
          map((e, i) =>
          <div key={i} style={{ display: 'flex', gap: 14, marginBottom: 16, position: 'relative' }}>
            <div style={{ width: 36, height: 36, borderRadius: '50%', background: palette.paper, border: `2px solid ${palette.green}30`, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0, fontSize: 16, zIndex: 1 }}>{e.icon}</div>
            <div style={{ flex: 1, paddingTop: 4 }}>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 2 }}>
                <span style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 10, color: palette.accent, fontWeight: 600 }}>{e.year}</span>
                <span style={{ fontFamily: '"DM Serif Display", serif', fontSize: 15, color: palette.ink }}>{e.title}</span>
              </div>
              <div style={{ fontSize: 12.5, color: palette.muted, lineHeight: 1.5 }}>{e.text}</div>
            </div>
          </div>
          )}
      </div>
    </div>

    {/* WhatsApp Channel */}
    <div style={{ padding: '22px 22px 4px' }}>
      <SectionLabel palette={palette}>Immer aktuell</SectionLabel>
      <a href="https://whatsapp.com/channel/0029VbCuLaCK5cDO3x13sp0s" target="_blank" rel="noreferrer" style={{ textDecoration: 'none', display: 'block', marginTop: 12 }}>
        <div style={{
            borderRadius: 16, padding: 16, display: 'flex', alignItems: 'center', gap: 14,
            background: 'linear-gradient(135deg, #25D366 0%, #128C7E 100%)',
            boxShadow: '0 6px 20px rgba(37,211,102,0.3)'
          }}>
          <div style={{ width: 48, height: 48, borderRadius: 24, background: 'rgba(255,255,255,0.2)', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
            <svg width="26" height="26" viewBox="0 0 24 24" fill="white">
              <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347z" />
              <path d="M12 0C5.373 0 0 5.373 0 12c0 2.122.554 4.122 1.527 5.855L.057 23.1a.75.75 0 00.921.921l5.245-1.47A11.952 11.952 0 0012 24c6.627 0 12-5.373 12-12S18.627 0 12 0zm0 22a9.954 9.954 0 01-5.07-1.386l-.361-.215-3.762 1.054 1.054-3.762-.215-.361A9.954 9.954 0 012 12C2 6.486 6.486 2 12 2s10 4.486 10 10-4.486 10-10 10z" />
            </svg>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 17, color: '#fff', lineHeight: 1.2 }}>WhatsApp Kanal folgen</div>
            <div style={{ fontSize: 12, color: 'rgba(255,255,255,0.85)', marginTop: 3, lineHeight: 1.4 }}>
              Wochenkarte, Sonderbiere, aktuelle Öffnungszeiten &amp; mehr
            </div>
          </div>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.7)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
            <path d="M9 6l6 6-6 6" />
          </svg>
        </div>
      </a>
    </div>
    <div style={{ padding: '22px 22px 28px' }}>
      <div style={{
          height: 160, borderRadius: 14, overflow: 'hidden', position: 'relative',
          background: palette.green,
          backgroundImage: `
          repeating-linear-gradient(35deg, ${palette.greenDark}40 0 1px, transparent 1px 26px),
          repeating-linear-gradient(125deg, ${palette.greenDark}40 0 1px, transparent 1px 26px),
          linear-gradient(135deg, ${palette.green}, ${palette.greenDark})
        `,
          display: 'flex', alignItems: 'center', justifyContent: 'center'
        }}>
        {/* fake roads */}
        <svg style={{ position: 'absolute', inset: 0 }} viewBox="0 0 200 100" preserveAspectRatio="none">
          <path d="M0 60 Q 60 50 100 55 T 200 50" stroke={palette.cream + '40'} strokeWidth="3" fill="none" />
          <path d="M80 0 L 95 100" stroke={palette.cream + '30'} strokeWidth="2" fill="none" />
        </svg>
        <div style={{
            background: palette.accent, color: palette.cream, padding: '10px 14px',
            borderRadius: 30, fontFamily: 'Manrope', fontWeight: 700, fontSize: 12,
            display: 'flex', alignItems: 'center', gap: 8, position: 'relative',
            boxShadow: `0 4px 16px ${palette.ink}40`
          }}>
          <Icon name="pin" size={14} /> Kirchplatz 2
        </div>
      </div>
    </div>

    {/* Haustiere */}
    <div style={{ padding: '0 22px 28px' }}>
      <div style={{
          padding: 14, borderRadius: 12,
          background: palette.accent + '10',
          border: `1px solid ${palette.accent}25`,
          display: 'flex', alignItems: 'flex-start', gap: 10
        }}>
        <span style={{ fontSize: 18, flexShrink: 0, marginTop: 2 }}>🐾</span>
        <div>
          <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 15, color: palette.ink, marginBottom: 3 }}>Haustiere</div>
          <div style={{ fontSize: 12.5, color: palette.muted, lineHeight: 1.5 }}>
            Im Innenbereich sind Haustiere leider nicht erlaubt. Im Außenbereich sind eure Vierbeiner herzlich willkommen.
          </div>
        </div>
      </div>

      {/* FAQ Link */}
      {goto &&
        <div style={{ padding: '0 22px 28px' }}>
          <button onClick={() => goto('faq')} style={{
            width: '100%', padding: '14px 18px', borderRadius: 14, border: 'none',
            background: palette.green, cursor: 'pointer', textAlign: 'left',
            display: 'flex', alignItems: 'center', gap: 14, fontFamily: 'Manrope',
            boxShadow: `0 4px 14px ${palette.green}30`
          }}>
            <div style={{ width: 40, height: 40, borderRadius: 20, background: 'rgba(255,255,255,0.15)', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
              <span style={{ fontSize: 20 }}>❓</span>
            </div>
            <div style={{ flex: 1 }}>
              <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 16, color: palette.cream }}>Häufige Fragen</div>
              <div style={{ fontSize: 12, color: palette.cream, opacity: 0.8, marginTop: 2 }}>Alles zu Bier, Hotel, Umgebung & mehr</div>
            </div>
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.7)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M9 6l6 6-6 6" /></svg>
          </button>
        </div>
        }
    </div>
  </PaperBg>);

};

const ContactRow = ({ icon, k, v, palette, link, onPress }) =>
<div onClick={onPress || undefined} style={{
  background: palette.paper, borderRadius: 12, padding: 14,
  display: 'flex', alignItems: 'center', gap: 12,
  border: `1px solid ${palette.green}12`,
  cursor: onPress || link ? 'pointer' : 'default'
}}>
    <div style={{
    width: 36, height: 36, borderRadius: 18,
    background: link ? '#25D36618' : palette.green + '14',
    display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0
  }}>
      {link ?
    <svg width="18" height="18" viewBox="0 0 24 24" fill="#25D366">
          <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347z" /><path d="M12 0C5.373 0 0 5.373 0 12c0 2.122.554 4.122 1.527 5.855L.057 23.1a.75.75 0 00.921.921l5.245-1.47A11.952 11.952 0 0012 24c6.627 0 12-5.373 12-12S18.627 0 12 0zm0 22a9.954 9.954 0 01-5.07-1.386l-.361-.215-3.762 1.054 1.054-3.762-.215-.361A9.954 9.954 0 012 12C2 6.486 6.486 2 12 2s10 4.486 10 10-4.486 10-10 10z" />
        </svg> :

    <Icon name={icon} size={18} color={palette.green} />
    }
    </div>
    <div style={{ flex: 1, minWidth: 0 }}>
      <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 10, color: palette.muted, letterSpacing: 0.15, textTransform: 'uppercase' }}>{k}</div>
      {link ?
    <a href={link} target="_blank" rel="noreferrer" style={{
      fontFamily: '"DM Serif Display", serif', fontSize: 15, color: '#25D366',
      marginTop: 2, display: 'block', textDecoration: 'none'
    }}>{v}</a> :

    <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 15, color: palette.ink, marginTop: 2, overflow: 'hidden', textOverflow: 'ellipsis' }}>{v}</div>
    }
    </div>
  </div>;


// ─────────────────────────────────────────────────────────────
// BIER & BRAUEREI
// ─────────────────────────────────────────────────────────────
const BEERS = [
{
  name: "Gottlieb's Lieblingstrunk",
  style: 'Dunkles Vollbier',
  abv: '5,4 %',
  plato: '13,5 °P',
  be: '17 BE',
  color: '#3a1f08',
  desc: 'Angelehnt an ein früheres Märzen — ausgeprägte Malzaromen mit einer Note von Karamell und Schokolade, leichte Restsüße.',
  person: 'Wilhelm Gottlieb Zapf (1857–1944)',
  story: 'Der Gründer. Gelernter Bierbrauer aus dem Steigerwald, zog 1883 nach Uettingen — und trank sein Dunkles am liebsten warm zur Genesung.',
  gen: '1. Generation'
},
{
  name: "Elsa's Goldrausch",
  style: 'Helles Vollbier',
  abv: '4,9 %',
  plato: '11,8 °P',
  be: '22 BE',
  color: '#d4a234',
  desc: 'Leichte Malzaromatik mit dezenter Süße und harmonischer Hopfung — der Klassiker.',
  person: 'Elsa Zapf (1899–1957)',
  story: 'Die zweite Generation. Bekannt für ihre Fernfahrer-Station: Auch nachts um 3 Uhr kamen Trucker an — und bekamen ein gutes Essen.',
  gen: '2. Generation'
},
{
  name: "Hanna's Mühlenweiße",
  style: 'Weizenbier',
  abv: '5,2 %',
  plato: '12,5 °P',
  be: '13 BE',
  color: '#e6c87a',
  desc: 'Leicht fruchtig mit einer Note von Nelke und Banane. Angenehmer Körper und Spritzigkeit.',
  person: 'Hanna Zapf (1927–2018)',
  story: 'Wirtin von 1951 bis 2018. Sie stammte aus der Uettinger „Unteren Mühle" — ihr Vater brachte das erste elektrische Licht nach Uettingen.',
  gen: '3. Generation'
}];


const BeerScreen = ({ palette }) =>
<PaperBg palette={palette}>
    <div style={{ padding: '22px 22px 6px' }}>
      <SectionLabel palette={palette}>Hausbrauerei</SectionLabel>
      {/* Logo */}
      <div style={{ margin: '14px 0 6px', textAlign: 'center' }}>
        <img src="uploads/Zapfbraeu_Logo_RGB.png" alt="Zapfbräu" style={{ width: '70%', maxWidth: 200, display: 'block', margin: '0 auto' }} />
      </div>
      <H1 palette={palette} style={{ fontSize: 30, marginTop: 10 }}>
        Drei Generationen, <i style={{ color: palette.accent }}>drei Biere</i>
      </H1>
      <div style={{ fontSize: 13, color: palette.muted, marginTop: 6, lineHeight: 1.45 }}>
        Seit 2018 brauen wir wieder selbst. Jedes Bier trägt den Namen der Generation, die unser Haus geprägt hat.
      </div>
    </div>

    <div style={{ padding: '18px 22px 28px', display: 'flex', flexDirection: 'column', gap: 16 }}>
      {BEERS.map((b) =>
    <div key={b.name} style={{
      background: palette.paper, borderRadius: 18,
      border: `1px solid ${palette.green}15`, overflow: 'hidden'
    }}>
          {/* Color band */}
          <div style={{
        height: 6,
        background: `linear-gradient(90deg, ${b.color} 0%, ${b.color}88 100%)`
      }} />

          <div style={{ padding: '16px 16px 14px' }}>
            {/* Header row */}
            <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 10, marginBottom: 10 }}>
              <div style={{ flex: 1 }}>
                <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9.5, letterSpacing: '0.18em', textTransform: 'uppercase', color: palette.accent, marginBottom: 4 }}>{b.gen}</div>
                <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 20, color: palette.ink, lineHeight: 1.1 }}>{b.name}</div>
              </div>
              {/* Color swatch circle */}
              <div style={{
            width: 36, height: 36, borderRadius: '50%', flexShrink: 0, marginTop: 4,
            background: b.color,
            boxShadow: `0 2px 8px ${b.color}66, inset 0 1px 2px rgba(255,255,255,0.2)`
          }} />
            </div>

            {/* Style + stats */}
            <div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginBottom: 10 }}>
              <Pill palette={palette}>{b.style}</Pill>
              <span style={{ display: 'inline-flex', alignItems: 'center', padding: '4px 10px', borderRadius: 100, background: palette.green + '10', color: palette.green, fontSize: 11, fontWeight: 600, fontFamily: 'Manrope', gap: 4 }}>
                {b.abv}
              </span>
              <span style={{ display: 'inline-flex', alignItems: 'center', padding: '4px 10px', borderRadius: 100, background: palette.green + '10', color: palette.muted, fontSize: 11, fontFamily: 'JetBrains Mono, monospace' }}>
                {b.plato} · {b.be}
              </span>
            </div>

            {/* Description */}
            <div style={{ fontSize: 13, color: palette.ink, lineHeight: 1.5, marginBottom: 12 }}>{b.desc}</div>

            {/* Story */}
            <div style={{
          padding: '10px 12px', borderRadius: 10,
          background: palette.green + '08', borderLeft: `3px solid ${palette.accent}`
        }}>
              <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9.5, letterSpacing: '0.12em', textTransform: 'uppercase', color: palette.accent, marginBottom: 4 }}>{b.person}</div>
              <div style={{ fontSize: 12, color: palette.muted, lineHeight: 1.5, fontStyle: 'italic' }}>{b.story}</div>
            </div>
          </div>
        </div>
    )}
    </div>
  </PaperBg>;


// ─────────────────────────────────────────────────────────────
// BUCHEN HUB — Tisch oder Zimmer
// ─────────────────────────────────────────────────────────────
const BookHub = ({ palette, goto }) =>
<PaperBg palette={palette}>
    <div style={{ padding: '28px 22px 10px' }}>
      <SectionLabel palette={palette}>Reservierung</SectionLabel>
      <H1 palette={palette} style={{ fontSize: 30, marginTop: 6 }}>
        Was möchtest du <i style={{ color: palette.accent }}>buchen?</i>
      </H1>
    </div>
    <div style={{ padding: '18px 22px 28px', display: 'flex', flexDirection: 'column', gap: 14 }}>
      <button onClick={() => goto('book')} style={{
      background: palette.green, color: palette.cream, border: 'none',
      borderRadius: 18, padding: '22px 20px', textAlign: 'left', cursor: 'pointer',
      display: 'flex', alignItems: 'center', gap: 16,
      boxShadow: `0 6px 20px ${palette.green}30`
    }}>
        <div style={{ width: 52, height: 52, borderRadius: 26, background: palette.accent, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
          <Icon name="calendar" size={26} color={palette.cream} />
        </div>
        <div style={{ flex: 1 }}>
          <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, lineHeight: 1.1 }}>Tisch reservieren</div>
          <div style={{ fontSize: 12.5, opacity: 0.82, marginTop: 4 }}>In Wirtsstube oder Biergarten · Do–So</div>
        </div>
        <Icon name="chevron" size={18} color={palette.cream} />
      </button>
      <button onClick={() => goto('rooms')} style={{
      background: palette.paper, color: palette.ink, border: `1px solid ${palette.green}18`,
      borderRadius: 18, padding: '22px 20px', textAlign: 'left', cursor: 'pointer',
      display: 'flex', alignItems: 'center', gap: 16
    }}>
        <div style={{ width: 52, height: 52, borderRadius: 26, background: palette.green + '14', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
          <Icon name="bed" size={26} color={palette.green} />
        </div>
        <div style={{ flex: 1 }}>
          <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 22, color: palette.ink, lineHeight: 1.1 }}>Zimmer buchen</div>
          <div style={{ fontSize: 12.5, color: palette.muted, marginTop: 4 }}>11 Gästezimmer · Verfügbarkeit im Buchungssystem</div>
        </div>
        <Icon name="chevron" size={18} color={palette.muted} />
      </button>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        {[
      '🍽️ Tisch: 15 Min. freigehalten · 90 Min. Sitzzeit · Haustiere innen nicht erlaubt',
      '🔑 Check-in ab 14:00 Uhr · Check-out bis 10:00 Uhr',
      '🍳 Frühstück 15 €/Person · Do/Fr 7:30–10:00 · Sa/So 8:00–10:00 · Anmeldung bis 15:00 Uhr am Anreisetag',
      '🅿️ Kostenlos im abschließbaren Innenhof oder rund um die Kirche',
      '🐾 Haustiere leider nicht gestattet',
      '🚭 Nichtraucherzimmer · Rauchen im Hof / auf Balkonen erlaubt',
      '💳 Bargeld & EC-Karte vor Ort · Rechnung auf Anfrage per Mail'].
      map((txt, i) =>
      <div key={i} style={{ padding: '9px 12px', borderRadius: 10, background: palette.green + '08', fontSize: 11.5, color: palette.ink, lineHeight: 1.5 }}>{txt}</div>
      )}
      </div>
    </div>
  </PaperBg>;


// ─────────────────────────────────────────────────────────────
// FOTO-SLIDER (Bildergalerie)
// ─────────────────────────────────────────────────────────────
const GALLERY_ITEMS = [
{ id: 'zapf-wirtsstube', label: 'Wirtsstube', sub: 'Gemütlich & traditionell', src: null },
{ id: 'zapf-biergarten', label: 'Brauhaus Uettingen', sub: 'Das alte Brauhaus nebenan', src: 'uploads/20210712_125425.jpg' },
{ id: 'zapf-brauerei', label: 'Am Kirchplatz', sub: 'Seit 1883 in Familienbesitz', src: 'uploads/20210712_125622.jpg' },
{ id: 'zapf-gastehaus', label: 'Gästehaus', sub: '11 Zimmer im Hof', src: 'uploads/IMG_20170120_131630.jpg' }];


const GallerySlider = ({ palette }) => {
  const [active, setActive] = React.useState(0);
  return (
    <div style={{ padding: '22px 0 6px' }}>
      <div style={{ padding: '0 22px', marginBottom: 10 }}>
        <SectionLabel palette={palette}>Eindrücke</SectionLabel>
      </div>
      <div style={{ display: 'flex', gap: 10, overflowX: 'auto', padding: '4px 22px 12px' }}>
        {GALLERY_ITEMS.map((item, i) =>
        <div key={item.id} onClick={() => setActive(i)} style={{
          flexShrink: 0, width: 190, borderRadius: 14, overflow: 'hidden', cursor: 'pointer',
          border: active === i ? `2px solid ${palette.accent}` : '2px solid transparent',
          transition: 'border-color 0.2s'
        }}>
            {item.src ?
          <img src={item.src} alt={item.label}
          style={{ width: '100%', height: '120px', objectFit: 'cover', display: 'block' }} /> :

          <image-slot id={item.id} placeholder={item.label} shape="rect"
          style={{ width: '100%', height: '120px', display: 'block' }} />
          }
            <div style={{ background: palette.paper, padding: '6px 10px' }}>
              <div style={{ fontFamily: '"DM Serif Display", serif', fontSize: 14, color: palette.ink }}>{item.label}</div>
              <div style={{ fontSize: 11, color: palette.muted, marginTop: 1 }}>{item.sub}</div>
            </div>
          </div>
        )}
      </div>
    </div>);

};

// ─────────────────────────────────────────────────────────────
// IN-APP BROWSER — opens URLs in an iframe overlay
// ─────────────────────────────────────────────────────────────
const InAppBrowser = ({ url, title, palette, onClose }) =>
<div style={{
  position: 'absolute', inset: 0, zIndex: 50,
  display: 'flex', flexDirection: 'column',
  background: palette.paper
}}>
    <div style={{
    display: 'flex', alignItems: 'center', gap: 10, padding: '10px 14px',
    background: palette.green, flexShrink: 0
  }}>
      <button onClick={onClose} style={{
      width: 34, height: 34, borderRadius: 17, border: 'none', cursor: 'pointer',
      background: 'rgba(255,255,255,0.15)', display: 'flex', alignItems: 'center', justifyContent: 'center'
    }}>
        <Icon name="arrowLeft" size={16} color={palette.cream} />
      </button>
      <div style={{ flex: 1, fontFamily: '"DM Serif Display", serif', fontSize: 16, color: palette.cream, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{title}</div>
    </div>
    <iframe
    src={url}
    style={{ flex: 1, border: 'none', background: 'white', display: 'block' }}
    title={title} />
  
  </div>;


// ─────────────────────────────────────────────────────────────
// FAQ SCREEN
// ─────────────────────────────────────────────────────────────
const FAQ_DATA = [
{ cat: 'Restaurant & Biergarten', items: [
  { q: 'Gibt es glutenfreie Gerichte?', a: 'Das halbe Hähnchen mit Pommes und Salat ist definitiv glutenfrei — seit Jahrzehnten ein Klassiker. Bitte sprecht unser Personal an.' },
  { q: 'Warum sind abends nicht immer alle Gerichte da?', a: 'Frische-Philosophie: Wenn wir von allem viel vorrätig haben, können wir nicht frisch kochen. Wer z.B. ein Schäufele möchte, kann vorbestellen — wir halten es zurück.' },
  { q: 'Sonntag Mittag: Wie lange kann ich sitzen bleiben?', a: 'Wir haben zwei Sitzzeiten. Bei Reservierung um 11:30 Uhr bitten wir, den Tisch um 13:00 Uhr freizugeben, damit wir auch anderen Gästen Platz bieten können.' },
  { q: 'Kann man halbe Portionen bestellen?', a: 'Ja, für ausgewählte Gerichte. Wir ziehen 1,50 € vom Preis ab — nicht bei allen Gerichten möglich. Personal fragen.' },
  { q: 'Zahlung: Apple Pay oder Google Pay?', a: 'Ja, moderne kontaktlose Zahlungsmittel wie Apple Pay und Google Pay werden akzeptiert.' },
  { q: 'Gibt es Hochstühle oder Wickelmöglichkeiten?', a: '3 Hochstühle in der Gaststätte, 2 im Biergarten. Wickelplatz im 1. OG des Wirtshauses.' }]
},
{ cat: 'Brauerei & Bier', items: [
  { q: 'Kann man Bier in Flaschen kaufen?', a: 'Ja, zum Mitnehmen — einfach ansprechen.' },
  { q: 'Gibt es alkoholfreies Bier?', a: 'Momentan nicht — wir führen ausschließlich hausgebraute Biere.' },
  { q: 'Wie lange ist das Bier haltbar?', a: 'Unsere naturbelassenen Biere ca. 8 Wochen.' }]
},
{ cat: 'Hotel & Übernachtung', items: [
  { q: 'Gibt es barrierefreie Zimmer?', a: 'Alle Zimmer sind im 1. oder 2. OG — leider kein Aufzug.' },
  { q: 'Familienzimmer oder Zustellbetten?', a: 'Ja, ein Vierbettzimmer: Doppelbett + Stockbett (zwei normale Betten übereinander).' },
  { q: 'Minibar oder Getränke auf dem Zimmer?', a: 'Im Gästehaus (blaues Haus, EG) gibt es eine kleine Snackbar mit Getränken und Snacks. Ansonsten gerne im Wirtshaus.' },
  { q: 'Stornierung?', a: 'Bis 2 Wochen vorher: kostenlos. Bis 3 Tage: 50 %. Ab 3 Tage: voller Betrag. Bei Neubuchung erstatten wir.' },
  { q: 'Allergikerfreundliche Zimmer?', a: 'Auf Anfrage: allergikerfreundliche Bettdecken.' }]
},
{ cat: 'Umgebung & Freizeit', items: [
  { q: 'Wanderwege oder Radstrecken in der Nähe?', a: 'Direkt ab unserem Haus startet der Kulturweg durch Uettingen. Wir liegen an der Romantischen Straße. Radwege vorhanden.' },
  { q: 'Sehenswürdigkeiten in der Umgebung?', a: 'Uettinger Schloss, fränkische Bierkultur und malerische Dörfer. Weitere Infos auf unserer Website.' },
  { q: 'Fahrräder abstellen?', a: 'Sichere Plätze mit Überdachung im Hof und 6 E-Bike-Ladestationen. Ladekabel bitte mitbringen.' }]
}];


const FaqAccordion = ({ items, palette }) => {
  const [open, setOpen] = React.useState(null);
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
      {items.map((item, i) =>
      <div key={i} style={{ borderRadius: 12, overflow: 'hidden', border: `1px solid ${palette.green}20` }}>
          <button onClick={() => setOpen(open === i ? null : i)} style={{
          width: '100%', textAlign: 'left', padding: '12px 14px', border: 'none', cursor: 'pointer',
          background: open === i ? palette.green : palette.green + '14',
          display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 10,
          fontFamily: 'Manrope', fontSize: 13, fontWeight: 600,
          color: open === i ? palette.cream : palette.green,
          borderRadius: open === i ? '12px 12px 0 0' : '12px',
          transition: 'background 0.15s, color 0.15s'
        }}>
            <span style={{ flex: 1, lineHeight: 1.3 }}>{item.q}</span>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none"
          stroke={open === i ? palette.cream : palette.muted} strokeWidth="2.5"
          strokeLinecap="round" strokeLinejoin="round"
          style={{ transform: open === i ? 'rotate(180deg)' : 'none', transition: 'transform 0.2s', flexShrink: 0 }}>
              <path d="M6 9l6 6 6-6" />
            </svg>
          </button>
          {open === i &&
        <div style={{ padding: '12px 14px', background: palette.cream, fontSize: 13, color: palette.ink, lineHeight: 1.6 }}>
              {item.a}
            </div>
        }
        </div>
      )}
    </div>);

};

const FaqScreen = ({ palette }) =>
<PaperBg palette={palette}>
    <div style={{ padding: '22px 22px 8px' }}>
      <SectionLabel palette={palette}>Häufige Fragen</SectionLabel>
      <H1 palette={palette} style={{ fontSize: 28, marginTop: 6 }}>
        Noch Fragen? <i style={{ color: palette.accent }}>Wir haben Antworten.</i>
      </H1>
    </div>
    <div style={{ padding: '14px 22px 28px', display: 'flex', flexDirection: 'column', gap: 22 }}>
      {FAQ_DATA.map((cat) =>
    <div key={cat.cat}>
          <H2 palette={palette} style={{ fontSize: 17, marginBottom: 10 }}>{cat.cat}</H2>
          <FaqAccordion items={cat.items} palette={palette} />
        </div>
    )}
    </div>
  </PaperBg>;


Object.assign(window, {
  DEFAULT_APP_DATA,
  InAppBrowser,
  FaqScreen,
  StampPassScreen, CodeModal,
  BookHub, BookScreen, RoomsScreen, InfoScreen, BeerScreen,
  GallerySlider
});