// screens.jsx — all app screens (display-only catalog)

const fav = ['con-leche-360', 'latte-choco', 'mila-carne', 'alfajor-rosa', 'cafe-tonic', 'servicio-mate'].map(id => productById(id)).filter(Boolean);

// ── Quick-access tile ──────────────────────────────
function QuickTile({ icon, label, sub, onClick }) {
  return (
    <button onClick={onClick} className="card lift quick-tile">
      <span className="quick-ico"><Icon name={icon} size={22} sw={1.9} /></span>
      <span style={{ display: 'block' }}>
        <span style={{ display: 'block', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 14.5, color: 'var(--c-ink)', lineHeight: 1.2 }}>{label}</span>
        <span style={{ display: 'block', fontSize: 11.5, color: 'var(--c-ink-soft)', marginTop: 3, lineHeight: 1.3 }}>{sub}</span>
      </span>
    </button>
  );
}

// ── HOME ────────────────────────────────────────────
function HomeScreen() {
  const { t, lang } = useLang();
  const { go } = useNav();
  return (
    <div className="az-screen az-enter" style={{ paddingTop: 14 }}>
      <OpenStrip />
      {/* hero with layered Andes */}
      <div className="hero">
        <div className="hero-sky" />
        <div className="hero-sun" />
        <div className="hero-andes"><Andes height={120} /></div>
        <div style={{ position: 'relative', zIndex: 2 }}>
          <div className="hero-kicker"><Icon name="bus" size={14} sw={1.9} />{lang === 'en' ? 'Esquel bus terminal' : 'Terminal de Esquel'}</div>
          <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 28, lineHeight: 1.06, letterSpacing: '-.015em', whiteSpace: 'pre-line', color: '#fff', marginTop: 8 }}>{t.tagline}</div>
          <p style={{ margin: '11px 0 17px', fontSize: 13.5, lineHeight: 1.5, color: 'rgba(255,255,255,.88)', maxWidth: 290 }}>{t.heroSub}</p>
          <div style={{ display: 'flex', gap: 9 }}>
            <button className="btn btn-primary" onClick={() => go('menu')}><Icon name="coffee" size={18} sw={1.9} />{t.seeMenu}</button>
            <button className="btn btn-glass" onClick={() => go('combos')}>{t.combosCta}</button>
          </div>
        </div>
      </div>

      {/* quick access */}
      <div style={{ marginTop: 22 }}>
        <div className="h-eyebrow" style={{ marginBottom: 11 }}>{t.quick}</div>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 11 }}>
          <QuickTile icon="coffee" label={t.menu} sub={lang === 'en' ? 'Coffee, mate & food' : 'Café, mate y comida'} onClick={() => go('menu')} />
          <QuickTile icon="bag" label={lang === 'en' ? 'Your order' : 'Tu pedido'} sub={lang === 'en' ? 'Go to the counter' : 'Acercate al mostrador'} onClick={() => go('order')} />
          <QuickTile icon="mountain" label="Esquel" sub={lang === 'en' ? 'What to do' : 'Qué hacer'} onClick={() => go('esquel')} />
          <QuickTile icon="pin" label={t.where} sub={lang === 'en' ? 'Hours & map' : 'Horarios y mapa'} onClick={() => go('place')} />
        </div>
      </div>

      {/* featured rail */}
      <div style={{ marginTop: 24 }}>
        <SectionHead title={t.featured} sub={lang === 'en' ? 'What everyone grabs.' : 'Lo que todos se llevan.'} />
        <div className="rail">
          {fav.map(p => <ProductMini key={p.id} p={p} />)}
        </div>
      </div>

      {/* tourism teaser */}
      <button onClick={() => go('esquel')} className="card lift" style={{ width: '100%', marginTop: 22, padding: 0, overflow: 'hidden', cursor: 'pointer', textAlign: 'left', display: 'block', position: 'relative' }}>
        <div style={{ position: 'relative', height: 138 }}>
          <Photo src={TEASER_PHOTO} icon="leaf" tone="forest" height="100%" />
          <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(0deg, rgba(20,40,30,.82), rgba(20,40,30,.05))', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', padding: 16, pointerEvents: 'none' }}>
            <div className="h-eyebrow" style={{ color: 'var(--c-gold)' }}>{lang === 'en' ? 'Before you travel' : 'Antes de viajar'}</div>
            <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 19, color: '#fff', marginTop: 3 }}>{t.whatToDo}</div>
          </div>
          <span style={{ position: 'absolute', right: 14, bottom: 14, width: 36, height: 36, borderRadius: 999, background: 'rgba(255,255,255,.94)', color: 'var(--c-brand)', display: 'flex', alignItems: 'center', justifyContent: 'center', pointerEvents: 'none' }}><Icon name="arrowR" size={18} sw={2.2} /></span>
        </div>
      </button>

      <PickupNote />
    </div>
  );
}

