/* WhatsApp-inspired shared theme */
:root {
  --wa-green: #25d366;
  --wa-teal: #075e54;
  --wa-teal-mid: #128c7e;
  --wa-bg: #f4f2ee;
  --wa-sent: #d9fdd3;
  --wa-received: #ffffff;
  --wa-text: #111b21;
  --wa-muted: #667781;
  --wa-border: #e9edef;
  --wa-panel: #f0f2f5;
  --wa-blue: #34b7f1;
}

* {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  color: var(--wa-text);
}

/* Chat wallpaper pattern — subtle */
.wa-chat-bg {
  background-color: var(--wa-bg);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cdc4' fill-opacity='0.12'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Message bubbles */
.msg-bubble {
  width: fit-content;
  max-width: 85%;
  padding: 8px 12px 6px;
  border-radius: 8px;
  font-size: 14.2px;
  line-height: 19px;
  word-break: break-word;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-bubble.sent {
  align-self: flex-end;
  background: var(--wa-sent);
  border-top-right-radius: 0;
}

.msg-bubble.received {
  align-self: flex-start;
  background: var(--wa-received);
  border-top-left-radius: 0;
}

.msg-bubble.has-media {
  padding: 3px 3px 5px;
  max-width: min(280px, 85vw);
}

.msg-bubble .msg-text {
  white-space: pre-wrap;
}

.msg-bubble .msg-meta {
  display: flex;
  justify-content: flex-end;
  padding: 2px 2px 0;
  margin-top: 2px;
}

.msg-bubble.has-media .msg-meta {
  padding: 0 6px 2px;
}

.msg-bubble .time {
  font-size: 11px;
  line-height: 14px;
  color: var(--wa-muted);
  white-space: nowrap;
  padding: 0 2px;
}

.msg-media {
  display: block;
  line-height: 0;
  max-width: 100%;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.04);
}

.msg-media--video {
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #0b141a;
}

.msg-media img,
.msg-media video {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 240px;
  height: auto;
  object-fit: contain;
  vertical-align: bottom;
}
.msg-media--video video {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
  cursor: default;
}

.msg-media--image img {
  cursor: pointer;
}

@media (min-width: 768px) {
  .msg-bubble.has-media {
    max-width: min(320px, 85%);
  }

  .msg-media img,
  .msg-media video {
    max-height: 280px;
  }
}

.msg-bubble .file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--wa-teal-mid);
  text-decoration: none;
  background: rgba(0, 0, 0, 0.05);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}

.msg-bubble.sent .file-link {
  color: var(--wa-teal);
}

.msg-bubble .file-link:hover {
  text-decoration: underline;
}

/* Typing indicator animation */
@keyframes wa-dot-pulse {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

.wa-typing-dots span {
  width: 5px;
  height: 5px;
  background: var(--wa-muted);
  border-radius: 50%;
  animation: wa-dot-pulse 1.4s infinite;
}

.wa-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.wa-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* Upload menu */
.upload-menu.hidden {
  display: none !important;
}

.upload-menu .menu-item:hover {
  background: #f5f6f6;
}

/* Device list item (admin) */
.device-item.active {
  background: #f0f2f5;
}

.device-item:hover:not(.active) {
  background: #f5f6f6;
}

/* Scrollbar styling (desktop admin) */
@media (min-width: 768px) {
  .wa-scroll::-webkit-scrollbar {
    width: 6px;
  }
  .wa-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
  }
}

/* Mobile safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .wa-safe-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* SVG icons */
.wa-icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.wa-icon-lg {
  width: 1.375rem;
  height: 1.375rem;
}

.wa-icon-sm {
  width: 1rem;
  height: 1rem;
}

.wa-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wa-icon-wrap-muted {
  color: var(--wa-muted);
}

.upload-menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 9999px;
  flex-shrink: 0;
}

.upload-menu-icon .wa-icon {
  width: 1.125rem;
  height: 1.125rem;
}

.upload-menu-icon-image {
  color: #54656f;
}

.upload-menu-icon-video {
  color: #54656f;
}

.upload-menu-icon-file {
  color: #54656f;
}

.upload-btn {
  color: var(--wa-muted);
}

.upload-btn:hover {
  color: var(--wa-teal-mid);
}

.upload-btn .wa-icon {
  width: 1.375rem;
  height: 1.375rem;
}

.msg-bubble .file-link .wa-icon-wrap {
  color: inherit;
}

.attach-file-preview {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 240px;
  font-size: 0.875rem;
  color: var(--wa-text);
}

.attach-file-preview .truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
