/* ═══════════════════════════════════════════════════════════════════
   IrishHub — Modern Messenger-Style Chat Widget
   Shared across citizenship, mortgage, and driving pages
   ═══════════════════════════════════════════════════════════════════ */

/* ── Section background ──────────────────────────────────────────── */
.chat-section {
  background: var(--light-grey);
  padding: var(--space-2xl) 0;
}

/* ── Card container (slightly smaller for better proportion and UX) ─── */
.chat-card {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  border: 1px solid rgba(15, 81, 50, 0.06);
  transition: box-shadow var(--transition-normal);
}

.chat-card:hover {
  box-shadow: var(--shadow-lg);
}

/* ── Header ──────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  background: linear-gradient(135deg, var(--dublin-green), var(--irish-green));
  color: var(--white);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-header-left h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--white);
}

.chat-header-right {
  display: flex;
  align-items: center;
}

.status-online {
  font-size: 0.65rem;
  color: #4ade80;
  font-weight: 600;
}

.chat-badge-free {
  background: rgba(255, 255, 255, 0.15);
  color: var(--white);
  font-size: 0.65rem;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-weight: 500;
  letter-spacing: 0.02em;
  backdrop-filter: blur(4px);
}

/* ── Messages area (slightly shorter so page feels less dominated by chat) ─ */
.chat-messages {
  height: 400px;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  background: var(--white);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(15, 81, 50, 0.12);
  border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 81, 50, 0.2);
}

/* ── Message bubbles ─────────────────────────────────────────────── */
.message {
  display: flex;
  gap: 0.5rem;
  max-width: 88%;
  align-items: flex-start;
}

.message.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* ── Avatars ─────────────────────────────────────────────────────── */
.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--green-50);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.user-message .message-avatar {
  background: var(--dublin-green);
  color: var(--white);
}

/* ── Bubble content ──────────────────────────────────────────────── */
.message-content {
  background: var(--light-grey);
  border-radius: 1rem 1rem 1rem 0.25rem;
  padding: 0.625rem 0.9rem;
  box-shadow: none;
  border: 1px solid rgba(15, 81, 50, 0.04);
}

.user-message .message-content {
  background: linear-gradient(135deg, var(--irish-green), var(--dublin-green));
  color: var(--white);
  border-radius: 1rem 1rem 0.25rem 1rem;
  border: none;
}

/* Sender label — only the first strong (e.g. "IrishHub AI") is block; bold in text stays inline */
.message-content strong {
  display: inline;
  font-weight: 700;
}

.message-content > strong:first-of-type {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--medium-grey);
  margin-bottom: 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.user-message .message-content > strong:first-of-type {
  color: rgba(255, 255, 255, 0.65);
}

/* ── Message text ────────────────────────────────────────────────── */
.message-text p {
  margin: 0.2rem 0;
  font-size: 0.85rem;
  line-height: 1.55;
}

.message-text p:first-child { margin-top: 0; }
.message-text p:last-child  { margin-bottom: 0; }

.message-text ul,
.message-text ol {
  margin: 0.4rem 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
}

.message-text li {
  margin: 0.15rem 0;
}

.message-text .chat-heading {
  font-size: 0.85rem;
  font-weight: 700;
  margin: 0.4rem 0 0.2rem;
  color: var(--dublin-green);
}

.user-message .message-text p,
.user-message .message-text li {
  color: var(--white);
}

.user-message .message-text .chat-heading {
  color: var(--celtic-gold);
}

/* Also style <p> directly inside .message-content (for welcome messages) */
.message-content p {
  font-size: 0.85rem;
  line-height: 1.55;
  margin: 0.2rem 0;
}

.message-content p:first-of-type { margin-top: 0; }
.message-content p:last-of-type  { margin-bottom: 0; }

.user-message .message-content p {
  color: var(--white);
}

/* ── Page Link after AI response ─────────────────────────────────── */
.chat-page-link {
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.chat-page-link a {
  display: inline-block;
  font-size: 0.8rem;
  color: var(--dublin-green);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s;
}

.chat-page-link a:hover {
  color: var(--irish-green);
  text-decoration: underline;
}

/* ── Typing indicator ────────────────────────────────────────────── */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 0.4rem 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--medium-grey);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Suggestion chips ────────────────────────────────────────────── */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 1.25rem;
  background: var(--white);
  border-top: 1px solid rgba(15, 81, 50, 0.05);
}

