/* OK ITHAKI V249525 — SINGLE NOTIFICATION CENTER / BIL / SOUND / ENCRYPTED EXTERNAL SYNC */
(function(){
'use strict';
if(window.__ITHAKI_V249525_NOTIFICATION_OWNER__)return;
window.__ITHAKI_V249525_NOTIFICATION_OWNER__={version:'V249525',singleCenter:true,singleBil:true,masterNotifications:true,sound:true,badgeResetOnOpen:true,externalCalendar:true,encryptedPhoneDesktopSync:true,at:Date.now()};
const I=()=>window.ITH=window.ITH||{}; const S=()=>window.state||I().state||{}; const $=id=>document.getElementById(id);
const esc=s=>String(s==null?'':s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const LS={master:'ith525_notifications_enabled',sound:'ith525_notification_sound',bil:'ith525_bil_enabled',opened:'ith525_notifications_opened_at',seen:'ith525_notification_seen_keys',syncEnabled:'ith525_external_sync_enabled',syncSecret:'ith525_external_sync_secret'};
let pollTimer=0,hideTimer=0,syncTimer=0,lastBilAction=null,lastExternalItems=[];
function bool(k,d=true){try{const v=localStorage.getItem(k);return v==null?d:v==='1'}catch(e){return d}}
function setBool(k,v){try{localStorage.setItem(k,v?'1':'0')}catch(e){}return !!v}
function masterOn(){return bool(LS.master,true)} function soundOn(){return bool(LS.sound,true)} function bilOn(){return bool(LS.bil,true)}
function room(){return String(S().room||localStorage.getItem('ith_room')||'ithaki-phone-test')}
function device(){return String(S().device||localStorage.getItem('ith_device')||'')}
function api(path){if(/^https?:/i.test(path))return path;let b=String(S().api||'').replace(/\/+$/,'');if(!b||/appassets\.androidplatform\.net/i.test(b))b='https://ok-ithaki.gr';return b+path}
function nativeObj(){return window.OKITHAKI_ANDROID||window.AndroidBridge||null}
function nativeCall(name,...args){try{const n=nativeObj();if(n&&typeof n[name]==='function')return n[name](...args)}catch(e){}return null}
function toast(m,ms=4500){try{if(typeof I().toast==='function')return I().toast(String(m),ms)}catch(e){}const t=$('toast');if(t){t.textContent=String(m);t.classList.add('show');clearTimeout(toast._t);toast._t=setTimeout(()=>t.classList.remove('show'),ms)}else console.log(m)}
function createdMs(x){let v=Number(x.created_at||x.updated_at||x.time||x.ts||0);if(v>0&&v<2e10)v*=1000;return v||Date.now()}
function noticeKey(x,p='n'){return String(x.id||x.event_id||x.message_id||x.notification_id||p+'|'+(x.type||x.kind||'')+'|'+(x.from_id||x.sender_id||x.title||'')+'|'+createdMs(x))}
function noticeType(x){return String(x.type||x.kind||x.event_type||x.item_type||'notification').toLowerCase()}
function noticeName(x){return String(x.from_name||x.sender_name||x.peer_name||x.nickname||x.title||'Μέλος').trim()||'Μέλος'}
function normalize(x,source){const y=Object.assign({},x);y.__source=source;y.__key=noticeKey(y,source);y.__created=createdMs(y);return y}
function dedupe(a){const m=new Map();a.forEach(x=>{if(!x||!x.__key)return;const old=m.get(x.__key);if(!old||x.__created>old.__created)m.set(x.__key,x)});return [...m.values()].sort((a,b)=>b.__created-a.__created)}
function localNotices(){try{return (JSON.parse(localStorage.getItem('ith_notifications')||'[]')||[]).map(x=>normalize(x,'local'))}catch(e){return[]}}
function externalNativeItems(){try{return JSON.parse(String(nativeCall('getExternalMessageCenterItemsV249477')||'[]'))||[]}catch(e){return[]}}
function externalItems(){const a=externalNativeItems().map(x=>normalize(x,'external-phone'));const b=(window.__ITHAKI_EXTERNAL_SYNC_ITEMS_V249525__||[]).map(x=>normalize(Object.assign({synced_from_phone:true},x),'external-sync'));lastExternalItems=dedupe([...a,...b]);return lastExternalItems}
async function getJson(path){const r=await fetch(api(path),{cache:'no-store',credentials:'include'});if(!r.ok)throw new Error('HTTP '+r.status);return r.json()}
async function postJson(path,data){const r=await fetch(api(path),{method:'POST',headers:{'Content-Type':'application/json'},credentials:'include',body:JSON.stringify(data)});if(!r.ok)throw new Error('HTTP '+r.status);return r.json()}
async function fetchInternal(){const out=[...localNotices()];if(!device())return dedupe(out);const urls=[['/api/notifications/social/v249247?room_id='+encodeURIComponent(room())+'&device_id='+encodeURIComponent(device())+'&limit=120','social'],['/api/notifications/light/v249242?room_id='+encodeURIComponent(room())+'&device_id='+encodeURIComponent(device())+'&limit=120','light'],['/api/notifications?room_id='+encodeURIComponent(room())+'&device_id='+encodeURIComponent(device())+'&limit=200','friend']];for(const [u,p] of urls){try{const d=await getJson(u);(d.items||[]).forEach(x=>out.push(normalize(x,p)))}catch(e){}}return dedupe(out)}
async function allNotices(){await syncExternal(false).catch(()=>{});const internal=await fetchInternal();const ext=externalItems().map(x=>Object.assign(x,{__external:true}));return dedupe([...internal,...ext])}
function isMessage(x){return /message|dm|chat|secure/.test(noticeType(x))}
function textFor(x){if(x.__external)return (x.title?x.title+': ':'')+String(x.body||'');const t=noticeType(x),n=noticeName(x);if(isMessage(x))return 'Έχεις μήνυμα από '+n+'.';if(/like|reaction/.test(t))return 'Έχεις like από '+n+' στη δημοσίευσή σου.';if(/follow/.test(t))return 'Σε ακολουθεί ο/η '+n+'.';if(/profile.*view|view.*profile/.test(t))return 'Ο/Η '+n+' είδε το προφίλ σου.';if(/post.*view|view.*post/.test(t))return 'Ο/Η '+n+' είδε τη δημοσίευσή σου.';if(/comment/.test(t))return 'Ο/Η '+n+' σχολίασε τη δημοσίευσή σου.';if(/reply/.test(t))return 'Ο/Η '+n+' σου απάντησε.';if(/friend|contact/.test(t))return 'Έχεις αίτημα φιλίας από '+n+'.';return String(x.text||x.body||x.title||'Νέα ειδοποίηση.')}
function routeNotice(x){if(x.__external){openExternalCenter(x);return}const peer=String(x.from_id||x.sender_id||x.peer_id||'');if(isMessage(x)&&peer){const f=I().startDM||I().openDMWith;if(typeof f==='function')return f.call(I(),peer)}if(typeof I().notifyCenter==='function')I().notifyCenter()}
function playSound(){if(!masterOn()||!soundOn())return;const r=nativeCall('playNotificationSoundV249525');if(r!==null)return;try{if(typeof I().playAppAlert==='function'){I().playAppAlert('message');return}}catch(e){}try{const C=window.AudioContext||window.webkitAudioContext,a=new C(),o=a.createOscillator(),g=a.createGain();o.frequency.value=880;g.gain.setValueAtTime(.16,a.currentTime);g.gain.exponentialRampToValueAtTime(.001,a.currentTime+.24);o.connect(g);g.connect(a.destination);o.start();o.stop(a.currentTime+.25)}catch(e){}}
function bilFace(){return '<span class="ith525BilFace"><i class="shell"></i><i class="head"><i class="eye l"></i><i class="eye r"></i><i class="mouth"></i></i><i class="foot l"></i><i class="foot r"></i></span>'}
function pageName(){return String(document.body?.dataset.page||S().page||'home')}
function notificationOpen(){const m=$('memberMenu');return !!(m&&m.classList.contains('show')&&m.querySelector('#ith525NotificationCenter,#ith525NotificationSettings'))}
function ensureBil(){cleanupBil();const duplicates=[...document.querySelectorAll('#ith525BilDock')];duplicates.slice(1).forEach(x=>x.remove());let d=duplicates[0]||$('ith525BilDock');if(!d){d=document.createElement('button');d.id='ith525BilDock';d.type='button';d.innerHTML=bilFace()+'<span id="ith525BilSpeech"></span>';d.onclick=()=>{if(typeof lastBilAction==='function'){const a=lastBilAction;lastBilAction=null;a()}else openCenter()};document.body.appendChild(d)}d.hidden=!bilOn()||!(pageName()==='home'||notificationOpen());document.body.classList.toggle('ith525NotificationsOpen',notificationOpen());return d}
function showBil(text,action){if(!bilOn()||!masterOn())return;const d=ensureBil(),s=$('ith525BilSpeech');if(!d||!s)return;lastBilAction=action||null;d.hidden=false;s.textContent=String(text||'');s.classList.add('show');clearTimeout(hideTimer);hideTimer=setTimeout(()=>s.classList.remove('show'),5000)}
const OLD_IDS=['ith523HomeBilCard','ith523BilNotificationCard','ith524BilDock','ith477BilNotificationCard','ith509BilNotificationCard','ithBilGreenTurtleV249461','ithBilMenuV249461','ithBilPopV249461','ithBilStableV249475','ithBilStableMenuV249475','ithProfileBilCardV249476','ithAdminContactCardV249476'];
function cleanupBil(){OLD_IDS.forEach(id=>$(id)?.remove());document.querySelectorAll('[data-bil-notification-card],.bil473Preview,.bil475Preview,.ithBilHomeCardV249472').forEach(x=>{if(!x.closest('#ith525BilDock')&&!x.closest('#ith525NotificationSettings'))x.remove()})}
function applyNativeSettings(){nativeCall('setNotificationMasterEnabledV249525',masterOn());nativeCall('setNotificationSoundEnabledV249525',soundOn())}
function resetBadgeNative(){nativeCall('resetNotificationBadgeV249525')}
function bell(){return $('ithNotifyFabV249238')||document.querySelector('.ithNotifyFabV249238,[data-notifications-fab]')}
function setBadge(n){const b=bell();if(!b)return;let x=b.querySelector('.badge');if(!x){x=document.createElement('span');x.className='badge';b.appendChild(x)}x.textContent=n>99?'99+':String(n);x.style.display=n>0&&masterOn()?'grid':'none';b.setAttribute('aria-label','Ειδοποιήσεις '+n)}
function openedAt(){return Number(localStorage.getItem(LS.opened)||0)}
async function updateBadge(){if(!masterOn()){setBadge(0);return 0}const a=await allNotices();const n=a.filter(x=>x.__created>openedAt()&&x.unread!==false&&String(x.status||'unread')!=='read').length;setBadge(n);return n}
function seenSet(){try{return new Set(JSON.parse(localStorage.getItem(LS.seen)||'[]'))}catch(e){return new Set()}}
function saveSeen(s){try{localStorage.setItem(LS.seen,JSON.stringify([...s].slice(-350)))}catch(e){}}
async function poll(){cleanupBil();ensureBil();applyNativeSettings();let a=[];try{a=await allNotices()}catch(e){}const seen=seenSet();const fresh=a.filter(x=>!seen.has(x.__key));a.forEach(x=>seen.add(x.__key));saveSeen(seen);if(masterOn()&&fresh.length){const newest=fresh.sort((x,y)=>y.__created-x.__created)[0];if(!(newest.__external&&nativeObj()))playSound();showBil(textFor(newest),()=>routeNotice(newest))}await updateBadge().catch(()=>{})}
function closeMenu(){try{if(typeof I().closeMember==='function')I().closeMember();else $('memberMenu')?.classList.remove('show')}catch(e){}}
function internalCard(x){const t=noticeType(x),peer=String(x.from_id||x.sender_id||x.peer_id||''),pending=/friend|contact/.test(t)&&String(x.status||'pending')==='pending'&&String(x.to_id||device())===device();return '<section class="ith525NoticeCard" data-key="'+esc(x.__key)+'"><div class="ith525NoticeTop"><b>'+esc(textFor(x))+'</b><small>'+esc(new Date(x.__created).toLocaleString())+'</small></div><div class="ith525Actions">'+(isMessage(x)&&peer?'<button data-a="dm" data-peer="'+esc(peer)+'">💬 Μηνύματα</button>':'<button data-a="detail">Άνοιγμα</button>')+(pending?'<button class="green" data-a="accept" data-peer="'+esc(peer)+'" data-id="'+esc(x.id||x.event_id||'')+'">✓ Αποδοχή</button><button class="danger" data-a="reject" data-peer="'+esc(peer)+'" data-id="'+esc(x.id||x.event_id||'')+'">× Απόρριψη</button>':'')+'</div></section>'}
function externalCard(x){return '<section class="ith525NoticeCard external" data-key="'+esc(x.__key)+'"><div class="ith525NoticeTop"><span class="ith525Source">'+esc(String(x.source||'APP').toUpperCase())+'</span><b>'+esc(x.title||'Εξωτερικό μήνυμα')+'</b><small>'+esc(new Date(x.__created).toLocaleString())+'</small></div><p>'+esc(x.body||'')+'</p><div class="ith525Actions"><button data-a="external-center">📨 Κέντρο Μηνυμάτων</button><button data-a="external-open" data-id="'+esc(x.id||'')+'" data-source="'+esc(x.source||'')+'">↗ Άνοιγμα εφαρμογής</button></div></section>'}
async function markViewed(a){const now=Date.now();localStorage.setItem(LS.opened,String(now));setBadge(0);resetBadgeNative();const ids=a.filter(x=>x.__source==='social'&&x.id).map(x=>x.id);if(ids.length)postJson('/api/notifications/read/v249247',{room_id:room(),device_id:device(),ids:ids.slice(0,100)}).catch(()=>{});try{localStorage.setItem('ith525_last_center_open',String(now))}catch(e){}}
async function openCenter(){const menu=$('memberMenu');if(!menu)return false;document.body.classList.add('ith525NotificationsOpen');menu.classList.add('show','fullAvatarMenuV249231');menu.innerHTML='<div id="ith525NotificationCenter" class="ith525Panel"><div class="ith525Head"><button data-top="back">‹</button><b>🔔 Κέντρο Ειδοποιήσεων</b><button data-top="external">📨</button><button data-top="calendar">📅</button><button data-top="settings">⚙️</button><button data-top="close">×</button></div><div class="ith525Loading">Φόρτωση…</div></div>';ensureBil();let a=[];try{a=await allNotices()}catch(e){}await markViewed(a);const root=$('ith525NotificationCenter');if(!root)return false;const internal=a.filter(x=>!x.__external),external=a.filter(x=>x.__external);root.innerHTML='<div class="ith525Head"><button data-top="back">‹</button><b>🔔 Κέντρο Ειδοποιήσεων</b><button title="Κέντρο Μηνυμάτων" data-top="external">📨</button><button title="Ημερολόγιο" data-top="calendar">📅</button><button title="Ρυθμίσεις" data-top="settings">⚙️</button><button data-top="close">×</button></div><section class="ith525Summary"><b>'+a.length+' ειδοποιήσεις</b><span>Το καμπανάκι μηδενίστηκε. Οι επόμενες θα μετρήσουν από την αρχή.</span></section><h3>ΙΘΑΚΗ</h3><div>'+((internal.map(internalCard).join(''))||'<section class="ith525Empty">Δεν υπάρχουν ειδοποιήσεις ΙΘΑΚΗΣ.</section>')+'</div><h3>Άλλες εφαρμογές</h3><div>'+((external.map(externalCard).join(''))||'<section class="ith525Empty">Δεν υπάρχουν συγχρονισμένες εξωτερικές ειδοποιήσεις.</section>')+'</div>';
root.onclick=e=>{const top=e.target.closest('[data-top]');if(top){const a=top.dataset.top;if(a==='back'||a==='close'){document.body.classList.remove('ith525NotificationsOpen');closeMenu();return}if(a==='settings')return openSettings();if(a==='external')return openExternalCenter();if(a==='calendar')return openCalendar()}const b=e.target.closest('[data-a]');if(!b)return;const act=b.dataset.a;if(act==='dm'){const f=I().startDM||I().openDMWith;if(typeof f==='function')f.call(I(),b.dataset.peer);return}if(act==='detail')return; if(act==='accept'||act==='reject'){const fn=I().respondFriendProposalV249233||I().respondFriendProposalV249223;if(typeof fn==='function')fn.call(I(),b.dataset.id,act==='accept',b.dataset.peer,b.closest('[data-key]')?.dataset.key||'');setTimeout(openCenter,400);return}if(act==='external-center')return openExternalCenter();if(act==='external-open'){if(!nativeCall('openExternalNotificationV249477',b.dataset.id)&&!nativeCall('openExternalSourceAppV249477',b.dataset.source))toast('Η αρχική εφαρμογή ανοίγει μόνο από το κινητό που συνέλεξε την ειδοποίηση.');return}};return false}
function toggleRow(key,label,desc,on){return '<button class="ith525ToggleRow" data-setting="'+key+'"><span><b>'+esc(label)+'</b><small>'+esc(desc)+'</small></span><i class="'+(on?'on':'')+'">'+(on?'ON':'OFF')+'</i></button>'}
async function openSettings(){const menu=$('memberMenu');if(!menu)return false;menu.classList.add('show','fullAvatarMenuV249231');menu.innerHTML='<div id="ith525NotificationSettings" class="ith525Panel"><div class="ith525Head"><button data-top="center">‹</button><b>⚙️ Ρυθμίσεις ειδοποιήσεων</b><button data-top="close">×</button></div>'+toggleRow('master','Ειδοποιήσεις','Γενική ενεργοποίηση ή απενεργοποίηση ειδοποιήσεων.',masterOn())+toggleRow('sound','Ήχος','Ήχος όταν φτάνει νέα ειδοποίηση.',soundOn())+toggleRow('bil','Bil','Μία μόνο επιλογή Bil. Σε οδηγεί στο σωστό μήνυμα ή κέντρο.',bilOn())+'<section class="ith525SettingsCard"><b>Κέντρο άλλων εφαρμογών</b><div class="ith525Grid"><button data-action="external">📨 Κέντρο Μηνυμάτων</button><button data-action="calendar">📅 Ημερολόγιο ειδοποιήσεων</button><button data-action="access">🔐 Άδεια ειδοποιήσεων Android</button></div></section><section class="ith525SettingsCard"><b>Κρυπτογραφημένος συγχρονισμός κινητού–υπολογιστή</b><p>Ο server αποθηκεύει μόνο κρυπτογραφημένο snapshot. Το μυστικό παραμένει στις συσκευές σου.</p>'+toggleRow('sync','Συγχρονισμός','Ανέβασμα από κινητό και λήψη στον υπολογιστή.',bool(LS.syncEnabled,false))+'<div class="ith525Grid"><button data-action="sync-code">🗝️ Δημιουργία / εμφάνιση κωδικού</button><button data-action="sync-import">📥 Εισαγωγή κωδικού</button><button data-action="sync-now">↻ Συγχρονισμός τώρα</button></div><small id="ith525SyncStatus"></small></section></div>';ensureBil();const root=$('ith525NotificationSettings');root.onclick=async e=>{const top=e.target.closest('[data-top]');if(top){if(top.dataset.top==='center')return openCenter();document.body.classList.remove('ith525NotificationsOpen');return closeMenu()}const s=e.target.closest('[data-setting]');if(s){const k=s.dataset.setting;if(k==='master')setBool(LS.master,!masterOn());if(k==='sound')setBool(LS.sound,!soundOn());if(k==='bil')setBool(LS.bil,!bilOn());if(k==='sync')setBool(LS.syncEnabled,!bool(LS.syncEnabled,false));applyNativeSettings();if(!masterOn()){setBadge(0);resetBadgeNative()}return openSettings()}const a=e.target.closest('[data-action]');if(!a)return;if(a.dataset.action==='external')return openExternalCenter();if(a.dataset.action==='calendar')return openCalendar();if(a.dataset.action==='access'){nativeCall('openNotificationAccessSettingsV249477');return}if(a.dataset.action==='sync-code')return showSyncCode();if(a.dataset.action==='sync-import')return importSyncCode();if(a.dataset.action==='sync-now')return syncExternal(true)};return false}
function openExternalCenter(item){const f=I().openExternalMessageCenterV249477;if(typeof f==='function'){syncExternal(false).finally(()=>f.call(I(),true,item&&item.due_at?'calendar':undefined));return false}toast('Το Κέντρο Μηνυμάτων δεν είναι διαθέσιμο.');return false}
function openCalendar(){const f=I().openExternalMessageCenterV249477||I().renderLocalProfessionalCalendarV249477;if(typeof f==='function'){syncExternal(false).finally(()=>f.call(I(),true,'calendar'));return false}return false}
function bytesToB64u(bytes){let s='';bytes.forEach(b=>s+=String.fromCharCode(b));return btoa(s).replace(/\+/g,'-').replace(/\//g,'_').replace(/=+$/,'')}
function b64uToBytes(s){s=String(s||'').replace(/^ITH525-/,'').replace(/-/g,'+').replace(/_/g,'/');while(s.length%4)s+='=';const r=atob(s),a=new Uint8Array(r.length);for(let i=0;i<r.length;i++)a[i]=r.charCodeAt(i);return a}
function getSecret(){try{return localStorage.getItem(LS.syncSecret)||''}catch(e){return''}}
function ensureSecret(){let s=getSecret();if(!s){s='ITH525-'+bytesToB64u(crypto.getRandomValues(new Uint8Array(32)));localStorage.setItem(LS.syncSecret,s)}return s}
async function keyAndId(){const raw=b64uToBytes(ensureSecret());if(raw.length!==32)throw new Error('Μη έγκυρος κωδικός συγχρονισμού');const hash=new Uint8Array(await crypto.subtle.digest('SHA-256',raw));const id=[...hash].slice(0,20).map(b=>b.toString(16).padStart(2,'0')).join('');const key=await crypto.subtle.importKey('raw',raw,'AES-GCM',false,['encrypt','decrypt']);return{key,id}}
async function encryptItems(items){const {key,id}=await keyAndId(),iv=crypto.getRandomValues(new Uint8Array(12)),plain=new TextEncoder().encode(JSON.stringify(items));const ct=new Uint8Array(await crypto.subtle.encrypt({name:'AES-GCM',iv},key,plain));return{id,payload:JSON.stringify({v:1,alg:'AES-256-GCM',iv:bytesToB64u(iv),ct:bytesToB64u(ct)})}}
async function decryptItems(payload){const {key}=await keyAndId(),b=JSON.parse(payload),iv=b64uToBytes(b.iv),ct=b64uToBytes(b.ct),plain=await crypto.subtle.decrypt({name:'AES-GCM',iv},key,ct);return JSON.parse(new TextDecoder().decode(plain))}
function syncStatus(t){const x=$('ith525SyncStatus');if(x)x.textContent=t;toast(t,4000)}
async function showSyncCode(){const c=ensureSecret();try{await navigator.clipboard.writeText(c);syncStatus('Ο κωδικός αντιγράφηκε. Βάλ’ τον στον υπολογιστή.')}catch(e){prompt('Κωδικός συγχρονισμού — κράτησέ τον ιδιωτικό',c)}}
async function importSyncCode(){const c=prompt('Επικόλλησε τον κωδικό ITH525-…',getSecret());if(c===null)return;try{if(b64uToBytes(c.trim()).length!==32)throw 0;localStorage.setItem(LS.syncSecret,c.trim().startsWith('ITH525-')?c.trim():'ITH525-'+c.trim());setBool(LS.syncEnabled,true);await syncExternal(true);openSettings()}catch(e){toast('Ο κωδικός δεν είναι έγκυρος.')}}
async function syncExternal(show){if(!bool(LS.syncEnabled,false)||!getSecret()||!crypto?.subtle)return false;try{const native=externalNativeItems();const {id}=await keyAndId();if(nativeObj()&&native.length){const box=await encryptItems(native);await postJson('/api/external-center/sync/v249525',{sync_id:box.id,encrypted_payload:box.payload,item_count:native.length,updated_at:Date.now()});window.__ITHAKI_EXTERNAL_SYNC_ITEMS_V249525__=native;if(show)syncStatus('Η λίστα του κινητού συγχρονίστηκε κρυπτογραφημένα.');return true}const d=await getJson('/api/external-center/sync/v249525?sync_id='+encodeURIComponent(id));if(d.encrypted_payload){const items=await decryptItems(d.encrypted_payload);window.__ITHAKI_EXTERNAL_SYNC_ITEMS_V249525__=Array.isArray(items)?items:[];if(show)syncStatus('Η λίστα του κινητού φορτώθηκε στον υπολογιστή.');return true}if(show)syncStatus('Δεν υπάρχει ακόμη συγχρονισμένη λίστα από κινητό.')}catch(e){if(show)syncStatus('Ο συγχρονισμός απέτυχε: '+String(e.message||e))}return false}
function removeDuplicateSettings(){cleanupBil();document.querySelectorAll('#notifySettingsV249258,#notificationSettingsV249238,#ithNotificationSettingsV249238').forEach(h=>{if(h.closest('#ith525NotificationSettings'))return;h.querySelectorAll('#ith477BilNotificationCard,#ith509BilNotificationCard,#ith523BilNotificationCard,[data-bil-notification-card],.bil475Preview').forEach(x=>x.remove())})}
function installOwners(){const o=I();o.notifyCenter=openCenter;window.notifyCenter=openCenter;o.openNotificationSettingsV249238=openSettings;window.openNotificationSettingsV249238=openSettings;o.renderNotificationModeSettingsV249258=openSettings;window.renderNotificationModeSettingsV249258=openSettings;o.refreshNotificationBadgeV249238=updateBadge;window.refreshNotificationBadgeV249238=updateBadge;o.openNotificationCalendarV249525=openCalendar;o.syncExternalMessageCenterV249525=syncExternal;o.showBilNotificationV249525=showBil}
function css(){if($('ith525Style'))return;const s=document.createElement('style');s.id='ith525Style';s.textContent=`
#ithBilGreenTurtleV249461,#ithBilMenuV249461,#ithBilPopV249461,#ithBilStableV249475,#ithBilStableMenuV249475,#ith523HomeBilCard,#ith523BilNotificationCard,#ith524BilDock,#ith526BilDock,#ithProfileBilCardV249476,#ithAdminContactCardV249476,#ith477BilNotificationCard,#ith509BilNotificationCard,.ithBilHomeCardV249472,.bil473Preview,.bil475Preview{display:none!important;visibility:hidden!important;opacity:0!important;pointer-events:none!important}
#ith525BilDock{position:fixed;left:10px;bottom:calc(var(--bar,72px) + 22px);z-index:2147483600;width:58px;height:58px;border:0;background:transparent;padding:0;overflow:visible;filter:drop-shadow(0 8px 14px rgba(0,0,0,.44));touch-action:manipulation}body.ith525NotificationsOpen #ith525BilDock{bottom:calc(var(--bar,72px) + 82px)}#ith525BilDock[hidden]{display:none!important}.ith525BilFace{position:relative;display:block;width:58px;height:54px}.ith525BilFace .shell{position:absolute;left:5px;top:23px;width:43px;height:28px;border-radius:55%;background:radial-gradient(circle at 44% 23%,#ffe49c 0 18%,#62bf89 19% 55%,#246b50 56% 100%);border:1px solid #ffffff80}.ith525BilFace .head{position:absolute;left:23px;top:2px;width:27px;height:27px;border-radius:50%;background:#7bdaa0;border:1px solid #ffffff80}.ith525BilFace .eye{position:absolute;top:8px;width:4px;height:6px;border-radius:50%;background:#10231e}.ith525BilFace .eye.l{left:6px}.ith525BilFace .eye.r{right:6px}.ith525BilFace .mouth{position:absolute;left:8px;top:17px;width:10px;height:4px;border-bottom:2px solid #17392e;border-radius:0 0 9px 9px}.ith525BilFace .foot{position:absolute;top:47px;width:11px;height:6px;border-radius:99px;background:#62bf89}.ith525BilFace .foot.l{left:7px}.ith525BilFace .foot.r{right:8px}#ith525BilSpeech{position:absolute;left:50px;bottom:34px;width:min(300px,calc(100vw - 78px));padding:10px 12px;border-radius:16px 16px 16px 4px;background:#07131ff5;border:1px solid #7eebae60;color:#fff;font-size:13px;line-height:1.4;text-align:left;opacity:0;visibility:hidden;transform:translateY(5px);transition:.2s;box-shadow:0 13px 32px #0007;pointer-events:none}#ith525BilSpeech.show{opacity:1;visibility:visible;transform:none}
.ith525Panel{height:100%;overflow:auto;padding:10px 10px calc(var(--bar,72px) + 26px);box-sizing:border-box;-webkit-overflow-scrolling:touch}.ith525Head{position:sticky;top:0;z-index:20;display:flex;align-items:center;gap:7px;padding:8px;border-radius:15px;background:#07131fee;border:1px solid #ffffff18;backdrop-filter:blur(14px)}.ith525Head b{flex:1}.ith525Head button,.ith525Actions button,.ith525Grid button{border:1px solid #ffffff24;background:#ffffff10;color:#fff;border-radius:12px;padding:9px 11px}.ith525Summary,.ith525SettingsCard,.ith525NoticeCard,.ith525Empty{margin-top:10px;padding:12px;border-radius:16px;background:#ffffff0d;border:1px solid #ffffff17}.ith525Summary{display:flex;flex-direction:column;gap:4px}.ith525Summary span,.ith525NoticeCard small,.ith525SettingsCard p,.ith525ToggleRow small{opacity:.72}.ith525NoticeTop{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.ith525NoticeTop b{flex:1;min-width:180px}.ith525Actions{display:flex;gap:7px;flex-wrap:wrap;margin-top:10px}.ith525Actions .green{background:#36f0a02b;border-color:#36f0a070}.ith525Actions .danger{background:#ff5a5a20;border-color:#ff5a5a66}.ith525Source{padding:4px 7px;border-radius:99px;background:#ffd96e20;color:#ffd96e;font-size:11px;font-weight:900}.ith525ToggleRow{width:100%;display:flex;align-items:center;gap:10px;text-align:left;padding:12px;margin-top:9px;border:1px solid #ffffff1f;background:#ffffff0c;color:#fff;border-radius:15px}.ith525ToggleRow span{display:flex;flex-direction:column;gap:4px;flex:1}.ith525ToggleRow i{font-style:normal;min-width:48px;text-align:center;padding:7px;border-radius:99px;background:#ffffff12}.ith525ToggleRow i.on{background:#36f0a02a;color:#6ff0ad}.ith525Grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-top:10px}@media(max-width:520px){.ith525Grid{grid-template-columns:1fr}.ith525Head button{padding:8px}.ith525Head b{font-size:14px}}
`;document.head.appendChild(s)}
function maintain(){css();installOwners();removeDuplicateSettings();ensureBil();applyNativeSettings();if(notificationOpen())document.body.classList.add('ith525NotificationsOpen');else document.body.classList.remove('ith525NotificationsOpen')}
function migrate(){if(localStorage.getItem(LS.bil)==null){const old=localStorage.getItem('ith_bil_enabled_v249461');setBool(LS.bil,old!=='0')}if(localStorage.getItem(LS.master)==null)setBool(LS.master,true);if(localStorage.getItem(LS.sound)==null)setBool(LS.sound,true)}
function install(){I().openExactNotificationMessageCenterButtonV249525=openExternalCenter;window.openExactNotificationMessageCenterButtonV249525=openExternalCenter;migrate();css();installOwners();maintain();applyNativeSettings();clearInterval(pollTimer);pollTimer=setInterval(poll,15000);setTimeout(poll,1800);clearInterval(syncTimer);syncTimer=setInterval(()=>syncExternal(false),60000);setTimeout(()=>syncExternal(false),3500);new MutationObserver(()=>{clearTimeout(install._m);install._m=setTimeout(maintain,80)}).observe(document.body,{subtree:true,childList:true});['focus','pageshow'].forEach(n=>window.addEventListener(n,()=>{maintain();syncExternal(false);updateBadge()}));window.addEventListener('ithaki:page-changed',()=>setTimeout(maintain,50));setInterval(maintain,1000);try{localStorage.setItem('ith_frontend_build','V249525-notification-center-bil-sound-external-sync');document.documentElement.setAttribute('data-ithaki-v249525','notification-center-bil-sound-external-sync')}catch(e){}}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
