:root{
  --bg:#EEF1EC; --surface:#FBFCF9; --ink:#1D2A30; --muted:#5D6B70; --line:#D5DCD6;
  --work:#3B5B92; --work-soft:#DDE4F1;
  --travel:#1F8473; --travel-soft:#D3EDE7;
  --fun:#BC3F74; --fun-soft:#F5DBE6;
  --bday:#C2410C; --bday-soft:#FBE3D2;
  --today:#1D2A30; --onink:#FBFCF9;
  --ken:#1F6FE0; --linn:#E0356F; --both:#D99400;
  --shadow:0 10px 30px rgba(29,42,48,.12);
  color-scheme:light;
  box-sizing:border-box;
  padding-top:env(safe-area-inset-top,0px);
  padding-bottom:env(safe-area-inset-bottom,0px);
}
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]){
    --bg:#141B1E; --surface:#1C2529; --ink:#E7ECE8; --muted:#9AA8AB; --line:#2E3A3F;
    --work:#86A4DC; --work-soft:#26324A; --travel:#5CC5B1; --travel-soft:#1E3A35;
    --fun:#E98AB2; --fun-soft:#43263A; --bday:#F59E6B; --bday-soft:#46281A; --today:#E7ECE8; --onink:#141B1E;
    --ken:#6AA6FF; --linn:#FF7AA6; --both:#F2C14E;
    --shadow:0 10px 30px rgba(0,0,0,.45); color-scheme:dark;
  }
}
:root[data-theme="dark"]{
  --bg:#141B1E; --surface:#1C2529; --ink:#E7ECE8; --muted:#9AA8AB; --line:#2E3A3F;
  --work:#86A4DC; --work-soft:#26324A; --travel:#5CC5B1; --travel-soft:#1E3A35;
  --fun:#E98AB2; --fun-soft:#43263A; --bday:#F59E6B; --bday-soft:#46281A; --today:#E7ECE8; --onink:#141B1E;
  --ken:#6AA6FF; --linn:#FF7AA6; --both:#F2C14E;
  --shadow:0 10px 30px rgba(0,0,0,.45); color-scheme:dark;
}
*,*::before,*::after{box-sizing:inherit}
html{height:100%;scroll-padding-top:env(safe-area-inset-top,0px)}
body{margin:0;min-height:100%;background:var(--bg);color:var(--ink);font:16px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-tap-highlight-color:transparent}
button,input,select,textarea{font:inherit;color:inherit}
button{cursor:pointer}
:focus-visible{outline:3px solid var(--travel);outline-offset:2px}
.wrap{max-width:980px;margin:0 auto;padding:20px 16px 120px}
h1{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-weight:800;font-size:clamp(2rem,6vw,3.2rem);line-height:1;letter-spacing:-.02em;margin:8px 0 4px}
.sub{color:var(--muted);margin:0 0 20px}

