/* ============================================================
   Bankbyte AI Chat Widget — Flytande chattruta nere till höger
   Matchar appens designspråk: ljust, rent, systemfonter
   ============================================================ */

/* --- Öppna-knapp (flytande bubbla) --- */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3080EA, #1a5fcf);
  border: none;
  padding: 10px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 102, 204, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 9998;
  overflow: hidden;
}
.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 102, 204, 0.45);
}
.chat-fab-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.chat-fab.hidden { display: none; }

/* --- MAX-badge på bubblan --- */
.chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: linear-gradient(135deg, #F57C00, #E65100);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
  letter-spacing: 0.5px;
}

/* --- Chattfönster (container) --- */
.chat-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 48px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* --- Header --- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(135deg, #0066CC, #004C99);
  color: #fff;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-header-avatar svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}
.chat-header-info {
  flex: 1;
  min-width: 0;
}
.chat-header-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}
.chat-header-subtitle {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-top: 2px;
}
.chat-close-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* --- Meddelandeyta --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #F8F9FA;
}
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 3px;
}

/* --- Meddelanden --- */
.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: chatMsgIn 0.25s ease;
}
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg.bot {
  align-self: flex-start;
}
.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  margin-top: 2px;
}
.chat-msg.bot .chat-msg-avatar {
  background: #E6F2FF;
  color: #0066CC;
}
.chat-msg.user .chat-msg-avatar {
  background: #FFF3E0;
  color: #E65100;
}

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg.bot .chat-msg-bubble {
  background: #fff;
  color: #1A1A1A;
  border: 1px solid #E2E8F0;
  border-bottom-left-radius: 4px;
}
.chat-msg.user .chat-msg-bubble {
  background: linear-gradient(135deg, #0066CC, #004C99);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* --- Markdown i bot-svar --- */
.chat-msg.bot .chat-msg-bubble strong {
  font-weight: 700;
  color: #0066CC;
}
.chat-msg.bot .chat-msg-bubble ul,
.chat-msg.bot .chat-msg-bubble ol {
  margin: 6px 0;
  padding-left: 18px;
}
.chat-msg.bot .chat-msg-bubble li {
  margin-bottom: 3px;
}
.chat-msg.bot .chat-msg-bubble a {
  color: #0066CC;
  text-decoration: underline;
}
.chat-msg.bot .chat-msg-bubble p {
  margin: 0 0 8px 0;
}
.chat-msg.bot .chat-msg-bubble p:last-child {
  margin-bottom: 0;
}

/* --- Källor under bot-svar --- */
.chat-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #E2E8F0;
  font-size: 0.75rem;
  color: #5F6368;
}
.chat-sources summary {
  cursor: pointer;
  font-weight: 600;
  color: #5F6368;
}
.chat-sources ul {
  margin: 4px 0 0 0;
  padding-left: 16px;
}
.chat-sources li {
  margin-bottom: 2px;
}
.chat-sources a {
  color: #0066CC;
  text-decoration: none;
}
.chat-sources a:hover {
  text-decoration: underline;
}

/* --- Skrivindikator --- */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
  align-items: center;
}
.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94A3B8;
  animation: typingBounce 1.2s infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* --- Inmatning --- */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #E2E8F0;
  background: #fff;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  border: 1px solid #E2E8F0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color 0.2s ease;
  color: #1A1A1A;
  background: #F8F9FA;
}
.chat-input:focus {
  border-color: #0066CC;
  background: #fff;
}
.chat-input::placeholder {
  color: #94A3B8;
}
.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #0066CC, #004C99);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, opacity 0.15s ease;
  flex-shrink: 0;
}
.chat-send-btn:hover {
  transform: scale(1.05);
}
.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
.chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* --- Välkomstmeddelande (förslag-knappar) --- */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chat-suggestion-btn {
  background: #E6F2FF;
  color: #0066CC;
  border: 1px solid #B3D4FC;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
  font-family: inherit;
  line-height: 1.3;
}
.chat-suggestion-btn:hover {
  background: #CCE4FF;
  transform: translateY(-1px);
}

/* --- Rate limit / felmeddelande --- */
.chat-error {
  background: #FFF3E0;
  color: #E65100;
  border: 1px solid #FFE0B2;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.82rem;
  text-align: center;
  margin: 4px 0;
}

/* --- Metod-badge (qa_pair / groq) --- */
.chat-method-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
  margin-left: 6px;
  vertical-align: middle;
}
.chat-method-badge.qa {
  background: #DCFCE7;
  color: #166534;
}
.chat-method-badge.groq {
  background: #FEF3C7;
  color: #92400E;
}

/* --- Responsiv --- */
@media (max-width: 480px) {
  .chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  .chat-fab {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
  }
}
