/* OK ITHAKI V249526R10F21 — PUBLICATION RAIL / GENERAL AVATAR MENU / PREVIEW-ONLY SECURITY */
(function(){
'use strict';
if(window.__ITHAKI_V249517_MESSAGES_EXACT_COMMUNITY__) return;
window.__ITHAKI_V249517_MESSAGES_EXACT_COMMUNITY__={version:'V249526R10F21',singleOwner:true,exactMessagesScreen:true,directFileList:true,realCheckboxes:true,transparentMembersBar:true,at:Date.now()};
window.__ITHAKI_V249516_STABLE_COMMUNITY_OPEN_TOOLS__=true;
window.__ITHAKI_V249516_COMMUNITY_SINGLE_OWNER__=true;
window.__ITHAKI_V249517_COMMUNITY_SINGLE_OWNER__=true;
window.__ITHAKI_R10F2_COMMUNITY_EXCLUSIVE_OWNER__={version:'R10F18',exclusiveFirstPaint:true,atomicCompleteRender:true,serverResponseDedup:true,at:Date.now()};
const COMMUNITY_ATOMIC_COMPLETE_RENDER_R10F13=true;
const COMMUNITY_MESSAGE_SCREEN_STABLE_R10F18=true;
const COMMUNITY_SCOPED_SIDE_ACTIONS_R10F20=true;
const COMMUNITY_REACTIONS_REPLIES_TRANSLATE_R10F20=true;
const COMMUNITY_SECURE_PREVIEW_R10F20=true;
const COMMUNITY_RAIL_PUBLICATIONS_ONLY_R10F21=true;
const COMMUNITY_AVATAR_GENERAL_MENU_R10F21=true;
const I=()=>window.ITH||{};
const S=()=>window.state||I().state||{};
const $=id=>document.getElementById(id);
const esc=s=>String(s??'').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const CATS=[
 ['all','🧭','Όλες'],['general','💬','Γενικά'],['holidays','🏖️','Διακοπές'],['fashion','👗','Μόδα'],['hobbies','🧩','Χόμπι'],['landscapes','🏞️','Τοπία'],['travel','✈️','Ταξίδια'],['photography','📷','Φωτογραφία'],['music','🎵','Μουσική'],['art','🎨','Τέχνη'],['technology','💻','Τεχνολογία'],['engineering','⚙️','Μηχανικοί και τεχνίτες'],['sports','🏃','Αθλητισμός'],['cooking','🍲','Μαγειρική'],['nature','🌿','Φύση και κήπος'],['family','👨‍👩‍👧','Οικογένεια'],['support','🤝','Υποστήριξη'],['philosophy','🧠','Φιλοσοφία'],['books','📚','Βιβλία'],['local','📍','Τοπικές κοινότητες'],['other','✨','Άλλο']
];
const GREEK_TITLE={
 'Better world':'🌍 Καλύτερος κόσμος','Work and dignity':'🛠️ Εργασία και αξιοπρέπεια','Life philosophy':'🧭 Φιλοσοφία ζωής','Environment':'🌱 Περιβάλλον','Justice':'⚖️ Δικαιοσύνη','Studies and learning':'🎓 Σπουδές και μάθηση','Technology for people':'🤖 Τεχνολογία για τον άνθρωπο','Health and balance':'🫶 Υγεία και ισορροπία','Holidays':'🏖️ Διακοπές','Fashion':'👗 Μόδα','Hobbies':'🧩 Χόμπι','Landscapes':'🏞️ Τοπία'
};
let kind='community',cat='all',spaces=[],busy=false,createCat='general',createKind='community';
let view='list',activeSpace=null,openingId='',rendering=false,restoreTimer=0,observer=null;
let membersLoadedFor='',membersLoadedAt=0,filePickerActive=false,pendingJoin=null;
let loadPromiseR10F13=null,loadGenerationR10F13=0,lastListSignatureR10F13='';
let messageLoadPromiseR10F18=null,messageLoadGenerationR10F18=0,messageAbortR10F18=null,lastMessageSignatureR10F18='',messageSendBusyR10F18=false,liveMessageRefreshTimerR10F18=0,communityReplyToR10F20=null,communitySuspendedR10F20=false,lastCommunityRowsR10F21=[];

function room(){return String(S().room||localStorage.getItem('ith_room')||'ithaki-phone-test')}
function device(){return String(S().device||localStorage.getItem('ith_device')||'')}
function communityCacheKeyR10F10(){return 'ith_communities_r10f2_'+room()+'_'+device()}
function nickname(){return String(S().name||localStorage.getItem('ith_name')||localStorage.getItem('ith_nickname')||'Μέλος')}
function apiBase(){let b=String(S().api||I().state?.api||location.origin||'').replace(/\/+$/,'');if(!/^https?:/i.test(b)||/appassets\.androidplatform\.net/i.test(b))b='https://ok-ithaki.gr';return b}
async function api(path,opt={}){
 const h=Object.assign({'Content-Type':'application/json'},opt.headers||{});
 try{const t=localStorage.getItem('ith_public_token')||localStorage.getItem('ith_token')||'';if(t)h['X-ITHAKI-TOKEN']=t}catch(e){}
 const r=await fetch(apiBase()+path,Object.assign({cache:'no-store'},opt,{headers:h}));
 let d={};try{d=await r.json()}catch(e){d={detail:await r.text()}}
 if(!r.ok)throw Error(d.detail||('HTTP '+r.status));return d;
}
function toast(m,ms=5500){try{if(I().toast)return I().toast(m,ms);const t=$('toast');if(t){t.textContent=m;t.classList.add('show');setTimeout(()=>t.classList.remove('show'),ms);return}}catch(e){}alert(m)}
function title(x){const raw=String(x?.title_el||x?.title||'Κοινότητα').trim();return GREEK_TITLE[raw]||raw}
function desc(x){return String(x?.description_el||x?.description||'').trim()}
function catName(k){const c=CATS.find(x=>x[0]===k)||CATS[CATS.length-1];return c[1]+' '+c[2]}
function accessName(v){return v==='invite'?'Με αίτημα και έγκριση':v==='private_code'?'Με κωδικό μέλους':'Ανοιχτή'}
function iconFor(x){const c=CATS.find(c=>c[0]===String(x?.topic_category||'general'));return c?c[1]:((x?.space_kind||x?.category)==='room'?'🏠':'🌐')}
function normalizeSpaceTitleV249526R4(v){return String(v||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/[^a-zA-Z0-9\u0370-\u03ff]+/g,' ').replace(/\s+/g,' ').trim().toLocaleLowerCase('el')}
function spaceScoreV249526R4(x){return (x?.is_owner?1000000:0)+(x?.is_member?500000:0)+Number(x?.message_count||0)*100+Number(x?.member_count||0)*10+Number(x?.last_activity||0)/1000000000}
function canonicalSpaceTitleV249526R6(x){return normalizeSpaceTitleV249526R4(title(x))}
function canonicalSpaceIdR10F13(x){return String(x?.subroom_id||x?.room_id||x?.id||'').trim().toLocaleLowerCase('en')}
function dedupeSpacesV249526R4(list){const out=[],byId=new Map(),byTitle=new Map();for(const raw of Array.isArray(list)?list:[]){const x=Object.assign({},raw),id=canonicalSpaceIdR10F13(x),kind=String(x.space_kind||x.category||'community').trim().toLocaleLowerCase('en'),titleKey=canonicalSpaceTitleV249526R6(x),tk=titleKey?(kind+'|'+titleKey):'';let idx=id&&byId.has(id)?byId.get(id):(tk&&byTitle.has(tk)?byTitle.get(tk):-1);if(idx<0){idx=out.length;out.push(x);if(id)byId.set(id,idx);if(tk)byTitle.set(tk,idx)}else if(spaceScoreV249526R4(x)>spaceScoreV249526R4(out[idx])){out[idx]=x;if(id)byId.set(id,idx);if(tk)byTitle.set(tk,idx)}}return out}
function randomCode(){const a='ABCDEFGHJKLMNPQRSTUVWXYZ23456789';let s='';if(window.crypto&&crypto.getRandomValues){const b=new Uint8Array(10);crypto.getRandomValues(b);for(const n of b)s+=a[n%a.length]}else for(let i=0;i<10;i++)s+=a[Math.floor(Math.random()*a.length)];return s}
function saveCreatorCode(id,code){try{localStorage.setItem('ith_space_creator_code_v249510_'+id,code)}catch(e){}}
function followKey(){return 'ith_space_subscriptions_v249281'}
function followedIds(){try{return JSON.parse(localStorage.getItem(followKey())||'[]')}catch(e){return[]}}
function isFollowed(id){return followedIds().includes(String(id))}
function saveFollow(id,on){let a=followedIds().map(String);if(on&&!a.includes(String(id)))a.push(String(id));if(!on)a=a.filter(x=>x!==String(id));try{localStorage.setItem(followKey(),JSON.stringify(a))}catch(e){}}

function addCss(){if($('ith516Css'))return;const st=document.createElement('style');st.id='ith516Css';st.textContent=`
body[data-page="spaces"] #spacesPage{height:calc(100dvh - var(--top) - var(--bar));min-height:0;overflow:hidden!important;padding:0!important}.ith516Shell{height:100%;min-height:0;display:block;overflow:hidden;padding:8px;box-sizing:border-box}.ith516Shell.viewChat .ith516ListScreen,.ith516Shell.viewCreate .ith516ListScreen,.ith516Shell.viewJoin .ith516ListScreen{display:none!important}.ith516Shell.viewChat .ith516ChatScreen{display:flex!important}.ith516Shell.viewCreate .ith516CreateScreen{display:flex!important}.ith516Shell.viewJoin .ith522JoinScreen{display:flex!important}
.ith516ListScreen{height:100%;min-height:0;display:flex;flex-direction:column;gap:8px;overflow:hidden}.ith516Hero{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:20px;background:linear-gradient(135deg,rgba(255,217,110,.13),rgba(54,240,160,.08));border:1px solid rgba(255,217,110,.22);box-shadow:0 12px 38px rgba(0,0,0,.22)}.ith516Hero .ship{width:42px;height:42px;border-radius:16px;display:grid;place-items:center;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.12);font-size:23px}.ith516Hero .text{min-width:0;flex:1}.ith516Hero b{display:block;color:#ffd96e;font-size:17px}.ith516Hero small{display:block;color:rgba(238,247,255,.76);line-height:1.32}
.ith516CreateCta{position:relative!important;z-index:90!important;pointer-events:auto!important;touch-action:manipulation!important;width:100%;min-height:68px;border:2px solid rgba(255,217,110,.78)!important;border-radius:20px!important;padding:10px 15px!important;display:flex!important;align-items:center!important;gap:13px!important;text-align:left!important;background:linear-gradient(135deg,rgba(255,211,92,.28),rgba(54,240,160,.18))!important;color:#fff!important;box-shadow:0 10px 34px rgba(0,0,0,.28),0 0 0 3px rgba(255,217,110,.06)!important}.ith516CreateCta .plus{font-size:34px;line-height:1;color:#ffe18a}.ith516CreateCta b{display:block;font-size:17px;color:#ffe49c}.ith516CreateCta small{display:block;margin-top:2px;color:rgba(255,255,255,.80)}
.ith516Kinds{display:grid;grid-template-columns:1fr 1fr auto;gap:7px;position:relative;z-index:70}.ith516Kinds button{min-height:42px;pointer-events:auto!important;touch-action:manipulation!important}.ith516Cats{position:relative!important;z-index:80!important;display:flex;gap:7px;overflow-x:auto;overflow-y:hidden;padding:4px 2px 7px;scrollbar-width:none;pointer-events:auto!important;touch-action:pan-x!important}.ith516Cats::-webkit-scrollbar{display:none}.ith516CatBtn{position:relative!important;z-index:81!important;flex:0 0 auto;white-space:nowrap;border-radius:999px;padding:10px 13px;border:1px solid rgba(255,255,255,.17);background:rgba(255,255,255,.08);color:#fff;font-weight:900;pointer-events:auto!important;touch-action:manipulation!important;cursor:pointer}.ith516CatBtn.on{background:linear-gradient(135deg,rgba(54,240,160,.28),rgba(255,217,110,.22));border-color:rgba(255,217,110,.68);color:#ffe39b;box-shadow:0 0 0 2px rgba(255,217,110,.07)}
.ith516Tools{display:flex;gap:8px}.ith516Tools .search{flex:1;min-height:42px;border-radius:999px;padding:8px 13px;background:rgba(255,255,255,.07);border:1px solid rgba(255,255,255,.12);color:#fff}.ith516List{flex:1 1 auto;min-height:0;overflow-y:auto!important;overflow-x:hidden!important;-webkit-overflow-scrolling:touch;padding:2px 2px 14px;touch-action:pan-y;overscroll-behavior:contain}.ith516Row{cursor:pointer;pointer-events:auto!important;touch-action:manipulation!important}.ith516Row .avatar{display:grid!important;place-items:center!important;background:linear-gradient(135deg,rgba(54,240,160,.18),rgba(255,217,110,.18))!important;color:#fff;font-size:22px}.ith516Row .who small{white-space:normal!important;line-height:1.25}.ith516Pills{display:flex;gap:5px;flex-wrap:wrap;margin-top:5px}.ith516Pill{font-size:10px;border-radius:999px;padding:3px 6px;background:rgba(255,255,255,.08)}
.ith522JoinScreen{height:100%;min-height:0;display:none;flex-direction:column;overflow:hidden;background:rgba(5,18,31,.995);border-radius:20px;border:1px solid rgba(255,217,110,.22);position:relative;z-index:2147482000;pointer-events:auto!important}.ith522JoinHead{flex:0 0 auto;display:flex;align-items:center;gap:9px;padding:10px;border-bottom:1px solid rgba(255,255,255,.10);background:rgba(3,12,21,.98)}.ith522JoinHead b{flex:1;color:#ffe39b;font-size:17px}.ith522JoinBody{flex:1 1 auto;min-height:0;overflow-y:auto;padding:12px;display:grid;gap:11px;-webkit-overflow-scrolling:touch}.ith522JoinRules{padding:13px;border-radius:17px;background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.12);white-space:pre-wrap;line-height:1.45}.ith522RuleCheck{display:flex;align-items:center;gap:12px;width:100%;min-height:62px;padding:12px;border-radius:17px;border:2px solid rgba(255,255,255,.18);background:rgba(255,255,255,.07);color:#fff;text-align:left;pointer-events:auto!important;touch-action:manipulation!important;position:relative;z-index:2147482100}.ith522RuleCheck .box{width:30px;height:30px;flex:0 0 30px;border-radius:8px;border:2px solid rgba(255,255,255,.62);display:grid;place-items:center;font-size:22px;background:rgba(0,0,0,.24)}.ith522RuleCheck[aria-checked="true"]{border-color:#58f0a0;background:rgba(54,240,160,.15)}.ith522RuleCheck[aria-checked="true"] .box{background:#27d985;border-color:#8affc2;color:#04150e}.ith522JoinSubmit{min-height:54px!important;font-weight:950!important;font-size:16px!important}.ith522JoinScreen input,.ith522JoinScreen textarea{width:100%;box-sizing:border-box;min-height:44px;border-radius:14px;margin-top:5px}body.ith522CommunityChatOpen #memberMenu:not(.ith522AllowedOverlay),body.ith522CommunityChatOpen #plusSheet,body.ith522CommunityChatOpen #previewModal:not(.show){pointer-events:none!important}.ith522ForeignOverlayClosed{display:none!important;pointer-events:none!important}
.ith516CreateScreen{height:100%;min-height:0;display:none;flex-direction:column;overflow:hidden;background:rgba(5,18,31,.98);border-radius:20px;border:1px solid rgba(255,217,110,.18)}.ith516CreateHead{flex:0 0 auto;display:flex;align-items:center;gap:9px;padding:10px;border-bottom:1px solid rgba(255,255,255,.10)}.ith516CreateHead b{font-size:18px;color:#ffe39b}.ith516CreateBody{flex:1 1 auto;min-height:0;overflow-y:auto;padding:12px;-webkit-overflow-scrolling:touch}.ith516CreateCard{display:grid;gap:12px;padding:13px;border-radius:18px;background:rgba(255,255,255,.055);border:1px solid rgba(255,255,255,.11)}.ith516CreateCard label{font-weight:850}.ith516CreateCard input,.ith516CreateCard textarea,.ith516CreateCard select{width:100%;box-sizing:border-box;margin-top:5px;min-height:44px;border-radius:14px}.ith516CreateCatGrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-top:7px;position:relative;z-index:100;pointer-events:auto!important}.ith516CreateCat{position:relative!important;z-index:101!important;min-height:54px;border-radius:16px;border:1px solid rgba(255,255,255,.14);background:rgba(255,255,255,.07);color:#fff;font-weight:900;text-align:left;padding:10px;pointer-events:auto!important;touch-action:manipulation!important;cursor:pointer}.ith516CreateCat.on{border-color:rgba(255,217,110,.78);background:linear-gradient(135deg,rgba(255,217,110,.24),rgba(54,240,160,.18));color:#ffe39b;box-shadow:0 0 0 2px rgba(255,217,110,.08)}.ith516Submit{min-height:54px!important;font-size:16px!important;font-weight:950!important;border-radius:17px!important}.ith516Notice{padding:10px;border-radius:15px;background:rgba(255,211,105,.1);border:1px solid rgba(255,211,105,.22)}
.ith516ChatScreen{height:100%;min-height:0;display:none;flex-direction:column;overflow:hidden;background:rgba(4,17,29,.98);border-radius:19px}.ith516ChatScreen .chatPane{height:100%!important;min-height:0!important;display:flex!important;flex-direction:column!important;overflow:hidden!important}.ith516ChatScreen .chatHead{flex:0 0 auto!important;min-height:48px!important}.ith516ChatScreen .messages{flex:1 1 0!important;min-height:0!important;max-height:none!important;overflow-y:auto!important;-webkit-overflow-scrolling:touch!important}.ith516ChatScreen .composer{flex:0 0 auto!important;position:sticky!important;bottom:0!important;z-index:3!important;background:rgba(6,20,35,.96)!important;border-top:1px solid rgba(255,255,255,.10)!important;padding-bottom:calc(6px + env(safe-area-inset-bottom,0px))!important}.ith516ChatAvatar{width:40px;height:40px;border-radius:50%;display:grid;place-items:center;background:linear-gradient(135deg,rgba(54,240,160,.20),rgba(255,217,110,.18));border:1px solid rgba(255,217,110,.26);font-size:20px}.ith516ChatTitle{min-width:0;flex:1}.ith516ChatTitle b{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ith516ChatTitle small{display:block;color:rgba(238,247,255,.65);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ith516CommunityTools{flex:0 0 auto;display:flex;gap:6px;overflow-x:auto;padding:6px 7px;border-bottom:1px solid rgba(255,255,255,.08);scrollbar-width:none}.ith516CommunityTools::-webkit-scrollbar{display:none}.ith516CommunityTools button{flex:0 0 auto;min-height:36px;border-radius:999px;padding:7px 10px;font-size:12px;white-space:nowrap}.ith516MessageSearch{display:none;flex:0 0 auto;padding:7px;background:rgba(255,255,255,.045);border-bottom:1px solid rgba(255,255,255,.08)}.ith516MessageSearch.show{display:flex}.ith516MessageSearch input{width:100%;min-height:40px;border-radius:999px;padding:8px 12px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.14);color:#fff}.ith516PanelList{display:grid;gap:8px;max-height:64vh;overflow:auto}.ith516PanelRow{display:flex;gap:9px;align-items:center;padding:10px;border-radius:15px;background:rgba(255,255,255,.055);border:1px solid rgba(255,255,255,.09)}.ith516PanelRow span{flex:1}.ith516Rules{white-space:pre-wrap;line-height:1.5}.ith516FollowOn{background:linear-gradient(135deg,#54f0a0,#91ffd0)!important;color:#09251a!important}.ith516Role{font-size:10px;border-radius:999px;padding:3px 7px;background:rgba(255,217,110,.14);color:#ffe39b}.ith516Answer{padding:7px 9px;border-radius:12px;background:rgba(255,255,255,.05);margin-top:5px;white-space:pre-wrap}.ith516PollOption{width:100%;display:flex;justify-content:space-between;gap:8px;margin:6px 0;min-height:42px}.ith516EventActions{display:flex;gap:6px;flex-wrap:wrap;margin-top:8px}.ith516StaffActions{display:flex;gap:5px;flex-wrap:wrap}.ith516JoinRules{max-height:22vh;overflow:auto;white-space:pre-wrap;line-height:1.45;padding:10px;border-radius:14px;background:rgba(255,217,110,.08)}

.ith517MembersBar{flex:0 0 auto;display:flex;align-items:center;gap:8px;min-height:46px;overflow-x:auto;overflow-y:hidden;padding:5px 8px;background:rgba(255,255,255,.018)!important;border-top:1px solid rgba(255,255,255,.035);border-bottom:1px solid rgba(255,255,255,.045);backdrop-filter:blur(9px);-webkit-backdrop-filter:blur(9px);scrollbar-width:none}.ith517MembersBar::-webkit-scrollbar{display:none}.ith517MemberChip{position:relative;flex:0 0 auto;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:2px 5px;border:0!important;border-radius:999px;background:transparent!important;color:rgba(239,248,255,.82);font-size:11px;white-space:nowrap;box-shadow:none!important}.ith517MemberAvatar{position:relative;width:30px;height:30px;border-radius:50%;display:grid;place-items:center;overflow:hidden;background:rgba(255,255,255,.075);border:1px solid rgba(255,255,255,.10);font-weight:950}.ith517MemberAvatar img{width:100%;height:100%;object-fit:cover}.ith517MemberDot{position:absolute;right:1px;bottom:1px;width:8px;height:8px;border-radius:50%;background:#7b8591;border:2px solid rgba(4,17,29,.95)}.ith517MemberDot.on{background:#36f0a0;box-shadow:0 0 8px rgba(54,240,160,.65)}.ith517MembersEmpty{padding:5px 8px;color:rgba(238,247,255,.58);font-size:11px}.ith516ChatScreen .chatTitle{min-width:0;flex:1}.ith516ChatScreen .chatTitle b{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ith516ChatScreen .chatTitle .typing{font-size:11px;color:rgba(238,247,255,.64);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ith516ChatScreen .chatAvatarBtn{flex:0 0 auto}.ith516ChatScreen .composer textarea{min-height:42px!important;max-height:118px!important}.ith516ChatScreen .composer .icon{flex:0 0 auto}.ith516ChatScreen #spacePinnedBoxV249281:empty{display:none}.ith516ChatScreen #spacePinnedBoxV249281{flex:0 0 auto}.ith517CheckRow{position:relative;display:grid!important;grid-template-columns:28px 1fr;align-items:center;gap:10px;min-height:50px;padding:10px 11px;border-radius:15px;background:rgba(255,255,255,.055);border:1px solid rgba(255,255,255,.10);pointer-events:auto!important;touch-action:manipulation!important;cursor:pointer}.ith517CheckRow input[type=checkbox]{display:block!important;appearance:auto!important;-webkit-appearance:checkbox!important;opacity:1!important;visibility:visible!important;pointer-events:auto!important;position:relative!important;z-index:3!important;width:23px!important;height:23px!important;min-height:23px!important;margin:0!important;padding:0!important;accent-color:#36f0a0!important}.ith517CheckRow span{min-width:0}.ith517CheckRow.checked{border-color:rgba(54,240,160,.56);background:rgba(54,240,160,.10)}.ith517InviteList{display:grid;gap:8px;max-height:55vh;overflow-y:auto;padding:2px;-webkit-overflow-scrolling:touch}.ith517InvitePerson{display:grid;grid-template-columns:28px auto 1fr!important}.ith517InviteAvatar{width:38px;height:38px;border-radius:50%;display:grid;place-items:center;overflow:hidden;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.10)}.ith517InviteAvatar img{width:100%;height:100%;object-fit:cover}.ith517InvitePerson small{display:block;color:rgba(238,247,255,.60);font-size:10px;overflow-wrap:anywhere}.ith517ToolGrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}.ith517ToolGrid button{min-height:52px;text-align:left;border-radius:16px;background:rgba(255,255,255,.065);border:1px solid rgba(255,255,255,.10);padding:10px;color:#fff;font-weight:900}.ith517HiddenFile{position:fixed!important;width:1px!important;height:1px!important;opacity:0!important;pointer-events:none!important;left:-9999px!important;top:-9999px!important}
.ith516ChatScreen{background:linear-gradient(180deg,rgba(4,18,30,.99),rgba(2,11,20,.99));border:1px solid rgba(255,255,255,.08);border-radius:22px;overflow:hidden}.ith516ChatScreen .chatPane{height:100%;min-height:0;display:flex;flex-direction:column}.ith516ChatScreen #spaceMsgs{flex:1 1 auto;min-height:0;overflow-y:auto!important;overscroll-behavior:contain;padding:10px 9px 18px!important;scroll-behavior:smooth}.ith516ChatScreen .composer{flex:0 0 auto;position:relative!important;z-index:35!important;margin:0!important;padding:8px!important;background:rgba(4,17,29,.96)!important;border-top:1px solid rgba(255,255,255,.09)!important;backdrop-filter:blur(16px)}.ith516ChatScreen .composer textarea{background:rgba(255,255,255,.07)!important;border:1px solid rgba(255,255,255,.12)!important}.ithCommunityBubbleR10F18{contain:layout style;overflow-wrap:anywhere}.ithCommunityBubbleR10F18 .communityMediaR10F18{margin-top:8px}.ithCommunityBubbleR10F18 .communityMediaR10F18 img,.ithCommunityBubbleR10F18 .communityMediaR10F18 video{display:block;max-width:100%;max-height:52vh;border-radius:16px;background:#000}.ithCommunityBubbleR10F18 .communityMediaR10F18 audio{width:100%}.ithCommunityBubbleR10F18 .communityFileR10F18{display:flex;align-items:center;gap:9px;padding:10px;border-radius:14px;background:rgba(255,255,255,.06);color:inherit;text-decoration:none}.ithCommunityBubbleR10F18 .communityFileR10F18 b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ithCommunityBubbleR10F18 .ithCommunityTranslateR10F17{margin-top:8px}.ithCommunityStableNoteR10F18{font-size:10px;color:rgba(220,239,249,.56);text-align:center;padding:5px}

.ith519CommunityFeedBar{flex:0 0 auto;display:flex;align-items:center;gap:9px;min-height:74px;overflow-x:auto;overflow-y:hidden;padding:7px 8px;background:transparent!important;border:0!important;box-shadow:none!important;backdrop-filter:none!important;-webkit-backdrop-filter:none!important;scrollbar-width:none;overscroll-behavior-x:contain}.ith519CommunityFeedBar::-webkit-scrollbar{display:none}.ith519CommunityFeedPerson{flex:0 0 auto;width:66px;min-width:66px;display:grid;justify-items:center;gap:4px;border:0;background:transparent;color:#eef8ff;padding:0;touch-action:manipulation}.ith519CommunityFeedPerson .avatarDotWrap{width:48px;height:48px;display:block;position:relative}.ith519CommunityFeedPerson .avatar{width:48px!important;height:48px!important;min-width:48px!important;border-radius:50%!important;display:grid!important;place-items:center!important;overflow:hidden!important;background:transparent!important;border:2px solid rgba(255,215,110,.72)!important;box-shadow:0 6px 20px rgba(0,0,0,.28),0 0 0 3px rgba(255,215,110,.08)!important;color:#fff!important;font-weight:950!important}.ith519CommunityFeedPerson .avatar img{width:100%!important;height:100%!important;object-fit:cover!important;display:block!important}.ith519CommunityFeedPerson .avatarDotWrap>i{position:absolute;right:0;bottom:1px;width:11px;height:11px;border-radius:50%;background:#7b8591;border:2px solid rgba(4,17,29,.96)}.ith519CommunityFeedPerson .avatarDotWrap>i.on{background:#36f0a0;box-shadow:0 0 9px rgba(54,240,160,.7)}.ith519CommunityFeedPerson small{width:64px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:center;font-size:10px;color:rgba(239,248,255,.76)}.ith519CommunityFeedPerson.self .avatar{border-color:#36f0a0!important;box-shadow:0 6px 20px rgba(0,0,0,.28),0 0 0 3px rgba(54,240,160,.12)!important}.ith519CommunityFeedPerson:active{transform:scale(.96)}
.ith517MembersBar.ith519CommunityFeedBar{min-height:70px;padding:6px 8px;border-top:1px solid rgba(255,255,255,.035)!important;border-bottom:1px solid rgba(255,255,255,.045)!important}.ith517MembersBar .ith519CommunityFeedPerson{width:60px;min-width:60px}.ith517MembersBar .ith519CommunityFeedPerson .avatarDotWrap,.ith517MembersBar .ith519CommunityFeedPerson .avatar{width:44px!important;height:44px!important;min-width:44px!important}.ith517MembersBar .ith519CommunityFeedPerson small{width:58px}
.ithCommunityBubbleR10F18{display:grid!important;grid-template-columns:38px minmax(0,1fr)!important;column-gap:8px!important;align-items:start!important}.ithCommunityBubbleR10F18.mine{grid-template-columns:minmax(0,1fr) 38px!important}.ithCommunityMessageAvatarR10F19{grid-column:1;grid-row:1 / span 6;width:36px;height:36px;border:0;background:transparent;padding:0;align-self:start}.ithCommunityBubbleR10F18.mine .ithCommunityMessageAvatarR10F19{grid-column:2}.ithCommunityMessageAvatarR10F19 .avatarDotWrap{display:block;position:relative;width:36px;height:36px}.ithCommunityMessageAvatarR10F19 .avatar{width:36px!important;height:36px!important;min-width:36px!important;border-radius:50%!important;display:grid!important;place-items:center!important;overflow:hidden!important;background:transparent!important;border:1px solid rgba(255,215,110,.52)!important;color:#fff!important;font-size:12px!important;font-weight:950!important}.ithCommunityMessageAvatarR10F19 img{width:100%!important;height:100%!important;object-fit:cover!important}.ithCommunityMessageAvatarR10F19 i{position:absolute;right:-1px;bottom:-1px;width:9px;height:9px;border-radius:50%;background:#7b8591;border:2px solid rgba(4,17,29,.96)}.ithCommunityMessageAvatarR10F19 i.on{background:#36f0a0}.ithCommunityMessageContentR10F19{grid-column:2;min-width:0}.ithCommunityBubbleR10F18.mine .ithCommunityMessageContentR10F19{grid-column:1}.ithCommunityMessageContentR10F19>b{display:block;margin-bottom:3px}.ithCommunityMessageContentR10F19 .msgBody{white-space:pre-wrap}.ith519InviteAvatar .avatar,.ith517InviteAvatar .avatar{width:38px!important;height:38px!important;min-width:38px!important}
@media(max-width:760px){.ith516Shell{padding:6px}.ith516Hero{border-radius:17px;padding:8px 9px}.ith516Hero .ship{width:36px;height:36px;font-size:20px;border-radius:14px}.ith516CreateCta{min-height:64px}.ith516Kinds{grid-template-columns:1fr 1fr auto}.ith516Kinds button{font-size:12px;padding:7px}.ith516CreateCatGrid{grid-template-columns:1fr 1fr}.ith516ChatScreen .chatHead{height:48px!important;min-height:48px!important}.ith516ChatScreen .chatHead .optionalHeadAction{display:none!important}}
`;document.head.appendChild(st)}

function shellHtml(){return `<div id="ith516Shell" data-community-owner="r10f19" class="ith516Shell dmContactFirstShellV249235">
<section id="ith516ListScreen" class="ith516ListScreen dmFriendScreenV249235">
 <div class="ith516Hero dmFriendHeroV249235"><button type="button" class="icon" data-ith516-action="home">‹</button><div class="ship">🏘️</div><div class="text"><b>Χώροι και Κοινότητες</b><small>Διάλεξε κατηγορία και άνοιξε τη συζήτηση όπως ακριβώς στα Μηνύματα.</small></div></div>
 <div id="ith519CommunityFeedBarList" class="ith519CommunityFeedBar" aria-label="Ενεργά μέλη και δημοσιεύσεις"></div>
 <button type="button" id="ith516CreateCta" class="ith516CreateCta" data-ith516-action="create"><span class="plus">＋</span><span><b>ΔΗΜΙΟΥΡΓΙΑ ΝΕΑΣ ΚΟΙΝΟΤΗΤΑΣ</b><small>Όνομα, κατηγορία, πρόσβαση και δικαιώματα δημιουργού</small></span></button>
 <div class="ith516Kinds"><button type="button" id="ith516RoomsBtn" class="btn" data-ith516-action="kind" data-kind="room">🏠 Δωμάτια</button><button type="button" id="ith516CommunitiesBtn" class="btn green" data-ith516-action="kind" data-kind="community">🌐 Όλες οι κοινότητες</button><button type="button" class="btn" data-ith516-action="reload">🔄</button></div>
 <div id="ith516Cats" class="ith516Cats"></div>
 <div class="ith516Tools dmFriendToolsV249235"><input id="ith516Search" class="search" placeholder="Αναζήτηση κοινότητας..."><button type="button" class="icon" data-ith516-action="reload">🔄</button></div>
 <div id="ith516List" class="ith516List dmFriendListV249235"></div>
</section>
<section id="ith516CreateScreen" class="ith516CreateScreen">
 <div class="ith516CreateHead"><button type="button" class="icon" data-ith516-action="close-create">‹</button><b id="ith516CreateTitle">Νέα κοινότητα</b><span class="spacer"></span><button type="button" class="icon" data-ith516-action="close-create">×</button></div>
 <div class="ith516CreateBody"><div class="ith516CreateCard">
  <label>Τίτλος<input id="ith516Title" maxlength="100" placeholder="Όνομα κοινότητας"></label>
  <label>Σύντομη περιγραφή<textarea id="ith516Desc" rows="3" placeholder="Τι συζητάμε σε αυτή την κοινότητα"></textarea></label>
  <label>Κανόνες κοινότητας<textarea id="ith516Rules" rows="4" placeholder="Σεβασμός, ασφάλεια, τι επιτρέπεται και τι όχι"></textarea></label>
  <label>Μήνυμα καλωσορίσματος<textarea id="ith516Welcome" rows="2" placeholder="Μήνυμα που θα βλέπει το νέο μέλος"></textarea></label>
  <div><b>Ερωτήσεις συμμετοχής — προαιρετικά, έως 3</b><input id="ith516Question1" maxlength="180" placeholder="1η ερώτηση"><input id="ith516Question2" maxlength="180" placeholder="2η ερώτηση"><input id="ith516Question3" maxlength="180" placeholder="3η ερώτηση"></div>
  <div><b>Κατηγορία</b><div id="ith516CreateCats" class="ith516CreateCatGrid"></div></div>
  <label>Πρόσβαση<select id="ith516Access"><option value="public">Ανοιχτή — μπαίνουν άμεσα</option><option value="invite">Με αίτημα και έγκριση δημιουργού</option><option value="private_code">Με κωδικό μέλους</option></select></label>
  <label>Κωδικός μέλους — μόνο για κλειστή κοινότητα<input id="ith516JoinCode" maxlength="40"></label>
  <label>Κωδικός δημιουργού<input id="ith516CreatorCode" maxlength="80"></label>
  <div class="ith516Notice">Ο κωδικός δημιουργού αποθηκεύεται στον server μόνο ως ασφαλές hash. Κράτησέ τον για αποδοχή, απόρριψη και μπλοκάρισμα μελών.</div>
  <button type="button" class="btn green ith516Submit" data-ith516-action="submit-create">✓ ΔΗΜΙΟΥΡΓΙΑ ΚΟΙΝΟΤΗΤΑΣ</button>
 </div></div>
</section>
<section id="ith522JoinScreen" class="ith522JoinScreen" aria-hidden="true">
 <div class="ith522JoinHead"><button type="button" class="icon" data-ith516-action="join-close">‹</button><b id="ith522JoinTitle">Συμμετοχή</b><button type="button" class="icon" data-ith516-action="join-close">×</button></div>
 <div id="ith522JoinBody" class="ith522JoinBody"></div>
</section>
<section id="ith516ChatScreen" class="ith516ChatScreen dmChatScreenV249235">
 <div class="chatPane">
  <div class="chatHead"><button type="button" class="icon" data-ith516-action="close-chat">‹</button><button id="ith516ChatAvatar" type="button" class="avatar chatAvatarBtn" data-ith516-action="info">🌐</button><div class="chatTitle"><b id="spaceTitle">Κοινότητα</b><div id="ith516ChatMeta" class="typing">Ανοιχτή συζήτηση</div></div><button type="button" class="icon chatActionBtn" title="Φωτογραφία" data-ith516-action="photo">📷</button><button type="button" class="icon chatActionBtn" title="Βίντεο" data-ith516-action="video">🎥</button><button type="button" class="icon chatActionBtn" title="Ηχητικό μήνυμα" data-ith516-action="audio">🎙️</button><button type="button" class="icon chatActionBtn" title="Κλειδαριά κοινότητας" onclick="ITH.openE2EPanel&&ITH.openE2EPanel()">🔐</button><button type="button" class="icon" title="Εργαλεία κοινότητας" data-ith516-action="tools">⋯</button></div>
  <div id="ith517MembersBar" class="ith517MembersBar ith519CommunityFeedBar groupMembersBarV249282" aria-label="Μέλη κοινότητας και δημοσιεύσεις"><span class="ith517MembersEmpty">Φόρτωση μελών…</span></div>
  <div id="ith516MessageSearch" class="ith516MessageSearch"><input id="ith516MessageSearchInput" placeholder="Αναζήτηση μέσα στη συζήτηση..."></div>
  <div id="spacePinnedBoxV249281"></div>
  <div id="spaceMsgs" class="messages"><div class="card">Διάλεξε κοινότητα ή δωμάτιο.</div></div>
  <div id="ith517ReplyBox" class="card" style="display:none;margin:0 9px 6px;padding:8px"></div>
  <div class="composer"><button type="button" class="icon" title="Επιλογή αρχείου" data-ith516-action="file">📎</button><textarea id="spaceInput" placeholder="Γράψε μήνυμα στην κοινότητα..."></textarea><button type="button" id="ith524SpaceSend" class="icon ith524Send">➤</button></div>
  <input id="ith517SpaceFileInput" class="ith517HiddenFile" type="file" accept=".txt,.md,.csv,image/jpeg,image/png,image/webp,image/heic,image/heif,video/mp4,video/webm,video/quicktime,video/3gpp">
  <input id="ith517SpacePhotoInput" class="ith517HiddenFile" type="file" accept="image/*" capture="environment">
  <input id="ith517SpaceVideoInput" class="ith517HiddenFile" type="file" accept="video/*" capture="environment">
 </div>
</section>
</div>`}

function renderCats(){const h=$('ith516Cats');if(!h)return;h.style.display=kind==='community'?'flex':'none';h.innerHTML=CATS.map(c=>`<button type="button" class="ith516CatBtn ${cat===c[0]?'on':''}" data-ith516-action="category" data-category="${c[0]}">${c[1]} ${c[2]}</button>`).join('')}
function renderCreateCats(){const h=$('ith516CreateCats');if(!h)return;h.innerHTML=CATS.filter(c=>c[0]!=='all').map(c=>`<button type="button" class="ith516CreateCat ${createCat===c[0]?'on':''}" data-ith516-action="create-category" data-category="${c[0]}">${c[1]} ${c[2]}</button>`).join('')}
function applyView(){const sh=$('ith516Shell');if(!sh)return;sh.classList.toggle('viewChat',view==='chat');sh.classList.toggle('viewCreate',view==='create');sh.classList.toggle('viewJoin',view==='join');const js=$('ith522JoinScreen');if(js)js.setAttribute('aria-hidden',view==='join'?'false':'true');document.body?.classList.toggle('ith522CommunityChatOpen',view==='chat');renderGlobalCommunityFeedBarR10F19();if(view==='chat'&&activeSpace){const t=$('spaceTitle');if(t)t.textContent=title(activeSpace);const av=$('ith516ChatAvatar');if(av){av.innerHTML='';av.textContent=iconFor(activeSpace)}const m=$('ith516ChatMeta');if(m)m.textContent=catName(activeSpace.topic_category||'general')+' · '+accessName(activeSpace.access_type)+' · '+({creator:'Δημιουργός',moderator:'Συντονιστής',member:'Μέλος'}[activeSpace.role]||'Μέλος');updateFollowButton();loadMembersBar(false)}}
async function sendCommunityPayloadDirectR10F17(channel,payload){
 const ch=String(channel||S().currentSpaceChannel||(S().currentSpace?('space:'+S().currentSpace):''));
 let p=payload;if(p&&typeof p==='object')p=JSON.stringify(p);p=String(p==null?'':p);
 if(!ch)throw Error('Δεν έχει επιλεγεί κοινότητα.');if(!p.trim())return false;
 const tok=(()=>{try{return localStorage.getItem('ith_public_token')||localStorage.getItem('ith_token')||''}catch(_e){return''}})(),h={'Content-Type':'application/json'};if(tok)h['X-ITHAKI-TOKEN']=tok;
 const body={room_id:room(),channel:ch,sender_id:device(),nickname:nickname(),language:String(localStorage.getItem('ith_ui_lang_v249141')||localStorage.getItem('ith_ui_lang')||'el'),text:/^\s*[\[{]/.test(p)?p:JSON.stringify({body:p})};
 const r=await fetch(apiBase()+'/api/messages/send',{method:'POST',cache:'no-store',credentials:'include',headers:h,body:JSON.stringify(body)});let d={};try{d=await r.json()}catch(_e){}
 if(!r.ok||d.ok===false)throw Error(String(d.detail||d.message||d.note||('HTTP '+r.status)));return d
}
async function sendCommunityTextR10F15(){
 const input=$('spaceInput'),text=String(input?.value||'').trim(),channel=String(S().currentSpaceChannel||(S().currentSpace?('space:'+S().currentSpace):'')),btn=$('ith524SpaceSend');
 if(!text)return false;if(!channel)return toast('Άνοιξε πρώτα μια κοινότητα.');if(messageSendBusyR10F18)return false;
 messageSendBusyR10F18=true;if(btn){btn.disabled=true;btn.classList.add('sending');btn.textContent='…'}
 try{const chk=await api('/api/safety/text_check_v249545',{method:'POST',body:JSON.stringify({text,context:'community_message'})});if(chk&&chk.blocked)throw Error(chk.message||'Το κείμενο χρειάζεται έλεγχο ασφαλείας.');await sendCommunityPayloadDirectR10F17(channel,{body:text,reply_to:communityReplyToR10F20});input.value='';clearCommunityReplyR10F20();await loadMessagesStable(true);setTimeout(()=>input?.focus(),40);return false}
 catch(e){toast('Δεν στάλθηκε: '+String(e.message||e),7000);return false}
 finally{messageSendBusyR10F18=false;if(btn){btn.disabled=false;btn.classList.remove('sending');btn.textContent='➤'}}
}
function messageVisibleTextR10F17(v){let x=String(v??'');try{const d=JSON.parse(x);if(d&&typeof d==='object')x=String(d.body||d.text||d.caption||x)}catch(_e){}return x}
function communityTargetLangR10F17(){return String(localStorage.getItem('ith_global_language_r10f7')||localStorage.getItem('ith_ui_lang_v249141')||localStorage.getItem('ith_ui_lang')||'el').toLowerCase().startsWith('en')?'en':'el'}
async function translateCommunityBubbleR10F17(btn){const bubble=btn.closest('.bubble'),body=bubble?.querySelector('.msgBody');if(!body)return false;const original=String(body.dataset.r10f17Original||body.textContent||'').trim();if(!original)return false;if(btn.dataset.state==='translated'){body.textContent=original;btn.dataset.state='original';btn.classList.remove('on');btn.textContent=communityTargetLangR10F17()==='en'?'🌐 Translate':'🌐 Μετάφραση';return false}btn.disabled=true;const old=btn.textContent;btn.textContent='…';try{let base=String(S().api||I().state?.api||'').replace(/\/+$/,'');if(!/^https?:/i.test(base)||/appassets\.androidplatform\.net/i.test(base))base='https://ok-ithaki.gr';const r=await fetch(base+'/api/bridge/translate/reference_v249526r10f8',{method:'POST',cache:'no-store',credentials:'include',headers:{'Content-Type':'application/json'},body:JSON.stringify({text:original,source_lang:'auto',target_lang:communityTargetLangR10F17(),log_unknown:true})});const d=await r.json();if(!r.ok||d.ok===false)throw Error(d.note||d.detail||('HTTP '+r.status));body.textContent=String(d.translated||original);btn.dataset.state='translated';btn.classList.add('on');btn.textContent=communityTargetLangR10F17()==='en'?'↩ Original':'↩ Πρωτότυπο'}catch(e){toast('Μετάφραση: '+String(e.message||e),6000);btn.textContent=old}finally{btn.disabled=false}return false}

function parseCommunityPayloadR10F18(raw){let body=String(raw??''),media=null,reply_to=null,kind='',publication=false,payload=null;try{const d=JSON.parse(body);if(d&&typeof d==='object'){payload=d;body=String(d.body||d.text||d.caption||'');media=d.media||((d.url||d.file_url||d.media_url)?d:null);reply_to=d.reply_to||null;kind=String(d.post_kind||d.kind||d.type||'').toLowerCase();publication=!!(media||d.publication===true||d.is_post===true||d.poll||d.options||['post','publication','photo','image','video','audio','file','poll','wisdom','event'].includes(kind))}}catch(_e){}return{body,media,reply_to,kind,publication,payload}}
function communityMessageIdR10F18(m){return String(m?.message_id||m?.id||[m?.sender_id||'',m?.created_at||'',m?.text||''].join('|'))}
function communityMediaUrlR10F18(v){const u=String(v||'');if(!u)return'';if(/^https?:/i.test(u))return u;if(u.startsWith('/'))return apiBase()+u;return apiBase()+'/'+u.replace(/^\/+/, '')}
function communityMediaHtmlR10F18(m){if(!m||typeof m!=='object')return'';const kind=String(m.kind||m.media_kind||'').toLowerCase(),mime=String(m.mime_type||m.type||'').toLowerCase(),url=communityMediaUrlR10F18(m.url||m.file_url||m.media_url||'');if(!url)return'';const src=esc(url),name=esc(m.filename||m.name||'Αρχείο');if(kind==='photo'||kind==='image'||mime.startsWith('image/'))return `<div class="communityMediaR10F18"><img src="${src}" loading="lazy" alt="${name}"></div>`;if(kind==='video'||mime.startsWith('video/'))return `<div class="communityMediaR10F18"><video src="${src}" controls playsinline preload="metadata"></video></div>`;if(kind==='audio'||mime.startsWith('audio/'))return `<div class="communityMediaR10F18"><audio src="${src}" controls preload="metadata"></audio></div>`;return `<div class="communityMediaR10F18"><a class="communityFileR10F18" href="${src}" target="_blank" rel="noopener"><span>📎</span><b>${name}</b><span>↗</span></a></div>`}
function communityTimeR10F18(v){try{let n=Number(v);if(Number.isFinite(n)){if(n<1e12)n*=1000;return new Date(n).toLocaleString(document.documentElement.lang?.startsWith('en')?'en-GB':'el-GR',{day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'})}const d=new Date(v);if(!Number.isNaN(d.getTime()))return d.toLocaleString(document.documentElement.lang?.startsWith('en')?'en-GB':'el-GR',{day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'})}catch(_e){}return String(v||'')}
function dedupeCommunityMessagesR10F18(list){const out=[],seen=new Set();for(const m of Array.isArray(list)?list:[]){const k=communityMessageIdR10F18(m);if(seen.has(k))continue;seen.add(k);out.push(m)}out.sort((a,b)=>Number(a.created_at||0)-Number(b.created_at||0));return out}

function communityReplyHtmlR10F20(reply){if(!reply||typeof reply!=='object')return'';return `<div class="ithCommunityReplyQuoteR10F20"><b>↪ ${esc(reply.nickname||'Μέλος')}</b><span>${esc(String(reply.body||'').slice(0,180))}</span></div>`}
function clearCommunityReplyR10F20(){communityReplyToR10F20=null;const box=$('ith517ReplyBox');if(box){box.style.display='none';box.innerHTML=''}return false}
function setCommunityReplyR10F20(bubble){const body=bubble?.querySelector('.msgBody'),name=bubble?.querySelector('.ithCommunityMessageContentR10F19>b')?.textContent||'Μέλος';communityReplyToR10F20={message_id:String(bubble?.dataset.mid||''),sender_id:String(bubble?.dataset.sender||''),nickname:String(name),body:String(body?.dataset.r10f17Original||body?.textContent||'').slice(0,500)};const box=$('ith517ReplyBox');if(box){box.style.display='grid';box.innerHTML=`<div><b>↪ Απάντηση στον/στην ${esc(name)}</b><div>${esc(communityReplyToR10F20.body.slice(0,160))}</div></div><button type="button" class="icon" data-community-clear-reply="1">×</button>`;box.querySelector('[data-community-clear-reply]')?.addEventListener('click',clearCommunityReplyR10F20)}$('spaceInput')?.focus();return false}
function savedCommunityKeyR10F20(mid){return 'ith_community_saved_'+room()+'_'+String(activeSpace?.subroom_id||'')+'_'+mid}
async function communityMessageActionR10F20(btn){const bubble=btn.closest('.ithCommunityBubbleR10F18'),mid=String(bubble?.dataset.mid||''),sender=String(bubble?.dataset.sender||''),body=String(bubble?.querySelector('.msgBody')?.dataset.r10f17Original||bubble?.querySelector('.msgBody')?.textContent||''),a=String(btn.dataset.communityMsgAction||'');if(!mid)return false;if(a==='reply')return setCommunityReplyR10F20(bubble);if(a==='translate')return translateCommunityBubbleR10F17(bubble.querySelector('[data-community-translate-r10f17]'));if(a==='save'){const k=savedCommunityKeyR10F20(mid),on=localStorage.getItem(k)==='1';localStorage.setItem(k,on?'0':'1');btn.classList.toggle('on',!on);toast(on?'Αφαιρέθηκε από τα αποθηκευμένα.':'Αποθηκεύτηκε μόνο για αυτή την Κοινότητα.');return false}if(a==='share'){const text=(activeSpace?.title||'Κοινότητα')+' — '+body;try{if(navigator.share)await navigator.share({title:activeSpace?.title||'Κοινότητα',text});else{await navigator.clipboard.writeText(text);toast('Το κείμενο αντιγράφηκε.')}}catch(_e){}return false}if(a==='report'){const reason=prompt('Περιέγραψε τον λόγο αναφοράς:','')||'';if(!reason.trim())return false;await api('/api/rooms/report_message',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:String(activeSpace?.subroom_id||''),message_id:mid,reporter_id:device(),reason})});toast('Η αναφορά στάλθηκε για έλεγχο.');return false}if(a==='delete'){if(sender!==device())return false;if(!confirm('Να διαγραφεί αυτό το μήνυμα από την Κοινότητα;'))return false;await api('/api/messages/delete',{method:'POST',body:JSON.stringify({room_id:room(),channel:S().currentSpaceChannel,device_id:device(),message_id:mid})});await loadMessagesStable(true);return false}if(a==='react'){const d=await api('/api/rooms/message_reaction_v249545',{method:'POST',body:JSON.stringify({room_id:room(),channel:S().currentSpaceChannel,message_id:mid,device_id:device(),emoji:'❤️'})});btn.classList.toggle('on',!!d.active);const c=btn.querySelector('small');if(c)c.textContent=String(d.count||0);return false}return false}
async function loadCommunityReactionCountsR10F20(rows){if(!rows?.length||!activeSpace)return;const ids=rows.map(communityMessageIdR10F18).filter(Boolean).join(',');if(!ids)return;try{const d=await api('/api/rooms/message_reactions_v249545?room_id='+encodeURIComponent(room())+'&channel='+encodeURIComponent(S().currentSpaceChannel||'')+'&device_id='+encodeURIComponent(device())+'&message_ids='+encodeURIComponent(ids));for(const [mid,row] of Object.entries(d.items||{})){const b=document.querySelector(`.ithCommunityBubbleR10F18[data-mid="${CSS.escape(mid)}"] [data-community-msg-action="react"]`);if(b){b.classList.toggle('on',!!row.mine);const c=b.querySelector('small');if(c)c.textContent=String(row.count||0)}}}catch(_e){}}
function communityActionRailR10F20(mid,mine){return `<aside class="ithCommunityActionRailR10F20" aria-label="Ενέργειες μηνύματος Κοινότητας"><button type="button" data-community-msg-action="react" title="Μου αρέσει">❤️<small>0</small></button><button type="button" data-community-msg-action="reply" title="Απάντηση">💬</button><button type="button" data-community-msg-action="save" title="Αποθήκευση">🔖</button><button type="button" data-community-msg-action="share" title="Κοινοποίηση">📤</button><button type="button" data-community-msg-action="translate" title="Μετάφραση">🌐</button><button type="button" data-community-msg-action="report" title="Αναφορά">🚩</button>${mine?'<button type="button" data-community-msg-action="delete" title="Διαγραφή">🗑️</button>':''}</aside>`}
function communityTextActionsR10F21(){return `<div class="ithCommunityTextActionsR10F21"><button type="button" data-community-msg-action="reply">💬 Απάντηση</button></div>`}
function communityPublicationRowsR10F21(id){id=String(id||'');return lastCommunityRowsR10F21.filter(m=>String(m?.sender_id||'')===id&&parseCommunityPayloadR10F18(m?.text).publication)}
function showCommunityMemberPublicationsR10F21(id){const person=canonicalPersonR10F19(id),rows=communityPublicationRowsR10F21(id);const html=rows.length?rows.map(m=>{const p=parseCommunityPayloadR10F18(m.text);return `<article class="card ithCommunityMemberPublicationR10F21"><b>${esc(person.nickname||'Μέλος')}</b>${p.body?`<div>${esc(p.body)}</div>`:''}${communityMediaHtmlR10F18(p.media)}<small>${esc(communityTimeR10F18(m.created_at))}</small></article>`}).join(''):'<div class="card">Δεν υπάρχουν ακόμη δημοσιεύσεις αυτού του μέλους στην επιλεγμένη Κοινότητα.</div>';return panel('🌐 Δημοσιεύσεις στην Κοινότητα',html)}
async function sendCommunityInviteR10F21(id){if(!activeSpace||!id||id===device())return false;const p=canonicalPersonR10F19(id);try{await api('/api/rooms/invite',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,from_id:device(),from_name:nickname(),to_id:id,to_name:p.nickname||id})});toast('Η πρόσκληση για την Κοινότητα στάλθηκε.')}catch(e){toast('Δεν στάλθηκε η πρόσκληση: '+String(e.message||e))}return false}
async function appendCommunityActionsToGeneralMenuR10F21(id){const menu=$('memberMenu');if(!menu||!activeSpace)return false;const grid=menu.querySelector('.grid')||menu;grid.querySelectorAll('[data-r10f21-community-action]').forEach(e=>e.remove());const p=canonicalPersonR10F19(id);const posts=document.createElement('button');posts.type='button';posts.className='tile';posts.dataset.r10f21CommunityAction='posts';posts.innerHTML='<b>🌐</b>Δημοσιεύσεις στην Κοινότητα';posts.onclick=()=>showCommunityMemberPublicationsR10F21(id);grid.appendChild(posts);if(id!==device()&&!p.online){const invite=document.createElement('button');invite.type='button';invite.className='tile';invite.dataset.r10f21CommunityAction='invite';invite.innerHTML='<b>＋</b>Πρόσκληση στην Κοινότητα';invite.onclick=()=>sendCommunityInviteR10F21(id);grid.appendChild(invite)}menu.classList.add('show');return true}
function openCommunityAvatarMenuR10F21(id){id=String(id||'');if(!id)return false;const a=I();try{if(typeof a.member==='function')a.member(id);else if(typeof window.showMemberMenu==='function')window.showMemberMenu(id);else return openMemberPostsR10F19(id)}catch(_e){return openMemberPostsR10F19(id)}setTimeout(()=>appendCommunityActionsToGeneralMenuR10F21(id),40);setTimeout(()=>appendCommunityActionsToGeneralMenuR10F21(id),180);return false}
function renderCommunityMessagesAtomicR10F18(list){const box=$('spaceMsgs');if(!box||communitySuspendedR10F20)return false;const rows=dedupeCommunityMessagesR10F18(list);lastCommunityRowsR10F21=rows.slice();const sig=rows.map(communityMessageIdR10F18).join('|');if(sig===lastMessageSignatureR10F18&&box.dataset.messageOwner==='r10f20')return true;const nearBottom=box.scrollHeight-box.scrollTop-box.clientHeight<100;const html=rows.map(m=>{const p=parseCommunityPayloadR10F18(m.text),mid=esc(communityMessageIdR10F18(m)),sender=String(m.sender_id||''),mine=sender===device(),person=canonicalPersonR10F19(sender,{nickname:m.nickname||'Μέλος',avatar:m.avatar||'',online:m.online||m.active});return `<div class="bubble ${mine?'mine':''} ${p.publication?'communityPublicationR10F21':'communitySimpleTextR10F21'} ithCommunityBubbleR10F18" data-mid="${mid}" data-sender="${esc(sender)}"><button type="button" class="ithCommunityMessageAvatarR10F19" data-community-member-menu="${esc(sender)}" title="${esc(mine?'Το προφίλ μου':'Ενέργειες μέλους')}">${canonicalAvatarHtmlR10F19(person)}</button><div class="ithCommunityMessageContentR10F19"><b>${esc(person.nickname||'Μέλος')}</b>${communityReplyHtmlR10F20(p.reply_to)}<div class="msgBody" data-r10f18-original="${esc(p.body)}">${esc(p.body)}</div>${communityMediaHtmlR10F18(p.media)}<button type="button" class="ithCommunityTranslateR10F17" data-community-translate-r10f17="1" data-state="original">${communityTargetLangR10F17()==='en'?'🌐 Translate':'🌐 Μετάφραση'}</button>${p.publication?'':communityTextActionsR10F21()}<div class="meta">${esc(communityTimeR10F18(m))}</div></div>${p.publication?communityActionRailR10F20(mid,mine):''}</div>`}).join('')||'<div class="card">Ξεκίνα τη συζήτηση της κοινότητας.</div>';box.dataset.messageOwner='r10f20';box.innerHTML=html;lastMessageSignatureR10F18=sig;decorateCommunityMessagesR10F17();bindCommunityFeedBarR10F19(box);box.querySelectorAll('[data-community-msg-action]').forEach(b=>b.addEventListener('click',e=>{e.preventDefault();e.stopPropagation();communityMessageActionR10F20(b).catch(x=>toast('Η ενέργεια δεν ολοκληρώθηκε: '+String(x.message||x))) }));loadCommunityReactionCountsR10F20(rows);if(nearBottom||!box.dataset.r10f18Seen){box.scrollTop=box.scrollHeight;box.dataset.r10f18Seen='1'}return true}
function scheduleCommunityMessageRefreshR10F18(){clearTimeout(liveMessageRefreshTimerR10F18);liveMessageRefreshTimerR10F18=setTimeout(()=>{if(view==='chat'&&activeSpace)loadMessagesStable(true)},120);return false}

