/* OK ITHAKI V249475
 * All server Feed posts visible, one stable Home startup, one stable Bil owner,
 * and one audible Feed media owner. No database or user-content mutation.
 */
(function(){
  'use strict';
  if(window.__ITHAKI_V249475_COMPLETE__)return;
  window.__ITHAKI_V249475_COMPLETE__={version:'V249475',installedAt:Date.now()};
  window.__ITHAKI_V249475_OWNS_BIL__=true;
  window.__ITHAKI_V249475_OWNS_AUDIO__=true;
  window.__ITHAKI_V249475_FEED_OWNER__=true;
  window.__ITHAKI_V249473_FEED_AUDIO_OWNER__=true;

  var BIL_KEY='ith_bil_enabled_v249461',BIL_ID='ithBilStableV249475',MENU_ID='ithBilStableMenuV249475';
  var activeMedia=null,audioUnlocked=false,mediaTimer=0,bootReleased=false,userNavigated=false,notifyTimer=0;
  function I(){return window.ITH||(window.ITH={})}
  function english(){try{return String(localStorage.getItem('ith_ui_lang_v249141')||localStorage.getItem('ith_ui_lang')||document.documentElement.lang||'el').toLowerCase().indexOf('en')===0}catch(e){return false}}
  function tr(el,en){return english()?en:el}
  function esc(v){return String(v==null?'':v).replace(/[&<>\"]/g,function(c){return {'&':'&amp;','<':'&lt;','>':'&gt;','\"':'&quot;'}[c]})}
  function normalBoot(){return window.__ITHAKI_V249475_NORMAL_BOOT__!==false}
  function bilEnabled(){try{return localStorage.getItem(BIL_KEY)!=='0'}catch(e){return true}}
  function onFeed(){return !!(document.body&&document.body.dataset.page==='feed')}
  function onHome(){return !!(document.body&&document.body.dataset.page==='home')}

  function addCss(){if(document.getElementById('ithV249475Css'))return;var s=document.createElement('style');s.id='ithV249475Css';s.textContent=`
    #${BIL_ID}{position:fixed;left:14px;bottom:calc(var(--bar,68px) + 18px);z-index:2147483500;width:74px;height:64px;display:none;place-items:center;border:0;background:transparent!important;padding:0;filter:drop-shadow(0 7px 12px rgba(0,0,0,.35))}
    .bil475{position:relative;width:70px;height:58px;display:block}.bil475Shell{position:absolute;left:8px;top:20px;width:49px;height:31px;border-radius:52% 48% 47% 53%;background:linear-gradient(145deg,#70d679,#176a39);border:2px solid rgba(225,255,229,.8);box-shadow:inset -7px -7px 0 rgba(0,48,22,.22)}
    .bil475Head{position:absolute;right:0;top:6px;width:29px;height:28px;border-radius:49% 51% 48% 52%;background:linear-gradient(145deg,#91e88d,#2b8e4a);border:2px solid rgba(232,255,232,.82);animation:bil475Head 9s ease-in-out infinite;transform-origin:45% 105%}
    .bil475Eye{position:absolute;top:7px;width:5px;height:6px;border-radius:50%;background:#06160a;box-shadow:0 0 0 1px rgba(255,255,255,.5)}.bil475Eye.l{left:6px}.bil475Eye.r{right:6px}.bil475Mouth{position:absolute;left:8px;top:17px;width:11px;height:5px;border-bottom:2px solid #08220f;border-radius:0 0 10px 10px}
    .bil475Foot{position:absolute;top:45px;width:14px;height:8px;border-radius:50%;background:#3c9e52;border:1px solid rgba(225,255,225,.6)}.bil475Foot.l{left:11px}.bil475Foot.r{left:39px}.bil475Tail{position:absolute;left:1px;top:31px;width:14px;height:10px;background:#3e9e51;clip-path:polygon(100% 0,0 50%,100% 100%)}
    @keyframes bil475Head{0%,100%{transform:rotate(-.5deg)}50%{transform:rotate(.7deg)}}
    #${MENU_ID}{position:fixed;left:12px;bottom:calc(var(--bar,68px) + 92px);z-index:2147483600;width:min(380px,calc(100vw - 24px));max-height:min(70dvh,620px);overflow:auto;padding:14px;border-radius:22px;background:rgba(5,18,31,.98);color:#fff;border:1px solid rgba(255,255,255,.18);box-shadow:0 24px 80px rgba(0,0,0,.6)}
    #${MENU_ID} .bil475HeadRow{display:flex;gap:10px;align-items:center}#${MENU_ID} .bil475HeadRow>.bil475{width:64px;flex:0 0 64px}#${MENU_ID} .bil475Actions{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:12px}#${MENU_ID} button{min-height:46px;border-radius:13px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.12);padding:9px;font-weight:750}
    .bil475Preview{display:flex;align-items:center;gap:12px;padding:12px;margin-top:10px;border-radius:15px;background:rgba(10,35,26,.44)}.bil475Toggle{display:grid!important;grid-template-columns:1fr 1fr!important;gap:8px!important;margin-top:10px!important}.bil475Toggle button{min-height:48px!important;border-radius:12px!important;font-weight:850!important}.bil475Toggle button.active{outline:2px solid rgba(100,230,135,.95)!important;background:rgba(30,125,66,.38)!important}
  `;document.head.appendChild(s)}
  function face(){return '<span class="bil475" aria-hidden="true"><i class="bil475Tail"></i><i class="bil475Foot l"></i><i class="bil475Foot r"></i><i class="bil475Shell"></i><i class="bil475Head"><i class="bil475Eye l"></i><i class="bil475Eye r"></i><i class="bil475Mouth"></i></i></span>'}

  function ensureBil(){if(window.__ITHAKI_V249525_NOTIFICATION_OWNER__)return null;if(window.__ITHAKI_V249523_SHARE_BIL_OWNER__)return null;addCss();var enabled=bilEnabled(),b=document.getElementById(BIL_ID);if(!b&&document.body){b=document.createElement('button');b.id=BIL_ID;b.type='button';b.innerHTML=face();b.onclick=function(e){e.preventDefault();e.stopPropagation();return openBil()};document.body.appendChild(b)}if(b){if(!b.querySelector('.bil475'))b.innerHTML=face();b.setAttribute('aria-label',tr('Άνοιγμα Bil','Open Bil'));b.style.display=enabled&&onHome()&&!document.getElementById(MENU_ID)?'grid':'none'}return b}
  function nextWisdom(){var el=['Άκου πρώτα και απάντησε ήρεμα.','Η καθαρή επικοινωνία χτίζει εμπιστοσύνη.','Μία μικρή παύση αποφεύγει μία μεγάλη παρεξήγηση.','Η ΙΘΑΚΗ αρχίζει από τον σεβασμό.'],en=['Listen first and answer calmly.','Clear communication builds trust.','A short pause can prevent a large misunderstanding.','ITHAKI begins with respect.'];var a=english()?en:el;return a[Math.floor(Math.random()*a.length)]}
  function openRoute(page){var fn=I().stableRouteV249429||I().page||window.page;if(typeof fn==='function')return fn.call(I(),page,'v249475-bil');return false}
  function openBil(){var old=document.getElementById(MENU_ID);if(old){old.remove();ensureBil();return false}var d=document.createElement('section');d.id=MENU_ID;d.innerHTML='<div class="bil475HeadRow">'+face()+'<div><b style="font-size:19px">Bil</b><div>'+esc(tr('Ο μικρός πράσινος φίλος της ΙΘΑΚΗΣ','ITHAKI’s little green friend'))+'</div></div><button data-a="close" style="margin-left:auto">×</button></div><p id="bil475Text">'+esc(nextWisdom())+'</p><div class="bil475Actions"><button data-a="next">✦ '+esc(tr('Άλλος λόγος','Another saying'))+'</button><button data-a="messages">💬 '+esc(tr('Μηνύματα','Messages'))+'</button><button data-a="wall">🕊️ '+esc(tr('Τοίχος','Wall'))+'</button><button data-a="lighthouse">🕯️ '+esc(tr('Φάρος','Lighthouse'))+'</button><button data-a="bottle">🍾 '+esc(tr('Μπουκάλι','Bottle'))+'</button><button data-a="notifications">🔔 '+esc(tr('Ειδοποιήσεις','Notifications'))+'</button><button data-a="disable" style="grid-column:1/-1">⏸ '+esc(tr('Απενεργοποίηση Bil','Disable Bil'))+'</button></div>';d.onclick=function(e){var b=e.target.closest('[data-a]');if(!b)return;e.preventDefault();e.stopPropagation();var a=b.dataset.a;if(a==='close'){d.remove();ensureBil();return}if(a==='next'){var t=document.getElementById('bil475Text');if(t)t.textContent=nextWisdom();return}if(a==='disable'){setBil(false);d.remove();return}d.remove();if(a==='messages')return openRoute('dm');if(a==='wall'){var f=I().openCurrentWallV249440||I().openWallV411||window.openWallV411;if(typeof f==='function')return f()}if(a==='lighthouse'){var l=I().openLighthouseV249278||window.openLighthouseV249278;if(typeof l==='function')return l()}if(a==='bottle'){var q=I().openBottleSeaV249274||window.openBottleSeaV249274;if(typeof q==='function')return q('compose')}if(a==='notifications'){var n=I().openNotificationSettingsV249238||window.openNotificationSettingsV249238;if(typeof n==='function'){var r=n();setTimeout(function(){renderNotificationSettings(true)},30);return r}}};document.body.appendChild(d);ensureBil();return false}
  function setBil(on){try{localStorage.setItem(BIL_KEY,on?'1':'0');localStorage.setItem('ithaki_companion_v249258',on?'bil':'none')}catch(e){}if(!on){var m=document.getElementById(MENU_ID);if(m)m.remove()}ensureBil();renderNotificationSettings(true);return false}

  function currentMode(){try{return localStorage.getItem('ithaki_push_mode_v249258')||'fcm_default'}catch(e){return'fcm_default'}}
  function renderNotificationSettings(force){var el=document.getElementById('notifySettingsV249258');if(!el)return'';if(!force&&el.dataset.v249475Owner==='1')return el.innerHTML;var m=currentMode(),on=bilEnabled(),modes=english()?[
    ['fcm_default','1. FCM default','Closed app through Firebase/FCM and open app through the internal bell. Recommended.'],['background','2. Background','Gentler operation while the app is in the background.'],['open_app','3. Open app','Notifications only while you are inside ITHAKI.'],['stay_awake','4. Always awake','Keeps a live connection. Faster, but may use more battery.'],['no_closed','5. No closed-app notifications','No FCM push while the application is closed.']
  ]:[['fcm_default','1. FCM προεπιλογή','Κλειστή εφαρμογή με Firebase/FCM και ανοιχτή εφαρμογή με το εσωτερικό καμπανάκι. Προτείνεται.'],['background','2. Παρασκήνιο','Πιο ήπια λειτουργία όταν η εφαρμογή είναι στο παρασκήνιο.'],['open_app','3. Ανοιχτή εφαρμογή','Ειδοποιήσεις μόνο όσο βρίσκεσαι μέσα στην ΙΘΑΚΗ.'],['stay_awake','4. Δεν κοιμάται','Κρατά ζωντανή σύνδεση. Πιο άμεσο, αλλά μπορεί να χρησιμοποιεί περισσότερη μπαταρία.'],['no_closed','5. Χωρίς ειδοποιήσεις με κλειστή εφαρμογή','Δεν εμφανίζεται FCM push όταν η εφαρμογή είναι κλειστή.']];var cards=modes.map(function(x){return '<button class="modeCardV249258 '+(m===x[0]?'active':'')+'" onclick="return ITH.setNotificationMode(\''+x[0]+'\')"><b>'+esc(x[1])+'</b><small>'+esc(x[2])+'</small></button>'}).join('');el.dataset.v249475Owner='1';el.innerHTML='<div class="card"><b>🔔 '+esc(tr('Επιλογές ειδοποιήσεων','Notification options'))+'</b><div class="date">'+esc(tr('Διάλεξε έναν τρόπο ώστε να μη δημιουργούνται διπλές ειδοποιήσεις ή κλήσεις.','Choose one mode so duplicate notifications or calls are not created.'))+'</div><div class="modeGridV249258" style="margin-top:10px">'+cards+'</div></div><div class="card"><b>🐢 Bil</b><div class="bil475Preview">'+face()+'<div><b>Bil</b><div>'+esc(on?tr('Εμφανίζεται στην Αρχική.','Shown on Home.'):tr('Δεν εμφανίζεται στην Αρχική.','Hidden from Home.'))+'</div><small>'+esc(tr('Δύο μάτια και ένα στόμα.','Two eyes and one mouth.'))+'</small></div></div><div class="bil475Toggle"><button class="'+(on?'active':'')+'" onclick="return ITH.setBilStableV249475(true)">'+esc(tr('Ενεργοποιημένος','Enabled'))+'</button><button class="'+(!on?'active':'')+'" onclick="return ITH.setBilStableV249475(false)">'+esc(tr('Απενεργοποιημένος','Disabled'))+'</button></div></div>';return el.innerHTML}
  function installNotificationOwner(){if(window.__ITHAKI_V249525_NOTIFICATION_OWNER__)return;I().setBilStableV249475=setBil;window.setBilStableV249475=setBil;I().renderNotificationSettingsV249475=renderNotificationSettings;I().renderNotificationModeSettingsV249258=function(){return renderNotificationSettings(true)};window.renderNotificationModeSettingsV249258=I().renderNotificationModeSettingsV249258;clearTimeout(notifyTimer);notifyTimer=setTimeout(function(){renderNotificationSettings(true)},20)}

  function allMedia(){try{return Array.prototype.slice.call(document.querySelectorAll('#feedPage video,#feedPage audio'))}catch(e){return[]}}
  function stopMedia(m){if(!m)return;try{m.pause()}catch(e){}try{m.muted=true;m.defaultMuted=true;m.volume=0;m.removeAttribute('data-v249475-audible')}catch(e){}}
  function visibleRatio(m){try{var r=m.getBoundingClientRect(),vw=innerWidth||document.documentElement.clientWidth,vh=innerHeight||document.documentElement.clientHeight,w=Math.max(0,Math.min(vw,r.right)-Math.max(0,r.left)),h=Math.max(0,Math.min(vh,r.bottom)-Math.max(0,r.top));return r.width>0&&r.height>0?(w*h)/(r.width*r.height):0}catch(e){return 0}}
  function chooseActive(candidate){var best=null,score=0;allMedia().forEach(function(m){if(!m.isConnected)return;var s=visibleRatio(m);if(s>score){score=s;best=m}});if(candidate&&visibleRatio(candidate)>=Math.max(.25,score-.03))best=candidate;return score>=.18?best:null}
  function enforceAudio(tryPlay,candidate){if(!onFeed()||document.hidden){activeMedia=null;allMedia().forEach(stopMedia);return null}var next=chooseActive(candidate);activeMedia=next;allMedia().forEach(function(m){if(m!==activeMedia){stopMedia(m);return}try{m.defaultMuted=false;m.muted=!audioUnlocked;m.volume=audioUnlocked?1:0;m.removeAttribute('muted');m.setAttribute('playsinline','');m.setAttribute('data-v249475-audible','1')}catch(e){}});if(activeMedia&&audioUnlocked&&tryPlay){try{var p=activeMedia.play();if(p&&p.catch)p.catch(function(){})}catch(e){}}return activeMedia}
  function stopAll(){activeMedia=null;allMedia().forEach(stopMedia)}
  function installAudioOwner(){I().enforceSingleFeedAudioV249475=enforceAudio;I().stopAllFeedMediaV249475=stopAll;document.addEventListener('play',function(e){var m=e.target;if(!m||!m.closest||!m.closest('#feedPage'))return;var active=chooseActive(m);if(active!==m){stopMedia(m);return}activeMedia=m;enforceAudio(false,m)},true);document.addEventListener('volumechange',function(e){var m=e.target;if(!m||!m.closest||!m.closest('#feedPage'))return;if(m!==activeMedia&&!m.muted)stopMedia(m)},true);['pointerdown','touchstart','click'].forEach(function(n){document.addEventListener(n,function(e){if(e.target&&e.target.closest&&e.target.closest('#feedPage')){audioUnlocked=true;enforceAudio(true)}},{capture:true,passive:true})});window.addEventListener('scroll',function(){enforceAudio(false)},{capture:true,passive:true});window.addEventListener('resize',function(){enforceAudio(false)},{passive:true});document.addEventListener('visibilitychange',function(){if(document.hidden)stopAll();else enforceAudio(false)},{passive:true});window.addEventListener('pagehide',stopAll);setInterval(function(){if(onFeed())enforceAudio(false);else if(activeMedia)stopAll()},120)}

  function clearFeedFilters(){try{localStorage.setItem('ith_feed_category_v249429','all');localStorage.removeItem('ith_feed_selected_keyword_v249429')}catch(e){}var q=document.getElementById('ithFeedSearchInputV249429');if(q)q.value=''}
  function refreshFeedAfterPublish(){clearFeedFilters();setTimeout(function(){var f=I().openProfessionalFeedV249429||I().openProfessionalFeedV249430||I().loadFeed;if(typeof f==='function')f.call(I(),'post-send-v249475')},90);setTimeout(function(){var dev='';try{dev=String((window.state&&window.state.device)||(I().state&&I().state.device)||localStorage.getItem('ith_device')||'')}catch(e){}var cards=Array.prototype.slice.call(document.querySelectorAll('#feedPage .ithFeedStageV249429'));var own=cards.find(function(c){return dev&&String(c.dataset.v249429Sender||'')===dev})||cards[0];if(own){own.hidden=false;own.style.removeProperty('display');try{own.scrollIntoView({block:'center',behavior:'smooth'})}catch(e){own.scrollIntoView()}}},700)}

  function visualHome(){try{var st=window.state||I().state||window.__ITHAKI_CORE_STATE__;if(st)st.page='home';document.body.dataset.page='home';document.querySelectorAll('.page').forEach(function(p){p.classList.remove('active')});var h=document.getElementById('homePage');if(h)h.classList.add('active');document.querySelectorAll('#nav button[data-page]').forEach(function(b){b.classList.toggle('active',b.dataset.page==='home')})}catch(e){}}
  function stabilizeHome(){if(!normalBoot()||userNavigated)return;window.__ITHAKI_V249475_BOOT_READY__=true;try{var f=I().stableRouteV249429||I().page||window.page;if(typeof f==='function')f.call(I(),'home','v249475-stable-home')}catch(e){}visualHome();try{if(typeof I().applyProfessionalHomeV249461==='function')I().applyProfessionalHomeV249461(true)}catch(e){}visualHome();ensureBil()}
  function releaseBoot(){if(bootReleased)return;bootReleased=true;stabilizeHome();requestAnimationFrame(function(){requestAnimationFrame(function(){document.documentElement.removeAttribute('data-ithaki-v249475-boot');ensureBil()})})}

  function run(){installNotificationOwner();ensureBil();if(document.getElementById('notifySettingsV249258'))renderNotificationSettings(false);if(onFeed())enforceAudio(false);document.documentElement.setAttribute('data-ithaki-v249475','feed-display-stable-home-bil')}
  function install(){addCss();installAudioOwner();installNotificationOwner();document.addEventListener('click',function(e){var t=e.target&&e.target.closest&&e.target.closest('#nav button,[data-page],[data-v249461-route]');if(t&&Date.now()-(window.__ITHAKI_V249475_COMPLETE__.installedAt||0)>350){userNavigated=true;document.documentElement.removeAttribute('data-ithaki-v249475-boot')}},true);window.addEventListener('ithaki:page-changed',function(e){var p=String(e&&e.detail&&e.detail.page||document.body&&document.body.dataset.page||'');if(p!=='feed')stopAll();setTimeout(function(){ensureBil();run()},20)});window.addEventListener('ithaki:publication-sent',refreshFeedAfterPublish);window.addEventListener('storage',function(){ensureBil();renderNotificationSettings(true)});if(document.body){var o=new MutationObserver(function(rs){var notify=false,media=false;rs.forEach(function(r){Array.prototype.forEach.call(r.addedNodes||[],function(n){if(!n||n.nodeType!==1)return;if(n.id==='notifySettingsV249258'||n.querySelector&&n.querySelector('#notifySettingsV249258'))notify=true;if(n.matches&&n.matches('video,audio')||n.querySelector&&n.querySelector('video,audio'))media=true})});if(notify)renderNotificationSettings(true);if(media)enforceAudio(false);ensureBil()});o.observe(document.body,{subtree:true,childList:true})}if(normalBoot()){stabilizeHome();setTimeout(stabilizeHome,80);setTimeout(releaseBoot,220)}else{window.__ITHAKI_V249475_BOOT_READY__=true;document.documentElement.removeAttribute('data-ithaki-v249475-boot')}run();setInterval(run,1800);Object.assign(I(),{forceStableHomeV249475:stabilizeHome,ensureBilStableV249475:ensureBil,openBilStableV249475:openBil,refreshAllFeedPostsV249475:refreshFeedAfterPublish})}
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
