/* global React, ReactDOM */
const { useState } = React;

// ===== Palette presets =====
const PALETTES = {
  "azul-celeste": {
    name: "Azul institucional",
    ink: "#0a1f3d", "ink-soft": "#1f3a63",
    blue: "#0f4c8a", "blue-strong": "#093766",
    sky: "#6cb6e0", sun: "#f4b740",
    terracotta: "#c75b3c", cream: "#f8f3e7",
    paper: "#fdfbf5", line: "#e6dfcc",
    muted: "#6b6552", green: "#3f7d4e",
  },
  "azul-profundo": {
    name: "Azul profundo",
    ink: "#0b1a33", "ink-soft": "#1c2e52",
    blue: "#1d3a8a", "blue-strong": "#0e235f",
    sky: "#8db4e8", sun: "#ffc857",
    terracotta: "#d96a3a", cream: "#f4f1e8",
    paper: "#fbf9f2", line: "#e2dccc",
    muted: "#666075", green: "#3f8060",
  },
  "verde-tierra": {
    name: "Verde y tierra",
    ink: "#1d2a1f", "ink-soft": "#324235",
    blue: "#2d5a3d", "blue-strong": "#1d3d28",
    sky: "#a8c4a2", sun: "#e8a93d",
    terracotta: "#b8552e", cream: "#f5f1e3",
    paper: "#fbf8ec", line: "#e0d9c2",
    muted: "#675e4a", green: "#3f7d4e",
  },
  "bordo-clasico": {
    name: "Bordó clásico",
    ink: "#231013", "ink-soft": "#3a1c22",
    blue: "#8a1c2b", "blue-strong": "#5e0e1b",
    sky: "#d6a0a5", sun: "#e8b440",
    terracotta: "#c75b3c", cream: "#f5ede2",
    paper: "#fbf6ec", line: "#e4d7c2",
    muted: "#6e5a4a", green: "#4a7050",
  },
};

const PALETTE_OPTIONS = Object.entries(PALETTES).map(([k, v]) => ({
  key: k, name: v.name,
  colors: [v.blue, v.sky, v.sun, v.cream]
}));

const DEFAULTS = /*EDITMODE-BEGIN*/{
  "palette": "azul-celeste"
}/*EDITMODE-END*/;

function applyPalette(key) {
  const p = PALETTES[key] || PALETTES["azul-celeste"];
  const root = document.documentElement;
  Object.entries(p).forEach(([k, v]) => {
    if (k === "name") return;
    root.style.setProperty(`--${k}`, v);
  });
}

// ===== Icons =====
const Icon = {
  Phone: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/></svg>,
  Alert: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>,
  Doc: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="9" y1="13" x2="15" y2="13"/><line x1="9" y1="17" x2="13" y2="17"/></svg>,
  Calendar: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>,
  Card: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="2" y="5" width="20" height="14" rx="2"/><line x1="2" y1="10" x2="22" y2="10"/></svg>,
  Map: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><polygon points="1 6 1 22 8 18 16 22 23 18 23 2 16 6 8 2 1 6"/><line x1="8" y1="2" x2="8" y2="18"/><line x1="16" y1="6" x2="16" y2="22"/></svg>,
  Shop: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M3 9l1-5h16l1 5"/><path d="M3 9v11a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1V9"/><path d="M3 9h18"/><path d="M9 21V13h6v8"/></svg>,
  Arrow: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><line x1="7" y1="17" x2="17" y2="7"/><polyline points="7 7 17 7 17 17"/></svg>,
  Pin: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/></svg>,
  Mail: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></svg>,
  Fb: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"/></svg>,
  Ig: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" {...p}><rect x="2" y="2" width="20" height="20" rx="5"/><path d="M16 11.4A4 4 0 1 1 12.6 8 4 4 0 0 1 16 11.4z"/><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"/></svg>,
  Yt: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M23 7s-.2-1.6-.8-2.3c-.8-.9-1.7-.9-2.1-1C16.7 3.5 12 3.5 12 3.5s-4.7 0-8.1.2c-.4 0-1.3 0-2.1 1C1.2 5.4 1 7 1 7S.8 8.9.8 10.7v1.7C.8 14.1 1 16 1 16s.2 1.6.8 2.3c.8.9 1.9.9 2.4 1 1.7.2 7.8.2 7.8.2s4.7 0 8.1-.3c.4-.1 1.3-.1 2.1-1 .6-.7.8-2.3.8-2.3s.2-1.9.2-3.7v-1.7C23.2 8.9 23 7 23 7zM9.7 14.5V7.9l6.3 3.3-6.3 3.3z"/></svg>,
  Sun: (p) => <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>,
  Search: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>,
};

