
(()=>{
  const BUILD='V249332-clean-frontend-rebuild';
  const TOKEN='OKITHAKI_PUBLIC_BETA_TOKEN_SERVER_ONLY_2026';
  const TEST_TUNNEL_BASE='https://ok-ithaki.gr';
  const ITH_DOMAIN_BASE='https://ok-ithaki.gr';
  const BAR=68;
  const $=id=>document.getElementById(id);
  const esc=s=>String(s??'').replace(/[&<>"']/g,m=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[m]));
  const room=()=>localStorage.getItem('ith_room')||'ithaki-phone-test';
  const device=()=>localStorage.getItem('ith_device')||'dev_'+Math.random().toString(36).slice(2);
  const viewer=()=>device();
  function cleanBaseUrl(x){x=String(x||'').trim(); if(!x) return ''; try{x=decodeURIComponent(x)}catch{}; return x.replace(/\/$/,'');}
  function queryParam(name){try{return new URL(location.href).searchParams.get(name)||''}catch{return ''}}
  function androidBridgeServerBase(){try{ if(window.OKITHAKI_ANDROID && typeof window.OKITHAKI_ANDROID.getServerBase==='function') return cleanBaseUrl(window.OKITHAKI_ANDROID.getServerBase()||''); }catch{} try{ if(window.AndroidBridge && typeof window.AndroidBridge.getServerBase==='function') return cleanBaseUrl(window.AndroidBridge.getServerBase()||''); }catch{} return ''; }
  function requestedServerBase(){ return cleanBaseUrl(queryParam('server')||queryParam('api')||queryParam('base')); }
  function apiBase(){ const forced=requestedServerBase()||androidBridgeServerBase(); if(forced) return forced; if(location.protocol.startsWith('http')) return location.origin; return TEST_TUNNEL_BASE||ITH_DOMAIN_BASE; }
  const api=p=>apiBase()+p;
  async function fetchJson(path,opt={}){ const headers=Object.assign({'X-ITHAKI-TOKEN':TOKEN}, opt.headers||{}); if(opt.body && typeof opt.body!=='string' && !(opt.body instanceof FormData)) headers['Content-Type']='application/json'; const res=await fetch(api(path), Object.assign({}, opt, {headers})); if(!res.ok) throw new Error(path+' '+res.status); return res.json(); }
  function injectCss(){ if($('ithClean332Css')) return; const st=document.createElement('style'); st.id='ithClean332Css'; st.textContent=`
    body[data-page="feed"] #feedPage{padding:0!important;overflow:hidden!important;background:#000!important}
    body[data-page="feed"] #feedPage>.feedList,body[data-page="feed"] #feedPage .feedList,body[data-page="feed"] #feedPage #ithakiTikTokFeedListV249307,body[data-page="feed"] #feedPage #ithCleanFeed332{position:absolute!important;inset:0!important;width:100%!important;height:100dvh!important;min-height:100dvh!important;max-height:100dvh!important;overflow-y:auto!important;overflow-x:hidden!important;scroll-snap-type:y mandatory!important;scroll-padding:0!important;scroll-behavior:smooth!important;-webkit-overflow-scrolling:touch!important;overscroll-behavior-y:contain!important;background:#000!important;margin:0!important;padding:0!important;box-sizing:border-box!important;z-index:1!important}
    body[data-page="feed"] #feedPage .feedList>*{scroll-snap-align:start!important;scroll-snap-stop:always!important}
    body[data-page="feed"] #feedPage .feedList>.post,body[data-page="feed"] #feedPage .feedList>.feedGoldWisdomCard,body[data-page="feed"] #feedPage .feedList>.feedGoldPollCard,body[data-page="feed"] #feedPage .feedList>.feedProCard{position:relative!important;height:100dvh!important;min-height:100dvh!important;max-height:100dvh!important;width:100%!important;margin:0!important;padding:0!important;border-radius:0!important;border:0!important;background:#000!important;box-shadow:none!important;overflow:hidden!important;display:flex!important;align-items:center!important;justify-content:center!important}
    body[data-page="feed"] #feedPage .postHead{position:absolute!important;top:12px!important;left:12px!important;right:64px!important;z-index:8!important;margin:0!important;padding:8px 10px!important;border-radius:18px!important;background:linear-gradient(180deg,rgba(0,0,0,.50),rgba(0,0,0,.12))!important;backdrop-filter:blur(8px)!important;border:1px solid rgba(255,255,255,.08)!important}
    body[data-page="feed"] #feedPage .post .postMediaWrap,body[data-page="feed"] #feedPage .post .mediaInline,body[data-page="feed"] #feedPage .post .postMediaWrap video,body[data-page="feed"] #feedPage .post .postMediaWrap img,body[data-page="feed"] #feedPage .post .mediaInline video,body[data-page="feed"] #feedPage .post .mediaInline img,body[data-page="feed"] #feedPage video.feedVideo{width:100%!important;height:100dvh!important;max-height:100dvh!important;min-height:100dvh!important;object-fit:cover!important;background:#000!important;border-radius:0!important;margin:0!important;padding:0!important;border:0!important}
    body[data-page="feed"] #feedPage .leftActions,body[data-page="feed"] #feedPage .feedGoldCardActions,body[data-page="feed"] #feedPage .pollPostActions{position:absolute!important;right:8px!important;left:auto!important;top:50%!important;transform:translateY(-50%)!important;z-index:12!important;display:flex!important;flex-direction:column!important;gap:10px!important;align-items:center!important;justify-content:center!important;background:rgba(0,0,0,.24)!important;padding:6px 4px!important;border-radius:18px!important;border:1px solid rgba(255,255,255,.08)!important}
    body[data-page="feed"] #feedPage .pollPostActions{top:auto!important;bottom:96px!important;transform:none!important}
    body[data-page="feed"] #feedPage .actionIcon,body[data-page="feed"] #feedPage .feedGoldCardActions .btn,body[data-page="feed"] #feedPage .pollPostActions .actionIcon{width:46px!important;min-width:46px!important;height:46px!important;min-height:46px!important;border-radius:16px!important;background:rgba(0,0,0,.28)!important;color:#fff!important;display:grid!important;place-items:center!important;font-size:22px!important}
    body[data-page="feed"] #feedPage .count{font-size:11px!important;color:#fff!important;text-shadow:0 2px 6px rgba(0,0,0,.8)!important}
    body[data-page="feed"] #feedPage .textClamp,body[data-page="feed"] #feedPage .pollAsText,body[data-page="feed"] #feedPage .postTextOverlayV249332{position:absolute!important;left:12px!important;right:72px!important;bottom:92px!important;z-index:9!important;max-height:24dvh!important;overflow:auto!important;padding:10px 12px!important;border-radius:18px!important;background:linear-gradient(180deg,rgba(0,0,0,.10),rgba(0,0,0,.55))!important;color:#fff!important;line-height:1.45!important;white-space:pre-wrap!important;backdrop-filter:blur(6px)!important;border:1px solid rgba(255,255,255,.08)!important}
    body[data-page="feed"] #feedPage .textClamp:empty,body[data-page="feed"] #feedPage .pollAsText:empty{display:none!important}
    body[data-page="feed"] #feedPage .feedGoldWisdomCard,body[data-page="feed"] #feedPage .feedGoldPollCard{background:#000!important}
    body[data-page="feed"] #feedPage .feedGoldCardInner,body[data-page="feed"] #feedPage .pollFeedCard,body[data-page="feed"] #feedPage .professionalPollCard{width:min(86vw,620px)!important;max-height:min(76dvh,640px)!important;overflow-y:auto!important;overflow-x:hidden!important;border-radius:24px!important;background:radial-gradient(circle at 20% 0%,rgba(255,217,110,.16),transparent 35%),linear-gradient(145deg,#171108,#2d1806 55%,#070504)!important;border:1px solid rgba(255,217,110,.30)!important;box-shadow:0 18px 60px rgba(0,0,0,.45)!important;padding:14px 14px 18px!important;color:#fff7dc!important}
    body[data-page="feed"] #feedPage .feedGoldLogo img{width:56px!important;height:56px!important;object-fit:contain!important}
    body[data-page="feed"] #feedPage .feedGoldCardActions{background:transparent!important;border:0!important;box-shadow:none!important}
    body[data-page="feed"] #previewModal:not(.show){display:none!important;pointer-events:none!important}
    body[data-page="feed"] #previewModal.show{display:grid!important;z-index:2147483646!important}
    body[data-page="feed"] #feedPage .feedToolbar332{position:fixed!important;top:10px!important;left:10px!important;right:10px!important;z-index:2147483640!important;display:flex!important;gap:8px!important;align-items:center!important;padding:8px 10px!important;border-radius:18px!important;background:linear-gradient(180deg,rgba(0,0,0,.56),rgba(0,0,0,.22))!important;border:1px solid rgba(255,255,255,.08)!important;backdrop-filter:blur(10px)!important}
    body[data-page="feed"] #feedPage .feedToolbar332 input{flex:1!important;min-width:0!important;border-radius:14px!important;padding:10px!important;background:rgba(255,255,255,.08)!important;border:1px solid rgba(255,255,255,.12)!important}
    .bookBtn332{position:fixed!important;top:10px!important;right:10px!important;z-index:2147483647!important;width:48px!important;height:48px!important;border-radius:16px!important;background:linear-gradient(180deg,rgba(255,217,110,.34),rgba(255,217,110,.18))!important;border:1px solid rgba(255,217,110,.45)!important;box-shadow:0 16px 32px rgba(0,0,0,.28)!important;font-size:24px!important;display:grid!important;place-items:center!important;color:#fff7dc!important}
    .bookModal332{position:fixed!important;inset:0!important;z-index:2147483647!important;display:none;place-items:center;background:rgba(0,0,0,.62)!important;backdrop-filter:blur(10px)!important;padding:12px!important}
    .bookModal332.show{display:grid!important}
    .bookPanel332{width:min(780px,100%)!important;max-height:92dvh!important;display:flex!important;flex-direction:column!important;gap:10px!important;padding:14px!important;border-radius:26px!important;background:rgba(8,22,38,.98)!important;border:1px solid rgba(255,255,255,.12)!important;box-shadow:0 24px 90px rgba(0,0,0,.60)!important;color:#eef7ff!important}
    .bookScroll332{overflow:auto!important;max-height:60dvh!important;display:grid!important;gap:8px!important}
    .bookGrid332{display:grid!important;grid-template-columns:1fr 1fr 110px!important;gap:8px!important}
    .bookRow332{display:grid!important;grid-template-columns:1fr 1fr auto!important;gap:8px!important;align-items:center!important;padding:8px!important;border-radius:16px!important;background:rgba(255,255,255,.05)!important;border:1px solid rgba(255,255,255,.08)!important}
    body[data-page="dm"] #dmPage{padding:0!important;overflow:hidden!important}
    body[data-page="dm"] #dmPage .dmShell,body[data-page="dm"] #dmPage .dmContactFirstShellV249235,body[data-page="dm"] #dmPage .dmPanelV249314,body[data-page="dm"] #dmPage .dmPanelV249316{position:absolute!important;inset:0!important;display:grid!important;grid-template-columns:minmax(250px,340px) 1fr!important;min-height:100dvh!important;height:100dvh!important;overflow:hidden!important;background:rgba(0,0,0,.02)!important}
    body[data-page="dm"] #dmPage .peoplePane,body[data-page="dm"] #dmPage .dmFriendScreenV249235{display:flex!important;flex-direction:column!important;min-height:0!important;height:100%!important;overflow:hidden!important;border-right:1px solid rgba(255,255,255,.08)!important;background:rgba(255,255,255,.03)!important}
    body[data-page="dm"] #dmPage .peopleList,body[data-page="dm"] #dmPage .dmFriendListV249235,body[data-page="dm"] #dmPage .dmPanelV249314,body[data-page="dm"] #dmPage .dmPanelV249316{flex:1 1 auto!important;min-height:0!important;overflow-y:auto!important;overflow-x:hidden!important;-webkit-overflow-scrolling:touch!important;touch-action:pan-y!important;padding:10px!important;box-sizing:border-box!important}
    body[data-page="dm"] #dmPage .person{width:100%!important;display:flex!important}
    @media(max-width:760px){
      body[data-page="dm"] #dmPage .dmShell,body[data-page="dm"] #dmPage .dmContactFirstShellV249235,body[data-page="dm"] #dmPage .dmPanelV249314,body[data-page="dm"] #dmPage .dmPanelV249316{grid-template-columns:1fr!important;grid-template-rows:minmax(180px,40dvh) 1fr!important}
      body[data-page="dm"] #dmPage .peoplePane,body[data-page="dm"] #dmPage .dmFriendScreenV249235{border-right:0!important;border-bottom:1px solid rgba(255,255,255,.08)!important}
      body[data-page="feed"] #feedPage .postHead{top:62px!important}
      body[data-page="feed"] #feedPage .textClamp,body[data-page="feed"] #feedPage .pollAsText{bottom:84px!important;left:10px!important;right:68px!important;max-height:22dvh!important}
    }
  `; document.head.appendChild(st); }
  function ensureBookUi(){
    if(!$('ithBookBtn332')){ const btn=document.createElement('button'); btn.id='ithBookBtn332'; btn.className='bookBtn332'; btn.type='button'; btn.textContent='📚'; btn.title='Βιβλίο Μετάφρασης'; btn.addEventListener('click',e=>{e.preventDefault(); e.stopPropagation(); openBook();}); document.body.appendChild(btn); }
    if(!$('ithBookModal332')){ const modal=document.createElement('div'); modal.id='ithBookModal332'; modal.className='bookModal332'; modal.innerHTML=`<div class="bookPanel332"><div class="row" style="display:flex;gap:8px;align-items:center"><b style="font-size:18px;color:#ffd36e">📚 Βιβλίο Μετάφρασης</b><div style="margin-left:auto;display:flex;gap:8px"><button class="btn" id="bookRefresh332" type="button">Ανανέωση</button><button class="btn danger" id="bookClose332" type="button">Κλείσιμο</button></div></div><div class="row bookGrid332"><input id="bookSource332" placeholder="Λέξη / φράση"><input id="bookTarget332" placeholder="Μετάφραση"><button class="btn gold" id="bookSave332" type="button">Αποθήκευση</button></div><div class="row" style="display:flex;gap:8px;align-items:center"><input id="bookPair332" placeholder="el->en" value="el->en" style="max-width:120px"><button class="btn" id="bookUnknowns332" type="button">Άγνωστες</button><a class="btn" href="${api('/api/bridge/dictionary/unknowns.csv')}" target="_blank" rel="noopener">CSV</a></div><div id="bookStatus332" class="card" style="padding:10px">Φόρτωση...</div><div id="bookUnknownList332" class="bookScroll332"></div></div>`; modal.addEventListener('click',e=>{ if(e.target===modal) closeBook(); }); document.body.appendChild(modal); $('bookClose332').onclick=closeBook; $('bookRefresh332').onclick=refreshBook; $('bookSave332').onclick=saveBook; $('bookUnknowns332').onclick=refreshBook; }
  }
  async function refreshBook(){ ensureBookUi(); const statusBox=$('bookStatus332'), list=$('bookUnknownList332'); statusBox.textContent='Φόρτωση...'; list.innerHTML=''; try{ const [st, unk] = await Promise.all([fetchJson('/api/bridge/dictionary/status'), fetchJson('/api/bridge/dictionary/unknowns')]); statusBox.innerHTML=`<div><b>Κατάσταση:</b> ${esc(JSON.stringify(st))}</div>`; const lines=(unk.last||[]).slice().reverse(); list.innerHTML = lines.length ? lines.map(line=>`<div class="bookRow332"><div>${esc(line)}</div><div></div><button class="btn" type="button" data-line="${esc(line)}">Χρήση</button></div>`).join('') : '<div class="card" style="padding:10px">Δεν υπάρχουν νέες άγνωστες λέξεις.</div>'; list.querySelectorAll('button[data-line]').forEach(btn=>btn.onclick=()=>{ const raw=btn.getAttribute('data-line')||''; const parts=raw.split(','); $('bookSource332').value=(parts[3]||'').replace(/^"|"$/g,''); const pair=(parts[1]||'el')+'->'+(parts[2]||'en'); $('bookPair332').value=pair; $('bookTarget332').focus(); }); }catch(err){ statusBox.textContent='Σφάλμα φόρτωσης λεξικού: '+err; } }
  async function saveBook(){ const source=$('bookSource332')?.value?.trim()||''; const target=$('bookTarget332')?.value?.trim()||''; const pair=$('bookPair332')?.value?.trim()||'el->en'; const [src_lang,dst_lang] = pair.includes('->') ? pair.split('->',2) : ['el','en']; if(!source || !target) return; try{ await fetchJson('/api/bridge/dictionary/add',{method:'POST', body: JSON.stringify({source,target,src_lang,dst_lang,kind:'word'})}); $('bookSource332').value=''; $('bookTarget332').value=''; refreshBook(); }catch(err){ alert('Αποτυχία αποθήκευσης: '+err); } }
  function openBook(){ ensureBookUi(); $('ithBookModal332')?.classList.add('show'); refreshBook(); return false; }
  function closeBook(){ $('ithBookModal332')?.classList.remove('show'); return false; }
  function ensureFeedToolbar(){ const feed=$('feedPage'); if(!feed) return; let bar=feed.querySelector('.feedToolbar332'); if(bar) return; bar=document.createElement('div'); bar.className='feedToolbar332'; bar.innerHTML=`<button class="btn" type="button" id="feedBack332">‹</button><div style="display:flex;align-items:center;gap:8px;min-width:0"><img src="ok_ithaki_ship_logo.png" alt="" style="width:30px;height:30px;object-fit:contain"><b style="white-space:nowrap">ΡΟΗ</b></div><input id="feedSearch332" placeholder="Αναζήτηση στη ροή"><button class="btn" type="button" id="feedRefresh332">↻</button><button class="btn gold" type="button" id="feedBook332">📚</button>`; feed.appendChild(bar); $('feedBack332').onclick=()=>window.ITH&&ITH.page?ITH.page('home'):false; $('feedRefresh332').onclick=()=>loadFeedClean(); $('feedBook332').onclick=()=>openBook(); $('feedSearch332').addEventListener('input', filterFeed); }
  function filterFeed(){ const q=($('feedSearch332')?.value||'').trim().toLowerCase(); const list=$('feedPage')?.querySelector('.feedList'); if(!list) return; [...list.children].forEach(el=>{ const txt=(el.textContent||'').toLowerCase(); el.style.display=!q || txt.includes(q) ? '' : 'none'; }); }
  function cleanFeedDom(){ injectCss(); ensureBookUi(); ensureFeedToolbar(); const feed=$('feedPage'); if(!feed) return; const list=feed.querySelector('.feedList')||feed.querySelector('#ithakiTikTokFeedListV249307'); if(!list) return; list.id='ithCleanFeed332'; [...list.children].forEach(el=>{ if(el.nodeType!==1) return; if(el.classList.contains('post')||el.className){ el.classList.add('ithCleanCard332'); }
      const txt=el.querySelector('.textClamp'); if(txt){ const raw=(txt.textContent||'').trim(); if(!raw) txt.style.display='none'; else txt.classList.add('postTextOverlayV249332'); }
      el.querySelectorAll('video,img').forEach(m=>{ m.setAttribute('playsinline',''); m.setAttribute('webkit-playsinline',''); m.muted = true; });
    }); filterFeed(); }
  function enhanceDm(){ injectCss(); const dm=$('dmPage'); if(!dm) return; }
  function loadFeedClean(){ const fn = (window.ITH&&window.ITH.loadFeed && window.ITH.loadFeed!==loadFeedClean) ? window.ITH.loadFeed : (window.loadFeed && window.loadFeed!==loadFeedClean ? window.loadFeed : null); if(fn){ try{ const r=fn(); setTimeout(cleanFeedDom,80); setTimeout(cleanFeedDom,320); return r; }catch(err){ console.warn('loadFeedClean wrap failed', err); } } setTimeout(cleanFeedDom,0); return false; }
  function wrapNav(){ if(window.__ith332Wrapped) return; window.__ith332Wrapped=1; const origPage=(window.ITH&&window.ITH.page)?window.ITH.page.bind(window.ITH):(window.page?window.page.bind(window):null); if(origPage){ const wrapped=function(id){ const r=origPage(id); setTimeout(()=>{ if(id==='feed') cleanFeedDom(); if(id==='dm') enhanceDm(); },80); return r; }; window.page=wrapped; window.ITH=window.ITH||{}; window.ITH.page=wrapped; }
    const origLoad=(window.ITH&&window.ITH.loadFeed)?window.ITH.loadFeed.bind(window.ITH):(window.loadFeed?window.loadFeed.bind(window):null); if(origLoad){ const wrappedLoad=function(){ const r=origLoad(); setTimeout(cleanFeedDom,80); setTimeout(cleanFeedDom,320); return r; }; window.loadFeed=wrappedLoad; window.ITH=window.ITH||{}; window.ITH.loadFeed=wrappedLoad; }
    const origDM=(window.openDM && window.openDM!==enhanceDm)?window.openDM.bind(window):null; if(origDM){ window.openDM=function(){ const r=origDM(); setTimeout(enhanceDm,80); return r; }; }
    window.ITH=window.ITH||{}; Object.assign(window.ITH,{openTranslationBookV249332:openBook, closeTranslationBookV249332:closeBook, loadFeedCleanV249332:loadFeedClean});
  }
  function install(){ injectCss(); ensureBookUi(); wrapNav(); if(document.body?.dataset?.page==='feed') setTimeout(cleanFeedDom,120); if(document.body?.dataset?.page==='dm') setTimeout(enhanceDm,120); const mo=new MutationObserver(()=>{ if(document.body?.dataset?.page==='feed') cleanFeedDom(); if(document.body?.dataset?.page==='dm') enhanceDm(); }); mo.observe(document.documentElement,{childList:true,subtree:true}); }
  if(document.readyState==='loading') document.addEventListener('DOMContentLoaded', install, {once:true}); else install();
})();