function decorateCommunityMessagesR10F17(){
 const root=$('spaceMsgs');if(!root)return;
 root.querySelectorAll('.bubble').forEach(b=>{const body=b.querySelector('.msgBody');if(!body)return;if(!body.dataset.r10f17Original){const visible=messageVisibleTextR10F17(body.dataset.r10f18Original||body.textContent||'');body.dataset.r10f17Original=visible;body.textContent=visible;body.setAttribute('data-no-translate','1')}let btn=b.querySelector('[data-community-translate-r10f17]');if(!btn){btn=document.createElement('button');btn.type='button';btn.className='ithCommunityTranslateR10F17';btn.dataset.communityTranslateR10f17='1';btn.dataset.state='original';btn.textContent=communityTargetLangR10F17()==='en'?'🌐 Translate':'🌐 Μετάφραση';(b.querySelector('.meta')||b).insertAdjacentElement('beforebegin',btn)}if(btn.dataset.r10f18Bound!=='1'){btn.dataset.r10f18Bound='1';btn.addEventListener('click',e=>{e.preventDefault();e.stopPropagation();translateCommunityBubbleR10F17(btn)})}})
}
function bindActions(){
 const root=$('ith516Shell');if(!root||root.__ith516BoundR10F18)return;root.__ith516BoundR10F18=true;
 root.addEventListener('click',async e=>{const b=e.target.closest('[data-ith516-action]');if(!b||!root.contains(b))return;e.preventDefault();e.stopPropagation();e.stopImmediatePropagation();const a=b.dataset.ith516Action;
 if(a==='home')return I().page&&I().page('home');if(a==='kind')return setKind(b.dataset.kind);if(a==='category')return setCat(b.dataset.category);if(a==='create')return showCreate(kind);if(a==='create-category'){createCat=CATS.some(c=>c[0]===b.dataset.category)?b.dataset.category:'general';renderCreateCats();return false}if(a==='reload')return loadSpaces(true);if(a==='close-create')return closeCreate();if(a==='join-close')return closeJoinPanel();if(a==='join-toggle')return toggleJoinAccept();if(a==='join-submit')return submitJoinPanel();if(a==='submit-create')return submitCreate();if(a==='open-space')return openSpace(b.dataset.spaceId);if(a==='close-chat')return closeChat();if(a==='photo')return openSpaceFilePicker('photo');if(a==='video')return openSpaceFilePicker('video');if(a==='file')return openSpaceFilePicker('file');if(a==='audio')return startSpaceAudio();if(a==='tools')return openCommunityTools();if(a==='info')return openInfo();if(a==='members')return openMembers();if(a==='pins')return openPins();if(a==='search-messages')return toggleMessageSearch();if(a==='follow')return toggleFollow();if(a==='invite')return inviteMembers();if(a==='polls')return openPolls();if(a==='events')return openEvents();if(a==='manage')return openManage()},true);
 const q=$('ith516Search');if(q)q.addEventListener('input',renderList,{passive:true});const mq=$('ith516MessageSearchInput');if(mq)mq.addEventListener('input',filterMessages,{passive:true});const sb=$('ith524SpaceSend');if(sb){sb.addEventListener('click',e=>{e.preventDefault();e.stopPropagation();e.stopImmediatePropagation();sendCommunityTextR10F15()},true)}const input=$('spaceInput');if(input)input.addEventListener('keydown',e=>{if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();sendCommunityTextR10F15()}});bindSpaceFileInputs()
}
function loadCachedSpacesR10F2(){try{sessionStorage.removeItem(communityCacheKeyR10F10())}catch(e){}return false}
function markCommunityReadyR10F2(){document.documentElement.removeAttribute('data-ithaki-community-r7-pending');document.documentElement.setAttribute('data-ithaki-community-r7-ready','1');document.documentElement.setAttribute('data-ithaki-community-r10f2-ready','1');document.documentElement.setAttribute('data-ithaki-community-r10f13-ready','1')}
function hasCanonicalShellR10F14(){const sh=$('ith516Shell');return !!(sh&&sh.dataset.communityOwner==='r10f18')}
function replaceForeignShellR10F14(){const page=$('spacesPage');if(!page)return false;if(!hasCanonicalShellR10F14()){page.innerHTML=shellHtml();bindActions();window.COMMUNITY_OLD_SHELL_REPLACED_R10F14=true}else bindActions();return true}
function renderPage(){addCss();setTimeout(decorateCommunityMessagesR10F17,80);document.documentElement.removeAttribute('data-ithaki-community-r7-pending');const page=$('spacesPage');if(!page)return false;rendering=true;document.body&&document.body.setAttribute('data-page','spaces');page.classList.add('active');replaceForeignShellR10F14();renderGlobalCommunityFeedBarR10F19();renderCats();renderCreateCats();updateKindButtons();applyView();const l=$('ith516List');if(l&&!spaces.length){l.removeAttribute('data-community-stable');l.innerHTML='<div class="card dmEmptyV249235"><b>Φόρτωση κοινοτήτων…</b><small>Η πλήρης λίστα θα εμφανιστεί μία φορά, μετά τον έλεγχο διπλοεγγραφών.</small></div>'}loadSpaces(false);setTimeout(()=>{rendering=false},0);try{document.documentElement.setAttribute('data-ithaki-v249517-active','community-feed-bar-unified-avatars-r10f19')}catch(e){}return false}
function suspendCommunitiesV249545(reason){communitySuspendedR10F20=true;messageLoadGenerationR10F18++;try{messageAbortR10F18?.abort?.()}catch(_e){}clearTimeout(liveMessageRefreshTimerR10F18);document.querySelectorAll('#spacesPage video,#spacesPage audio').forEach(m=>{try{m.pause()}catch(_e){}});return true}
function activateSpacesPage(){try{communitySuspendedR10F20=false;const s=S();s.page='spaces';window.state=s;window.ITH=window.ITH||{};window.ITH.state=s;view='list';activeSpace=null;document.body&&document.body.setAttribute('data-page','spaces');document.querySelectorAll('.page').forEach(p=>p.classList.remove('active'));const page=$('spacesPage');if(page)page.classList.add('active');document.querySelectorAll('.nav button').forEach(b=>b.classList.toggle('active',String(b.dataset.page||'')==='spaces'));$('plusSheet')?.classList.remove('show');if(!hasCanonicalShellR10F14())renderPage();else{applyView();if(spaces.length)renderList(false);else loadSpaces(false)}return false}catch(e){toast('Δεν άνοιξαν οι κοινότητες: '+(e.message||e));return false}}
function updateKindButtons(){const rb=$('ith516RoomsBtn'),cb=$('ith516CommunitiesBtn'),cta=$('ith516CreateCta');if(rb)rb.classList.toggle('green',kind==='room');if(cb)cb.classList.toggle('green',kind==='community');if(cta){cta.querySelector('b').textContent=kind==='room'?'ΔΗΜΙΟΥΡΓΙΑ ΝΕΟΥ ΔΩΜΑΤΙΟΥ':'ΔΗΜΙΟΥΡΓΙΑ ΝΕΑΣ ΚΟΙΝΟΤΗΤΑΣ';cta.querySelector('small').textContent=kind==='room'?'Όνομα, κατηγορία και πρόσβαση δωματίου':'Όνομα, κατηγορία, πρόσβαση και δικαιώματα δημιουργού'}}
async function loadSpaces(force=false){if(loadPromiseR10F13&&!force)return loadPromiseR10F13;const generation=++loadGenerationR10F13,before=$('ith516List'),controller=typeof AbortController!=='undefined'?new AbortController():null,timeout=controller?setTimeout(()=>controller.abort(),15000):0;busy=true;const task=(async()=>{try{const d=await api('/api/rooms/overview_v249510?room_id='+encodeURIComponent(room())+'&device_id='+encodeURIComponent(device()),controller?{signal:controller.signal}:{});if(generation!==loadGenerationR10F13)return false;spaces=dedupeSpacesV249526R4((d.rooms||[]).map(x=>Object.assign({},x)));const st=S();st.spaces=spaces;try{sessionStorage.removeItem(communityCacheKeyR10F10())}catch(e){}renderList(true);markCommunityReadyR10F2();const refresh=I().refreshVisibleCommunityUiV249519||window.refreshVisibleCommunityUiV249519;if(typeof refresh==='function')setTimeout(()=>{try{refresh.call(I())}catch(_e){}},0);return true}catch(e){if(generation!==loadGenerationR10F13)return false;const l=$('ith516List');if(l){l.removeAttribute('data-community-stable');l.innerHTML='<div class="card dmEmptyV249235"><b>Δεν φορτώθηκαν οι κοινότητες.</b><small>'+esc(e.name==='AbortError'?'Η σύνδεση άργησε.':e.message)+'</small><button type="button" class="btn green" data-ith516-action="reload">↻ Νέα προσπάθεια</button></div>'}markCommunityReadyR10F2();return false}finally{if(timeout)clearTimeout(timeout)}})();loadPromiseR10F13=task;try{return await task}finally{if(loadPromiseR10F13===task)loadPromiseR10F13=null;busy=false}}
function filtered(){const q=String($('ith516Search')?.value||'').trim().toLocaleLowerCase('el');return spaces.filter(x=>{const k=String(x.space_kind||x.category||'community');if(k!==kind)return false;if(kind==='community'&&cat!=='all'&&String(x.topic_category||'general')!==cat)return false;if(q&&!String(title(x)+' '+desc(x)+' '+catName(x.topic_category||'general')).toLocaleLowerCase('el').includes(q))return false;return true})}
function renderList(force=false){const l=$('ith516List');if(!l)return;const arr=dedupeSpacesV249526R4(filtered()),query=String($('ith516Search')?.value||'').trim().toLocaleLowerCase('el'),signature=kind+'|'+cat+'|'+query+'|'+arr.map(x=>canonicalSpaceIdR10F13(x)+'~'+canonicalSpaceTitleV249526R6(x)+'~'+Number(x.member_count||0)+'~'+Number(x.message_count||0)+'~'+(x.is_member?'1':'0')).join('||');if(!force&&signature===lastListSignatureR10F13&&l.dataset.communityStable==='1')return;l.setAttribute('data-community-list-owner','r10f18');l.setAttribute('data-community-stable','1');lastListSignatureR10F13=signature;l.innerHTML=arr.map(x=>{const id=String(x.subroom_id||x.room_id||x.id||''),status=x.blocked?'Μπλοκαρισμένη':(x.is_member?'Είσαι μέλος':accessName(x.access_type));return `<div role="button" tabindex="0" class="dmFriendRowV249235 ith516Row" data-ith516-action="open-space" data-space-id="${esc(id)}"><span class="avatar">${iconFor(x)}</span><span class="who"><b>${esc(title(x))}</b><small>${esc(desc(x)||catName(x.topic_category||'general'))}</small><span class="ith516Pills"><span class="ith516Pill">${esc(catName(x.topic_category||'general'))}</span><span class="ith516Pill">👥 ${Number(x.member_count||0)}</span><span class="ith516Pill">💬 ${Number(x.message_count||0)}</span><span class="ith516Pill">${esc(status)}</span></span></span><span class="go"><span class="msgGo">💬 Άνοιγμα</span></span></div>`}).join('')||'<div class="card dmEmptyV249235">Δεν βρέθηκαν κοινότητες σε αυτή την κατηγορία.</div>'}
function setKind(v){kind=v==='room'?'room':'community';cat='all';view='list';updateKindButtons();renderCats();const s=$('ith516Search');if(s)s.placeholder=kind==='room'?'Αναζήτηση δωματίου...':'Αναζήτηση κοινότητας...';renderList();return false}
function setCat(v){cat=CATS.some(c=>c[0]===v)?v:'all';renderCats();renderList();return false}
function showCreate(v){createKind=v==='room'?'room':'community';createCat='general';view='create';applyView();const t=$('ith516CreateTitle');if(t)t.textContent=createKind==='room'?'Νέο δωμάτιο':'Νέα κοινότητα';const code=$('ith516CreatorCode');if(code)code.value=randomCode();const titleInput=$('ith516Title');if(titleInput)titleInput.value='';const descInput=$('ith516Desc');if(descInput)descInput.value='';['ith516Rules','ith516Welcome','ith516Question1','ith516Question2','ith516Question3'].forEach(id=>{const e=$(id);if(e)e.value='' });const join=$('ith516JoinCode');if(join)join.value='';const access=$('ith516Access');if(access)access.value='public';renderCreateCats();setTimeout(()=>titleInput?.focus(),60);return false}
function closeCreate(){view='list';applyView();return false}
async function submitCreate(){const titleValue=String($('ith516Title')?.value||'').trim(),creator=String($('ith516CreatorCode')?.value||'').trim();if(!titleValue)return toast('Βάλε τίτλο στην κοινότητα.');if(creator.length<6)return toast('Ο κωδικός δημιουργού θέλει τουλάχιστον 6 χαρακτήρες.');const questions=['ith516Question1','ith516Question2','ith516Question3'].map(id=>String($(id)?.value||'').trim()).filter(Boolean);const btn=document.querySelector('[data-ith516-action="submit-create"]');if(btn){btn.disabled=true;btn.textContent='Δημιουργία...'}try{const d=await api('/api/rooms/create_v249516',{method:'POST',body:JSON.stringify({room_id:room(),owner_id:device(),owner_name:nickname(),title:titleValue,description:String($('ith516Desc')?.value||''),rules_text:String($('ith516Rules')?.value||''),welcome_text:String($('ith516Welcome')?.value||''),membership_questions:questions,space_kind:createKind,topic_category:createCat,access_type:$('ith516Access')?.value||'public',join_code:String($('ith516JoinCode')?.value||''),creator_code:creator})});saveCreatorCode(d.subroom_id,creator);toast('Η κοινότητα δημιουργήθηκε πλήρως. Κράτησε τον κωδικό δημιουργού: '+creator,9000);kind=createKind;cat=createCat;await loadSpaces(true);view='list';applyView();renderCats();updateKindButtons();renderList();return false}catch(e){toast('Δεν δημιουργήθηκε: '+e.message,7000);return false}finally{if(btn){btn.disabled=false;btn.textContent=createKind==='room'?'✓ ΔΗΜΙΟΥΡΓΙΑ ΔΩΜΑΤΙΟΥ':'✓ ΔΗΜΙΟΥΡΓΙΑ ΚΟΙΝΟΤΗΤΑΣ'}}}
function closeForeignOverlays(){['memberMenu','plusSheet'].forEach(id=>{const e=$(id);if(e){e.classList.remove('show','open','active','fullAvatarMenuV249231');e.setAttribute('aria-hidden','true')}});document.querySelectorAll('#ith520Panel,#ith521App,.ith521App,.ith518Panel,.ith519Panel').forEach(e=>e.remove())}
function ensureChatVisible(){if(view!=='chat'||!activeSpace)return;if(!$('ith516Shell')){closeForeignOverlays();renderPage()}view='chat';applyView()}
async function loadMessagesStable(force=false){
 ensureChatVisible();const box=$('spaceMsgs'),channel=String(S().currentSpaceChannel||(activeSpace?('space:'+activeSpace.subroom_id):''));if(!box||!channel)return false;
 if(messageLoadPromiseR10F18&&!force)return messageLoadPromiseR10F18;if(messageAbortR10F18&&force)try{messageAbortR10F18.abort()}catch(_e){}
 const generation=++messageLoadGenerationR10F18,controller=typeof AbortController!=='undefined'?new AbortController():null;messageAbortR10F18=controller;if(!box.dataset.messageOwner)box.innerHTML='<div class="card">Φόρτωση μηνυμάτων…</div>';
 const task=(async()=>{try{const h={};try{const t=localStorage.getItem('ith_public_token')||localStorage.getItem('ith_token')||'';if(t)h['X-ITHAKI-TOKEN']=t}catch(_e){}const r=await fetch(apiBase()+'/api/messages?room_id='+encodeURIComponent(room())+'&channel='+encodeURIComponent(channel)+'&since=0&limit=300',{cache:'no-store',credentials:'include',headers:h,signal:controller?.signal});let d={};try{d=await r.json()}catch(_e){}if(!r.ok)throw Error(String(d.detail||('HTTP '+r.status)));if(generation!==messageLoadGenerationR10F18)return false;return renderCommunityMessagesAtomicR10F18(d.messages||[])}catch(e){if(e?.name==='AbortError'||generation!==messageLoadGenerationR10F18)return false;box.innerHTML='<div class="card"><b>Δεν φορτώθηκαν τα μηνύματα.</b><small>'+esc(e.message||e)+'</small><button type="button" class="btn green" onclick="ITH.loadSpaceMessages(true)">↻ Νέα προσπάθεια</button></div>';return false}finally{ensureChatVisible()}})();messageLoadPromiseR10F18=task;try{return await task}finally{if(messageLoadPromiseR10F18===task)messageLoadPromiseR10F18=null;if(messageAbortR10F18===controller)messageAbortR10F18=null}
}
function staffCodeKey(id,role){return role==='moderator'?'ith_space_moderator_code_v249516_'+id:'ith_space_creator_code_v249510_'+id}
function getStaffCode(id,role){try{return localStorage.getItem(staffCodeKey(id,role))||''}catch(e){return''}}
function setStaffCode(id,role,code){try{localStorage.setItem(staffCodeKey(id,role),code)}catch(e){}}
async function enterSpaceChat(x,detail){closeForeignOverlays();pendingJoin=null;const s=S();s.spaces=spaces;s.currentSpace=String(x.subroom_id);s.currentSpaceChannel='space:'+x.subroom_id;activeSpace=Object.assign({},x,detail?.room||{});view='chat';applyView();try{I().wsSubscribe&&I().wsSubscribe(s.currentSpaceChannel)}catch(e){}await Promise.all([loadMessagesStable(),loadMembersBar(true)]);ensureChatVisible();if(activeSpace.welcome_text)toast(activeSpace.welcome_text,6500);setTimeout(()=>{$('spaceInput')?.focus();ensureChatVisible()},80);return false}
function closeJoinPanel(){pendingJoin=null;view='list';applyView();return false}
function joinAccepted(){return $('ith522AcceptRules')?.getAttribute('aria-checked')==='true'}
function toggleJoinAccept(){const b=$('ith522AcceptRules');if(!b)return false;const on=b.getAttribute('aria-checked')!=='true';b.setAttribute('aria-checked',on?'true':'false');b.querySelector('.box').textContent=on?'✓':'';return false}
function openJoinPanel(x,detail){closeForeignOverlays();const r=detail.room||{},qs=Array.isArray(r.membership_questions)?r.membership_questions:[];pendingJoin={space:x,room:r,questions:qs};const body=$('ith522JoinBody'),head=$('ith522JoinTitle');if(!body||!head){renderPage();return openJoinPanel(x,detail)}head.textContent='Συμμετοχή · '+title(x);const inputs=qs.map((q,i)=>`<label><b>${esc(q)}</b><textarea id="ith522JoinAnswer${i}" rows="2"></textarea></label>`).join('');const code=r.access_type==='private_code'?'<label><b>Κωδικός μέλους</b><input id="ith522JoinCodePrompt" autocomplete="off"></label>':'';body.innerHTML=`<div class="ith522JoinRules"><b>Κανόνες</b><div>${esc(r.rules_text||desc(x)||'Σεβασμός και ασφάλεια για όλα τα μέλη.')}</div></div>${inputs}${code}<button type="button" id="ith522AcceptRules" class="ith522RuleCheck" role="checkbox" aria-checked="false" data-ith516-action="join-toggle"><span class="box"></span><span><b>Αποδέχομαι τους κανόνες</b><small>Πάτησε οπουδήποτε στη γραμμή για επιλογή.</small></span></button><button type="button" class="btn green ith522JoinSubmit" data-ith516-action="join-submit">✓ ΣΥΜΜΕΤΟΧΗ ΚΑΙ ΑΝΟΙΓΜΑ ΣΥΖΗΤΗΣΗΣ</button>`;view='join';applyView();return false}
async function submitJoinPanel(){const p=pendingJoin;if(!p)return false;if(!joinAccepted())return toast('Τσέκαρε ότι αποδέχεσαι τους κανόνες.');const btn=document.querySelector('#ith522JoinBody [data-ith516-action="join-submit"]');if(btn){btn.disabled=true;btn.textContent='Σύνδεση…'}try{const answers=p.questions.map((_,i)=>String($('ith522JoinAnswer'+i)?.value||'').trim());const d=await api('/api/rooms/join_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:p.space.subroom_id,device_id:device(),nickname:nickname(),join_code:String($('ith522JoinCodePrompt')?.value||''),answers,rules_accepted:true})});if(d.pending){toast('Το αίτημα και οι απαντήσεις στάλθηκαν στον δημιουργό.');return closeJoinPanel()}p.space.is_member=true;return await enterSpaceChat(p.space,{room:Object.assign({},p.room,{role:'member',is_member:true})})}catch(e){toast('Δεν ολοκληρώθηκε η συμμετοχή: '+e.message,7000);return false}finally{if(btn){btn.disabled=false;btn.textContent='✓ ΣΥΜΜΕΤΟΧΗ ΚΑΙ ΑΝΟΙΓΜΑ ΣΥΖΗΤΗΣΗΣ'}}}
async function openSpace(id){id=String(id||'');if(!id||openingId===id)return false;const x=spaces.find(s=>String(s.subroom_id)===id);if(!x)return toast('Δεν βρέθηκε η κοινότητα.');if(x.blocked)return toast('Δεν έχεις πρόσβαση σε αυτή την κοινότητα.');openingId=id;try{const detail=await api('/api/rooms/detail_v249516?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(id)+'&device_id='+encodeURIComponent(device()));const r=detail.room||{};if(r.is_member||r.is_owner)return enterSpaceChat(x,detail);const needsPanel=(Array.isArray(r.membership_questions)&&r.membership_questions.length>0)||r.access_type!=='public'||String(r.rules_text||'').trim();if(needsPanel)return openJoinPanel(x,detail);const d=await api('/api/rooms/join_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:id,device_id:device(),nickname:nickname(),answers:[],rules_accepted:true})});if(d.pending){toast('Το αίτημα συμμετοχής στάλθηκε.');return false}x.is_member=true;return enterSpaceChat(x,{room:Object.assign({},r,{role:'member',is_member:true})})}catch(e){toast('Δεν άνοιξε η κοινότητα: '+e.message,7000);return false}finally{openingId=''}}
function closeChat(){view='list';activeSpace=null;pendingJoin=null;document.body?.classList.remove('ith522CommunityChatOpen');const s=S();s.currentSpace='';s.currentSpaceChannel='';closeForeignOverlays();applyView();return false}
function panel(titleText,body){const m=$('memberMenu');if(!m)return false;m.innerHTML=`<div class="row"><button class="icon" data-ith516-panel-close>‹</button><b>${esc(titleText)}</b><button class="icon" style="margin-left:auto" data-ith516-panel-close>×</button></div><div class="ith516PanelList">${body}</div>`;m.classList.add('show','fullAvatarMenuV249231');m.querySelectorAll('[data-ith516-panel-close]').forEach(b=>b.addEventListener('click',()=>m.classList.remove('show','fullAvatarMenuV249231')));bindCheckRows(m);return false}