// ===== Header with mega-menu =====
function MegaMenu({ item, open }) {
  if (!item.children) return null;
  // Multi-column layout if any child has its own children
  const hasGrandchildren = item.children.some(c => c.children && c.children.length);
  return (
    <div className={`mega ${open ? 'open' : ''} ${hasGrandchildren ? 'wide' : ''}`}>
      <div className="mega-inner">
        {item.children.map((c, i) => (
          <div key={i} className="mega-col">
            {c.slug
              ? <a className="mega-head" href={window.link(c.slug, c.external)}>{c.label}</a>
              : <div className="mega-head">{c.label}</div>}
            {c.children && (
              <ul>
                {c.children.map((cc, j) => (
                  <li key={j}>
                    <a href={window.link(cc.slug, cc.external)}>{cc.label}</a>
                  </li>
                ))}
              </ul>
            )}
          </div>
        ))}
      </div>
    </div>
  );
}

function Header({ currentSlug }) {
  const [open, setOpen] = useState(null);
  const [mobileOpen, setMobileOpen] = useState(false);
  const [expanded, setExpanded] = useState({});
  // Cerrar drawer al cambiar de ruta y liberar el scroll del body
  React.useEffect(() => {
    setMobileOpen(false);
    document.body.style.overflow = '';
  }, [currentSlug]);
  React.useEffect(() => {
    document.body.style.overflow = mobileOpen ? 'hidden' : '';
  }, [mobileOpen]);
  return (
    <>
      <div className="utility">
        <div className="container">
          <div className="left">
            <span className="urgent"><Icon.Alert style={{width:14, height:14, verticalAlign:'middle', marginRight:6}}/> Urgencias 24h · <strong>100 · 107 · 911</strong></span>
            <span style={{opacity:.4}} className="util-divider">|</span>
            <span className="util-hours"><span className="dot"/>Comuna abierta hoy 7:00–13:00</span>
          </div>
          <div className="right">
            <a href="tel:+543564492253" className="util-phone"><Icon.Phone style={{width:13, height:13, verticalAlign:'middle', marginRight:6}}/>03564 492253</a>
            <a href="#/contacto" className="util-contact">Contacto</a>
            <a href="#" className="pill"><Icon.Search/> <span className="pill-label">Buscar</span></a>
          </div>
        </div>
      </div>
      <div className="flag-stripe"><i/><i/><i/></div>
      <header className="header">
        <div className="container">
          <a href="#/" className="brand">
            <img src="assets/logo-zenon.png" alt="Comuna de Zenón Pereyra"/>
            <div className="brand-text">
              <div className="small">Gobierno Comunal</div>
              <div className="name">Comuna de<br/>Zenón Pereyra</div>
            </div>
          </a>
          <nav className="main" onMouseLeave={() => setOpen(null)}>
            {window.NAV.map((item, i) => {
              const hasMenu = !!item.children;
              const isActive = item.slug === currentSlug ||
                (item.children && item.children.some(c =>
                  c.slug === currentSlug ||
                  (c.children && c.children.some(cc => cc.slug === currentSlug))
                ));
              return (
                <div key={i} className="nav-item"
                     onMouseEnter={() => setOpen(hasMenu ? i : null)}>
                  <a
                    href={window.link(item.slug || "#", item.external)}
                    className={(item.cta ? "cta " : "") + (isActive ? "active" : "")}
                    target={item.external ? "_blank" : undefined}
                    rel={item.external ? "noopener" : undefined}
                  >
                    {item.label}
                    {hasMenu && <span className="chev">▾</span>}
                    {item.external && <span className="ext">↗</span>}
                  </a>
                  {hasMenu && <MegaMenu item={item} open={open === i}/>}
                </div>
              );
            })}
          </nav>
          <button className="burger" aria-label="Menú" onClick={() => setMobileOpen(v => !v)}>
            <span/><span/><span/>
          </button>
        </div>
      </header>

      {/* Mobile drawer */}
      <div className={`mobile-nav ${mobileOpen ? 'open' : ''}`}>
        <div className="mobile-nav-head">
          <div className="brand-mini">
            <img src="assets/logo-zenon.png" alt=""/>
            <span>Zenón Pereyra</span>
          </div>
          <button className="close" aria-label="Cerrar" onClick={() => setMobileOpen(false)}>×</button>
        </div>
        <ul className="mobile-list">
          {window.NAV.map((item, i) => {
            const hasMenu = !!item.children;
            const isOpen = expanded[i];
            const toggle = () => setExpanded(e => ({ ...e, [i]: !e[i] }));
            return (
              <li key={i} className={hasMenu ? 'has-sub' : ''}>
                <div className="mn-row">
                  {item.slug ? (
                    <a href={window.link(item.slug, item.external)}
                       target={item.external ? "_blank" : undefined}
                       rel={item.external ? "noopener" : undefined}
                       className={item.cta ? "cta" : ""}>
                      {item.label}{item.external && " ↗"}
                    </a>
                  ) : (
                    <button type="button" className="mn-section" onClick={toggle}>
                      {item.label}
                    </button>
                  )}
                  {hasMenu && (
                    <button className={`expand ${isOpen ? 'on' : ''}`}
                            onClick={toggle}
                            aria-label="Expandir">▾</button>
                  )}
                </div>
                {hasMenu && isOpen && (
                  <ul className="mobile-sub">
                    {item.children.map((c, j) => (
                      <li key={j}>
                        {c.slug
                          ? <a href={window.link(c.slug, c.external)}
                               target={c.external ? "_blank" : undefined}
                               rel={c.external ? "noopener" : undefined}>{c.label}{c.external && " ↗"}</a>
                          : <span className="mn-sub-label">{c.label}</span>}
                        {c.children && (
                          <ul className="mobile-sub-sub">
                            {c.children.map((cc, k) => (
                              <li key={k}>
                                {cc.slug
                                  ? <a href={window.link(cc.slug, cc.external)}
                                       target={cc.external ? "_blank" : undefined}
                                       rel={cc.external ? "noopener" : undefined}>{cc.label}{cc.external && " ↗"}</a>
                                  : <span className="mn-sub-label">{cc.label}</span>}
                              </li>
                            ))}
                          </ul>
                        )}
                      </li>
                    ))}
                  </ul>
                )}
              </li>
            );
          })}
        </ul>
      </div>
      {mobileOpen && <div className="mobile-scrim" onClick={() => setMobileOpen(false)}/>}
    </>
  );
}

