:root{
  --blue:#0a84ff; --navy:#0a1f44; --bg:#f2f2f7; --gray:#e9e9eb;
  --text:#1c1c1e; --muted:#8e8e93; --border:#d1d1d6; --card:#ffffff;
}
*{box-sizing:border-box}
html,body{margin:0;padding:0;height:100%}
body{font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:var(--bg);color:var(--text)}
#app{max-width:780px;margin:0 auto;height:100dvh;display:flex;flex-direction:column;background:var(--bg)}
#topbar{height:58px;background:#fff;border-bottom:1px solid var(--border);display:flex;align-items:center;gap:10px;padding:0 12px;flex:none}
#backBtn{border:0;background:none;font-size:32px;line-height:1;color:var(--blue);cursor:pointer;padding:0 6px}
.avatar-wrap{position:relative;border:0;background:none;padding:0;cursor:default;width:40px;height:40px;flex:none}
.avatar-wrap img{width:40px;height:40px;border-radius:50%;object-fit:cover;display:block}
#ownerMonogram{display:flex;align-items:center;justify-content:center;width:40px;height:40px;border-radius:50%;background:var(--navy);color:#fff;font-size:20px;font-weight:600}
#avatarBadge{position:absolute;right:-2px;bottom:-2px;background:#fff;border-radius:50%;font-size:12px;line-height:1;padding:2px}
.title{flex:1;text-align:center;min-width:0}
#ownerName{font-size:16px;font-weight:600;color:var(--navy);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.title .sub{font-size:12px;color:var(--muted)}
.spacer{width:40px;flex:none}
#visitorInfo{display:flex;align-items:center;gap:10px;background:#fff;border-bottom:1px solid var(--border);padding:8px 14px;flex:none}
#visitorInfo img,#visitorMonogram{width:36px;height:36px;border-radius:50%;object-fit:cover;flex:none}
#visitorMonogram{display:flex;align-items:center;justify-content:center;background:#c7c7cc;color:#fff;font-weight:600;font-size:16px}
.vinfo{min-width:0}
#visitorNameLine{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#visitorEmailLine{font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#ownerWrap{flex:1;display:flex;min-height:0}
#threadList{flex:1;overflow-y:auto;background:#fff;border-right:1px solid var(--border)}
#chatPane{flex:1;display:flex;flex-direction:column;min-width:0;min-height:0}
.thread-row{display:flex;gap:10px;align-items:center;padding:12px 14px;border-bottom:1px solid #ececee;cursor:pointer;width:100%;border-left:0;border-right:0;border-top:0;background:#fff;text-align:left;font:inherit}
.thread-row.active{background:#eef5ff}
.thread-row img,.thread-row .tmono{width:42px;height:42px;border-radius:50%;object-fit:cover;flex:none}
.thread-row .tmono{display:flex;align-items:center;justify-content:center;background:#c7c7cc;color:#fff;font-weight:600}
.thread-row .tmain{flex:1;min-width:0}
.thread-row .tname{font-weight:600;font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.thread-row .tprev{font-size:13px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.thread-row .tmeta{text-align:right;flex:none}
.thread-row .ttime{font-size:11px;color:var(--muted)}
.unread-badge{display:inline-block;min-width:20px;height:20px;border-radius:10px;background:var(--blue);color:#fff;font-size:12px;line-height:20px;text-align:center;padding:0 6px;margin-top:4px}
.empty{padding:24px;text-align:center;color:var(--muted);font-size:14px}
#messages{flex:1;overflow-y:auto;padding:16px 14px;display:flex;flex-direction:column;gap:6px}
.msg-row{display:flex;align-items:flex-end;gap:7px;max-width:100%}
.msg-row.sent{justify-content:flex-end}
.msg-row.received{justify-content:flex-start}
.msg-avatar{width:28px;height:28px;border-radius:50%;object-fit:cover;flex:none}
.msg-mono{width:28px;height:28px;border-radius:50%;background:var(--navy);color:#fff;display:flex;align-items:center;justify-content:center;font-size:13px;font-weight:600;flex:none}
.msg-col{display:flex;flex-direction:column;max-width:74%}
.bubble{padding:8px 12px;border-radius:18px;font-size:16px;line-height:1.35;word-break:break-word;white-space:pre-wrap}
.sent .bubble{background:var(--blue);color:#fff;border-bottom-right-radius:4px}
.received .bubble{background:var(--gray);color:var(--text);border-bottom-left-radius:4px}
.receipt{font-size:11px;color:var(--muted);text-align:right;padding:2px 6px 0 0}
.msg-row.received .receipt{text-align:left;padding:2px 0 0 6px}
.bubble img.attach{display:block;max-width:230px;border-radius:12px}
.file-chip{display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none;font-size:14px}
.voice{display:flex;align-items:center;gap:8px;min-width:170px}
.voice button{border:0;background:rgba(255,255,255,.25);color:#fff;width:30px;height:30px;border-radius:50%;cursor:pointer;font-size:13px;flex:none}
.received .voice button{background:rgba(0,0,0,.08);color:var(--text)}
.wave{display:flex;align-items:center;gap:2px;height:22px;flex:1}
.wave i{display:block;width:3px;border-radius:2px;background:currentColor;opacity:.85}
.voice .dur{font-size:12px;opacity:.85;flex:none}
.card{background:var(--card);border:1px solid var(--border);border-radius:14px;padding:14px;margin:4px 0}
#welcomeCard .bubble{margin-bottom:10px}
.welcome-btns{display:flex;gap:8px;flex-wrap:wrap}
.chip{border:1.5px solid var(--blue);color:var(--blue);background:#fff;border-radius:999px;padding:8px 16px;font-size:15px;cursor:pointer}
.chip:active{background:#eef5ff}
.details-title{font-weight:600;font-size:16px}
.details-sub{font-size:13px;color:var(--muted);margin:2px 0 10px}
.field{display:block;margin-bottom:10px}
.field span{display:block;font-size:13px;color:var(--muted);margin-bottom:4px}
.field input{width:100%;border:1px solid var(--border);border-radius:10px;padding:10px 12px;font-size:16px;font:inherit}
.photo-row{display:flex;align-items:center;gap:10px;margin-bottom:12px;font-size:15px}
.photo-row span{flex:1}
#dPhotoBtn{border:1.5px solid var(--blue);color:var(--blue);background:#fff;border-radius:999px;padding:7px 14px;font-size:14px;cursor:pointer}
#dPhotoPreview{width:44px;height:44px;border-radius:50%;object-fit:cover}
#dSubmit{width:100%;border:0;background:var(--blue);color:#fff;border-radius:999px;padding:11px;font-size:16px;cursor:pointer}
#waitingNote{font-size:13px;color:var(--muted);text-align:center;padding:6px 18px}
#composer{flex:none;background:#fff;border-top:1px solid var(--border);padding:8px 10px calc(8px + env(safe-area-inset-bottom));position:relative}
#tray{display:flex;gap:8px;margin-bottom:8px}
.tray-btn{flex:1;border:1px solid var(--border);background:#f9f9fb;border-radius:12px;padding:10px;font-size:14px;cursor:pointer}
#emojiPop{position:absolute;left:10px;right:10px;bottom:calc(100% + 6px);background:#fff;border:1px solid var(--border);border-radius:14px;padding:10px;display:grid;grid-template-columns:repeat(6,1fr);gap:4px;box-shadow:0 6px 24px rgba(0,0,0,.12);z-index:5}
#emojiPop button{border:0;background:none;font-size:24px;cursor:pointer;padding:6px}
.composer-row{display:flex;align-items:flex-end;gap:6px}
#plusBtn,#emojiBtn,#micBtn{width:36px;height:36px;flex:none;border-radius:50%;border:0;background:#f0f0f3;font-size:20px;cursor:pointer;color:#333}
#msgInput{flex:1;resize:none;border:1px solid var(--border);border-radius:18px;padding:9px 12px;font-size:16px;font:inherit;max-height:120px;outline:none}
#sendBtn{width:36px;height:36px;flex:none;border-radius:50%;border:0;background:var(--blue);color:#fff;font-size:18px;cursor:pointer}
#recBar{display:flex;align-items:center;gap:10px;padding:6px 2px 10px}
.rec-dot{width:10px;height:10px;border-radius:50%;background:#ff3b30;animation:pulse 1s infinite}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}
#recTime{font-size:14px;font-variant-numeric:tabular-nums}
.rec-wave{display:flex;align-items:center;gap:2px;height:20px;flex:1}
.rec-wave i{display:block;width:3px;height:10px;border-radius:2px;background:var(--blue);animation:wb 0.8s infinite ease-in-out}
.rec-wave i:nth-child(2){animation-delay:.1s}.rec-wave i:nth-child(3){animation-delay:.2s}.rec-wave i:nth-child(4){animation-delay:.3s}.rec-wave i:nth-child(5){animation-delay:.4s}.rec-wave i:nth-child(6){animation-delay:.5s}.rec-wave i:nth-child(7){animation-delay:.6s}
@keyframes wb{0%,100%{height:6px}50%{height:18px}}
#recCancel{border:1px solid var(--border);background:#fff;border-radius:999px;padding:7px 12px;cursor:pointer}
#recSend{border:0;background:var(--blue);color:#fff;border-radius:999px;padding:8px 14px;cursor:pointer}
@media (max-width:820px){
  #threadList{border-right:0}
  body.owner-list #chatPane{display:none}
  body:not(.owner-list) #threadList{display:none}
}
@media (min-width:821px){
  #ownerWrap #threadList{flex:0 0 300px}
  #backBtn{display:none}
}