function bindCheckRows(root){(root||document).querySelectorAll?.('[data-ith517-check-row]').forEach(row=>{if(row.__ith517Bound)return;row.__ith517Bound=true;const input=row.querySelector('input[type=checkbox]');if(!input)return;const sync=()=>row.classList.toggle('checked',!!input.checked);input.addEventListener('change',sync);input.addEventListener('click',e=>e.stopPropagation());row.addEventListener('click',e=>{if(e.target===input)return;e.preventDefault();e.stopPropagation();input.checked=!input.checked;input.dispatchEvent(new Event('change',{bubbles:true}))});sync()})}
function initials(name){const a=String(name||'Μ').trim().split(/\s+/).filter(Boolean);return ((a[0]?.[0]||'Μ')+(a[1]?.[0]||'')).toUpperCase()}
function canonicalPersonR10F19(id,fallback={}){id=String(id||'');const self=id&&id===device();let p={};try{const sp=S().people;if(sp instanceof Map)p=sp.get(id)||{};else if(Array.isArray(sp))p=sp.find(x=>String(x?.id||x?.device_id||'')===id)||{}}catch(_e){}if(!Object.keys(p).length){try{p=contactArray().find(x=>String(x.id||x.device_id||'')===id)||{}}catch(_e){}}if(self)p=Object.assign({},p,{id,device_id:id,nickname:nickname(),avatar:String(S().avatar||localStorage.getItem('ith_avatar')||''),animal:String(S().animal||localStorage.getItem('ith_animal')||'')});return Object.assign({},fallback,p,{id:id||String(p.id||p.device_id||''),device_id:id||String(p.device_id||p.id||''),nickname:String(p.nickname||p.display_name||fallback.nickname||'Μέλος'),avatar:String(p.avatar||p.photo||fallback.avatar||''),animal:String(p.animal||fallback.animal||''),online:!!(p.online||p.active||fallback.online||self),self})}
function avatarSourceR10F19(a){a=String(a||'').trim();if(!a||a.startsWith('animal:'))return'';if(/^data:image\//i.test(a)||/^https?:\/\//i.test(a)||/^blob:/i.test(a)||a.startsWith('/'))return a;if(/^[\w./-]+\.(png|jpe?g|gif|webp|svg)(\?.*)?$/i.test(a))return a;return''}
function canonicalAvatarHtmlR10F19(person={}){const p=canonicalPersonR10F19(person.id||person.device_id||'',person),raw=String(p.avatar||p.animal||''),animal=raw.startsWith('animal:')?raw.slice(7):(!avatarSourceR10F19(raw)&&raw?raw:''),src=avatarSourceR10F19(raw),fallback=esc(initials(p.nickname));return `<span class="avatarDotWrap"><span class="avatar">${src?`<img src="${esc(src)}" alt="" loading="lazy" onerror="this.remove();this.parentElement.textContent='${fallback}'">`:esc(animal||fallback)}</span><i class="${p.online?'on':'off'}"></i></span>`}
function openMemberPostsR10F19(id,startPost=''){id=String(id||'');if(!id)return false;const a=I();try{if(typeof a.openMemberFeed==='function')return a.openMemberFeed(id,String(startPost||''));if(typeof window.openMemberFeed==='function')return window.openMemberFeed(id,String(startPost||''));if(id===device()&&typeof a.page==='function')return a.page('feed');if(typeof a.member==='function')return a.member(id)}catch(_e){}return false}
function activePeopleR10F19(){const out=[],seen=new Set(),push=p=>{const id=String(p?.id||p?.device_id||'');if(!id||seen.has(id))return;seen.add(id);out.push(canonicalPersonR10F19(id,p))};push({id:device(),nickname:nickname(),avatar:String(S().avatar||localStorage.getItem('ith_avatar')||''),animal:String(S().animal||localStorage.getItem('ith_animal')||''),online:true,self:true});try{contactArray().filter(p=>p.online||p.active).forEach(push)}catch(_e){}return out.slice(0,28)}
function feedPersonButtonR10F19(p){const self=String(p.id||p.device_id||'')===device(),label=self?(document.documentElement.lang?.startsWith('en')?'My posts':'Οι δημοσιεύσεις μου'):String(p.nickname||'Μέλος');return `<button type="button" class="ith519CommunityFeedPerson ${self?'self':''}" data-community-member-posts="${esc(p.id||p.device_id||'')}" title="${esc(label)}">${canonicalAvatarHtmlR10F19(p)}<small>${esc(self?(document.documentElement.lang?.startsWith('en')?'Me':'Εγώ'):p.nickname||'Μέλος')}</small></button>`}
function bindCommunityFeedBarR10F19(bar){bar?.querySelectorAll('[data-community-member-posts],[data-community-member-menu]').forEach(b=>{if(b.dataset.r10f21Bound==='1')return;b.dataset.r10f21Bound='1';b.addEventListener('click',e=>{e.preventDefault();e.stopPropagation();openCommunityAvatarMenuR10F21(b.dataset.communityMemberMenu||b.dataset.communityMemberPosts||'')})})}
function renderGlobalCommunityFeedBarR10F19(){const bar=$('ith519CommunityFeedBarList');if(!bar)return false;const people=activePeopleR10F19(),sig=people.map(p=>[p.id,p.avatar,p.animal,p.online?1:0].join('~')).join('|');if(bar.dataset.sig===sig)return true;bar.dataset.sig=sig;bar.innerHTML=people.map(feedPersonButtonR10F19).join('')||'<span class="ith517MembersEmpty">Δεν υπάρχει ενεργό μέλος τώρα.</span>';bindCommunityFeedBarR10F19(bar);return true}
function contactArray(){let a=[];try{if(typeof window.peopleArray==='function')a=window.peopleArray()||[]}catch(e){}if(!a.length){const s=S();a=[...(Array.isArray(s.people)?s.people:[]),...(Array.isArray(s.friends)?s.friends:[])]}const seen=new Set();return a.map(p=>Object.assign({},p,{id:String(p.id||p.device_id||p.peer_id||'')})).filter(p=>p.id&&!seen.has(p.id)&&seen.add(p.id))}
function setInviteChecks(on){document.querySelectorAll('#ith517InviteList .ith517InviteCheck').forEach(x=>{x.checked=!!on;x.dispatchEvent(new Event('change',{bubbles:true}))});return false}
async function sendInvites(){if(!activeSpace)return false;const selected=[...document.querySelectorAll('#ith517InviteList .ith517InviteCheck:checked')];if(!selected.length)return toast('Τσέκαρε τουλάχιστον ένα μέλος.');const btn=$('ith517SendInvites');if(btn)btn.disabled=true;let ok=0;for(const x of selected){try{await api('/api/rooms/invite',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,from_id:device(),from_name:nickname(),to_id:x.value,to_name:x.dataset.name||x.value})});ok++}catch(e){}}if(btn)btn.disabled=false;$('memberMenu')?.classList.remove('show','fullAvatarMenuV249231');toast('Στάλθηκαν '+ok+' προσκλήσεις.');return false}
function fileKind(file,requested){const t=String(file?.type||'').toLowerCase(),n=String(file?.name||'').toLowerCase();if(t.startsWith('image/')||/\.(jpg|jpeg|png|webp|gif|heic|heif)$/.test(n))return'photo';if(t.startsWith('video/')||/\.(mp4|mov|m4v|webm|3gp|mkv|avi)$/.test(n))return'video';if(t.startsWith('audio/')||/\.(mp3|m4a|aac|wav|ogg|opus)$/.test(n))return'audio';return requested||'file'}
function bindSpaceFileInputs(){[['ith517SpaceFileInput','file'],['ith517SpacePhotoInput','photo'],['ith517SpaceVideoInput','video']].forEach(([id,requested])=>{const input=$(id);if(!input||input.__ith517Bound)return;input.__ith517Bound=true;input.addEventListener('change',async()=>{const f=input.files&&input.files[0];filePickerActive=false;window.__ITHAKI_ACTIVE_FILE_CONTEXT_V249517='';if(!f){ensureChatVisible();return}ensureChatVisible();const target=S().currentSpaceChannel||('space:'+(activeSpace?.subroom_id||'')),open=I().secureOpenPreviewV249545||window.secureOpenPreviewV249545||I().openPreview||window.openPreview;if(typeof open==='function')await open.call(I(),'space',f,fileKind(f,requested),target);else toast('Η ασφαλής προεπισκόπηση αρχείου δεν είναι διαθέσιμη.');setTimeout(ensureChatVisible,80)});})}
function openSpaceFilePicker(kind){if(!activeSpace)return toast('Άνοιξε πρώτα κοινότητα ή δωμάτιο.');ensureChatVisible();bindSpaceFileInputs();const id=kind==='photo'?'ith517SpacePhotoInput':kind==='video'?'ith517SpaceVideoInput':'ith517SpaceFileInput';const input=$(id);if(!input)return toast('Δεν φορτώθηκε η επιλογή αρχείου.');try{input.value=''}catch(e){}filePickerActive=true;window.__ITHAKI_ACTIVE_FILE_CONTEXT_V249517='space';try{input.click()}catch(e){filePickerActive=false;window.__ITHAKI_ACTIVE_FILE_CONTEXT_V249517='';toast('Δεν άνοιξε η λίστα αρχείων: '+e.message)}return false}
function nativeFileChooserReturnedV249517(){if(window.__ITHAKI_ACTIVE_FILE_CONTEXT_V249517==='space'||filePickerActive){setTimeout(ensureChatVisible,0);setTimeout(ensureChatVisible,120);setTimeout(()=>{filePickerActive=false;window.__ITHAKI_ACTIVE_FILE_CONTEXT_V249517=''},1800);return true}try{const old=I().previewChooserReturnedV249400;if(typeof old==='function')return old.call(I())}catch(e){}return true}
function startSpaceAudio(){if(!activeSpace)return false;try{const f=I().startAudioRecording||window.startAudioRecording;if(typeof f==='function')return f.call(I(),'space',S().currentSpaceChannel||'')}catch(e){}return toast('Η εγγραφή ήχου δεν είναι διαθέσιμη.')}
async function loadMembersBar(force){const bar=$('ith517MembersBar');if(!bar||!activeSpace)return false;const id=String(activeSpace.subroom_id||'');if(!force&&membersLoadedFor===id&&Date.now()-membersLoadedAt<15000)return false;membersLoadedFor=id;membersLoadedAt=Date.now();bar.innerHTML='<span class="ith517MembersEmpty">Φόρτωση μελών…</span>';try{const d=await api('/api/rooms/members?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(id));if(!activeSpace||String(activeSpace.subroom_id)!==id)return false;const raw=(d.members||[]).slice(0,32),seen=new Set(),members=[];const add=p=>{const mid=String(p?.device_id||p?.id||'');if(!mid||seen.has(mid))return;seen.add(mid);members.push(canonicalPersonR10F19(mid,p))};add({id:device(),nickname:nickname(),avatar:String(S().avatar||localStorage.getItem('ith_avatar')||''),animal:String(S().animal||localStorage.getItem('ith_animal')||''),online:true,self:true});raw.forEach(add);bar.innerHTML=members.map(feedPersonButtonR10F19).join('')||'<span class="ith517MembersEmpty">Δεν εμφανίζονται μέλη ακόμη.</span>';bindCommunityFeedBarR10F19(bar)}catch(e){bar.innerHTML='<span class="ith517MembersEmpty">Τα μέλη δεν φορτώθηκαν.</span>'}return false}
function openCommunityTools(){if(!activeSpace)return false;panel('⋯ Εργαλεία κοινότητας',`<div class="ith517ToolGrid"><button id="ith517ToolInfo">ℹ️ Κανόνες και πληροφορίες</button><button id="ith517ToolMembers">👥 Όλα τα μέλη</button><button id="ith517ToolPins">📌 Καρφιτσωμένα</button><button id="ith517ToolSearch">🔎 Αναζήτηση μηνυμάτων</button><button id="ith517ToolFollow">🔔 Ειδοποιήσεις</button><button id="ith517ToolInvite">＋ Πρόσκληση μελών</button><button id="ith517ToolPolls">🗳️ Ψηφοφορίες</button><button id="ith517ToolEvents">📅 Εκδηλώσεις</button><button id="ith517ToolManage">🛡️ Συντονισμός</button></div>`);const close=()=>$('memberMenu')?.classList.remove('show','fullAvatarMenuV249231');[['ith517ToolInfo',openInfo],['ith517ToolMembers',openMembers],['ith517ToolPins',openPins],['ith517ToolSearch',()=>{close();toggleMessageSearch()}],['ith517ToolFollow',toggleFollow],['ith517ToolInvite',inviteMembers],['ith517ToolPolls',openPolls],['ith517ToolEvents',openEvents],['ith517ToolManage',openManage]].forEach(([id,fn])=>$((id))?.addEventListener('click',()=>{close();fn()}));return false}
function openInfo(){if(!activeSpace)return false;return panel('ℹ️ Πληροφορίες και κανόνες',`<div class="card"><h3>${esc(title(activeSpace))}</h3><div class="ith516Pills"><span class="ith516Pill">${esc(catName(activeSpace.topic_category||'general'))}</span><span class="ith516Pill">${esc(accessName(activeSpace.access_type))}</span><span class="ith516Pill">👥 ${Number(activeSpace.member_count||0)}</span></div></div><div class="card"><b>Κανόνες / περιγραφή</b><div class="ith516Rules">${esc(activeSpace.rules_text||desc(activeSpace)||'Ο δημιουργός δεν έχει γράψει ακόμη κανόνες. Ισχύουν οι βασικοί κανόνες σεβασμού και ασφάλειας της ΙΘΑΚΗΣ.')}</div></div>`)}
async function openMembers(){if(!activeSpace)return false;panel('👥 Μέλη','<div class="card">Φόρτωση μελών…</div>');try{const d=await api('/api/rooms/members?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(activeSpace.subroom_id));const html=(d.members||[]).map(m=>`<div class="ith516PanelRow"><span><b>${esc(m.nickname||'Μέλος')}</b><small>${esc(m.device_id||'')}</small></span></div>`).join('')||'<div class="card">Δεν εμφανίζονται μέλη ακόμη.</div>';panel('👥 Μέλη',html)}catch(e){panel('👥 Μέλη','<div class="card">Δεν φορτώθηκαν τα μέλη.</div>')}return false}
async function openPins(){if(!activeSpace)return false;panel('📌 Καρφιτσωμένα','<div class="card">Φόρτωση…</div>');try{const d=await api('/api/rooms/pins?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(activeSpace.subroom_id));const html=(d.pins||[]).map(p=>`<div class="card"><b>${esc(p.nickname||'Ανακοίνωση')}</b><div>${esc(p.text||p.note||'')}</div><small>${esc(p.message_created_at||p.created_at||'')}</small></div>`).join('')||'<div class="card">Δεν υπάρχουν καρφιτσωμένα μηνύματα.</div>';panel('📌 Καρφιτσωμένα / ανακοινώσεις',html)}catch(e){panel('📌 Καρφιτσωμένα','<div class="card">Δεν φορτώθηκαν.</div>')}return false}
function toggleMessageSearch(){const p=$('ith516MessageSearch');if(!p)return false;p.classList.toggle('show');if(p.classList.contains('show'))setTimeout(()=>$('ith516MessageSearchInput')?.focus(),40);else{const q=$('ith516MessageSearchInput');if(q)q.value='';filterMessages()}return false}
function filterMessages(){const q=String($('ith516MessageSearchInput')?.value||'').trim().toLocaleLowerCase('el');document.querySelectorAll('#spaceMsgs .bubble,#spaceMsgs .card').forEach(el=>{el.style.display=!q||String(el.textContent||'').toLocaleLowerCase('el').includes(q)?'':'none'})}
function updateFollowButton(){const b=$('ith516FollowBtn');if(!b||!activeSpace)return;const on=isFollowed(activeSpace.subroom_id);b.classList.toggle('ith516FollowOn',on);b.textContent=on?'🔔 Ειδοποιήσεις ενεργές':'🔕 Ενεργοποίηση ειδοποιήσεων'}
async function toggleFollow(){if(!activeSpace)return false;const id=String(activeSpace.subroom_id);const on=!isFollowed(id);saveFollow(id,on);updateFollowButton();try{await api('/api/rooms/subscribe',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:id,device_id:device(),nickname:nickname(),enabled:on})});toast(on?'Οι ειδοποιήσεις της κοινότητας ενεργοποιήθηκαν.':'Οι ειδοποιήσεις της κοινότητας σταμάτησαν.')}catch(e){saveFollow(id,!on);updateFollowButton();toast('Δεν άλλαξαν οι ειδοποιήσεις.')}return false}
function inviteMembers(){if(!activeSpace)return false;const list=contactArray().filter(p=>String(p.id||p.device_id||'')&&String(p.id||p.device_id||'')!==device()).slice(0,160);const rows=list.map(p=>{const id=String(p.id||p.device_id||'');const nm=String(p.nickname||p.display_name||'Μέλος');return `<label class="ith517CheckRow ith517InvitePerson" data-ith517-check-row><input type="checkbox" class="ith517InviteCheck" value="${esc(id)}" data-name="${esc(nm)}"><span class="ith517InviteAvatar">${canonicalAvatarHtmlR10F19(canonicalPersonR10F19(id,p))}</span><span><b>${esc(nm)}</b><small>${esc(id)}${p.online||p.active?' · ενεργός':''}</small></span></label>`}).join('')||'<div class="card">Δεν βρέθηκαν φίλοι ή επαφές.</div>';panel('＋ Πρόσκληση μελών',`<div class="card row" style="gap:7px;flex-wrap:wrap"><button id="ith517CheckAll" class="btn">Όλοι</button><button id="ith517CheckNone" class="btn">Κανένας</button><span class="date">Τσέκαρε τα μέλη που θέλεις.</span></div><div id="ith517InviteList" class="ith517InviteList">${rows}</div><button id="ith517SendInvites" class="btn green">Αποστολή προσκλήσεων</button>`);$('ith517CheckAll')?.addEventListener('click',()=>setInviteChecks(true));$('ith517CheckNone')?.addEventListener('click',()=>setInviteChecks(false));$('ith517SendInvites')?.addEventListener('click',sendInvites);return false}
async function openPolls(){if(!activeSpace)return false;panel('🗳️ Ψηφοφορίες','<div class="card">Φόρτωση…</div>');try{const d=await api('/api/rooms/polls_v249516?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(activeSpace.subroom_id)+'&device_id='+encodeURIComponent(device()));let html=(d.polls||[]).map(p=>`<div class="card"><b>${esc(p.question)}</b>${(p.options||[]).map(o=>`<button class="btn ith516PollOption" data-poll="${esc(p.poll_id)}" data-option="${esc(o.option_id)}"><span>${esc(o.label)}</span><span>${Number(o.votes||0)}${p.my_option_id===o.option_id?' ✓':''}</span></button>`).join('')}</div>`).join('')||'<div class="card">Δεν υπάρχουν ψηφοφορίες.</div>';if(['creator','moderator'].includes(activeSpace.role))html='<button id="ith516CreatePoll" class="btn green">＋ Νέα ψηφοφορία</button>'+html;panel('🗳️ Ψηφοφορίες',html);document.querySelectorAll('[data-poll][data-option]').forEach(b=>b.addEventListener('click',async()=>{try{await api('/api/rooms/polls/vote_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),poll_id:b.dataset.poll,option_id:b.dataset.option})});openPolls()}catch(e){toast(e.message)}}));$('ith516CreatePoll')?.addEventListener('click',createPoll)}catch(e){panel('🗳️ Ψηφοφορίες','<div class="card">Δεν φορτώθηκαν: '+esc(e.message)+'</div>')}return false}
async function createPoll(){const q=prompt('Ερώτηση ψηφοφορίας:')||'';if(!q)return;const raw=prompt('Επιλογές χωρισμένες με |, τουλάχιστον δύο:','Ναι | Όχι')||'';const options=raw.split('|').map(x=>x.trim()).filter(Boolean);if(options.length<2)return toast('Χρειάζονται τουλάχιστον δύο επιλογές.');const role=activeSpace.role||'creator';let code=getStaffCode(activeSpace.subroom_id,role);if(!code){code=prompt(role==='moderator'?'Κωδικός συντονιστή:':'Κωδικός δημιουργού:')||'';if(code)setStaffCode(activeSpace.subroom_id,role,code)}try{await api('/api/rooms/polls/create_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),staff_code:code,question:q,options})});openPolls()}catch(e){toast(e.message)}}
async function openEvents(){if(!activeSpace)return false;panel('📅 Εκδηλώσεις','<div class="card">Φόρτωση…</div>');try{const d=await api('/api/rooms/events_v249516?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(activeSpace.subroom_id)+'&device_id='+encodeURIComponent(device()));let html=(d.events||[]).map(e=>`<div class="card"><b>${esc(e.title)}</b><div>${esc(e.description||'')}</div><small>${new Date(Number(e.starts_at||0)*1000).toLocaleString('el-GR')} · ${esc(e.location||'')} · 👥 ${Number(e.going_count||0)}</small><div class="ith516EventActions"><button class="btn" data-event="${esc(e.event_id)}" data-rsvp="going">Θα πάω${e.my_response==='going'?' ✓':''}</button><button class="btn" data-event="${esc(e.event_id)}" data-rsvp="interested">Ενδιαφέρομαι${e.my_response==='interested'?' ✓':''}</button></div></div>`).join('')||'<div class="card">Δεν υπάρχουν εκδηλώσεις.</div>';if(['creator','moderator'].includes(activeSpace.role))html='<button id="ith516CreateEvent" class="btn green">＋ Νέα εκδήλωση</button>'+html;panel('📅 Εκδηλώσεις',html);document.querySelectorAll('[data-event][data-rsvp]').forEach(b=>b.addEventListener('click',async()=>{try{await api('/api/rooms/events/rsvp_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),nickname:nickname(),event_id:b.dataset.event,response:b.dataset.rsvp})});openEvents()}catch(e){toast(e.message)}}));$('ith516CreateEvent')?.addEventListener('click',createEvent)}catch(e){panel('📅 Εκδηλώσεις','<div class="card">Δεν φορτώθηκαν: '+esc(e.message)+'</div>')}return false}
async function createEvent(){const title=prompt('Τίτλος εκδήλωσης:')||'';if(!title)return;const when=prompt('Ημερομηνία και ώρα, π.χ. 2026-08-15 20:00:')||'';const ms=Date.parse(when.replace(' ','T'));if(!Number.isFinite(ms))return toast('Η ημερομηνία δεν αναγνωρίστηκε.');const locationText=prompt('Τοποθεσία ή σύνδεσμος:')||'';const description=prompt('Περιγραφή:')||'';const role=activeSpace.role||'creator';let code=getStaffCode(activeSpace.subroom_id,role);if(!code){code=prompt(role==='moderator'?'Κωδικός συντονιστή:':'Κωδικός δημιουργού:')||'';if(code)setStaffCode(activeSpace.subroom_id,role,code)}try{await api('/api/rooms/events/create_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),staff_code:code,title,description,location:locationText,starts_at:ms/1000})});openEvents()}catch(e){toast(e.message)}}
async function openManage(){if(!activeSpace)return false;let role=activeSpace.role||(_communityRoleFallback());if(!['creator','moderator'].includes(role))return toast('Η διαχείριση είναι διαθέσιμη μόνο σε δημιουργό ή συντονιστή.');let code=getStaffCode(activeSpace.subroom_id,role);if(!code){code=prompt(role==='moderator'?'Κωδικός συντονιστή:':'Κωδικός δημιουργού:')||'';if(!code)return false;setStaffCode(activeSpace.subroom_id,role,code)}panel('🛡️ Συντονισμός','<div class="card">Φόρτωση…</div>');try{const d=await api('/api/rooms/staff/panel_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),staff_code:code})});activeSpace.role=d.role;let html='<div class="card"><button id="ith516EditRules" class="btn">✏️ Κανόνες / καλωσόρισμα</button></div>';html+='<div class="card"><b>Αιτήματα συμμετοχής</b>'+((d.pending||[]).map(r=>`<div class="ith516PanelRow"><span><b>${esc(r.nickname||r.device_id)}</b>${(r.answers||[]).map((a,i)=>`<div class="ith516Answer">${i+1}. ${esc(a)}</div>`).join('')}</span><div class="ith516StaffActions"><button class="btn green" data-request="${esc(r.request_id)}" data-accept="1">✓</button><button class="btn" data-request="${esc(r.request_id)}" data-accept="0">×</button></div></div>`).join('')||'<p>Δεν υπάρχουν εκκρεμή αιτήματα.</p>')+'</div>';html+='<div class="card"><b>Μέλη και ρόλοι</b>'+((d.members||[]).map(m=>`<div class="ith516PanelRow"><span><b>${esc(m.nickname||m.device_id)}</b> <span class="ith516Role">${esc(m.role||'member')}</span><small>${esc(m.device_id)}</small></span>${String(m.device_id)!==device()?`<div class="ith516StaffActions">${d.role==='creator'?`<button class="btn" data-role-target="${esc(m.device_id)}" data-role="${m.role==='moderator'?'member':'moderator'}">${m.role==='moderator'?'Αφαίρεση συντονιστή':'Κάνε συντονιστή'}</button>`:''}<button class="btn" data-block-target="${esc(m.device_id)}">⛔</button></div>`:''}</div>`).join(''))+'</div>';html+='<div class="card"><b>Ουρά αναφορών</b>'+((d.reports||[]).map(r=>`<div class="ith516PanelRow"><span>${esc(r.reason||'Αναφορά')}<small>${esc(r.message_id||'')}</small></span><div class="ith516StaffActions"><button class="btn" data-report="${esc(r.report_id)}" data-report-action="dismiss">Κλείσιμο</button><button class="btn" data-report="${esc(r.report_id)}" data-report-action="delete_message">Διαγραφή</button></div></div>`).join('')||'<p>Δεν υπάρχουν εκκρεμείς αναφορές.</p>')+'</div>';panel('🛡️ Συντονισμός · '+(d.role==='creator'?'Δημιουργός':'Συντονιστής'),html);document.querySelectorAll('[data-request]').forEach(b=>b.addEventListener('click',async()=>{try{await api('/api/rooms/staff/respond_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),staff_code:code,request_id:b.dataset.request,accepted:b.dataset.accept==='1'})});openManage()}catch(e){toast(e.message)}}));document.querySelectorAll('[data-role-target]').forEach(b=>b.addEventListener('click',async()=>{try{const r=await api('/api/rooms/staff/set_role_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),staff_code:code,target_id:b.dataset.roleTarget,role:b.dataset.role})});if(r.moderator_code)alert('Κωδικός συντονιστή — εμφανίζεται μία φορά:\n'+r.moderator_code);openManage()}catch(e){toast(e.message)}}));document.querySelectorAll('[data-block-target]').forEach(b=>b.addEventListener('click',async()=>{const reason=prompt('Λόγος μπλοκαρίσματος:')||'';try{await api('/api/rooms/staff/block_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),staff_code:code,target_id:b.dataset.blockTarget,blocked:true,reason})});openManage()}catch(e){toast(e.message)}}));document.querySelectorAll('[data-report]').forEach(b=>b.addEventListener('click',async()=>{try{await api('/api/rooms/staff/report_action_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),staff_code:code,report_id:b.dataset.report,action:b.dataset.reportAction,note:''})});openManage()}catch(e){toast(e.message)}}));$('ith516EditRules')?.addEventListener('click',async()=>{const rules=prompt('Κανόνες κοινότητας:',activeSpace.rules_text||'');if(rules===null)return;const welcome=prompt('Μήνυμα καλωσορίσματος:',activeSpace.welcome_text||'');try{await api('/api/rooms/staff/update_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:activeSpace.subroom_id,device_id:device(),staff_code:code,rules_text:rules,welcome_text:welcome||''})});activeSpace.rules_text=rules;activeSpace.welcome_text=welcome||'';toast('Οι πληροφορίες ενημερώθηκαν.');openManage()}catch(e){toast(e.message)}})}catch(e){toast('Δεν άνοιξε η διαχείριση: '+e.message,7000);try{localStorage.removeItem(staffCodeKey(activeSpace.subroom_id,role))}catch(_e){}}return false}
function _communityRoleFallback(){return activeSpace?.is_owner?'creator':'member'}
function canonical(){return false}
function addR10F20Css(){if($('ithCommunityR10F20Css'))return;const st=document.createElement('style');st.id='ithCommunityR10F20Css';st.textContent=`
.ithCommunityBubbleR10F18{position:relative!important;display:grid!important;grid-template-columns:auto minmax(0,1fr) auto!important;align-items:start!important;padding-right:6px!important}.ithCommunityBubbleR10F18.communitySimpleTextR10F21{grid-template-columns:auto minmax(0,1fr)!important;padding-right:10px!important}.ithCommunityTextActionsR10F21{display:flex;gap:7px;flex-wrap:wrap;margin-top:6px}.ithCommunityTextActionsR10F21 button{min-height:30px;padding:4px 9px;border-radius:999px;border:1px solid rgba(255,255,255,.14);background:rgba(255,255,255,.06);color:var(--text,#fff);font-size:10px;font-weight:850}.ithCommunityMemberPublicationR10F21{display:grid;gap:8px}.ithCommunityActionRailR10F20{align-self:center;display:flex;flex-direction:column;gap:5px;padding:6px 3px;border-radius:18px;background:rgba(5,13,22,.34);backdrop-filter:blur(12px);border:1px solid rgba(255,255,255,.12)}.ithCommunityActionRailR10F20 button{display:grid;place-items:center;min-width:37px;min-height:37px;border:0;border-radius:50%;background:rgba(255,255,255,.08);color:#fff;font-size:17px;cursor:pointer}.ithCommunityActionRailR10F20 button.on{background:rgba(255,77,120,.25);box-shadow:0 0 0 1px rgba(255,113,145,.45)}.ithCommunityActionRailR10F20 small{font-size:9px;line-height:1}.ithCommunityReplyQuoteR10F20{display:grid;gap:2px;border-left:3px solid var(--gold,#ffd36e);background:rgba(255,255,255,.05);border-radius:7px;padding:6px 8px;margin:4px 0 7px}.ithCommunityReplyQuoteR10F20 span{font-size:12px;opacity:.78}.ithSecurityResultV249545{display:grid;gap:3px;margin-top:8px;padding:9px;border:1px solid rgba(82,225,153,.35);border-radius:12px;background:rgba(17,122,78,.13)}.ithSecurityResultV249545 small{display:block;line-height:1.4}@media(max-width:620px){.ithCommunityBubbleR10F18{grid-template-columns:auto minmax(0,1fr) 42px!important}.ithCommunityBubbleR10F18.communitySimpleTextR10F21{grid-template-columns:auto minmax(0,1fr)!important}.ithCommunityActionRailR10F20{position:sticky;right:3px}.ithCommunityActionRailR10F20 button{min-width:35px;min-height:35px}}
`;document.head.appendChild(st)}
function install(){addCss();addR10F20Css();canonical();const o=I();if(!o)return;if(!o.__v249516BasePage&&typeof o.page==='function'&&!o.page.__v249517)o.__v249516BasePage=o.page;const base=o.__v249516BasePage;const pageOwner=function(id){if(String(id)==='spaces')return activateSpacesPage();return typeof base==='function'?base.apply(this,arguments):false};pageOwner.__v249517=true;o.sendCommunityPayloadR10F17=sendCommunityPayloadDirectR10F17;o.sendCommunityTextR10F15=sendCommunityTextR10F15;o.sendCommunityTextR10F17=sendCommunityTextR10F15;o.sendCommunityTextR10F18=sendCommunityTextR10F15;o.loadSpaceMessages=loadMessagesStable;o.appendSpaceMessage=scheduleCommunityMessageRefreshR10F18;window.sendCommunityPayloadR10F17=sendCommunityPayloadDirectR10F17;window.loadSpaceMessages=loadMessagesStable;window.appendSpaceMessage=scheduleCommunityMessageRefreshR10F18;try{Object.defineProperty(window,'sendΜήνυμαPayload',{configurable:false,enumerable:true,get:()=>sendCommunityPayloadDirectR10F17,set:()=>{}})}catch(_e){window.sendΜήνυμαPayload=sendCommunityPayloadDirectR10F17}try{Object.defineProperty(o,'sendΜήνυμαPayload',{configurable:false,enumerable:true,get:()=>sendCommunityPayloadDirectR10F17,set:()=>{}})}catch(_e){o.sendΜήνυμαPayload=sendCommunityPayloadDirectR10F17}Object.assign(o,{page:pageOwner,renderSpaces:renderPage,renderSpacesV249516:renderPage,activateSpacesPageV249516:activateSpacesPage,openCanonicalCommunitiesR10F14:activateSpacesPage,renderCanonicalCommunitiesR10F14:renderPage,openCanonicalCommunitiesR10F15:activateSpacesPage,renderCanonicalCommunitiesR10F15:renderPage,loadSpacesV249516:loadSpaces,renderSpacesListV249516:renderList,spacesKindV249516:setKind,spaceCategoryV249516:setCat,openCreateCommunityV249516:showCreate,submitCommunityV249516:submitCreate,openSpaceV249516:openSpace,closeSpaceChatV249516:closeChat,openCommunityInfoV249516:openInfo,openCommunityMembersV249516:openMembers,openCommunityPinsV249516:openPins,toggleCommunityFollowV249516:toggleFollow,openCommunityPollsV249516:openPolls,openCommunityEventsV249516:openEvents,openCommunityManagementV249516:openManage,openSpaceFilePickerV249517:openSpaceFilePicker,loadCommunityMembersBarV249517:loadMembersBar,openCommunityToolsV249517:openCommunityTools,nativeFileChooserReturnedV249517:nativeFileChooserReturnedV249517,bindCommunityCheckboxRowsV249517:bindCheckRows,decorateCommunityMessagesR10F17:decorateCommunityMessagesR10F17,renderCommunityFeedBarR10F19:renderGlobalCommunityFeedBarR10F19,openMemberPostsR10F19:openMemberPostsR10F19,canonicalAvatarHtmlR10F19:canonicalAvatarHtmlR10F19,closeCommunityJoinV249522:closeJoinPanel,toggleCommunityJoinCheckV249522:toggleJoinAccept,suspendCommunitiesV249545:suspendCommunitiesV249545,clearCommunityReplyR10F20:clearCommunityReplyR10F20,openCommunityAvatarMenuR10F21:openCommunityAvatarMenuR10F21,showCommunityMemberPublicationsR10F21:showCommunityMemberPublicationsR10F21,sendCommunityInviteR10F21:sendCommunityInviteR10F21});
 try{window.renderSpaces=renderPage;window.openSpace=openSpace;window.openCanonicalCommunitiesR10F14=activateSpacesPage;window.renderCanonicalCommunitiesR10F14=renderPage;window.openCanonicalCommunitiesR10F15=activateSpacesPage;window.renderCanonicalCommunitiesR10F15=renderPage;o.nativeFileChooserReturnedV249517=nativeFileChooserReturnedV249517}catch(e){}
 if(String(S().page||'')==='spaces'||document.body?.getAttribute('data-page')==='spaces'){if(!hasCanonicalShellR10F14())renderPage();else applyView()}
 try{document.documentElement.setAttribute('data-ithaki-v249517','messages-exact-community-file-list-checkboxes');localStorage.setItem('ith_frontend_build','V249526R10F21-lexicon-preview-feed-community-avatar')}catch(e){}}
