/* ===============================
   BASE LAYOUT
================================*/
body {
  margin: 0;
  padding: 0;
  background: #f3f4f6;
  font-family: Arial, sans-serif;
  display: flex;
  justify-content: center;
  padding-top: 30px;
}

.chat-wrapper {
  width: 100%;
  max-width: 460px;
  height: 650px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 15px 45px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===============================
   HEADER
================================*/
.chat-header {
  background: linear-gradient(135deg, #0073ff, #0055cc);
  padding: 16px;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 3px;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
}

.chat-title-group .chat-title {
  font-size: 16px;
  font-weight: bold;
}

.chat-title-group .chat-sub {
  font-size: 12px;
  opacity: 0.9;
}

.chat-status {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 7px;
  height: 7px;
  background: #22c55e;
  border-radius: 50%;
}

/* ===============================
   CHAT WINDOW
================================*/
.chat-window {
  flex: 1;
  padding: 12px;
  background: linear-gradient(to bottom, #fafafa, #e5e7eb);
  overflow-y: auto;
  position: relative;

  /* Samsung / WebKit flexbox safety */
  min-height: 0;
  overscroll-behavior: contain;
}

.msg {
  margin-bottom: 12px;
}

.msg,
.msg-bubble {
  max-height: none !important;
  overflow: visible !important;
  white-space: normal !important;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  max-width: 90%;
  line-height: 1.4;
  word-wrap: break-word;
}

.bot-msg .msg-bubble {
  background: #fff;
  border: 1px solid #ddd;
  color: #111;
  border-bottom-left-radius: 4px;
}

.user-msg .msg-bubble {
  background: linear-gradient(135deg, #0073ff, #0055cc);
  color: #fff;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.msg-meta {
  font-size: 11px;
  color: #666;
  margin-top: 3px;
}

/* ===============================
   IMPROVED ANSWER + SOURCE BLOCK
================================*/
.answer-text {
  margin-bottom: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.source-block {
  font-size: 0.85em;
  color: #555;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #e5e5e5;
}

.source-label {
  font-weight: bold;
  margin-right: 4px;
}

.source-link {
  color: #0073ff;
  text-decoration: underline;
  cursor: pointer;
}

.source-link:hover {
  color: #0050cc;
}

/* ===============================
   TYPING INDICATOR
================================*/
.typing-msg .msg-bubble {
  min-height: 28px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
}

.typing-dots {
  display: flex;
  gap: 6px;
}

.typing-dots div {
  width: 6px;
  height: 6px;
  background: #555;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

.typing-dots div:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dots div:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ===============================
   FOOTER / INPUT AREA
================================*/
.chat-footer {
  padding: 12px;
  border-top: 1px solid #ddd;
  background: #f9fafb;
}

.input-area {
  display: flex;
  gap: 10px;
}

.input-area input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid #ccc;
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  background: #fff;
}

.input-area input:focus {
  border-color: #0073ff;
  box-shadow: 0 0 0 1px rgba(0,115,255,0.25);
}

.send-btn {
  background: linear-gradient(135deg, #0073ff, #22d3ee);
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  color: #fff;
  font-weight: bold;
  cursor: pointer;
}

.send-btn:hover {
  opacity: 0.9;
}

/* ===============================
   FIXED MODAL INSIDE CHAT WINDOW
================================*/
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.45);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9998;
}

.modal-box {
  background: #fff;
  width: 90%;
  max-width: 380px;
  padding: 22px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  text-align: left;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 9999;
}

/* ===============================
   FLOATING BUTTON + CHAT PANEL
================================*/
.chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  background: #007bff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.chat-toggle-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  pointer-events: none;
}

/* Enlarged + stronger desktop panel shell */
.chat-container {
  position: fixed;
  bottom: 90px;
  right: 10px;
  width: 480px;        /* was 380px */
  height: 650px;       /* was 550px */
  background: rgba(15, 23, 42, 0.96);  /* dark shell behind white card */
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid #111827;
  box-shadow: 0 22px 60px rgba(0,0,0,0.80);
  z-index: 9998;
}

.chat-container.hidden {
  display: none !important;
  pointer-events: none !important;
  height: 0 !important;
  width: 0 !important;
}

.chat-wrapper {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===============================
   PATCH: MESSAGE ALIGNMENT POLISH
   (Non-destructive overrides)
================================*/

/* Ensure message rows align cleanly */
.msg {
  display: flex;
}

/* Explicit alignment (prevents odd centering issues) */
.bot-msg {
  justify-content: flex-start;
}

.user-msg {
  justify-content: flex-end;
}

/* Improve bubble readability without changing design */
.msg-bubble {
  line-height: 1.55;          /* overrides earlier 1.4 */
  padding: 14px 16px;         /* slightly more breathing room */
}

/* Prevent assistant bubbles looking like panels */
.bot-msg .msg-bubble {
  background: #ffffff;
}

/* Improve helper / guidance text alignment */
.answer-text em {
  display: block;
  margin-top: 6px;
  font-size: 0.9em;
  opacity: 0.75;
}

/* Slightly improve vertical rhythm */
.msg-meta {
  margin-top: 4px;
}

/* ===============================
   PATCH: FIX ASSISTANT TEXT ALIGNMENT
================================*/

/* Force clean left alignment for assistant text */
.bot-msg .answer-text {
  text-align: left;
}

/* Prevent awkward vertical centering */
.bot-msg .msg-bubble {
  display: block;
}

/* Improve readability for multi-line assistant prompts */
.bot-msg .answer-text {
  line-height: 1.6;
}

/* ===============================
   PATCH: CHAT TOGGLE ICON (NO IMAGE CHANGE)
================================*/

/* Hide existing logo image visually */
.chat-toggle-logo {
  opacity: 0;
}

/* Add chat bubble icon via CSS */
.chat-toggle::after {
  content: "💬";
  font-size: 34px;
  color: #ffffff;
  position: absolute;
  line-height: 1;
}

/* ===============================
   PATCH: PRESSABLE CHAT BUTTONS (REFINED)
================================*/

/* Base button style */
.chat-topic-btn,
.chat-question-btn,
.chat-options button,
.send-btn {
  position: relative;
  cursor: pointer;

  -webkit-tap-highlight-color: transparent;

  transition:
    background-color 0.15s ease,
    transform 0.12s ease,
    box-shadow 0.12s ease;
}

/* Raised (default) */
.chat-topic-btn,
.chat-question-btn,
.chat-options button {
  background: #ffffff;
  color: #111;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;

  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.9),
    0 4px 0 #cbd5e1;
}

/* SEND button (keeps blue style but gains depth) */
.send-btn {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.35),
    0 4px 0 #0050cc;
}

/* Hover (desktop only) */
@media (hover: hover) {
  .chat-topic-btn:hover,
  .chat-question-btn:hover,
  .chat-options button:hover {
    background: #fff7d6; /* light warm yellow */
  }

  .send-btn:hover {
    filter: brightness(1.05);
  }
}

/* Active / pressed (mobile + desktop) */
.chat-topic-btn:active,
.chat-question-btn:active,
.chat-options button:active,
.send-btn:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.9),
    0 1px 0 #cbd5e1;
}

