:root {
  --bg: #eef4ff;
  --bg-grad: #d8e8ff;
  --card: rgba(255, 255, 255, 0.82);
  --text: #16213a;
  --muted: #5f6d8c;
  --line: #d6e2fa;
  --accent: #3b82f6;
  --accent-soft: #d7e9ff;
  --user: linear-gradient(145deg, #5aa6ff, #3b82f6);
  --bot: linear-gradient(155deg, #ffffff, #eef5ff);
}

* { box-sizing: border-box; }

/* ISSUE 3 FIX — prevent ALL horizontal overflow at root level */
html {
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 80% -10%, var(--bg-grad), var(--bg) 45%);
  line-height: 1.35;
  overflow-x: hidden;
  overflow-y: hidden;
  height: 100vh;
  width: 100%;
  max-width: 100vw;
}

.app-shell {
  width: 100%;
  max-width: 100vw;
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow: hidden;
  min-height: 0;
  /* ISSUE 3 FIX — lock layout inside viewport */
  position: relative;
  left: 0;
}

.card {
  border: 1px solid var(--line);
  background: linear-gradient(158deg, color-mix(in srgb, var(--card), #ffffff 16%), color-mix(in srgb, var(--card), #cfe7ff 12%));
  border-radius: 18px;
  box-shadow: 0 14px 30px rgba(82, 103, 160, 0.14), 0 2px 4px rgba(91, 126, 208, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 2px;
  position: sticky;
  top: 0;
  z-index: 100;
  /* ISSUE 4 FIX — prevent topbar from exceeding screen width */
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  flex-shrink: 0;
}

/* =========================================
   BRAND HEADER (TOP SECTION)
========================================= */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  /* ISSUE 4 FIX — allow brand to shrink so top-actions never overflow */
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

/* Logo */
.brand-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 8px;
  background: transparent;
  flex-shrink: 0;
}

/* Text container */
.brand div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
}

/* Main title */
.brand h1 {
  margin: 0;
  font-family: Orbitron, Inter, sans-serif;
  letter-spacing: 0.04em;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  /* ISSUE 4 FIX — prevent title from pushing layout wide */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Subtitle */
.brand p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Country line */
.brand .country {
  font-size: 10px;
  opacity: 0.7;
}
.country { font-weight: 600; }

/* ISSUE 4 FIX — top-actions must never shrink or wrap */
.top-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn,
.composer-btn,
.composer-send {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--card), #ffffff 40%);
  color: var(--text);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
  box-shadow: 0 4px 10px rgba(80, 111, 183, 0.12);
}

.icon-btn:hover,
.composer-btn:hover,
.composer-send:hover {
  transform: scale(1.05); /* ✅ instead of moving */
  box-shadow: 0 8px 14px rgba(80, 111, 183, 0.18);
}

.icon-btn:active,
.composer-btn:active,
.composer-send:active {
  transform: scale(0.97);
}

.panel {
  margin-top: 10px;
  padding: 10px;
  transform-origin: top;
  transition: transform 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  pointer-events: none;
}

.panel.panel-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.menu-list {
  display: grid;
  gap: 6px;
}

.menu-list button {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px;
  color: var(--text);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.menu-list button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(74, 108, 188, 0.14);
}

.menu-content {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.social-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.social-pill {
  text-decoration: none;
  border-radius: 999px;
  padding: 7px 11px;
  color: #fff;
  font-weight: 600;
  font-size: 0.74rem;
  box-shadow: 0 8px 16px rgba(22, 33, 58, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.social-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(22, 33, 58, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.social-web { background: linear-gradient(135deg, #0ea5e9, #0284c7); }
.social-yt { background: linear-gradient(135deg, #ff4d4d, #cc0000); }
.social-tiktok { background: linear-gradient(135deg, #141414, #32455c); }
.social-linkedin { background: linear-gradient(135deg, #1d8cf8, #0a66c2); }
.social-x { background: linear-gradient(135deg, #111, #444); }
.social-fb { background: linear-gradient(135deg, #2f7bf0, #1877f2); }

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  /* ISSUE 3 FIX */
  width: 100%;
  max-width: 100%;
}

.chat-window {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  min-height: 0;
  /* ISSUE 3 FIX — vertical scroll only, no horizontal drift */
  width: 100%;
  max-width: 100%;
  touch-action: pan-y;
  overscroll-behavior-x: none;
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 12px 0;
  /* ISSUE 3 FIX — bubbles must not push layout wide */
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.message.user { justify-content: flex-end; }

/* ISSUE 1 FIX — Avatar consistent on all devices */
.avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid var(--line);
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 6px;
}

.message.user .avatar { display: none; }

/* ISSUE 3 FIX — bubble-wrap must not exceed screen */
.bubble-wrap {
  max-width: 82%;
  min-width: 0;
  overflow: hidden;
}

.bubble {
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--bot);
  padding: 10px 14px;
  line-height: 1.45;
  /* ISSUE 3 FIX — text must wrap, not push layout */
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: 0 6px 14px rgba(84, 111, 179, 0.1);
  border-bottom-left-radius: 6px;
  /* ISSUE 1 FIX — consistent sizing */
  width: 100%;
  max-width: 100%;
}

.message.user .bubble {
  background: var(--user);
  color: #fff;
  border-bottom-right-radius: 6px;
  border-color: transparent;
  box-shadow: 0 8px 16px color-mix(in srgb, var(--accent), transparent 72%);
}

.message-in {
  animation: msgIn 0.2s ease;
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

time {
  display: inline-block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.66rem;
}

.attachment-preview {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: grid;
  gap: 6px;
}

.attachment-preview li {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 6px 8px;
  font-size: 0.72rem;
}
.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.file-preview-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 6px 8px;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
}

.file-preview-item img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

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





.composer {
  display: flex;
  align-items: center;
  gap: 6px;
  /* FIX — removed conflicting position:sticky + position:relative */
  position: relative;
  background: var(--card);
  padding: 6px;
  border-top: 1px solid var(--line);
  /* ISSUE 3 FIX — composer must never overflow */
  width: 100%;
  max-width: 100%;
  flex-shrink: 0;
}
#message-input {
  flex: 1;
  min-width: 40px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--card), #ffffff 45%);
  color: var(--text);
  min-height: 42px;
  padding: 0 12px;
}

.composer-btn input { display: none; }

.composer-send {
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent), #000 15%));
  color: #fff;
  border: none;
}

.recording {
  margin-top: 6px;
  color: #b6223f;
  font-size: 0.76rem;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  background: linear-gradient(145deg, #fff0f5, #ffe6ed);
  border: 1px solid #f2c2ce;
  border-radius: 999px;
  width: fit-content;
  padding: 4px 10px;
}

.wave {
  width: 38px;
  height: 10px;
  background: repeating-linear-gradient(90deg, #de2f56 0 4px, transparent 4px 7px);
  animation: wave 0.8s linear infinite;
}

@keyframes wave { from { background-position: 0 0; } to { background-position: 18px 0; } }

.install-banner {
  margin-top: 10px;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--card), #ffffff 34%), color-mix(in srgb, var(--accent), #ffffff 86%));
}

.install-banner button {
  border: none;
  border-radius: 12px;
  padding: 9px 12px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent), #ffffff 16%), var(--accent));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 14px color-mix(in srgb, var(--accent), transparent 75%);
}

.install-banner button:hover {
  transform: translateY(-1px);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent), #000 22%);
  animation: typing 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.12s; }
.typing-dots span:nth-child(3) { animation-delay: 0.24s; }

@keyframes typing {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-2px); opacity: 1; }
}

.composer-btn.is-recording {
  background: linear-gradient(145deg, #ff4d6e, #d63050);
  color: #fff;
  box-shadow: 0 0 0 0 rgba(214, 48, 80, 0.45);
  animation: micPulse 1.1s infinite;
}

@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(214, 48, 80, 0.45); }
  70% { box-shadow: 0 0 0 10px rgba(214, 48, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(214, 48, 80, 0); }
}

.footer {
  margin-top: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.footer a { color: var(--accent); }
.hidden { display: none !important; }


/* Attach Menu Container */
.attach-menu {
  position: absolute;
  bottom: 60px;
  left: 10px;

  background: #ffffff;
  border-radius: 12px;
  padding: 10px;

  box-shadow: 0 8px 20px rgba(0,0,0,0.15);

  display: flex;
  flex-direction: column;
  gap: 8px;

  z-index: 999;
}

/* Hidden state */
.hidden {
  display: none !important;
}

/* Each item */
.attach-item {
  display: flex;
  align-items: center;
  gap: 8px;

  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;

  transition: background 0.2s ease;
}

.attach-item:hover {
  background: #f2f6ff;
}
/* ===== Message Types Styling ===== */

/* Text (default) */
.bubble.type-text {
  font-size: 14px;
}

/* Voice messages */
.bubble.type-voice {
  background: linear-gradient(145deg, #eef6ff, #dbeafe);
  border-left: 3px solid var(--accent);
}

/* File / attachments */
.bubble.type-file {
  background: #f8fafc;
  border-left: 3px solid #64748b;
  font-weight: 500;
}
.file-preview {
  display: flex;
  gap: 8px;
  padding: 6px 10px;
  overflow-x: auto;
}

.file-preview-item {
  position: relative;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 6px;
}

.file-preview-item audio {
  height: 36px;
}

.remove-preview {
  position: absolute;
  top: -6px;
  right: -6px;
  background: red;
  color: white;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 10px;
  cursor: pointer;
}

.remove-preview {
  display: none !important;
}

.chat-image {
  max-width: 200px;
  max-height: 200px;
  width: auto;
  height: auto;
  border-radius: 10px;
  display: block;
}

/* 🔗 LINK CARD (MAIN DESIGN) */
.link-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 10px;
  margin-top: 6px;
  max-width: 260px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  transition: 0.2s ease;
}

.link-card:hover {
  transform: translateY(-1px);
}

/* 🏷 DOMAIN TEXT */
.link-domain {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 4px;
}

/* 🔗 LINK TEXT */
.chat-link {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #2563eb;
  text-decoration: none;
  word-break: break-all;
  margin-bottom: 8px;
}

.chat-link:hover {
  text-decoration: underline;
}

/* 🔘 BUTTON */
.link-btn {
  background: #111827;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  cursor: pointer;
}

/* 🎯 PLATFORM COLORS */
.link-card.facebook {
  border-left: 4px solid #1877f2;
}

.link-card.youtube {
  border-left: 4px solid #ff0000;
}

.link-card.instagram {
  border-left: 4px solid #e1306c;
}



/* =========================================================
   HEADER BRAND FIX (LOGO + TEXT ALIGNMENT) — DUPLICATE CLEANUP
   These are handled above. Keeping only mobile overrides below.
========================================================= */

/* Mobile optimization — 480px and below */
@media (max-width: 480px) {

  .app-shell {
    padding: 8px;
  }

  .topbar {
    padding: 8px 10px;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
  }

  .brand h1 {
    font-size: 11px;
    letter-spacing: 0.02em;
  }

  .brand p {
    font-size: 10px;
  }

  .brand .country {
    font-size: 9px;
  }

  .icon-btn,
  .composer-btn,
  .composer-send {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    /* ISSUE 4 FIX — ensure buttons are always tappable */
    flex-shrink: 0;
    touch-action: manipulation;
  }

  .bubble-wrap {
    max-width: 88%;
  }

  .bubble {
    padding: 9px 12px;
    font-size: 13px;
  }

  #message-input {
    font-size: 16px; /* prevents iOS zoom on focus */
    min-height: 40px;
  }

  .chat-window {
    padding-right: 0;
  }

  .message {
    margin: 10px 0;
  }
}


/* PROFILE FORM FIX */
#menu-content label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.75rem;
}

#menu-content input,
#menu-content select,
#menu-content textarea {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #ccd6f6;
  font-size: 0.75rem;
  outline: none;
}

#menu-content button {
  margin-top: 10px;
  width: 120px;
}



/* MODERN SOCIAL GRID */
.social-grid-modern {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.social-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  padding: 10px;
  border-radius: 12px;

  background: var(--accent-soft);
  text-decoration: none;
  color: var(--text);

  font-size: 12px;
  transition: 0.2s ease;
}

.social-item span {
  font-size: 18px;
  margin-bottom: 4px;
}

.social-item:hover {
  transform: translateY(-2px);
  background: var(--accent);
  color: white;
}


.whatsapp-float {
  position: fixed;
  bottom: 180px;
  right: 20px;

  width: 52px;
  height: 52px;

  border-radius: 50%;
  background: #25D366;

  display: flex;
  align-items: center;
  justify-content: center;

  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  z-index: 999;

  transition: transform 0.2s ease;
}

/* Hover effect */
.whatsapp-float:hover {
  transform: scale(1.1);
}

/* 🔥 Pulse Animation */
.whatsapp-float::before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(37, 211, 102, 0.5);
  animation: whatsapp-pulse 1.8s infinite;
  z-index: -1;
}

@keyframes whatsapp-pulse {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  70% {
    transform: scale(1.6);
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}



/* ===============================
   🔵 AI TYPING ANIMATION (PREMIUM)
   =============================== */

.typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 2px;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: #7a8ca5;
  border-radius: 50%;
  display: inline-block;
  animation: typingPulse 1.4s infinite ease-in-out;
}

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

@keyframes typingPulse {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

body.dark .typing-dots span {
  background: #cbd5e1;
}