function PickupNote() {
  const { t } = useLang();
  return (
    <div className="card" style={{ marginTop: 18, padding: 13, display: 'flex', gap: 10, alignItems: 'flex-start', background: 'color-mix(in srgb, var(--c-brand) 7%, var(--c-surface))' }}>
      <span style={{ color: 'var(--c-brand)', flexShrink: 0 }}><Icon name="info" size={19} sw={1.9} /></span>
      <p style={{ margin: 0, fontSize: 12.5, color: 'var(--c-ink-soft)', lineHeight: 1.5 }}>{t.pickupNote}</p>
    </div>
  );
}

// ── MENU ────────────────────────────────────────────
function MenuScreen() {
  const { t, lang } = useLang();
  const { go } = useNav();
  const [active, setActive] = React.useState('cafe');
  const refs = React.useRef({});
  const onChip = (id) => { setActive(id); const el = refs.current[id]; if (el) { const top = el.offsetTop - 70; el.closest('.az-scroll')?.scrollTo({ top, behavior: 'smooth' }); } };
  return (
    <div className="az-enter">
      <div className="chip-bar">
        <div className="rail" style={{ padding: '0 18px' }}>
          {CATEGORIES.map(c => (
            <button key={c.id} className={'chip' + (active === c.id ? ' is-on' : '')} onClick={() => onChip(c.id)}>
              <Icon name={c.icon} size={16} sw={1.9} />{lang === 'en' ? c.en : c.label}
            </button>
          ))}
        </div>
      </div>
      <div className="az-screen" style={{ paddingTop: 6 }}>
        <button onClick={() => go('combos')} className="card lift" style={{ width: '100%', cursor: 'pointer', textAlign: 'left', display: 'flex', alignItems: 'center', gap: 12, padding: 12, marginBottom: 18, background: 'color-mix(in srgb, var(--c-gold) 16%, var(--c-surface))' }}>
          <span style={{ width: 42, height: 42, borderRadius: 12, background: 'var(--c-accent)', color: '#fff', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}><Icon name="bag" size={22} sw={1.9} /></span>
          <span style={{ flex: 1 }}>
            <span style={{ display: 'block', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 15 }}>{t.combosTitle}</span>
            <span style={{ display: 'block', fontSize: 12, color: 'var(--c-ink-soft)' }}>{t.combosSub}</span>
          </span>
          <Icon name="chevR" size={20} sw={2} style={{ color: 'var(--c-ink-soft)' }} />
        </button>

        {CATEGORIES.map(c => (
          <div key={c.id} ref={el => refs.current[c.id] = el} style={{ scrollMarginTop: 70, marginBottom: 24 }}>
            <div className="cat-head">
              <span style={{ color: 'var(--c-brand)', display: 'flex' }}><Icon name={c.icon} size={19} sw={1.9} /></span>
              <h3 style={{ fontWeight: 700, fontSize: 18 }}>{lang === 'en' ? c.en : c.label}</h3>
              <span className="cat-rule" />
            </div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 9 }}>
              {PRODUCTS.filter(p => p.cat === c.id).map(p => <ProductCard key={p.id} p={p} />)}
            </div>
          </div>
        ))}
        <p style={{ fontSize: 11.5, color: 'var(--c-ink-soft)', textAlign: 'center', marginTop: 4, lineHeight: 1.5 }}>
          {lang === 'en' ? 'Prices may change. Ask at the counter.' : 'Los precios pueden variar. Consultá en el mostrador.'}
        </p>
      </div>
    </div>
  );
}

