/* Chat widget, shared by the field collector page and the in-house agent page */
/* ---------- Chat ---------- */
.chat-fab {
  position: fixed; right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
  background: #0A84FF; color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.45); z-index: 30; transition: transform .15s ease;
}
.chat-fab:active { transform: scale(.92); }
.chat-fab:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.chat-fab.ring { animation: chatRing .9s ease both; }
.chat-notify {
  position: fixed; right: calc(84px + env(safe-area-inset-right)); bottom: calc(26px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 6px; z-index: 30; cursor: pointer;
  background: #2C2C2E; color: #fff; border: 1px solid #48484A; border-radius: 999px;
  font: inherit; font-size: 14px; font-weight: 600; padding: 9px 14px; box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
.chat-notify[hidden] { display: none; }
@keyframes chatRing { 0%,100% { transform: rotate(0); } 15%,45%,75% { transform: rotate(-14deg) scale(1.08); } 30%,60% { transform: rotate(14deg) scale(1.08); } }
.chat-badge {
  position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: #FF453A; color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.chat-badge[hidden] { display: none; }
.chat-panel {
  position: fixed; right: calc(18px + env(safe-area-inset-right)); bottom: calc(86px + env(safe-area-inset-bottom));
  width: min(380px, calc(100vw - 32px)); height: min(520px, calc(100vh - 120px));
  background: #1C1C1E; border: 1px solid #38383A; border-radius: 18px; z-index: 30;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 12px 40px rgba(0,0,0,.6);
  animation: pop .25s cubic-bezier(.2,.8,.2,1) both;
}
.chat-panel[hidden] { display: none; }
@media (max-width: 480px) {
  .chat-panel { right: 16px; left: 16px; width: auto; }
}
.chat-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid #38383A; }
.chat-head h3 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-icon-btn { background: none; border: none; color: #0A84FF; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; padding: 4px 6px; }
.chat-icon-btn[hidden] { display: none; }
a.chat-icon-btn { text-decoration: none; white-space: nowrap; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.chat-msgs[hidden] { display: none; }
.chat-empty { margin: auto; color: #8E8E93; font-size: 14px; text-align: center; padding: 0 20px; }
.chat-msg { max-width: 80%; padding: 8px 12px; border-radius: 16px; font-size: 15px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }
.chat-msg.them { align-self: flex-start; background: #2C2C2E; color: #fff; border-bottom-left-radius: 4px; }
.chat-msg.me { align-self: flex-end; background: #0A84FF; color: #fff; border-bottom-right-radius: 4px; }
.chat-msg time { display: block; margin-top: 3px; font-size: 11px; opacity: .65; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #38383A; }
.chat-form[hidden] { display: none; }
.chat-form textarea {
  flex: 1; resize: none; height: 40px; max-height: 120px; background: #2C2C2E; border: none; outline: none;
  color: #fff; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 20px;
}
.chat-form button {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
  background: #0A84FF; color: #fff; display: flex; align-items: center; justify-content: center;
}
.chat-form button:disabled { opacity: .4; cursor: default; }
.chat-threads { flex: 1; overflow-y: auto; }
.chat-threads[hidden] { display: none; }
.chat-thread {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid #38383A; color: #fff; font: inherit; padding: 12px 14px; cursor: pointer;
}
.chat-thread:hover { background: #2C2C2E; }
.chat-thread .t-main { flex: 1; min-width: 0; }
.chat-thread .t-name { font-weight: 600; font-size: 15px; }
.chat-thread .t-phone { color: #0A84FF; font-size: 13px; }
.chat-thread .t-last { color: #8E8E93; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-thread .t-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #FF453A; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.chat-thread .t-avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; background: #3A3A3C; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px;
}
.chat-thread .t-avatar.admin { background: #0A84FF; }
.chat-thread .t-tag { margin-left: 4px; padding: 1px 7px; border-radius: 999px; background: rgba(48,209,88,.16); color: #30D158; font-size: 11px; font-weight: 600; vertical-align: 1px; }
.chat-search { padding: 8px 12px; border-bottom: 1px solid #38383A; }
.chat-search[hidden] { display: none; }
.chat-search input {
  width: 100%; box-sizing: border-box; padding: 8px 12px; border-radius: 10px; border: none;
  background: #2C2C2E; color: #fff; font: inherit; font-size: 15px; outline: none;
}
.chat-search input:focus-visible { box-shadow: 0 0 0 2px #0A84FF; }
body.locked .chat-fab, body.locked .chat-panel { display: none; }