function installCapture(){if(window.__ITHAKI_V249516_CAPTURE_INSTALLED__)return;window.__ITHAKI_V249516_CAPTURE_INSTALLED__=true;document.addEventListener('click',e=>{try{if(e.target?.closest?.('#ith516Shell'))return;const b=e.target?.closest?.('button,a,[data-page]');if(!b)return;const dp=String(b.getAttribute('data-page')||b.dataset?.page||'');const oc=String(b.getAttribute('onclick')||'');if(dp==='spaces'||/page\s*\(\s*['"]spaces['"]\s*\)/.test(oc)){e.preventDefault();e.stopImmediatePropagation();activateSpacesPage()}}catch(_e){}},true)}
function installObserver(){window.COMMUNITY_MESSAGE_NO_DOM_RESTORE_LOOP_R10F18=true;return true}
function keepOwner(){try{install();installObserver()}catch(e){}}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',()=>{installCapture();keepOwner()},{once:true});else{installCapture();keepOwner()}
window.COMMUNITY_SOURCE_SINGLE_START_R10F12=true;
window.COMMUNITY_ATOMIC_COMPLETE_RENDER_R10F13=true;
window.COMMUNITY_CANONICAL_SHELL_REPLACEMENT_R10F14=true;
window.COMMUNITY_HARD_SINGLE_OWNER_R10F15=true;
window.COMMUNITY_ONLY_RUNTIME_OWNER_R10F15=true;
window.COMMUNITY_DIRECT_SEND_R10F17=true;
window.COMMUNITY_MESSAGE_TRANSLATION_R10F17=true;
window.COMMUNITY_SEND_DIRECT_BOUND_R10F15=true;
window.COMMUNITY_MESSAGE_SINGLE_RENDER_OWNER_R10F18=true;
window.COMMUNITY_MESSAGE_ATOMIC_RENDER_R10F18=true;
window.COMMUNITY_MESSAGE_NO_LEGACY_LOAD_R10F18=true;
window.COMMUNITY_SEND_DIRECT_ONLY_R10F18=true;
window.COMMUNITY_TRANSPARENT_FEED_BAR_R10F19=true;
window.COMMUNITY_UNIFIED_HOME_AVATARS_R10F19=true;
window.COMMUNITY_AVATAR_OPENS_MEMBER_POSTS_R10F19=true;
/* compatibility preflight: data-community-owner="r10f14" replaceForeignShellR10F14 openCanonicalCommunitiesR10F14:activateSpacesPage */
})();

window.COMMUNITY_RAIL_PUBLICATIONS_ONLY_R10F21=true;
window.COMMUNITY_AVATAR_GENERAL_MENU_R10F21=true;