// ===== Hero =====
function Hero() {
  return (
    <section className="hero">
      <div className="container hero-grid">
        <div>
          <span className="eyebrow">
            <span className="stripe"><i/><i/><i/></span>
            Provincia de Santa Fe · Dpto. Castellanos
          </span>
          <h1>
            Un pueblo que <em>te abre la puerta</em><br/>
            todos los días.
          </h1>
          <p className="lede">
            Trámites más simples, información clara y un canal directo con quienes
            hacemos la comuna. Bienvenido al nuevo sitio de Zenón Pereyra.
          </p>
          <div className="btn-row">
            <a className="btn btn-primary" href="#/tramites">Hacer un trámite <Icon.Arrow/></a>
            <a className="btn btn-ghost" href="#/el-pueblo">Conocé el pueblo</a>
          </div>
          <div className="signature">
            <div className="avatar">VG</div>
            <div className="sig-text">
              <small>Mensaje de la Presidenta Comunal</small>
              <strong>Verónica J. Gallo · Comisión Comunal</strong>
            </div>
          </div>
        </div>
        <figure className="hero-figure">
          <div className="hero-art">
            <img src="assets/bg-fondo.jpg" alt="Acceso al pueblo de Zenón Pereyra"/>
            <div className="stamp">Desde 1892</div>
            <div className="badge">
              <div className="pin"><Icon.Pin style={{width:14, height:14}}/></div>
              <div>
                <div style={{fontWeight:600}}>Plaza San Martín</div>
                <div style={{color:'var(--muted)', fontSize:11.5}}>Corazón del pueblo</div>
              </div>
            </div>
          </div>
          <figcaption className="hero-note">
            Imagen provisoria · se reemplazará por una foto oficial del pueblo
          </figcaption>
        </figure>
      </div>

      <div className="container">
        <div className="hero-stats">
          <div className="stat">
            <div className="num">2.847</div>
            <div className="lbl">Vecinos y vecinas</div>
          </div>
          <div className="stat">
            <div className="num">132</div>
            <div className="lbl">Años de historia</div>
          </div>
          <div className="stat">
            <div className="num">48</div>
            <div className="lbl">Instituciones activas</div>
          </div>
          <div className="stat">
            <div className="num">14</div>
            <div className="lbl">Trámites en línea</div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ===== Accesos rápidos =====
const QUICK = [
  { ico: <Icon.Alert/>, label: "Urgencias", desc: "Bomberos · Policía · SAMCo", cls: "urgent", href: "#/urgencias" },
  { ico: <Icon.Doc/>, label: "Trámites", desc: "Hacelos en línea", cls: "featured", href: "#/tramites" },
  { ico: <Icon.Calendar/>, label: "Vencimientos", desc: "Calendario tributario", href: "#/vencimientos" },
  { ico: <Icon.Card/>, label: "Boleta Web", desc: "Pagá tu boleta", href: "https://zenonpereyra.boletaweb.com.ar", external: true },
  { ico: <Icon.Map/>, label: "Plano", href: "#/planos" },
  { ico: <Icon.Shop/>, label: "Guía de comercios", desc: "Industria y comercio local", href: "#/ciudadanos/guia-industria-y-comercio" },
];

function Quick() {
  return (
    <section className="section">
      <div className="container">
        <div className="section-head">
          <div>
            <div className="eyebrow-s">Accesos rápidos</div>
            <h2>Resolvé lo cotidiano <em>en pocos clics</em>.</h2>
          </div>
          <a href="#" className="link">Ver todos los servicios →</a>
        </div>
        <div className="quick-grid">
          {QUICK.map((q, i) => (
            <a key={i} className={`quick-tile ${q.cls || ""}`} href={q.href}
               target={q.external ? "_blank" : undefined} rel={q.external ? "noopener" : undefined}>
              <div className="ico">{q.ico}</div>
              <Icon.Arrow className="arrow"/>
              <div>
                <div className="label">{q.label}</div>
                {q.desc && <div className="desc">{q.desc}</div>}
              </div>
            </a>
          ))}
        </div>
      </div>
    </section>
  );
}

// ===== News + sidebar =====
const PH_COLORS = [
  { a: "#1668b8", b: "#093766" },
  { a: "#3f7d4e", b: "#1f3a63" },
  { a: "#c75b3c", b: "#7a2a14" },
  { a: "#f4b740", b: "#a06a16" },
];

function Ph({ idx, label }) {
  const c = PH_COLORS[idx % PH_COLORS.length];
  return (
    <div className="ph" style={{"--ph-a": c.a, "--ph-b": c.b}}>
      {label || "Foto"}
    </div>
  );
}

// ===== Weather (Open-Meteo, sin API key) =====
const ZP_COORDS = { lat: -31.56101, lon: -61.89622, tz: "America/Argentina/Cordoba" };

// WMO weather codes → texto en español (Open-Meteo doc oficial)
function describeWeather(code) {
  if (code === 0) return "Despejado";
  if (code === 1) return "Mayormente despejado";
  if (code === 2) return "Parcialmente nublado";
  if (code === 3) return "Nublado";
  if (code === 45 || code === 48) return "Niebla";
  if (code >= 51 && code <= 57) return "Llovizna";
  if (code >= 61 && code <= 67) return "Lluvia";
  if (code >= 71 && code <= 77) return "Nieve";
  if (code >= 80 && code <= 82) return "Chubascos";
  if (code >= 85 && code <= 86) return "Chubascos de nieve";
  if (code === 95) return "Tormenta";
  if (code === 96 || code === 99) return "Tormenta con granizo";
  return "Sin datos";
}

function uvLabel(uv) {
  if (uv == null) return "—";
  if (uv < 3)  return "Bajo";
  if (uv < 6)  return "Moderado";
  if (uv < 8)  return "Alto";
  if (uv < 11) return "Muy alto";
  return "Extremo";
}

function Weather() {
  const [w, setW] = useState(null);
  const [error, setError] = useState(false);

  React.useEffect(() => {
    const url = `https://api.open-meteo.com/v1/forecast`
      + `?latitude=${ZP_COORDS.lat}&longitude=${ZP_COORDS.lon}`
      + `&current=temperature_2m,relative_humidity_2m,apparent_temperature,weather_code,wind_speed_10m,uv_index`
      + `&timezone=${encodeURIComponent(ZP_COORDS.tz)}`;
    fetch(url)
      .then(r => r.ok ? r.json() : Promise.reject(new Error(`HTTP ${r.status}`)))
      .then(j => setW(j.current))
      .catch(() => setError(true));
  }, []);

  const ready = w && !error;
  const temp     = ready ? Math.round(w.temperature_2m) : "—";
  const apparent = ready ? Math.round(w.apparent_temperature) : null;
  const cond     = error ? "Sin conexión con el servicio del clima"
                 : ready ? describeWeather(w.weather_code)
                         : "Cargando…";
  const humidity = ready ? `${Math.round(w.relative_humidity_2m)}%` : "—";
  const wind     = ready ? `${Math.round(w.wind_speed_10m)} km/h` : "—";
  const uv       = ready ? uvLabel(w.uv_index) : "—";

  return (
    <div className="weather-card">
      <div className="top">
        <div className="city">Zenón Pereyra<small>Santa Fe · AR</small></div>
        <div className="sun-ico"/>
      </div>
      <div className="temp">{temp}<sup>°C</sup></div>
      <div className="cond">
        {cond}
        {apparent != null && <> · Sensación {apparent}°</>}
      </div>
      <div className="stats-mini">
        <div className="mini"><small>Humedad</small><b>{humidity}</b></div>
        <div className="mini"><small>Viento</small><b>{wind}</b></div>
        <div className="mini"><small>UV</small><b>{uv}</b></div>
      </div>
    </div>
  );
}

// ===== Date strip dinámico =====
const PICKUP_BY_DOW = {
  0: "Sin recolección",            // domingo
  1: "Húmedos y secos",            // lunes
  2: "Peligrosos · ramas y poda",  // martes
  3: "Húmedos y secos",            // miércoles
  4: "Peligrosos · ramas y poda",  // jueves
  5: "Húmedos y secos",            // viernes
  6: "Sin recolección",            // sábado
};

function TodayStrip() {
  const now = new Date();
  const cap = s => s.charAt(0).toUpperCase() + s.slice(1);
  const weekday = cap(now.toLocaleDateString("es-AR", { weekday: "long" }));
  const month   = cap(now.toLocaleDateString("es-AR", { month: "long" }));
  const pickup  = PICKUP_BY_DOW[now.getDay()];

  return (
    <div className="today-strip">
      <div className="date-num">{now.getDate()}</div>
      <div className="date-meta" style={{flex:1}}>
        <small>{weekday}</small>
        <strong>{month} · {now.getFullYear()}</strong>
      </div>
      <div style={{textAlign:'right'}}>
        <small style={{fontSize:11, opacity:.6, letterSpacing:'.1em', textTransform:'uppercase'}}>Recolección</small>
        <div style={{fontSize:14, fontWeight:600, marginTop:2}}>{pickup}</div>
      </div>
    </div>
  );
}

function News() {
  return (
    <section className="section cream">
      <div className="container">
        <div className="section-head">
          <div>
            <div className="eyebrow-s">Noticias y actualidad</div>
            <h2>Lo último que <em>pasa en el pueblo</em>.</h2>
          </div>
          <a href="#" className="link">Ver todas las noticias →</a>
        </div>

        <div className="news-row">
          <div className="news-grid">
            <article className="news-card feature">
              <div className="img"><Ph idx={0} label="Obra · Pavimento"/><span className="tag">Obras</span></div>
              <div className="body">
                <div className="meta">
                  <span>06 May 2026</span>
                  <span className="sep"/>
                  <span>Planeamiento Urbano</span>
                </div>
                <h3>Finalizó la primera etapa del pavimento en barrio Norte</h3>
                <p className="excerpt">
                  Se concretaron 14 cuadras de cordón cuneta y carpeta asfáltica.
                  En las próximas semanas comienza la segunda etapa que conectará con la ruta provincial 13.
                </p>
              </div>
            </article>

            <article className="news-card">
              <div className="img"><Ph idx={1} label="Reserva Ecológica"/><span className="tag">Medio Ambiente</span></div>
              <div className="body">
                <div className="meta"><span>02 May 2026</span><span className="sep"/><span>3 min</span></div>
                <h3>Jornada de plantación en la Reserva Ecológica Comunal</h3>
              </div>
            </article>

            <article className="news-card">
              <div className="img"><Ph idx={2} label="Fiesta Patronal"/><span className="tag">Cultura</span></div>
              <div className="body">
                <div className="meta"><span>29 Abr 2026</span><span className="sep"/><span>2 min</span></div>
                <h3>Cronograma completo de la Fiesta Patronal 2026</h3>
              </div>
            </article>
          </div>

          <aside className="sidebar">
            <Weather/>
            <TodayStrip/>

            <div className="card info-card">
              <h4>Info útil del día</h4>
              <ul className="info-list">
                <li><span className="dot"/><span className="lbl">Comuna · atención</span><span className="val">7:00–13:00</span></li>
                <li><span className="dot warn"/><span className="lbl">SAMCo · guardia</span><span className="val">24 h</span></li>
                <li><span className="dot warn"/><span className="lbl">Vencimiento TGI</span><span className="val">15 May</span></li>
                <li><span className="dot danger"/><span className="lbl">Corte calle Belgrano</span><span className="val">Hasta 18h</span></li>
              </ul>
            </div>
          </aside>
        </div>
      </div>
    </section>
  );
}

// ===== Mensaje vecinal =====
function Message() {
  return (
    <section className="section">
      <div className="container">
        <div className="message-block">
          <div>
            <span className="quote-mark">“</span>
            <h3>
              Zenón Pereyra es una comuna chica con horizonte grande.
              Trabajamos para que cada vecino sienta a su gobierno cerca,
              y a su pueblo creciendo todos los días.
            </h3>
            <div className="author">
              Mensaje de la Presidenta Comunal
              <strong>Verónica Jésica Gallo</strong>
            </div>
          </div>
          <div className="right">
            <div className="photo-frame"><Ph idx={3} label="Comuna · fachada"/></div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ===== Footer =====
function Footer() {
  return (
    <footer className="site">
      <div className="container">
        <div className="top">
          <div className="brand-foot">
            <div className="logo">
              <img src="assets/logo-zenon.png" alt="" style={{height:48, filter:'brightness(0) invert(1)', opacity:.95}}/>
              <div className="lockup">Zenón Pereyra<small>Santa Fe · Argentina</small></div>
            </div>
            <p>Sitio oficial de la Comuna de Zenón Pereyra. Información pública, trámites y novedades para vecinos, vecinas y visitantes.</p>
            <div className="socials">
              <a href="#" aria-label="Facebook"><Icon.Fb/></a>
              <a href="#" aria-label="Instagram"><Icon.Ig/></a>
              <a href="#" aria-label="YouTube"><Icon.Yt/></a>
            </div>
          </div>

          <div>
            <h5>Comuna</h5>
            <ul>
              <li><a href="#/autoridades">Autoridades</a></li>
              <li><a href="#/comuna/cultura-y-educacion">Cultura y Educación</a></li>
              <li><a href="#/comuna/desarrollo-social">Desarrollo Social</a></li>
              <li><a href="#/comuna/medio-ambiente">Medio Ambiente</a></li>
              <li><a href="#/comuna/produccion">Producción</a></li>
              <li><a href="#/comuna/planeamiento-urbano">Planeamiento Urbano</a></li>
            </ul>
          </div>

          <div>
            <h5>Ciudadanía</h5>
            <ul>
              <li><a href="#/tramites">Trámites</a></li>
              <li><a href="https://zenonpereyra.boletaweb.com.ar" target="_blank" rel="noopener">Boleta Web ↗</a></li>
              <li><a href="#/urgencias">Urgencias</a></li>
              <li><a href="#/vencimientos">Vencimientos</a></li>
              <li><a href="#/ciudadanos/guia-industria-y-comercio">Guía de comercios</a></li>
              <li><a href="#/el-pueblo">El Pueblo</a></li>
            </ul>
          </div>

          <div>
            <h5>Contacto</h5>
            <ul>
              <li className="contact-line"><Icon.Pin/> R. R. Prigioni 701</li>
              <li className="contact-line"><Icon.Phone/> +54 03564 492253</li>
              <li className="contact-line"><Icon.Mail/> <a href="mailto:info@zenonpereyra.gob.ar" style={{color:'inherit'}}>info@zenonpereyra.gob.ar</a></li>
            </ul>
          </div>
        </div>
        <div className="bottom">
          <div>
            © 2026 Comuna de Zenón Pereyra. Sitio oficial.
            <span style={{margin:'0 10px', opacity:.4}}>·</span>
            Desarrollado por <a href="https://www.pelatech.com.ar" target="_blank" rel="noopener" className="credit-link">Pelatech</a>
          </div>
          <div style={{display:'flex', gap:18}}>
            <a href="#">Términos</a>
            <a href="#">Privacidad</a>
            <a href="#">Accesibilidad</a>
          </div>
        </div>
      </div>
    </footer>
  );
}

// ===== Tweaks panel =====
function Tweaks() {
  const { TweaksPanel, useTweaks, TweakSection } = window;
  const [t, setTweak] = useTweaks(DEFAULTS);
  React.useEffect(() => { applyPalette(t.palette); }, [t.palette]);

  return (
    <TweaksPanel title="Tweaks">
      <TweakSection title="Paleta institucional" subtitle="Color base del sitio">
        <div style={{display:'flex', flexDirection:'column', gap:8}}>
          {PALETTE_OPTIONS.map(p => (
            <button
              key={p.key}
              onClick={() => setTweak('palette', p.key)}
              style={{
                display:'flex', alignItems:'center', gap:12,
                padding:'10px 12px',
                background: t.palette === p.key ? '#1f2937' : '#111827',
                border: t.palette === p.key ? '1px solid #60a5fa' : '1px solid #374151',
                borderRadius: 8,
                color: '#e5e7eb',
                cursor: 'pointer',
                textAlign: 'left',
                fontFamily: 'inherit',
                fontSize: 13,
              }}
            >
              <div style={{display:'flex', gap:2}}>
                {p.colors.map((c, i) => (
                  <div key={i} style={{width:14, height:22, background:c, borderRadius: i===0 ? '3px 0 0 3px' : i===3 ? '0 3px 3px 0' : 0}}/>
                ))}
              </div>
              <span>{p.name}</span>
            </button>
          ))}
        </div>
      </TweakSection>
    </TweaksPanel>
  );
}

// ===== Home =====
function Home() {
  return (<><Hero/><Quick/><News/><Message/></>);
}

// ===== Mount =====
function App() {
  React.useEffect(() => { applyPalette(DEFAULTS.palette); }, []);
  const path = window.useHashRoute();
  const isHome = path === "/" || path === "";
  return (
    <>
      <Header currentSlug={path}/>
      {isHome ? <Home/> : <window.Page slug={path}/>}
      <Footer/>
      <Tweaks/>
    </>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<App/>);
