:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  color: #20312a;
  background: #e9efeb;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }
button, textarea { font: inherit; }
.hidden { display: none !important; }
.chat-window {
  display: flex;
  flex-direction: column;
  width: min(860px, calc(100% - 32px));
  height: min(760px, calc(100dvh - 32px));
  min-height: 360px;
  margin: 16px auto;
  overflow: hidden;
  border: 1px solid #dce5df;
  border-radius: 18px;
  background: #f7faf8;
  box-shadow: 0 18px 55px #20392b18;
}
.brand-bar { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 12px; height: 48px; padding: 0 20px; background: #176b51; color: #fff; }
.brand-identity { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-identity img { display: block; flex: none; width: 32px; height: 32px; border-radius: 9px; }
.brand-bar strong { font-size: 16px; letter-spacing: .04em; white-space: nowrap; }
.brand-actions { display: flex; flex: none; align-items: center; gap: 8px; }
.brand-actions a, .brand-actions button { flex: none; padding: 5px 10px; border: 1px solid #ffffff75; border-radius: 8px; color: #fff; background: transparent; font: inherit; font-size: 14px; font-weight: 650; line-height: 20px; text-decoration: none; white-space: nowrap; cursor: pointer; }
.brand-actions button { border-color: #d2f0df; background: #e5f6eb; color: #176b51; }
.brand-actions a:hover { background: #ffffff1f; }
.brand-actions button:hover:not(:disabled) { background: #fff; }
.brand-actions button:disabled { opacity: .55; cursor: not-allowed; }
.chat-header {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  height: 72px;
  padding: 10px 20px;
  border-bottom: 1px solid #e2e9e4;
  background: #fff;
}
.chat-header strong {
  flex: 1;
  overflow: hidden;
  font-size: 17px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.call-button { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border: 0; border-radius: 12px; background: #e5f3eb; color: #176b51; cursor: pointer; }
.call-button svg { width: 20px; height: 20px; }
.call-button:disabled { opacity: .5; cursor: not-allowed; }
.avatar {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 48px;
  height: 48px;
  overflow: hidden;
  border-radius: 50%;
  background: #e3e7e5;
  color: #8a9590;
}
.avatar svg { width: 32px; height: 32px; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px clamp(14px, 4vw, 36px);
  background: #f2f6f3;
}
.empty-chat { height: 100%; display: grid; place-items: center; color: #85928b; font-size: 13px; }
.day-divider { display: flex; justify-content: center; margin: 16px 0; }
.day-divider span { padding: 5px 10px; border-radius: 9px; background: #e5ece8; color: #7a8981; font-size: 11px; }
.message-row { display: flex; margin: 9px 0; }
.message-row.visitor { justify-content: flex-end; }
.bubble {
  max-width: min(74%, 520px);
  padding: 10px 13px 7px;
  border: 1px solid #e0e8e2;
  border-radius: 15px 15px 15px 5px;
  background: #fff;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.message-row.visitor .bubble { border-color: #c2e9d9; border-radius: 15px 15px 5px 15px; background: #d7f2e6; }
.bubble img { display: block; max-width: min(100%, 380px); max-height: 360px; border-radius: 9px; object-fit: contain; cursor: zoom-in; }
.file-link { display: flex; align-items: center; gap: 9px; max-width: 320px; color: #2d6250; text-decoration: none; }
.file-link:hover { text-decoration: underline; }
.file-link svg { flex: none; width: 25px; height: 25px; }
.file-link span { overflow-wrap: anywhere; }
.call-invite { display: grid; gap: 8px; min-width: 190px; }
.call-invite strong { font-size: 15px; }
.call-invite small { color: #73837b; }
.call-invite button { justify-self: start; padding: 6px 14px; border: 0; border-radius: 9px; background: #087f5b; color: #fff; cursor: pointer; }
.message-meta { margin-top: 5px; color: #839189; font-size: 10px; text-align: right; }
.message-error { flex: none; padding: 8px 16px; background: #fff0ed; color: #a14c40; font-size: 12px; text-align: center; }
.composer {
  position: relative;
  display: flex;
  flex: none;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid #e0e8e2;
  background: #fff;
}
.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 13px;
  resize: none;
  outline: none;
  border: 1px solid #d7e2da;
  border-radius: 12px;
  background: #f7f9f7;
  line-height: 20px;
}
.composer textarea:focus { border-color: #65ac91; background: #fff; }
.composer button { flex: none; height: 44px; border: 0; border-radius: 12px; cursor: pointer; }
.composer button:disabled { opacity: .5; cursor: not-allowed; }
.image-button, .tool-button { display: grid; place-items: center; width: 44px; background: #edf4ef; color: #39755d; }
.image-button svg, .tool-button svg { width: 23px; height: 23px; }
#emoji-button { font-size: 29px; line-height: 1; }
.emoji-panel { position: absolute; bottom: calc(100% + 8px); left: 12px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; width: min(360px, calc(100vw - 24px)); max-height: 244px; overflow-y: auto; padding: 8px; border: 1px solid #dce5df; border-radius: 14px; background: #fff; box-shadow: 0 12px 30px #20392b20; }
.emoji-panel button { width: 44px; height: 44px; padding: 0; background: transparent; font-size: 29px; }
.emoji-panel button:hover { background: #edf4ef; }
.send-button { min-width: 64px; padding: 0 14px; background: #087f5b; color: #fff; font-weight: 700; }
.call-overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 18px; background: #0c1b16bb; }
.call-card { display: flex; flex-direction: column; align-items: center; width: min(350px, 100%); min-height: 380px; padding: 26px; border-radius: 24px; background: #182c25; color: #fff; box-shadow: 0 20px 60px #0005; }
.call-title { color: #b9d3c4; font-size: 14px; }
.call-peer { margin-top: 55px; font-size: 25px; font-weight: 750; text-align: center; }
.call-status { margin-top: 12px; color: #a9beb2; font-size: 13px; }
.call-frame { position: absolute; width: 1px; height: 1px; border: 0; opacity: 0; }
.call-actions { display: flex; gap: 22px; margin-top: auto; }
.call-actions button { min-width: 94px; height: 44px; border: 0; border-radius: 12px; background: #425b4e; color: #fff; font: inherit; cursor: pointer; }
.call-actions #call-accept { background: #258f69; }
.call-actions #call-decline { background: #d44c4c; }
.call-actions .hidden { display: none; }
#call-hangup { background: #d44c4c; }
@media (max-width: 720px) {
  .chat-window { width: 100%; height: 100dvh; min-height: 0; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
  .chat-header { height: 66px; padding: 9px 14px; }
  .brand-bar { height: 46px; padding: 0 14px; }
  .brand-actions { gap: 5px; }
  .brand-actions a, .brand-actions button { padding: 4px 7px; font-size: 12px; }
  .avatar { width: 44px; height: 44px; }
  .messages { padding: 14px 12px; }
  .bubble { max-width: 86%; }
  .composer { gap: 7px; padding: 9px 10px calc(9px + env(safe-area-inset-bottom)); }
  .send-button { min-width: 54px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