// ── COMBOS ──────────────────────────────────────────
function CombosScreen() {
  const { t, lang } = useLang();
  return (
    <div className="az-screen az-enter" style={{ paddingTop: 18 }}>
      <SectionHead eyebrow={lang === 'en' ? 'To go' : 'Para llevar'} title={t.combosTitle} sub={t.combosSub} />
      <div style={{ display: 'flex', flexDirection: 'column', gap: 13 }}>
        {COMBOS.map(c => <ComboCard key={c.id} c={c} />)}
      </div>
      <p style={{ fontSize: 12, color: 'var(--c-ink-soft)', textAlign: 'center', marginTop: 18, lineHeight: 1.5 }}>
        {lang === 'en' ? 'Suggestions — mix and match at the counter.' : 'Son sugerencias — armalo a tu gusto en el mostrador.'}
      </p>
    </div>
  );
}

// ── ESQUEL (tourism → products) ─────────────────────
function EsquelScreen() {
  const { t, lang } = useLang();
  return (
    <div className="az-screen az-enter" style={{ paddingTop: 18 }}>
      <SectionHead eyebrow="Patagonia" title={t.esquelTitle} sub={t.esquelSub} />
      <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
        {ACTIVITIES.map(a => (
          <div key={a.id} className="card" style={{ overflow: 'hidden' }}>
            <div style={{ position: 'relative', height: 132 }}>
              <Photo src={a.photo} icon={a.icon} tone={a.tone} height="100%" />
              <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(0deg, rgba(20,30,25,.74), rgba(20,30,25,0) 60%)', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', padding: 14, pointerEvents: 'none' }}>
                <span style={{ alignSelf: 'flex-start', fontSize: 10.5, fontWeight: 700, letterSpacing: '.04em', textTransform: 'uppercase', color: '#fff', background: 'rgba(0,0,0,.34)', padding: '4px 9px', borderRadius: 999, marginBottom: 6 }}>{a.meta}</span>
                <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 18, color: '#fff', lineHeight: 1.1 }}>{lang === 'en' ? a.en : a.name}</div>
              </div>
            </div>
            <div style={{ padding: '13px 14px 14px' }}>
              <p style={{ margin: '0 0 13px', fontSize: 13, color: 'var(--c-ink-soft)', lineHeight: 1.5 }}>{a.blurb}</p>
              <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 9 }}>
                <Icon name="bag" size={15} sw={1.9} style={{ color: 'var(--c-accent)' }} />
                <span className="h-eyebrow">{t.forTheRoad}</span>
              </div>
              <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
                {a.recs.map(id => <RecItem key={id} id={id} />)}
              </div>
              {a.comboId && (() => { const c = COMBOS.find(x => x.id === a.comboId); if (!c) return null; return (
                <div className="combo-link">
                  <span style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Icon name="bag" size={16} sw={1.9} style={{ color: 'var(--c-brand)' }} /><span style={{ fontWeight: 700, fontSize: 13 }}>{c.name}</span></span>
                  <span style={{ fontWeight: 700, fontSize: 13, color: 'var(--c-accent-ink)' }}>{t.approx} {fmt(comboTotal(c))}</span>
                </div>
              ); })()}
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

