@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --fasta-blue: #01a9e6;
  --fasta-blue-dark: #0187b8;
  --fasta-blue-light: #e6f7fd;
  --fasta-green: rgb(105, 190, 33);
  --fasta-green-dark: #5a9e1a;
  --fasta-green-light: #f0fae6;
  --fasta-white: #ffffff;
  --fasta-text: #1a1a2e;
  --fasta-muted: #6b7a99;
  --fasta-border: #d4eef9;
  --fasta-bg: #f4fbff;
}

/* ── Launcher wrapper ── */
.chat-launcher-wrapper {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 99999;
}

@media (min-width: 640px) {
  .chat-launcher-wrapper {
    bottom: 28px;
    right: 28px;
  }
}

.chat-launcher-row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 12px;
}

/* ── Tooltip — default (greeting) ── */
.chat-tooltip {
  position: relative;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 12px 14px;
  max-width: 200px;
  font-size: 13px;
  color: #333;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  animation: fadeInUp 0.25s ease;
}

@media (min-width: 640px) {
  .chat-tooltip {
    max-width: 220px;
    font-size: 14px;
  }
}

/* Tail pointing right toward the chat icon */
.chat-tooltip::after {
  content: '';
  position: absolute;
  bottom: 12px;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 8px solid #ffffff;
}


