/* =========================
   BASE CHAT INPUT
========================= */
#chatInput {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 14px;
  font-size: 15px;
  border: none;
  outline: none;
  border-radius: 12px;
  background: #020617;
  color: #fff;

  resize: none;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;

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

/* =========================
   PANEL + MESSAGES BASE
========================= */
#chatPanel {
  overscroll-behavior: contain;
}

#chatMessages {
  -webkit-overflow-scrolling: touch;
}

#chatMessages {
  gap: 10px;
}
/* =========================
   TYPING INDICATOR
========================= */
.typing {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--them);
  border-radius: 12px;
  width: max-content;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: bounce 1s infinite;
}

.dot:nth-child(2) {
  animation-delay: .15s;
}

.dot:nth-child(3) {
  animation-delay: .3s;
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: .5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* =========================
   MOBILE OPTIMIZATION
========================= */
@media (max-width: 600px) {

  /* FULL SCREEN CHAT */
  #chatPanel {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;

    height: 100dvh !important;   /* FIX MOBILE VIEWPORT BUG */
    bottom: 0 !important;

    display: flex;
    flex-direction: column;

    border-radius: 0 !important;
  }

  /* MESSAGES TAKE SPACE */
  #chatMessages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* INPUT ROW FIX */
  #chatInputRow {
    height: auto !important;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    display: flex;
    align-items: flex-end;
    gap: 8px;
  }

  /* TEXTAREA FIX (IMPORTANT CHANGE) */
  #chatInput {
    font-size: 16px !important;

    min-height: 44px !important;
    max-height: 140px !important;

    height: auto !important;

    line-height: 1.4;
  }

  /* BUTTON */
  #chatSendBtn {
    min-width: 70px;
  }

  /* TEXT SIZE */
  #chatMessages {
    font-size: 14px !important;
  }

  /* TOGGLE BUTTON */
  #chatToggleBtn {
    padding: 14px 18px !important;
    font-size: 14px;
  }
}
/* =========================
   GLOBAL TAP FIX (MOBILE UX)
========================= */
button,
span,
div[onclick] {
  -webkit-tap-highlight-color: transparent;
}
#chatCharCount {
  font-size: 11px;
  margin-left: 6px;
  margin-top: 4px;
  color: #94a3b8;
  user-select: none;
}

#chatCharCount.over {
  color: #ef4444;
  font-weight: 600;
}
#chatSendBtn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.bubble {
  max-width: 75%;
  min-width: 0;

  padding: 10px 12px;   /* more breathing room */
  border-radius: 14px;

  font-size: 15px;      /* slightly bigger */
  line-height: 1.5;     /* MUCH better readability */

  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;

  box-sizing: border-box;
}

.me {
  align-self: flex-end;

  background: #1f8f6a;  /* brighter, cleaner green */
  color: #ffffff;

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

  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.them {
  align-self: flex-start;

  background: #1f2c34;
  color: #e9edef;

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

  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.bubble {
  max-width: 75%;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.msg-user {
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 5px;
  letter-spacing: 0.2px;
}

.me .msg-user {
  color: #7fffd4;
}

.them .msg-user {
  color: #60a5fa;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;

  font-size: 12px;
  font-weight: 700;
  color: #fff;

  margin-bottom: 4px;
}