*, *::before, *::after { box-sizing: border-box; }

:root {
  --wa-green: #00a884;
  --wa-green-dark: #008069;
  --wa-header: #202c33;
  --wa-bg-chat: #0b141a;
  --wa-bubble-in: #202c33;
  --wa-bubble-out: #005c4b;
  --wa-text: #e9edef;
  --wa-text-secondary: #8696a0;
  --wa-text-tertiary: #aebac1;
  --wa-input-bg: #2a3942;
  --wa-divider: #222d34;
  --wa-shadow: 0 1px 0.5px rgba(11, 20, 26, .13);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  background: #111b21;
  color: var(--wa-text);
  overflow: hidden;
}

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: var(--wa-bg-chat);
  position: relative;
}

.chat-header {
  flex: 0 0 auto;
  background: var(--wa-header);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--wa-divider);
  z-index: 5;
}

.chat-header-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #6b7c85 url("/chat/profile.jpg") center / cover no-repeat;
  flex-shrink: 0;
  border: 2px solid rgba(0, 168, 132, 0.4);
}

.chat-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.chat-header-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--wa-text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-status {
  font-size: 13px;
  color: var(--wa-text-secondary);
  line-height: 1.2;
  margin-top: 2px;
}

.chat-header-status.online::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--wa-green);
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.chat-header-icons {
  display: flex;
  gap: 18px;
  color: var(--wa-text-tertiary);
}

.chat-header-icons svg {
  width: 22px;
  height: 22px;
  opacity: 0.85;
}

.chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 7%;
  background-color: var(--wa-bg-chat);
  background-image: url("/chat/background.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: local;
  position: relative;
}

.chat-body::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(11, 20, 26, 0.55);
  pointer-events: none;
  z-index: 0;
}

.chat-body > * { position: relative; z-index: 1; }

.chat-date { text-align: center; margin: 10px auto 18px; max-width: 200px; }
.chat-date span {
  display: inline-block;
  background: rgba(27, 38, 48, 0.85);
  color: var(--wa-text-tertiary);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  box-shadow: var(--wa-shadow);
}

.chat-system { text-align: center; margin: 0 auto 18px; max-width: 90%; }
.chat-system span {
  display: inline-block;
  background: rgba(24, 42, 56, 0.85);
  color: #ffd279;
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 8px;
  box-shadow: var(--wa-shadow);
  line-height: 1.4;
}

.chat-msg {
  max-width: 75%;
  margin-bottom: 8px;
  padding: 6px 10px 8px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.4;
  word-wrap: break-word;
  box-shadow: var(--wa-shadow);
  position: relative;
  clear: both;
  animation: msg-in 0.25s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg.in {
  background: var(--wa-bubble-in);
  float: left;
  border-top-left-radius: 0;
  margin-left: 4px;
}

.chat-msg.out {
  background: var(--wa-bubble-out);
  float: right;
  border-top-right-radius: 0;
  margin-right: 4px;
}

.chat-msg-time {
  font-size: 11px;
  color: var(--wa-text-secondary);
  float: right;
  margin: 4px 0 -4px 8px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.chat-msg.out .chat-msg-time { color: rgba(233, 237, 239, 0.65); }
.chat-clear { clear: both; }

.chat-footer {
  flex: 0 0 auto;
  background: var(--wa-header);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--wa-divider);
}

.chat-footer-icon {
  width: 24px;
  height: 24px;
  color: var(--wa-text-tertiary);
  flex-shrink: 0;
  opacity: 0.7;
}

.chat-footer-input {
  flex: 1;
  background: var(--wa-input-bg);
  border: none;
  border-radius: 22px;
  padding: 10px 16px;
  color: var(--wa-text);
  font-family: inherit;
  font-size: 14.5px;
  outline: none;
  cursor: not-allowed;
}

.chat-footer-input::placeholder { color: #6b7c85; }

.chat-footer-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wa-green);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: not-allowed;
  opacity: 0.7;
  flex-shrink: 0;
}

.chat-footer-send svg { width: 20px; height: 20px; fill: #fff; }

.chat-body::-webkit-scrollbar { width: 8px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb { background: rgba(134, 150, 160, 0.25); border-radius: 4px; }
.chat-body::-webkit-scrollbar-thumb:hover { background: rgba(134, 150, 160, 0.4); }

#form-root { display: block; clear: both; }
#site-root:empty { display: none; }
#site-root { clear: both; }

.locked, .open-note {
  margin: 8px 4px 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--wa-bubble-out);
  color: var(--wa-text);
  box-shadow: var(--wa-shadow);
  clear: both;
}

.locked { float: right; max-width: 75%; }
.open-note { float: none; max-width: none; background: transparent; box-shadow: none; padding: 0 4px 12px; }

body.is-stub .chat-header,
body.is-stub .chat-footer,
body.is-stub .chat-date,
body.is-stub .chat-system,
body.is-stub .chat-msg { display: none !important; }

body.is-stub { overflow: auto; background: #111b21; }

body.is-stub .chat-app {
  height: auto;
  min-height: 100dvh;
  max-width: none;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}

body.is-stub .chat-body {
  background: #111b21;
  background-image: none;
  overflow: visible;
}

body.is-stub .chat-body::before { display: none; }
body.is-stub #form-root { display: block !important; }
body.is-stub #site-root { display: none; }

@media (max-width: 600px) {
  .chat-body { padding: 12px 4%; }
  .chat-msg { max-width: 85%; }
  .chat-header-icons { gap: 14px; }
  .chat-header-icons svg { width: 20px; height: 20px; }
  .chat-header-avatar { width: 46px; height: 46px; }
}

@media (min-width: 900px) {
  .chat-app {
    max-width: 900px;
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
    margin: 20px auto;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  }
}