.chat-tooltip-close {
  background: none;
  border: none;
  padding: 2px;
  color: #bbb;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: -10px;
  pointer-events: auto;
  position: relative;
  z-index: 1;
  /* Minimum 44px touch target */
  min-width: 30px;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-tooltip-close:hover {
  color: #666;
}

/* ── Tooltip — reminder variant (green) ── */
.chat-tooltip.chat-tooltip--reminder {
  box-shadow: 0 4px 20px rgba(105, 190, 33, 0.4);
  animation: fadeInUp 0.25s ease;
}

.chat-tooltip.chat-tooltip--reminder::after {
  border-left-color: rgb(105, 190, 33);
}

.chat-tooltip.chat-tooltip--reminder .chat-tooltip-close {
  color: rgba(255, 255, 255, 0.7);
}

.chat-tooltip.chat-tooltip--reminder .chat-tooltip-close:hover {
  color: #fff;
}


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

/* ── Launcher button ── */
.chat-launcher {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(140deg, #01c4f5 0%, #01a8d4 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow:
    0 4px 20px rgba(1, 169, 230, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.15);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
  border: none;
  flex-shrink: 0;
  touch-action: manipulation;
}

@media (min-width: 640px) {
  .chat-launcher {
    width: 56px;
    height: 56px;
  }
}

.chat-launcher:hover {
  transform: scale(1.08);
  box-shadow:
    0 6px 28px rgba(1, 169, 230, 0.6),
    0 2px 10px rgba(0, 0, 0, 0.18);
}

.chat-launcher-icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.chat-unread {
  position: absolute;
  top: -2px;
  right: -2px;
  background: rgb(105, 190, 33);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* ── Chat window ── */
/* Mobile-first: full-screen */
.chat-window {
  position: fixed;
  inset: 0;
  width: 100%;
  /* fallback for browsers without dvh */
  height: 100%;
  height: 100dvh;
  background: #fff;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  animation: chatSlideUp 0.25s ease;
}

/* Tablet and up: bubble positioned bottom-right */
@media (min-width: 640px) {
  .chat-window {
    inset: auto;
    bottom: 96px;
    right: 28px;
    width: 380px;
    height: 560px;
    border-radius: 18px;
    box-shadow:
      0 24px 80px rgba(1, 169, 230, 0.22),
      0 8px 32px rgba(0, 0, 0, 0.1);
  }
}

@keyframes chatSlideUp {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── Header ── */
.chat-header {
  background: linear-gradient(135deg, #01c4f5 0%, #01a8d4 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  /* Respect status bar / notch */
  padding-top: max(14px, env(safe-area-inset-top));
}

@media (min-width: 640px) {
  .chat-header {
    padding-top: 14px;
  }
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.chat-header-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
  font-family: 'IBM Plex Sans', sans-serif;
}

.chat-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 2px;
  font-family: 'IBM Plex Sans', sans-serif;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgb(105, 190, 33);
  flex-shrink: 0;
}

.status-dot.offline {
  background: rgba(255, 255, 255, 0.3);
}

.chat-header-close {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: rgba(255, 255, 255, 0.85);
  /* 44px touch target on mobile */
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  touch-action: manipulation;
}

@media (min-width: 640px) {
  .chat-header-close {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }
}

.chat-header-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* ── Context bar ── */
.chat-context-bar {
  background: #e6f7fd;
  border-bottom: 1px solid #b8e4f7;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.context-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, #01c4f5 0%, #01a8d4 100%);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  font-family: 'IBM Plex Mono', monospace;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(1, 169, 230, 0.3);
}

/* ── Messages ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f4fbff;
  /* Prevent overscroll from affecting parent page on mobile */
  overscroll-behavior: contain;
}

@media (min-width: 640px) {
  .chat-messages {
    padding: 16px 14px;
  }
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: #b8e4f7;
  border-radius: 4px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}

@media (min-width: 640px) {
  .chat-msg {
    max-width: 80%;
  }
}

.chat-msg.assistant {
  align-self: flex-start;
}

.chat-msg.user {
  align-self: flex-end;
}

.chat-msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.chat-msg.user .chat-msg-meta {
  justify-content: flex-end;
}

.chat-msg-name {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-family: 'IBM Plex Mono', monospace;
}

.chat-msg.assistant .chat-msg-name {
  color: #01a9e6;
}

.chat-msg.user .chat-msg-name {
  color: #5a9e1a;
}

.chat-msg-time {
  font-size: 10px;
  color: #b0b8cc;
  font-family: 'IBM Plex Mono', monospace;
}

.chat-msg-bubble {
  padding: 10px 12px;
  /* 15px on mobile for readability */
  font-size: 15px;
  line-height: 1.65;
  word-break: break-word;
  font-family: 'IBM Plex Sans', sans-serif;
  width: fit-content;
  max-width: 100%;
  display: inline-block;
  box-sizing: border-box;
}

@media (min-width: 640px) {
  .chat-msg-bubble {
    font-size: 13.5px;
    padding: 10px;
  }
}

.chat-msg.assistant .chat-msg-bubble {
  background: linear-gradient(135deg, #01c4f5 0%, #01a8d4 100%);
  color: #fff;
  border: none;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 10px rgba(1, 169, 230, 0.25);
}

.chat-msg.user .chat-msg-bubble {
  background: linear-gradient(135deg, #7ecf2c 0%, #6abc22 100%);
  color: #fff;
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 10px rgba(105, 190, 33, 0.25);
}

/* ── Tool chips ── */
.chat-tool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.tool-chip {
  background: #f0fae6;
  color: #5a9e1a;
  border: 1px solid #c5e8a0;
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
  padding: 2px 8px;
  border-radius: 10px;
}

/* ── Typing indicator ── */
.chat-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #d4eef9;
  border-radius: 12px;
  border-bottom-left-radius: 3px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  background: #01a9e6;
  border-radius: 50%;
  display: inline-block;
  opacity: 0.4;
  animation: typingBounce 1.2s infinite ease-in-out;
}

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

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

/* ── Quick replies ── */
.chat-quick-replies {
  padding: 8px 12px 6px;
  display: flex;
  /* Horizontal scroll on mobile so long chips don't wrap badly */
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 6px;
  background: #fff;
  border-top: 1px solid #d4eef9;
  flex-shrink: 0;
  /* Hide scrollbar visually but keep functionality */
  scrollbar-width: none;
}

.chat-quick-replies::-webkit-scrollbar {
  display: none;
}

@media (min-width: 640px) {
  .chat-quick-replies {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

.quick-reply {
  background: #e6f7fd;
  border: 1px solid #b8e4f7;
  color: #0187b8;
  /* 15px to match bubble size on mobile */
  font-size: 13px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 500;
  /* Taller tap target */
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  touch-action: manipulation;
}

@media (min-width: 640px) {
  .quick-reply {
    font-size: 12px;
    padding: 5px 12px;
  }
}

.quick-reply:hover {
  background: #01a9e6;
  border-color: #01a9e6;
  color: #fff;
}

/* ── Input area ── */
.chat-input-area {
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #d4eef9;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  /* Push above home bar on iOS */
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

@media (min-width: 640px) {
  .chat-input-area {
    padding-bottom: 10px;
  }
}

.chat-input-area textarea {
  flex: 1;
  border: 1px solid #d4eef9;
  border-radius: 10px;
  padding: 9px 13px;
  /* 16px prevents iOS auto-zoom on focus */
  font-size: 16px;
  font-family: 'IBM Plex Sans', sans-serif;
  color: #1a1a2e;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  background: #f4fbff;
  -webkit-appearance: none;
}

@media (min-width: 640px) {
  .chat-input-area textarea {
    font-size: 13.5px;
    max-height: 100px;
  }
}

.chat-input-area textarea:focus {
  border-color: #01a9e6;
  background: #fff;
}

.chat-input-area textarea::placeholder {
  color: #b0b8cc;
}

.chat-send-btn {
  /* 44px minimum touch target */
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #01c4f5 0%, #01a8d4 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(1, 169, 230, 0.35);
}

@media (min-width: 640px) {
  .chat-send-btn {
    width: 38px;
    height: 38px;
    font-size: 14px;
  }
}

.chat-send-btn:hover {
  background: linear-gradient(135deg, #00b8e8 0%, #0099c5 100%);
}
.chat-send-btn:active {
  transform: scale(0.93);
}
.chat-send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}


/* ── Footer ── */
.chat-footer {
  text-align: center;
  padding: 6px;
  background: #fff;
  font-size: 10px;
  color: #b0b8cc;
  font-family: 'IBM Plex Mono', monospace;
  border-top: 1px solid #d4eef9;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.chat-footer img {
  height: 16px;
  vertical-align: middle;
  opacity: 0.6;
}
