:root {
  --app-height: 100dvh;
  --header: #1f3a32;
  --header-deep: #172d27;
  --accent: #55745f;
  --outgoing: #dfead5;
  --incoming: #ffffff;
  --wallpaper: #eee9df;
  --ink: #1b2722;
  --muted: #67716c;
  --line: #d8ddd8;
  --danger: #a44338;
  --shadow: 0 1px 1px #202c241c, 0 4px 18px #202c240d;
}

* { box-sizing: border-box; }
html { height: 100%; background: var(--header); }
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--wallpaper);
  color: var(--ink);
  font: 15px/1.42 Arial, Helvetica, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
button, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.chat-app {
  width: min(100%, 840px);
  height: var(--app-height);
  min-height: 320px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  margin: 0 auto;
  overflow: hidden;
  background: var(--wallpaper);
  box-shadow: 0 0 70px #172d2730;
}

.chat-header {
  z-index: 2;
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  background: linear-gradient(135deg, var(--header), var(--header-deep));
  color: #fff;
  box-shadow: 0 1px 8px #0003;
}

.site-back {
  width: 38px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #eaf0eb;
  font-size: 39px;
  font-family: Georgia, serif;
  font-weight: 300;
  line-height: 1;
}
.site-back:hover { background: #ffffff14; }

.avatar {
  position: relative;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid #ffffff46;
  border-radius: 50%;
  background: #d8ddce;
  color: #284036;
  font: 24px/1 Georgia, "Times New Roman", serif;
  box-shadow: inset 0 0 0 4px #ffffff25;
}
.presence-dot {
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 11px;
  height: 11px;
  border: 2px solid var(--header);
  border-radius: 50%;
  background: #72c285;
}
.contact-title { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.contact-title strong { overflow: hidden; font: 21px/1.15 Georgia, "Times New Roman", serif; text-overflow: ellipsis; white-space: nowrap; }
.contact-title span { overflow: hidden; margin-top: 3px; color: #d5ddd8; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.contact-title span.offline { color: #efc8c1; }
.brand-link { display: flex; align-items: end; flex-direction: column; margin-left: 12px; line-height: 1; }
.brand-link span { font: 12px/1 Georgia, serif; letter-spacing: .13em; }
.brand-link small { margin-top: 4px; color: #d5ddd8; font: italic 11px/1 Georgia, serif; }

.messages {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 18px clamp(12px, 4vw, 42px) 24px;
  background-color: var(--wallpaper);
  background-image:
    radial-gradient(circle at 14px 18px, #6374670c 0 1.5px, transparent 1.7px),
    radial-gradient(circle at 42px 49px, #6374670a 0 1.5px, transparent 1.7px),
    linear-gradient(135deg, transparent 47%, #63746708 48% 52%, transparent 53%),
    linear-gradient(45deg, transparent 47%, #ffffff30 48% 52%, transparent 53%);
  background-size: 64px 64px, 64px 64px, 76px 76px, 76px 76px;
  scrollbar-width: thin;
  scrollbar-color: #87948b transparent;
}

.chat-day { display: flex; justify-content: center; margin: 0 0 16px; }
.chat-day span {
  padding: 5px 11px;
  border-radius: 8px;
  background: #ffffffc7;
  color: #59635e;
  box-shadow: 0 1px 4px #00000010;
  font-size: 11px;
}
.message { max-width: min(76%, 560px); display: flex; margin: 4px 0; }
.message.visitor { justify-content: flex-end; margin-left: auto; }
.message.admin { justify-content: flex-start; margin-right: auto; }
.message-bubble {
  position: relative;
  min-width: 84px;
  padding: 8px 10px 6px;
  border-radius: 8px;
  background: var(--incoming);
  box-shadow: var(--shadow);
}
.message.admin .message-bubble { border-top-left-radius: 2px; }
.message.visitor .message-bubble { border-top-right-radius: 2px; background: var(--outgoing); }
.message.admin .message-bubble::before,
.message.visitor .message-bubble::before {
  position: absolute;
  top: 0;
  width: 10px;
  height: 12px;
  content: "";
}
.message.admin .message-bubble::before {
  left: -7px;
  background: linear-gradient(225deg, var(--incoming) 0 50%, transparent 51%);
}
.message.visitor .message-bubble::before {
  right: -7px;
  background: linear-gradient(135deg, var(--outgoing) 0 50%, transparent 51%);
}
.message-bubble p { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-bubble time { display: block; min-height: 14px; margin-top: 2px; color: #768079; font-size: 10px; line-height: 1; text-align: right; }
.message.visitor .message-bubble time::after { margin-left: 4px; color: #5f8e72; content: "✓"; font-size: 11px; }
.welcome-message { margin-top: 0; }
.privacy-note {
  width: fit-content;
  max-width: 520px;
  margin: 22px auto 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: #fff9;
  color: #6d746f;
  font-size: 10px;
  text-align: center;
}
.messages-loading, .messages-error { padding: 20px; color: var(--muted); font-size: 12px; text-align: center; }

.composer {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 9px;
  align-items: end;
  padding: 9px max(12px, env(safe-area-inset-right)) max(9px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid #cdd2cd;
  background: #f2f1ed;
}
.composer-field {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 15px;
  border: 1px solid #d8ddd8;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 1px 3px #00000009;
}
.composer-field:focus-within { border-color: #8ba193; box-shadow: 0 0 0 3px #66806d18; }
.composer textarea {
  width: 100%;
  min-height: 24px;
  max-height: 124px;
  padding: 1px 0;
  overflow-y: auto;
  resize: none;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 22px;
}
.composer textarea::placeholder { color: #818a84; opacity: 1; }
.send-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 7px #31483a30;
  cursor: pointer;
}
.send-button:hover { background: #486653; }
.send-button:active { transform: scale(.96); }
.send-button:disabled { cursor: wait; opacity: .55; }
.send-button svg { width: 23px; height: 23px; margin-left: 2px; fill: currentColor; }
.reply-status {
  position: absolute;
  right: 70px;
  bottom: calc(100% + 5px);
  max-width: calc(100% - 88px);
  margin: 0;
  padding: 5px 9px;
  border-radius: 7px;
  background: #fff;
  color: var(--danger);
  box-shadow: 0 2px 8px #0002;
  font-size: 11px;
}
.reply-status:empty { display: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
noscript { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: #fff; color: var(--ink); text-align: center; }

@media (max-width: 600px) {
  .chat-app { width: 100%; box-shadow: none; }
  .chat-header { min-height: 68px; gap: 9px; padding-bottom: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .site-back { width: 30px; font-size: 35px; }
  .avatar { width: 42px; height: 42px; font-size: 22px; }
  .contact-title strong { font-size: 19px; }
  .brand-link { display: none; }
  .messages { padding: 13px 12px 18px; }
  .message { max-width: 86%; }
  .privacy-note { max-width: 86%; }
}

@media (max-width: 360px) {
  .message { max-width: 91%; }
  .contact-title span { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