// ── PLACE (location & hours) ────────────────────────
function PlaceScreen() {
  const { t, lang } = useLang();
  const { go } = useNav();
  return (
    <div className="az-screen az-enter" style={{ paddingTop: 18 }}>
      <SectionHead eyebrow={lang === 'en' ? 'Bus terminal' : 'Terminal de ómnibus'} title={t.placeTitle} />
      {/* real Google Maps embed */}
      <div className="map-wrap">
        <iframe title="Mapa" src={PLACE.embed} loading="lazy" referrerPolicy="no-referrer-when-downgrade"
          style={{ border: 0, width: '100%', height: '100%', display: 'block' }}></iframe>
      </div>
      <div className="card" style={{ padding: 14, marginTop: 13, display: 'flex', gap: 11, alignItems: 'flex-start' }}>
        <span style={{ color: 'var(--c-accent)', marginTop: 1, flexShrink: 0 }}><Icon name="pin" size={22} sw={1.9} /></span>
        <div>
          <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 15 }}>{PLACE.name}</div>
          <div style={{ fontSize: 13, color: 'var(--c-ink)', marginTop: 2, fontWeight: 600 }}>{PLACE.addr}</div>
          <div style={{ fontSize: 12.5, color: 'var(--c-ink-soft)', marginTop: 2, lineHeight: 1.5 }}>
            {lang === 'en' ? 'Inside the Esquel bus terminal.' : PLACE.inside + '.'}<br />{PLACE.city}
          </div>
        </div>
      </div>

      {/* directions + menu */}
      <div style={{ display: 'flex', gap: 10, marginTop: 14 }}>
        <a className="btn btn-dark" style={{ flex: 1, textDecoration: 'none' }} href={PLACE.dir} target="_blank" rel="noopener"><Icon name="route" size={18} sw={1.9} />{t.directions}</a>
        <button className="btn btn-ghost" style={{ flex: 1 }} onClick={() => go('menu')}><Icon name="coffee" size={17} sw={1.9} />{t.seeMenu}</button>
      </div>

      {/* hours */}
      <div style={{ marginTop: 22 }}>
        <div className="cat-head" style={{ marginBottom: 11 }}>
          <Icon name="clock" size={18} sw={1.9} style={{ color: 'var(--c-brand)' }} />
          <h3 style={{ fontWeight: 700, fontSize: 17 }}>{t.hoursTitle}</h3>
          <span className="cat-rule" />
        </div>
        <div className="card" style={{ overflow: 'hidden' }}>
          {HOURS.map((r, i) => (
            <div key={i} style={{ display: 'flex', justifyContent: 'space-between', padding: '13px 15px', fontSize: 13.5, borderTop: i ? '1px solid var(--c-line)' : 'none' }}>
              <span style={{ color: 'var(--c-ink)' }}>{r.d}</span>
              <span style={{ fontWeight: 700, color: 'var(--c-ink)' }}>{r.h}</span>
            </div>
          ))}
        </div>
        <p style={{ fontSize: 11.5, color: 'var(--c-ink-soft)', textAlign: 'center', marginTop: 9 }}>
          {lang === 'en' ? 'Hours to confirm.' : 'Horarios a confirmar.'}
        </p>
      </div>

      <PickupNote />
    </div>
  );
}