/* Slight press delay (tactile feel) */
.chat-topic-btn:active,
.chat-question-btn:active,
.chat-options button:active,
.send-btn:active {
  transition-duration: 0.08s;
}

/* ===============================
   📱 MOBILE / SAMSUNG TUNING
================================*/
@media (max-width: 600px) {

  /* Floating button size */
  .chat-toggle {
    width: 50px;
    height: 50px;
    bottom: 16px;
    right: 16px;
  }

  .chat-toggle-logo {
    width: 28px;
    height: 28px;
  }

  /* Mobile shell – clearly separated from edges */
  .chat-container {
    position: fixed;
    top: env(safe-area-inset-top, 12px);
    right: 12px;
    left: 12px;
    bottom: calc(72px + env(safe-area-inset-bottom, 16px));

    width: auto;
    max-width: 100vw;
    height: auto;
    max-height: 80vh;

    border-radius: 18px;
    background: rgba(15, 23, 42, 0.96);
    box-shadow: 0 24px 70px rgba(0,0,0,0.85);
    border: 2px solid #111827;

    overflow: hidden;
    display: flex !important;
  }

  .chat-wrapper {
    height: 100%;
    max-height: none;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 16px;
  }

  /* Scroll region becomes flexible */
  .chat-window {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }

  /* Compact header */
  .chat-header {
    padding: 12px;
  }

  .chat-avatar {
    width: 34px;
    height: 34px;
  }

  .chat-title-group .chat-title {
    font-size: 15px;
  }

  .chat-title-group .chat-sub {
    font-size: 11px;
  }

  /* Compact bubbles */
  .msg-bubble {
    font-size: 13px;
    padding: 10px 12px;
    line-height: 1.5;
  }

  /* Fix send button cut-off on Samsung */
  .input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding-right: 4px;
    box-sizing: border-box;
  }

  .input-area input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    font-size: 14px;
    box-sizing: border-box;
  }

  .send-btn {
    flex-shrink: 0;
    width: 70px;
    padding: 8px 14px;
    font-size: 14px;
    text-align: center;
    border-radius: 999px;
  }

  /* Mobile sizing for icon */
  .chat-toggle::after {
    font-size: 26px;
  }
}