diff --git a/README.md b/README.md
index a4cd344..3f0b5fd 100644
--- a/README.md
+++ b/README.md
@@ -20,4 +20,4 @@ On Windows, `py -m http.server 8000` is also available on many Python installati
## Current scope
-Mail supports multiple IMAP/SMTP accounts, switching between them, and saving message attachments. Account credentials are kept in the OS-encrypted credential store. Contacts and calendar entries can be added, edited, and removed; they are saved locally on this device and do not sync to an address book or calendar server. Your display name is also saved locally and appears in the greeting.
+Mail supports multiple IMAP/SMTP accounts, switching between them, and saving message attachments. CalDAV and CardDAV servers can be added from the Calendar and Contacts views; credentials are kept in the OS-encrypted credential store, and events and contacts can sync and be edited on the server. Local contacts and events remain available without a DAV connection. Your display name is saved locally and appears in the greeting.
diff --git a/app.js b/app.js
index b5a767d..77dce00 100644
--- a/app.js
+++ b/app.js
@@ -1,26 +1,17 @@
if('serviceWorker'in navigator)window.addEventListener('load',()=>navigator.serviceWorker.register('./service-worker.js').catch(()=>{}));
-const messages = [
- {id:1, initials:'AL', color:'#ead1c1', sender:'Amelia Laurent', email:'amelia@northstar.design', subject:'The new studio is ready ✨', snippet:'I finally get to show you what we’ve been working on. There’s light in every corner.', time:'9:41 AM', date:'Today, 9:41 AM', unread:true, star:true, tags:['Design','New'], body:["Hey Mira,","After months of sketches, coffee, and very optimistic tape measurements, the new Northstar studio is ready. We wanted it to feel like a place you could arrive at slowly — the kind of room where morning light does most of the decorating.","I’ve attached the first look at the space. Come by next week? I’d love to make you that cardamom coffee you keep asking about.","Warmly,"] , signature:'Amelia', attachment:'northstar-studio.jpg', size:'4.8 MB'},
- {id:2, initials:'JK', color:'#d8e3d4', sender:'Jonah Kim', email:'jonah@fieldnotes.co', subject:'Re: Weekend in the mountains?', snippet:'The forecast looks perfect for Saturday. I found a cabin with a little wood stove...', time:'8:22 AM', date:'Today, 8:22 AM', unread:true, star:false, tags:['Personal'], body:["Morning!","The forecast looks perfect for Saturday. I found a cabin with a little wood stove and a trail that starts right behind it. Sending you the details now — it feels like exactly the kind of weekend we need.","Bring a book. I’ll bring the coffee and the slightly overambitious packing list.","See you soon,"] , signature:'Jonah'},
- {id:3, initials:'SP', color:'#e8d9e9', sender:'Sofia Park', email:'sofia@smallhours.works', subject:'A little idea for the spring launch', snippet:'What if the whole thing felt like opening a window after a long winter?', time:'Yesterday', date:'Yesterday, 4:16 PM', unread:true, star:true, tags:['Design'], body:["Hi Mira,","What if the whole spring launch felt like opening a window after a long winter? I put a few thoughts into a tiny moodboard. Soft color, honest materials, lots of breathing room.","Would love your instinct on it. No rush — just thought I’d put it somewhere sunny for you to find.","Sofia"]},
- {id:4, initials:'MR', color:'#d9e4e9', sender:'Mateo Rivera', email:'mateo@roam.travel', subject:'Your Lisbon itinerary is here', snippet:'Three quiet mornings, one very good bakery, and a tram ride that goes nowhere in particular.', time:'Yesterday', date:'Yesterday, 2:03 PM', unread:true, star:false, tags:['Travel'], body:["Your Lisbon itinerary is ready!","Three quiet mornings, one very good bakery, and a tram ride that goes nowhere in particular. I kept the afternoons open so you can wander. The bookshop and the tiny ceramics studio are both on the way from your hotel.","Everything is in the attached guide. Have the loveliest time — Lisbon is best when you let it surprise you.","Mateo"] , attachment:'lisbon-slow-guide.pdf', size:'2.1 MB'},
- {id:5, initials:'ED', color:'#eee1c6', sender:'Eden Foster', email:'eden@paperandpine.com', subject:'Thank you for yesterday', snippet:'Still thinking about the conversation and the lemon cake. Both were exactly what I needed.', time:'Oct 2', date:'Oct 2, 2026', unread:false, star:false, tags:['Personal'], body:["Mira,","Still thinking about our conversation and the lemon cake. Both were exactly what I needed. Thank you for making an ordinary Thursday feel like a small holiday.","I hope your weekend is full of slow breakfasts and absolutely no urgent emails.","Eden"]},
- {id:6, initials:'NB', color:'#d9d8ec', sender:'Noah Bennett', email:'noah@common-thread.org', subject:'Community garden — October notes', snippet:'The first seedlings are in, and our corner of the neighborhood is already greener.', time:'Oct 2', date:'Oct 2, 2026', unread:false, star:true, tags:['Personal'], body:["Hi everyone,","The first autumn seedlings are in and our corner of the neighborhood is already greener. Thank you to everyone who brought tools, snacks, and patient hands.","Next gathering is Sunday at ten. All levels of gardening optimism are welcome.","Noah"]},
- {id:7, initials:'IR', color:'#ead6d4', sender:'Iris Rowe', email:'iris@littlefern.press', subject:'The book you left at my place', snippet:'I’ve tucked in a note at the page where I stopped. You’ll know why when you get there.', time:'Oct 1', date:'Oct 1, 2026', unread:false, star:false, tags:['Personal'], body:["Hey you,","I’ve tucked a note in at the page where I stopped. You’ll know why when you get there. No rush returning it — I think this one likes a slow reader.","I’ll be home Sunday if you want to pick it up and stay for tea.","Iris"]},
- {id:8, initials:'AI', color:'#d6e3d9', sender:'Aster Intelligence', email:'updates@aster.ai', subject:'Your September reflections', snippet:'A small look back at what you made space for this month. Here’s to a softer October.', time:'Sep 30', date:'Sep 30, 2026', unread:false, star:false, tags:['Personal'], body:["September, in little moments","This month you spent more time outdoors, caught up with people you love, and made room for a new idea. That’s something worth keeping.","Here’s to a softer October — one with space for the things you haven’t thought of yet.","Aster"]}
-];
-const contacts=[['Amelia Laurent','amelia@northstar.design','Design partner','AL','#ead1c1'],['Jonah Kim','jonah@fieldnotes.co','Friend','JK','#d8e3d4'],['Sofia Park','sofia@smallhours.works','Creative director','SP','#e8d9e9'],['Mateo Rivera','mateo@roam.travel','Travel planner','MR','#d9e4e9'],['Eden Foster','eden@paperandpine.com','Friend','ED','#eee1c6'],['Noah Bennett','noah@common-thread.org','Garden club','NB','#d9d8ec'],['Iris Rowe','iris@littlefern.press','Friend','IR','#ead6d4']];
+const messages = [];
+const contacts=[];
let activeMessage=1,activeFolder='Inbox',activeView='mail',query='',toastTimer,selectedIds=new Set();
const $=s=>document.querySelector(s), $$=s=>[...document.querySelectorAll(s)];
function esc(x){return String(x).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}
-function renderList(){let rows=messages.filter(m=>{if(activeFolder==='Starred'&&!m.star)return false;if(activeFolder==='Inbox'&&m.archived)return false;if(activeFolder==='Archive'&&!m.archived)return false;if(activeFolder==='Trash'&&!m.deleted)return false;if(activeFolder==='Sent'&&!m.sent)return false;if(activeFolder==='Drafts')return false;if(activeFolder==='Snoozed')return false;if(m.deleted&&activeFolder!=='Trash')return false;return !query||`${m.sender} ${m.email} ${m.subject} ${m.snippet}`.toLowerCase().includes(query.toLowerCase())});$('#message-list').innerHTML=rows.length?rows.map(m=>`
`;$('#reader-archive').onclick=()=>{m.archived=true;toast('Moved to Archive');renderList();$('#reader-pane').innerHTML=emptyReader()};$('#reader-delete').onclick=()=>{m.deleted=true;toast('Moved to Trash');renderList();$('#reader-pane').innerHTML=emptyReader()};$('#reader-star').onclick=()=>{m.star=!m.star;renderList();openMessage(id)};$('#reply').onclick=()=>showCompose(m);$('#forward').onclick=()=>showCompose(m,true)}
function emptyReader(){return `
✉
Your inbox, at your pace
Select a message to read it here.
`}
function toast(s){const el=$('#toast');el.textContent=s;el.classList.add('visible');clearTimeout(toastTimer);toastTimer=setTimeout(()=>el.classList.remove('visible'),2300)}
-function showCompose(reply,forward=false){const root=$('#modal-root');root.innerHTML=`
${reply?(forward?'Forward message':'Reply to message'):'New message'}
`;const close=()=>root.innerHTML='';$('.modal-close').onclick=close;$('#discard').onclick=close;$('.modal-overlay').addEventListener('click',e=>{if(e.target.classList.contains('modal-overlay'))close()});$('#send').onclick=()=>{const to=$('#compose-to').value.trim();if(!to){$('#compose-to').focus();toast('Add a recipient to send your message');return}const subject=$('#compose-subject').value.trim()||'(no subject)';const body=$('#compose-body').value;messages.unshift({id:Date.now(),initials:'MS',color:'#dce9dd',sender:'Mira Sol',email:'mira@daybreak.studio',subject,snippet:body||'No message text',time:'Just now',date:'Today',unread:false,star:false,tags:['Sent'],body:body.split('\n').filter(Boolean)});close();toast('Message sent');renderList()};$('#compose-to').focus()}
+function showCompose(reply,forward=false){const root=$('#modal-root');root.innerHTML=`
${reply?(forward?'Forward message':'Reply to message'):'New message'}
`;const close=()=>root.innerHTML='';$('.modal-close').onclick=close;$('#discard').onclick=close;$('.modal-overlay').addEventListener('click',e=>{if(e.target.classList.contains('modal-overlay'))close()});$('#send').onclick=()=>{const to=$('#compose-to').value.trim();if(!to){$('#compose-to').focus();toast('Add a recipient to send your message');return}const subject=$('#compose-subject').value.trim()||'(no subject)';const body=$('#compose-body').value;messages.unshift({id:Date.now(),initials:(profileSettings.name||connectedMailAccount?.email?.split('@')[0]||'Me').split(/\\s+/).map(x=>x[0]).join('').slice(0,2).toUpperCase(),color:'#dce9dd',sender:(profileSettings.name||connectedMailAccount?.email?.split('@')[0]||'Me'),email:(connectedMailAccount?.email||''),subject,snippet:body||'No message text',time:'Just now',date:'Today',unread:false,star:false,sent:true,tags:['Sent'],body:body.split('\n').filter(Boolean)});close();toast('Message sent');renderList()};$('#compose-to').focus()}
function switchView(view){activeView=view;$$('.rail-button[data-view]').forEach(b=>b.classList.toggle('active',b.dataset.view===view));$('.mail-layout').classList.toggle('hidden',view!=='mail');$('#calendar-view').classList.toggle('hidden',view!=='calendar');$('#contacts-view').classList.toggle('hidden',view!=='contacts');$('#sidebar-title').textContent=view==='mail'?activeFolder:view==='calendar'?'Calendar':'Contacts';$('#crumb-parent').textContent=view==='mail'?'Mail':'Workspace';$('#crumb-current').textContent=view==='mail'?activeFolder:view==='calendar'?'Calendar':'Contacts';}
-function renderCalendar(){const days=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];const start=new Date(2026,9,1);const offset=start.getDay();const events={4:[['10:00','Studio catch-up','green'],[14,'A little time outside','gold']],7:[['11:30','Design review','blue']],11:[['09:00','Coffee with Jonah','gold'],[15,'Focus time','green']],15:[['13:00','Spring launch','blue']],18:[['10:00','Community garden','green']],22:[['16:00','Lisbon planning','gold']],27:[['09:30','Studio catch-up','blue']]};let cells='';for(let i=0;i<35;i++){const n=i-offset+1,valid=n>0&&n<=31,items=events[n]||[];cells+=`
${valid?n:''}${items.map(it=>`
${esc(it[1])}
`).join('')}
`}$('#calendar-view').innerHTML=`
YOUR TIME, WITH ROOM TO BREATHE
October 2026
A month that still has room for surprises.
${days.map(d=>`${d}`).join('')}
${cells}
Coming up
OCT 07
Design review11:30 AM · with Sofia Park
OCT 11
Coffee with Jonah9:00 AM · Little Fern Café
`;$('#new-event').onclick=()=>showEvent();$('#today-btn').onclick=()=>toast('You’re looking at this month');$('#prev-month').onclick=()=>toast('Previous month');$('#next-month').onclick=()=>toast('Next month');$$('.cal-cell').forEach(c=>c.onclick=e=>{if(e.target.closest('.event-chip'))toast(e.target.closest('.event-chip').dataset.event);else if(c.dataset.day)showEvent(c.dataset.day)})}
-function showEvent(day){const root=$('#modal-root');root.innerHTML=`
Make a little room for it
`;$$('.modal-close').forEach(b=>b.onclick=()=>root.innerHTML='');$('#save-event').onclick=()=>{const name=$('#event-name').value.trim();if(!name){$('#event-name').focus();toast('Give your event a name');return}root.innerHTML='';toast('Event added to your calendar') }}
-function renderContacts(){const cards=contacts.map(c=>`
${c[3]}
${esc(c[0])}${esc(c[1])}${esc(c[2])}
`).join('');$('#contacts-view').innerHTML=`
THE PEOPLE WHO MAKE LIFE FULLER
Your people
${contacts.length} familiar faces, all in one place.