// ── CART SCREEN ─────────────────────────────────────
function OrderNoteScreen() {
  const { lang } = useLang();
  const { cart, addToCart, removeFromCart, clearCart } = useCart();
  const { go } = useNav();
  const items = Object.entries(cart).filter(([_, v]) => v.qty > 0);
  const total = items.reduce((s, [_, v]) => s + (v.price > 0 ? v.price * v.qty : 0), 0);

  if (items.length === 0) return (
    <div className="az-screen az-enter" style={{ paddingTop: 48, display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center', gap: 18 }}>
      <div style={{ width: 72, height: 72, borderRadius: 999, background: 'color-mix(in srgb, var(--c-brand) 14%, var(--c-surface))', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--c-brand)' }}>
        <Icon name="bag" size={34} sw={1.7} />
      </div>
      <div>
        <div style={{ fontFamily: 'var(--font-display)', fontWeight: 800, fontSize: 22, color: 'var(--c-ink)', lineHeight: 1.1 }}>{lang === 'en' ? 'Your order is empty' : 'Tu pedido está vacío'}</div>
        <p style={{ margin: '10px auto 0', fontSize: 14, color: 'var(--c-ink-soft)', lineHeight: 1.6, maxWidth: 270 }}>{lang === 'en' ? 'Add items from the menu using the + buttons.' : 'Agregá productos desde la carta con los botones +.'}</p>
      </div>
      <button className="btn btn-primary" onClick={() => go('menu')}><Icon name="coffee" size={17} sw={1.9} />{lang === 'en' ? 'See menu' : 'Ver carta'}</button>
    </div>
  );

  return (
    <div className="az-screen az-enter" style={{ paddingTop: 14 }}>
      <SectionHead
        title={lang === 'en' ? 'Your order' : 'Tu pedido'}
        sub={lang === 'en' ? 'Show this screen at the counter' : 'Mostrá esta pantalla en el mostrador'}
      />

      <div style={{ display: 'flex', flexDirection: 'column', gap: 9 }}>
        {items.map(([id, v]) => (
          <div key={id} className="card prod-row" style={{ alignItems: 'center' }}>
            <Placeholder icon={v.icon} tone={v.tone} style={{ width: 52, height: 52, flexShrink: 0, borderRadius: 'var(--r-sm)' }} />
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 14.5, color: 'var(--c-ink)', lineHeight: 1.2 }}>{v.name}</div>
              {v.price > 0 && <div style={{ fontSize: 12, color: 'var(--c-ink-soft)', marginTop: 2 }}>{fmt(v.price)} c/u</div>}
            </div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, flexShrink: 0 }}>
              <button style={STEP_BTN} onClick={() => removeFromCart(id)}>−</button>
              <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 16, minWidth: 20, textAlign: 'center', color: 'var(--c-brand)' }}>{v.qty}</span>
              <button style={{ ...STEP_BTN, background: 'var(--c-brand)', color: '#fff', border: 'none' }} onClick={() => addToCart(id, v)}>+</button>
            </div>
            {v.price > 0 && (
              <div style={{ flexShrink: 0, minWidth: 56, textAlign: 'right' }}>
                <Price value={v.price * v.qty} />
              </div>
            )}
          </div>
        ))}
      </div>

      {total > 0 && (
        <div className="card" style={{ marginTop: 14, padding: '14px 18px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', background: 'color-mix(in srgb, var(--c-brand) 8%, var(--c-surface))' }}>
          <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 15, color: 'var(--c-ink)' }}>{lang === 'en' ? 'Approx. total' : 'Total aprox.'}</span>
          <Price value={total} size={20} />
        </div>
      )}

      <div className="card" style={{ marginTop: 12, padding: '18px 18px 20px', textAlign: 'center', background: 'color-mix(in srgb, var(--c-brand) 6%, var(--c-surface))' }}>
        <div style={{ color: 'var(--c-brand)', marginBottom: 8, display: 'flex', justifyContent: 'center' }}><Icon name="bag" size={28} sw={1.7} /></div>
        <div style={{ fontFamily: 'var(--font-display)', fontWeight: 800, fontSize: 18, color: 'var(--c-ink)', lineHeight: 1.1, marginBottom: 6 }}>
          {lang === 'en' ? 'Come to the counter!' : '¡Acercate al mostrador!'}
        </div>
        <p style={{ margin: 0, fontSize: 13, color: 'var(--c-ink-soft)', lineHeight: 1.5 }}>
          {lang === 'en' ? 'Show this screen and we\'ll prepare everything right away.' : 'Mostrá esta pantalla y te lo preparamos al momento.'}
        </p>
      </div>

      <button className="btn btn-ghost" style={{ width: '100%', marginTop: 14 }} onClick={clearCart}>
        <Icon name="trash" size={15} sw={1.9} />{lang === 'en' ? 'Clear order' : 'Limpiar pedido'}
      </button>
    </div>
  );
}

// ── NOSOTROS ─────────────────────────────────────────
function StarRating({ stars }) {
  return (
    <span style={{ display: 'inline-flex', gap: 2 }}>
      {[1,2,3,4,5].map(i => (
        <svg key={i} width="14" height="14" viewBox="0 0 24 24" fill={i <= stars ? 'var(--c-accent)' : 'none'}
          stroke={i <= stars ? 'var(--c-accent)' : 'var(--c-line)'} strokeWidth="1.8" strokeLinejoin="round">
          <path d="M12 3.5l2.5 5.3 5.5.7-4 3.9 1 5.6L12 16.4 7.5 19l1-5.6-4-3.9 5.5-.7L12 3.5Z"/>
        </svg>
      ))}
    </span>
  );
}

function ReviewCard({ r }) {
  return (
    <div className="card" style={{ padding: '13px 14px' }}>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
        <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 14, color: 'var(--c-ink)' }}>{r.name}</span>
        <StarRating stars={r.stars} />
      </div>
      <p style={{ margin: 0, fontSize: 13, color: 'var(--c-ink-soft)', lineHeight: 1.5 }}>{r.text}</p>
    </div>
  );
}