/* Quick add */
.quick{background:var(--surface);border:1px solid var(--line);border-radius:22px;padding:10px;display:flex;gap:8px;align-items:flex-end;box-shadow:var(--shadow);position:relative}
.quick input{flex:1;min-width:0;border:0;background:transparent;padding:12px 10px;font-size:1.05rem;outline:none}
.quick input::placeholder{color:var(--muted)}
.mic{width:48px;height:48px;border-radius:50%;border:1px solid var(--line);background:var(--bg);display:grid;place-items:center;flex:none}
.mic svg{width:22px;height:22px}
.mic.on{background:var(--fun);border-color:var(--fun);color:#fff;animation:pulse 1.4s infinite}
@keyframes pulse{0%{box-shadow:0 0 0 0 rgba(188,63,116,.5)}100%{box-shadow:0 0 0 14px rgba(188,63,116,0)}}
@media (prefers-reduced-motion:reduce){.mic.on{animation:none}}
.go{height:48px;padding:0 18px;border-radius:24px;border:0;background:var(--ink);color:var(--onink);font-weight:600;flex:none}
.go[disabled]{opacity:.5;cursor:default}
.hint{font-size:.88rem;color:var(--muted);margin:8px 6px 0;min-height:1.4em}
.hint.err{color:var(--fun)}
.quick textarea{flex:1;min-width:0;border:0;background:transparent;padding:12px 10px;font-size:1.05rem;line-height:1.4;outline:none;resize:none;max-height:40vh}
.quick textarea::placeholder{color:var(--muted)}
.pv{max-height:38vh;overflow:auto;border:1px solid var(--line);border-radius:12px;margin:12px 0 4px}
.pv div{display:flex;justify-content:space-between;gap:12px;padding:8px 12px;border-bottom:1px solid var(--line);font-size:.92rem}
.pv div:last-child{border-bottom:0}
.pv b{font-weight:600}
.pv span{color:var(--muted);text-align:right}
.pv .rr{display:flex;align-items:center;gap:6px}
.pv .rm{border:0;background:transparent;color:var(--muted);width:30px;height:30px;border-radius:50%;flex:none}
.pv .rm:hover{background:var(--bg);color:var(--fun)}

/* Toolbar */
.bar{display:flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between;margin:26px 0 12px}
.month{display:flex;align-items:center;gap:6px}
.month h2{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-weight:700;font-size:1.5rem;margin:0 6px;min-width:9.5ch;text-transform:capitalize}
.nav{width:38px;height:38px;border-radius:50%;border:1px solid var(--line);background:var(--surface)}
.todaybtn{height:38px;padding:0 14px;border-radius:19px;border:1px solid var(--line);background:var(--surface)}
.chips{display:flex;gap:6px;flex-wrap:wrap}
.chip{height:36px;padding:0 14px;border-radius:18px;border:1.5px solid var(--c);background:transparent;color:var(--ink);display:flex;align-items:center;gap:7px;font-weight:500}
.chip::before{content:"";width:10px;height:10px;border-radius:50%;background:var(--c)}
.chip[aria-pressed="false"]{opacity:.45;border-style:dashed}
.chip.plain{border-color:var(--line)}
.chip.plain::before{display:none}
.filters{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.seg{display:flex;border:1px solid var(--line);border-radius:18px;padding:2px;background:var(--surface)}
.seg button{height:32px;padding:0 12px;border-radius:16px;border:0;background:transparent;font-size:.9rem;color:var(--muted)}
.seg button[aria-pressed="true"]{background:var(--ink);color:var(--onink);font-weight:600}
.ev .pb{margin-left:auto;flex:none;min-width:30px;height:24px;padding:0 8px;border-radius:12px;background:var(--c);color:var(--onink);font-size:.75rem;font-weight:700;display:grid;place-items:center}

/* Grid */
.layout{display:grid;grid-template-columns:1.35fr 1fr;gap:18px;align-items:start}
@media (max-width:760px){.layout{grid-template-columns:1fr}}
.cal{background:var(--surface);border:1px solid var(--line);border-radius:18px;padding:10px}
.dow,.days{display:grid;grid-template-columns:repeat(7,1fr);gap:4px}
.dow div{font-size:.78rem;color:var(--muted);text-align:center;padding:4px 0}
.day{min-height:66px;border-radius:12px;border:1px solid transparent;background:transparent;padding:5px 4px;display:flex;flex-direction:column;align-items:center;gap:3px;min-width:0}
.day .n{font-weight:600;font-size:.95rem;width:28px;height:28px;display:grid;place-items:center;border-radius:50%}
.day.out{opacity:.35}
.day.today .n{background:var(--today);color:var(--onink)}
.day.sel{border-color:var(--ink);background:var(--bg)}
.day:hover{background:var(--bg)}
.bars{display:flex;flex-direction:column;gap:2px;width:100%}
.bars span{height:5px;border-radius:3px;background:var(--c)}
.more{font-size:.7rem;color:var(--muted);line-height:1}
.icons{display:flex;flex-wrap:wrap;justify-content:center;gap:2px;width:100%}
.ico{font-size:.78rem;line-height:1;width:21px;height:21px;display:grid;place-items:center;border-radius:6px;background:color-mix(in srgb, var(--c) 20%, transparent);box-shadow:inset 0 -2.5px 0 var(--c)}
@media (max-width:480px){.ico{width:17px;height:17px;font-size:.66rem;border-radius:5px}}
.dbtn{text-align:left;cursor:pointer}
.dp{border:1px solid var(--line);border-radius:14px;padding:10px;margin-top:8px;background:var(--bg)}
.dph{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px}
.dph button{width:34px;height:34px;border-radius:50%;border:1px solid var(--line);background:var(--surface)}
.dpg{display:grid;grid-template-columns:repeat(7,1fr);gap:2px;text-align:center}
.dpg span{font-size:.75rem;color:var(--muted);padding:4px 0}
.dpg button{height:36px;border:0;border-radius:10px;background:transparent}
.dpg button:hover{background:var(--surface)}
.dpg button.td{font-weight:700;text-decoration:underline}
.dpg button.on{background:var(--ink);color:var(--onink)}
.dpc{margin-top:8px;width:100%;height:36px;border-radius:10px;border:1px dashed var(--line);background:transparent}

/* Agenda */
.side h3{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-size:1.15rem;margin:4px 0 10px}
.list{display:flex;flex-direction:column;gap:8px;margin-bottom:26px}
.ev{display:flex;gap:12px;align-items:flex-start;background:var(--surface);border:1px solid var(--line);border-left:6px solid var(--c);border-radius:14px;padding:10px 12px;text-align:left;width:100%}
.ev .when{font-size:.8rem;color:var(--muted);min-width:54px;padding-top:2px}
.ev .t{font-weight:600;line-height:1.3}
.ev .m{font-size:.85rem;color:var(--muted)}
.empty{color:var(--muted);font-size:.95rem;padding:12px 2px}

/* FAB */
.fab{position:fixed;right:max(20px,env(safe-area-inset-right,0px));bottom:calc(22px + env(safe-area-inset-bottom,0px));height:58px;padding:0 24px 0 20px;border-radius:29px;border:0;background:var(--travel);color:#fff;font-weight:600;font-size:1.02rem;box-shadow:var(--shadow);display:flex;align-items:center;gap:8px;z-index:5}
.fab span{font-size:1.6rem;line-height:1;margin-top:-2px}

/* Dialog */
dialog{border:0;border-radius:24px;padding:0;width:min(520px,calc(100% - 24px));background:var(--surface);color:var(--ink);box-shadow:var(--shadow)}
dialog::backdrop{background:rgba(20,27,30,.45)}
.dlg{padding:22px}
.dlg h3{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-size:1.4rem;margin:0 0 14px}
.cats{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-bottom:14px}
.cat{border:1.5px solid var(--line);border-radius:14px;padding:10px 6px;background:transparent;font-weight:600;display:flex;flex-direction:column;align-items:center;gap:4px}
.cat .ic{font-size:1.4rem}
.cat[aria-checked="true"]{border-color:var(--c);background:var(--cs)}
label{display:block;font-size:.85rem;color:var(--muted);margin:10px 0 4px}
.f{width:100%;border:1px solid var(--line);border-radius:12px;background:var(--bg);padding:11px 12px}
.row{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.who{display:flex;gap:6px}
.who button{flex:1;height:40px;border-radius:12px;border:1.5px solid var(--line);background:transparent;font-weight:500}
.who button[aria-checked="true"]{border-color:var(--ink);background:var(--bg);font-weight:600}
.acts{display:flex;gap:8px;justify-content:space-between;margin-top:20px}
.acts .r{display:flex;gap:8px;margin-left:auto}
.btn{height:44px;padding:0 18px;border-radius:22px;border:1px solid var(--line);background:transparent;font-weight:600}
.btn.pri{background:var(--ink);color:var(--onink);border-color:var(--ink)}
.btn.del{color:var(--fun);border-color:transparent}
.ro{background:var(--fun-soft);color:var(--ink);border-radius:12px;padding:10px 12px;font-size:.9rem;margin-bottom:14px}
.status{font-size:.85rem;color:var(--muted);margin-top:10px}

/* ---- self-hosted additions ---- */
.top{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
.userbtn{margin-top:12px;height:40px;padding:0 14px;border-radius:20px;border:1px solid var(--line);background:var(--surface);font-weight:600;display:flex;align-items:center;gap:8px;flex:none}
.userbtn .dot{width:10px;height:10px;border-radius:50%;background:var(--c)}
.menu{position:absolute;right:16px;top:64px;background:var(--surface);border:1px solid var(--line);border-radius:16px;box-shadow:var(--shadow);padding:6px;z-index:10;min-width:220px}
.menu button{display:block;width:100%;text-align:left;border:0;background:transparent;padding:10px 12px;border-radius:10px}
.menu button:hover{background:var(--bg)}
.menu p{margin:6px 12px 8px;font-size:.85rem;color:var(--muted)}
.wrap{position:relative}
.login{min-height:100vh;display:grid;place-items:center;padding:24px 16px}
.login form{width:min(380px,100%);background:var(--surface);border:1px solid var(--line);border-radius:24px;padding:26px;box-shadow:var(--shadow)}
.login h1{font-size:2.2rem;margin:0 0 6px}
.login .btn{width:100%;margin-top:18px}
.login .err{color:var(--fun);min-height:1.4em;margin:10px 0 0;font-size:.9rem}
.who-pick{display:flex;gap:8px;margin-top:4px}
.who-pick button{flex:1;height:52px;border-radius:14px;border:1.5px solid var(--line);background:transparent;font-weight:600;display:flex;align-items:center;justify-content:center;gap:8px}
.who-pick button .dot{width:12px;height:12px;border-radius:50%;background:var(--c)}
.who-pick button[aria-pressed="true"]{border-color:var(--c);background:var(--bg)}
.offline{background:var(--both);color:#1D2A30;border-radius:12px;padding:8px 12px;font-size:.9rem;margin:0 0 14px}
.meta{font-size:.82rem;color:var(--muted);margin:-4px 0 10px}
.cat{font-size:.9rem}
@media (max-width:420px){.cat{font-size:.78rem;padding:8px 2px}.cat .ic{font-size:1.2rem}}
[hidden]{display:none !important}
.month h2{white-space:nowrap}
@media (max-width:480px){.month h2{font-size:1.2rem;min-width:0;margin:0 2px}.month{gap:4px}}
dialog{max-height:calc(100dvh - 24px);overflow:auto;overscroll-behavior:contain}

/* ================= v2: phone-first layout ================= */
.wrap{max-width:640px;padding:calc(12px + env(safe-area-inset-top,0px)) 16px calc(40px + env(safe-area-inset-bottom,0px))}
.top{align-items:center;margin:4px 0 14px}
.datelabel{margin:0;color:var(--muted);font-size:.95rem;font-weight:500}
.hello{font-size:1.85rem;margin:2px 0 0;line-height:1.1;letter-spacing:-.02em}
.avatar{width:46px;height:46px;border-radius:50%;border:0;background:var(--c);color:#fff;font-weight:700;font-size:1rem;flex:none;display:grid;place-items:center}
.menu{top:66px}
.card{background:var(--surface);border:1px solid var(--line);border-radius:24px;padding:16px}
.sechead{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:10px}
.sechead h2{font-size:1.25rem;margin:0;font-weight:700;white-space:nowrap;min-width:0;text-transform:capitalize}
.tools{display:flex;gap:6px}
.ghost{height:34px;padding:0 12px;border-radius:17px;border:1px solid var(--line);background:transparent;font-weight:600;font-size:.88rem;white-space:nowrap}
.ghost[aria-pressed="true"],.ghost[aria-expanded="true"]{background:var(--ink);color:var(--onink);border-color:var(--ink)}
.today .list{margin:0;gap:8px}
.today .ev{background:var(--bg);border-color:transparent;padding:12px 14px}
.today .ev .when{font-size:.95rem;font-weight:600;color:var(--ink);min-width:62px}
.today .ev .t{font-size:1.05rem}
.today .empty{padding:6px 2px 2px}
.peek{margin:12px 2px 0;font-size:.9rem;color:var(--muted)}
.peek b{color:var(--ink);font-weight:600}

/* composer */
.quick{margin-top:14px;border-radius:30px;padding:6px;align-items:center;box-shadow:none}
.quick textarea{padding:10px 6px;font-size:1rem}
.mic{width:52px;height:52px;background:var(--travel);border:0;color:#fff}
.mic svg{width:24px;height:24px}
.go{width:44px;height:44px;padding:0;border-radius:50%;display:grid;place-items:center}
.go svg{width:22px;height:22px}
.hint{margin:8px 8px 0;min-height:0}
.hint:empty{display:none}

/* day picker */
.picker{margin-top:24px}
.picker .sechead{margin-bottom:8px}
.filters{display:flex;flex-direction:column;gap:8px;margin:0 0 12px}
.strip{display:flex;gap:6px;overflow-x:auto;scroll-snap-type:x proximity;padding:2px 2px 8px;margin:0 -16px;padding-left:16px;padding-right:16px;scrollbar-width:none;-webkit-overflow-scrolling:touch}
.strip::-webkit-scrollbar{display:none}
.sd{flex:none;width:54px;height:82px;border-radius:18px;border:1px solid var(--line);background:var(--surface);display:flex;flex-direction:column;align-items:center;justify-content:flex-start;padding:8px 0 6px;gap:2px;scroll-snap-align:center}
.sd .w{font-size:.72rem;color:var(--muted);font-weight:500}
.sd .n{font-size:1.15rem;font-weight:700;line-height:1.3}
.sd .dots{display:flex;gap:2px;margin-top:2px;min-height:16px;align-items:center}
.sd .dots span{font-size:.62rem;line-height:1;width:16px;height:16px;border-radius:5px;display:grid;place-items:center;background:color-mix(in srgb, var(--c) 22%, transparent)}
.sd.wk .w{color:var(--fun)}
.sd.today{border-color:var(--ink);border-width:2px}
.sd.sel{background:var(--ink);border-color:var(--ink)}
.sd.sel .w,.sd.sel .n{color:var(--onink)}
.sd.first{margin-left:10px;position:relative}
.sd.first::before{content:attr(data-m);position:absolute;left:-12px;top:-2px;font-size:.62rem;color:var(--muted);writing-mode:vertical-rl;transform:rotate(180deg);text-transform:uppercase;letter-spacing:.06em}
.cal{padding:10px;border-radius:20px}
.mnav{display:flex;justify-content:space-between;margin-bottom:6px}
.day{min-height:58px}

/* selected day + upcoming */
.daysel,.upcoming{margin-top:22px}
.daysel h3,.upcoming h3{font-size:1.1rem;margin:0 0 10px;font-weight:700}
.list{margin-bottom:0}
.status{margin-top:20px;text-align:center}
.layout,.bar,.fab{display:none}

@media (min-width:760px){
  .hello{font-size:2.3rem}
}
.today .ev{border-color:transparent;border-left:6px solid var(--c)}