.suggestion-chip {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-full);
  padding: 0.35rem 0.75rem;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--dublin-green);
  font-weight: 500;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.suggestion-chip:hover {
  background: var(--irish-green);
  color: var(--white);
  border-color: var(--irish-green);
  transform: translateY(-1px);
}
.suggestion-chip:focus-visible {
  outline: 3px solid var(--irish-green);
  outline-offset: 2px;
}

/* ── Input area — pill shape ─────────────────────────────────────── */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.75rem 1.25rem;
  background: var(--white);
  border-top: 1px solid rgba(15, 81, 50, 0.05);
}

.chat-input-area input {
  flex: 1;
  padding: 0.65rem 1rem;
  border: 1.5px solid var(--grey-200);
  border-right: none;
  border-radius: var(--radius-full) 0 0 var(--radius-full);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-fast);
  background: var(--light-grey);
  color: var(--text-dark);
}

.chat-input-area input:focus {
  border-color: var(--irish-green);
}
.chat-input-area input:focus-visible {
  outline: 2px solid var(--irish-green);
  outline-offset: 2px;
}

.chat-input-area .chat-send-btn {
  padding: 0.65rem 1.1rem;
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
  white-space: nowrap;
  font-size: 0.85rem;
  border: 1.5px solid var(--irish-green);
  border-left: none;
  cursor: pointer;
}
.chat-input-area .chat-send-btn:focus-visible {
  outline: 3px solid var(--irish-green);
  outline-offset: 2px;
}

.send-text { display: none; }
.send-icon { font-size: 1rem; }

/* Unread nudge — when AI replies and chat is out of view */
.chat-unread-nudge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  padding: 0.35rem 0.65rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--dublin-green);
  background: var(--white);
  border: 1px solid var(--irish-green);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.chat-unread-nudge:hover {
  background: var(--irish-green);
  color: var(--white);
}
.chat-unread-nudge:focus-visible {
  outline: 3px solid var(--irish-green);
  outline-offset: 2px;
}

/* ── Disclaimer ──────────────────────────────────────────────────── */
.chat-disclaimer {
  padding: 0.4rem 1.25rem 0.6rem;
  background: var(--white);
  text-align: center;
}

.chat-disclaimer small {
  color: var(--medium-grey);
  font-size: 0.65rem;
}

.chat-disclaimer a {
  color: var(--irish-green);
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .chat-section {
    padding: var(--space-lg) 0;
  }

  .chat-card {
    max-width: 100%;
    border-radius: var(--radius-lg);
    margin-left: 0;
    margin-right: 0;
  }

  .chat-messages {
    height: 320px;
    min-height: 240px;
    padding: 0.75rem 1rem;
    -webkit-overflow-scrolling: touch;
  }

  .chat-header {
    padding: 0.75rem 1rem;
  }

  .chat-header-left h3 {
    font-size: 0.9rem;
  }

  .chat-input-area {
    padding: 0.6rem 0.75rem;
    gap: 0.25rem;
  }

  .chat-input-area input {
    min-height: 44px;
    font-size: 16px; /* prevents zoom on iOS */
    padding: 0.75rem 1rem;
  }

  .chat-input-area .chat-send-btn {
    min-width: 48px;
    min-height: 44px;
    padding: 0.75rem 1rem;
  }

  .chat-suggestions {
    padding: 0.5rem 0.75rem;
    gap: 0.35rem;
  }

  .suggestion-chip {
    font-size: 0.7rem;
    padding: 0.4rem 0.75rem;
    min-height: 36px;
  }

  .message {
    max-width: 92%;
  }

  .message-content {
    padding: 0.65rem 0.85rem;
  }

  .message-avatar {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
  }
}

@media (max-width: 380px) {
  .chat-messages {
    height: 280px;
  }

  .chat-suggestions {
    flex-direction: column;
  }

  .suggestion-chip {
    width: 100%;
    text-align: center;
  }
}

@media print {
  .chat-card { display: none; }
}