function ReviewForm({ onSubmit }) {
  const { t } = useLang();
  const [name, setName] = React.useState('');
  const [text, setText] = React.useState('');
  const [stars, setStars] = React.useState(5);
  const [sent, setSent] = React.useState(false);

  const submit = () => {
    if (!name.trim() || !text.trim()) return;
    onSubmit({ id: 'u-' + Date.now(), name: name.trim(), stars, text: text.trim() });
    setSent(true);
  };

  const MAPS_URL = 'https://www.google.com/maps?q=cafetería+la+z+esquel#lrd=0x961dad47c0746c73:0x9a52287c646e2396,3';

  if (sent) {
    return (
      <div className="card" style={{ padding: 18, textAlign: 'center', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 12 }}>
        <span style={{ color: 'var(--c-brand)' }}><Icon name="check" size={32} sw={2.2} /></span>
        <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 16, color: 'var(--c-ink)' }}>{t.reviewThanks}</div>
        <div style={{ width: '100%', height: 1, background: 'var(--c-line)' }} />
        <div style={{ fontSize: 13, color: 'var(--c-ink-soft)', lineHeight: 1.5 }}>
          {lang === 'en' ? '¿También nos dejás una reseña en Google Maps? Nos ayuda mucho 🙏' : '¿También nos dejás una reseña en Google Maps? Nos ayuda mucho 🙏'}
        </div>
        <a href={MAPS_URL} target="_blank" rel="noopener"
          style={{ display: 'inline-flex', alignItems: 'center', gap: 8, padding: '10px 20px', borderRadius: 999, background: '#4285F4', color: '#fff', textDecoration: 'none', fontWeight: 700, fontSize: 14 }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="#fff"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg>
          {lang === 'en' ? 'Review on Google Maps' : 'Reseña en Google Maps'}
        </a>
      </div>
    );
  }

  return (
    <div className="card" style={{ padding: '14px 14px 16px', display: 'flex', flexDirection: 'column', gap: 10 }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
        <span style={{ fontSize: 13, color: 'var(--c-ink-soft)', marginRight: 4 }}>Estrellas:</span>
        {[1,2,3,4,5].map(i => (
          <button key={i} onClick={() => setStars(i)} style={{ background: 'none', border: 'none', padding: 2, cursor: 'pointer', color: i <= stars ? 'var(--c-accent)' : 'var(--c-line)' }}>
            <svg width="22" height="22" viewBox="0 0 24 24" fill={i <= stars ? 'currentColor' : 'none'} stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round">
              <path d="M12 3.5l2.5 5.3 5.5.7-4 3.9 1 5.6L12 16.4 7.5 19l1-5.6-4-3.9 5.5-.7L12 3.5Z"/>
            </svg>
          </button>
        ))}
      </div>
      <input
        placeholder={t.reviewName}
        value={name}
        onChange={e => setName(e.target.value)}
        style={{ padding: '9px 12px', borderRadius: 'var(--r-sm)', border: '1.5px solid var(--c-line)', fontSize: 14, background: 'var(--c-bg)', color: 'var(--c-ink)', outline: 'none', fontFamily: 'inherit' }}
      />
      <textarea
        placeholder={t.reviewText}
        value={text}
        onChange={e => setText(e.target.value)}
        rows={3}
        style={{ padding: '9px 12px', borderRadius: 'var(--r-sm)', border: '1.5px solid var(--c-line)', fontSize: 13.5, background: 'var(--c-bg)', color: 'var(--c-ink)', outline: 'none', resize: 'none', fontFamily: 'inherit', lineHeight: 1.5 }}
      />
      <button className="btn btn-primary" onClick={submit} style={{ alignSelf: 'flex-end', paddingLeft: 22, paddingRight: 22 }}>{t.reviewSend}</button>
    </div>
  );
}

const REVIEWS_KEY = 'laz-user-reviews';

// helper: pick the right language string from a {es, en} object or plain string
function txt(field, lang) {
  if (!field) return '';
  if (typeof field === 'string') return field;
  return field[lang] || field.es || '';
}

// ── Photo gallery ───────────────────────────────────
function PhotoThumb({ ph, lang, onClick }) {
  return (
    <button onClick={onClick}
      style={{ padding: 0, border: 'none', borderRadius: 'var(--r-sm)', overflow: 'hidden', cursor: 'pointer', background: 'var(--c-surface)', aspectRatio: '4/3', position: 'relative', display: 'block', width: '100%' }}>
      <img src={ph.url} alt={txt(ph.caption, lang) || ''}
        style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }} />
      {ph.caption && txt(ph.caption, lang) && (
        <div style={{ position: 'absolute', bottom: 0, left: 0, right: 0, background: 'linear-gradient(0deg,rgba(0,0,0,.62),transparent)', padding: '18px 8px 7px', fontSize: 11.5, color: '#fff', fontWeight: 600, lineHeight: 1.3 }}>
          {txt(ph.caption, lang)}
        </div>
      )}
    </button>
  );
}

