*{box-sizing:border-box}
html,body{height:100%;margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;background:#e9f2f8;color:#16303f}
.hidden{display:none!important}
button,input{font:inherit}
button{cursor:pointer}
.icon{background:none;border:0;color:inherit;font-size:20px;padding:6px 10px}
#auth{height:100%;display:flex;align-items:center;justify-content:center;background:#2878a8}
#authForm{background:#fff;padding:28px;border-radius:12px;width:min(92vw,360px);display:flex;flex-direction:column;gap:10px}
#authForm h1{margin:0 0 6px;color:#16303f;font-size:22px}
#authForm .logo{width:84px;height:84px;align-self:center;border-radius:8px}
#authForm input{padding:11px;border:1px solid #ccc;border-radius:8px}
#authForm button{padding:11px;border:0;border-radius:8px;background:#2878a8;color:#fff;font-weight:600}
#authForm a{font-size:14px;color:#1f6f9f;text-align:center}
.err{color:#c0392b;margin:0;min-height:1em;font-size:14px}
#app{height:100%;display:flex;flex-direction:column}
#chatView{flex:1;display:flex;min-height:0}
#side{width:340px;max-width:100%;background:#fff;border-right:1px solid #ddd;display:flex;flex-direction:column}
#side header,#chatHead{background:#2878a8;color:#fff;padding:calc(10px + env(safe-area-inset-top)) 12px 10px;display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:56px}
#chatHead{justify-content:flex-start}
#chatSub{font-size:12px;opacity:.8;min-height:1em}
#back{display:none;font-size:28px;line-height:1}
#search{margin:8px;padding:9px 12px;border:1px solid #ddd;border-radius:20px;background:#f0f2f5}
#list{flex:1;overflow-y:auto}
.item{padding:12px 14px;border-bottom:1px solid #f0f0f0;display:flex;align-items:center;gap:10px;cursor:pointer}
.item:hover,.item.active{background:#f0f2f5}
.avatar{width:40px;height:40px;border-radius:50%;background:#3398cc;color:#fff;display:flex;align-items:center;justify-content:center;font-weight:600;flex:none;position:relative}
.avatar.on::after{content:"";position:absolute;right:0;bottom:0;width:11px;height:11px;border-radius:50%;background:#25d366;border:2px solid #fff}
.item .name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.badge{background:#2878a8;color:#fff;border-radius:11px;min-width:22px;padding:2px 7px;font-size:12px;text-align:center}
.side-actions{display:flex;gap:8px;padding:8px;padding-bottom:calc(8px + env(safe-area-inset-bottom));border-top:1px solid #eee}
.side-actions button{flex:1;padding:9px;border:1px solid #2878a8;color:#2878a8;background:#fff;border-radius:8px}
#main{flex:1;display:flex;flex-direction:column;min-width:0;background:#e9f2f8}
#msgs{flex:1;overflow-y:auto;padding:12px 8%;display:flex;flex-direction:column;gap:3px}
.msg{max-width:75%;padding:6px 9px;border-radius:8px;background:#fff;align-self:flex-start;box-shadow:0 1px 1px rgba(0,0,0,.12);word-wrap:break-word;overflow-wrap:anywhere;white-space:pre-wrap}
.msg.me{align-self:flex-end;background:#d3eaf7}
.msg .who{font-size:12px;font-weight:600;color:#1f6f9f}
.msg .time{font-size:11px;color:#5b6f7d;text-align:right;margin-top:2px}
.msg img{max-width:100%;max-height:300px;border-radius:6px;display:block;margin:2px 0}
.msg a.file{display:block;padding:8px;background:rgba(0,0,0,.05);border-radius:6px;color:#1f6f9f;text-decoration:none}
.day{align-self:center;background:#e1f2fb;color:#555;font-size:12px;padding:3px 10px;border-radius:8px;margin:8px 0}
#typing{height:18px;padding:0 8%;font-size:12px;color:#5b6f7d}
#composer{display:flex;align-items:center;gap:6px;padding:8px;padding-bottom:calc(8px + env(safe-area-inset-bottom));background:#f0f2f5}
#text{flex:1;padding:11px 14px;border:0;border-radius:22px}
.send{border:0;background:#3398cc;color:#fff;border-radius:50%;width:42px;height:42px}
.attach{cursor:pointer}
#modal{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:center;justify-content:center;z-index:10}
#modalBox{background:#fff;border-radius:12px;padding:18px;width:min(92vw,420px);max-height:80vh;overflow:auto}
#modalBox h3{margin-top:0}
#modalBox input{width:100%;padding:10px;border:1px solid #ccc;border-radius:8px;margin:6px 0}
#modalBox button{padding:9px 14px;margin:4px 4px 0 0;border:0;border-radius:8px;background:#3398cc;color:#fff}
#modalBox button.sec{background:#eee;color:#333}
#modalBox .row{padding:10px;border-bottom:1px solid #eee;cursor:pointer}
#modalBox .row:hover{background:#f5f5f5}
@media (max-width:760px){
  #side{width:100%}
  #main{position:fixed;inset:0;transform:translateX(100%);transition:transform .2s;z-index:5}
  body.chat-open #main{transform:none}
  #back{display:block}
  #msgs{padding:10px 10px}
  .msg{max-width:88%}
}

#modalBox.wide{width:min(94vw,640px)}
.tabs{display:flex;gap:6px;margin-bottom:10px}
#modalBox .tabs button{background:#e9f2f8;color:#16303f}
#modalBox .tabs button.active{background:#2878a8;color:#fff}
.muted{color:#5b6f7d;font-size:13px}
.note{background:#eef6fb;border-left:3px solid #3398cc;padding:8px 10px;font-size:13px;word-break:break-word;margin:8px 0}
.invite{background:#f4f8fb;border-radius:8px;padding:10px;margin-bottom:8px}
.invite code{background:#fff;border:1px solid #cfe3f0;border-radius:4px;padding:2px 6px;user-select:all;word-break:break-all}
.urow{display:flex;justify-content:space-between;gap:8px;align-items:center;flex-wrap:wrap;padding:10px 0;border-bottom:1px solid #eee}
.urow.off .uinfo{opacity:.55}
.uact{display:flex;gap:4px;flex-wrap:wrap}
#modalBox button.small{padding:6px 10px;font-size:13px;margin:0;background:#2878a8}
#modalBox button.small.sec{background:#eee;color:#333}

.muted.center{text-align:center;margin:0}
#modalBox .invite input{margin:6px 0}

/* bottom menu */
#tabbar{display:flex;background:#fff;border-top:1px solid #d9e6ee;padding-bottom:env(safe-area-inset-bottom);z-index:4;flex:none}
#tabbar button{flex:1;background:none;border:0;padding:8px 0 6px;display:flex;flex-direction:column;align-items:center;gap:2px;color:#5b6f7d;font-size:11px;position:relative}
#tabbar button.active{color:#2878a8;font-weight:600}
#tabbar svg{width:26px;height:26px}
#tabbar button.active svg path:first-child,#tabbar button.active svg rect{fill:rgba(51,152,204,.18)}
.tbadge{position:absolute;top:3px;left:calc(50% + 8px);background:#2878a8;color:#fff;border-radius:9px;min-width:18px;font-size:11px;padding:1px 5px;text-align:center;font-weight:600}
/* calendar */
#calView{flex:1;display:flex;flex-direction:column;min-height:0;background:#e9f2f8}
.calhead{background:#2878a8;color:#fff;padding:calc(10px + env(safe-area-inset-top)) 14px 10px;display:flex;justify-content:space-between;align-items:center;min-height:56px}
.calhead .sub{font-size:12px;opacity:.85}
.calhead button{border:1px solid rgba(255,255,255,.75);background:transparent;color:#fff;border-radius:16px;padding:5px 14px}
.legend{display:flex;gap:6px 14px;flex-wrap:wrap;padding:8px 14px;background:#fff;border-bottom:1px solid #d9e6ee;font-size:12px;color:#16303f}
.sw{display:inline-block;width:14px;height:14px;border-radius:3px;vertical-align:-3px;margin-right:5px}
.sw.hol{border:2px solid #d63a2f;background:#fdecea}
.sw.end{background:#2878a8}
.sw.today{border:2px solid #3398cc;background:#fff}
#calScroll{flex:1;overflow-y:auto;padding:12px;position:relative;-webkit-overflow-scrolling:touch}
.month{background:#fff;border-radius:12px;padding:12px;box-shadow:0 1px 2px rgba(0,0,0,.08);max-width:640px;margin:0 auto 14px}
.month h3{margin:0 0 8px;color:#16303f;font-size:17px}
.grid{display:grid;grid-template-columns:repeat(7,1fr);gap:3px;text-align:center}
.dow{font-size:11px;color:#5b6f7d;font-weight:600;padding:2px 0}
.cd{aspect-ratio:1/1;display:flex;align-items:center;justify-content:center;border-radius:8px;font-size:14px;color:#16303f;border:2px solid transparent}
.cd.empty{visibility:hidden}
.cd.we{color:#5b6f7d;background:#f3f7fa}
.cd.hol{border-color:#d63a2f;background:#fdecea;color:#8a1f17;font-weight:600}
.cd.end{background:#2878a8;color:#fff;font-weight:700}
.cd.after{opacity:.4}
.cd.today{border-color:#3398cc;font-weight:700;box-shadow:0 0 0 1px #3398cc}
.cd.today.hol{border-color:#d63a2f}
.mevents{margin-top:8px;border-top:1px solid #eef3f7;padding-top:6px;font-size:13px;color:#16303f}
.mevents div{padding:2px 0}
.mevents .dot{display:inline-block;width:10px;height:10px;border-radius:3px;margin-right:7px;vertical-align:-1px}
.mevents .dot.holiday{border:2px solid #d63a2f;background:#fdecea}
.mevents .dot.end{background:#2878a8}

.sw.tiel{border:2px solid #e07a1f;background:#fff1e3}
.cd.tiel{border-color:#e07a1f;background:#fff1e3;color:#8a4a0a;font-weight:600}
.mevents .dot.tielmes{border:2px solid #e07a1f;background:#fff1e3}