function PhotoLightbox({ photo, lang, onClose }) {
  if (!photo) return null;
  return (
    <div onClick={onClose}
      style={{ position: 'fixed', inset: 0, zIndex: 9999, background: 'rgba(0,0,0,.92)', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', padding: 20 }}>
      <img src={photo.url} alt={txt(photo.caption, lang) || ''}
        style={{ maxWidth: '100%', maxHeight: '78vh', objectFit: 'contain', borderRadius: 10 }} />
      {photo.caption && txt(photo.caption, lang) && (
        <p style={{ color: '#fff', marginTop: 12, fontSize: 14, textAlign: 'center', lineHeight: 1.4 }}>{txt(photo.caption, lang)}</p>
      )}
      <button onClick={onClose} style={{ marginTop: 18, padding: '8px 22px', borderRadius: 999, background: 'rgba(255,255,255,.18)', color: '#fff', border: 'none', fontSize: 13, fontWeight: 600, cursor: 'pointer' }}>Cerrar ✕</button>
    </div>
  );
}

// Full gallery modal — all photos in scrollable grid
function GalleryModal({ photos, lang, onClose }) {
  const [lightbox, setLightbox] = React.useState(null);
  return (
    <div style={{ position: 'fixed', inset: 0, zIndex: 9000, background: 'var(--c-bg)', display: 'flex', flexDirection: 'column' }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '14px 18px', background: 'var(--c-brand)', color: '#FBF6EC', flexShrink: 0 }}>
        <button onClick={onClose} style={{ background: 'none', border: 'none', color: '#FBF6EC', cursor: 'pointer', display: 'flex', alignItems: 'center', padding: 4 }}>
          <Icon name="chevL" size={22} sw={2.2} />
        </button>
        <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 17 }}>
          {lang === 'en' ? 'Photo gallery' : 'Galería de fotos'}
        </span>
        <span style={{ fontSize: 12, opacity: .75, marginLeft: 'auto' }}>{photos.length} {lang === 'en' ? 'photos' : 'fotos'}</span>
      </div>
      <div style={{ overflowY: 'auto', flex: 1, padding: 12 }}>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8 }}>
          {photos.map((ph, i) => <PhotoThumb key={ph.id || i} ph={ph} lang={lang} onClick={() => setLightbox(ph)} />)}
        </div>
        <div style={{ height: 20 }} />
      </div>
      <PhotoLightbox photo={lightbox} lang={lang} onClose={() => setLightbox(null)} />
    </div>
  );
}

// Preview: shows 4 photos + "Ver galería completa" button
function PhotoGallery({ photos, lang }) {
  const [showAll, setShowAll] = React.useState(false);
  const [lightbox, setLightbox] = React.useState(null);
  if (!photos || photos.length === 0) return null;
  const preview = photos.slice(0, 4);
  return (
    <>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8, marginBottom: photos.length > 4 ? 10 : 22 }}>
        {preview.map((ph, i) => <PhotoThumb key={ph.id || i} ph={ph} lang={lang} onClick={() => setLightbox(ph)} />)}
      </div>
      {photos.length > 4 && (
        <button className="btn btn-ghost" style={{ width: '100%', marginBottom: 22 }} onClick={() => setShowAll(true)}>
          <Icon name="image" size={16} sw={1.9} />
          {lang === 'en' ? `See all ${photos.length} photos` : `Ver las ${photos.length} fotos`}
        </button>
      )}
      <PhotoLightbox photo={lightbox} lang={lang} onClose={() => setLightbox(null)} />
      {showAll && <GalleryModal photos={photos} lang={lang} onClose={() => setShowAll(false)} />}
    </>
  );
}

function NosotrosScreen() {
  const { t, lang } = useLang();
  const { intro, stories, photos, reviews: baseReviews } = NOSOTROS;
  const [showForm, setShowForm] = React.useState(false);
  const [userReviews, setUserReviews] = React.useState(() => {
    try { return JSON.parse(localStorage.getItem(REVIEWS_KEY) || '[]'); } catch { return []; }
  });

  const handleReview = (r) => {
    const next = [r, ...userReviews];
    setUserReviews(next);
    try { localStorage.setItem(REVIEWS_KEY, JSON.stringify(next)); } catch {}
    setShowForm(false);
  };

  const allReviews = [...userReviews, ...baseReviews];

  return (
    <div className="az-screen az-enter" style={{ paddingTop: 18 }}>
      {/* Intro */}
      <div className="card" style={{ overflow: 'hidden', marginBottom: 18 }}>
        <div style={{ height: 7, background: 'linear-gradient(90deg, var(--c-brand), var(--c-accent))' }} />
        <div style={{ padding: '18px 16px 20px' }}>
          <div className="h-eyebrow" style={{ marginBottom: 6 }}>{t.nosotrosEyebrow}</div>
          <div style={{ fontFamily: 'var(--font-display)', fontWeight: 800, fontSize: 24, color: 'var(--c-ink)', lineHeight: 1.1, marginBottom: 10 }}>{intro.title}</div>
          <p style={{ margin: '0 0 12px', fontSize: 14, color: 'var(--c-ink-soft)', lineHeight: 1.65 }}>{txt(intro.body, lang)}</p>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12, fontWeight: 600, color: 'var(--c-brand)', background: 'color-mix(in srgb, var(--c-brand) 10%, var(--c-surface))', padding: '5px 11px', borderRadius: 999 }}>
            <Icon name="pin" size={13} sw={1.9} />{txt(intro.since, lang)}
          </div>
        </div>
      </div>

      {/* Galería de fotos */}
      {photos && photos.length > 0 && (
        <div style={{ marginBottom: 4 }}>
          <div className="cat-head" style={{ marginBottom: 11 }}>
            <Icon name="image" size={18} sw={1.9} style={{ color: 'var(--c-brand)' }} />
            <h3 style={{ fontWeight: 700, fontSize: 17 }}>{lang === 'en' ? 'Photo gallery' : 'Galería de fotos'}</h3>
            <span className="cat-rule" />
          </div>
          <PhotoGallery photos={photos} lang={lang} />
        </div>
      )}

      {/* Novedades / stories */}
      <div style={{ marginBottom: 22 }}>
        <div className="cat-head" style={{ marginBottom: 11 }}>
          <Icon name="star" size={18} sw={1.9} style={{ color: 'var(--c-brand)' }} />
          <h3 style={{ fontWeight: 700, fontSize: 17 }}>{t.storiesTitle}</h3>
          <span className="cat-rule" />
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
          {stories.map(s => (
            <div key={s.id} className="card" style={{ padding: '13px 14px' }}>
              <div style={{ fontSize: 11, fontWeight: 700, letterSpacing: '.05em', textTransform: 'uppercase', color: 'var(--c-accent-ink)', marginBottom: 4 }}>{s.date}</div>
              <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 15.5, color: 'var(--c-ink)', marginBottom: 5 }}>{txt(s.title, lang)}</div>
              <p style={{ margin: 0, fontSize: 13, color: 'var(--c-ink-soft)', lineHeight: 1.55 }}>{txt(s.body, lang)}</p>
            </div>
          ))}
        </div>
      </div>

      {/* Reseñas */}
      <div>
        <div className="cat-head" style={{ marginBottom: 11 }}>
          <Icon name="heart" size={18} sw={1.9} style={{ color: 'var(--c-brand)' }} />
          <h3 style={{ fontWeight: 700, fontSize: 17 }}>{t.reviewsTitle}</h3>
          <span className="cat-rule" />
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginBottom: 14 }}>
          {allReviews.map(r => <ReviewCard key={r.id} r={r} />)}
        </div>
        {!showForm
          ? <button className="btn btn-ghost" style={{ width: '100%' }} onClick={() => setShowForm(true)}>
              <Icon name="heart" size={16} sw={1.9} />{t.reviewsWrite}
            </button>
          : <ReviewForm onSubmit={handleReview} />
        }
      </div>
    </div>
  );
}

Object.assign(window, { HomeScreen, MenuScreen, CombosScreen, EsquelScreen, PlaceScreen, NosotrosScreen, OrderNoteScreen });
