/* ==========================================================================
   BAWAGO AI AGENT — MOBILE-FIRST DESIGN SYSTEM
   Optimized for smartphones (Google Pixel 9a, Samsung Galaxy, iPhone),
   tablets, and desktops.
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  --secondary: #0f172a;
  --text-main: #0f172a;
  --text-body: #334155;
  --text-muted: #64748b;
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-stream: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --success: #10b981;
  
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 36px -8px rgba(15, 23, 42, 0.12);
  
  --font-sans: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Touch target standard (Android Material 48dp / iOS 44pt) */
  --min-touch-target: 48px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   MOBILE DEFAULT (MOBILE-FIRST BASE STYLES)
   ========================================================================== */

body {
  font-family: var(--font-sans);
  background: var(--bg-card);
  color: var(--text-main);
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
}

/* Chat App Wrapper — Mobile fills entire screen cleanly */
.chat-app-wrapper {
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Mobile Header / App Bar */
.chat-header {
  min-height: 60px;
  padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
  padding-left: max(1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
  padding-bottom: 0.75rem;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  z-index: 20;
  flex-shrink: 0;
}

.agent-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.agent-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.agent-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #eff6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #e0e7ff;
  overflow: hidden;
}

.agent-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.online-indicator {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid #ffffff;
}

.agent-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.agent-name-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

.agent-name {
  font-size: 1.05rem; /* ~17px */
  font-weight: 800;
  color: var(--secondary);
  letter-spacing: -0.2px;
  line-height: 1.2;
}

.agent-badge {
  font-size: 0.7rem; /* ~11px */
  font-weight: 700;
  text-transform: uppercase;
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  letter-spacing: 0.4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.context-pill {
  font-size: 0.72rem;
  font-weight: 600;
  color: #1d4ed8;
  background: #dbeafe;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid #bfdbfe;
  animation: fadeIn 0.3s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
  flex-shrink: 1;
}

.agent-status {
  font-size: 0.8rem; /* ~13px */
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.clear-btn:hover,
.clear-btn:focus-visible {
  background: #f8fafc;
  color: var(--secondary);
  border-color: var(--border-strong);
}

.clear-btn:active {
  transform: scale(0.96);
  background: #f1f5f9;
}

/* Chat Messages Scroll Stream */
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-stream);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   MOBILE-FIRST WELCOME SECTION (NO MINIATURE BOXES)
   ========================================================================== */

.welcome-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1rem 0.25rem 1.5rem;
  margin: 0 auto;
  animation: fadeIn 0.35s ease;
}

.welcome-avatar-wrap {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.18);
  border: 3px solid #eff6ff;
  overflow: hidden;
  margin-bottom: 0.75rem;
  background: #ffffff;
  flex-shrink: 0;
}

.welcome-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.welcome-title {
  font-size: 1.45rem; /* ~23px */
  font-weight: 800;
  color: var(--secondary);
  letter-spacing: -0.3px;
  margin-bottom: 0.5rem;
  line-height: 1.25;
}

.welcome-text {
  font-size: 0.95rem; /* ~15.2px readable mobile body */
  color: var(--text-body);
  line-height: 1.55;
  margin-bottom: 1.25rem;
  max-width: 100%;
}

.welcome-text strong {
  color: var(--secondary);
}

.starter-chips-label {
  align-self: flex-start;
  font-size: 0.8rem; /* ~13px */
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.6px;
  margin-bottom: 0.65rem;
  padding-left: 0.25rem;
}

/* Suggested Question Action Cards (Thumb-friendly full-width on mobile) */
.starter-chips {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
}

.chip-btn {
  background: #ffffff;
  border: 1.5px solid var(--border);
  padding: 0.75rem 1rem;
  min-height: var(--min-touch-target);
  border-radius: 14px;
  font-size: 0.94rem; /* ~15px */
  font-weight: 500;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: left;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  width: 100%;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.chip-btn .chip-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.chip-btn .chip-label {
  flex: 1;
  line-height: 1.4;
  color: #1e293b;
  font-weight: 600;
}

.chip-btn .chip-arrow {
  color: #94a3b8;
  font-size: 1.25rem;
  font-weight: 400;
  flex-shrink: 0;
  margin-left: 0.25rem;
}

.chip-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.chip-btn:active {
  background: #eff6ff;
  border-color: #93c5fd;
  color: var(--primary);
  transform: scale(0.99);
}

/* ==========================================================================
   CHAT MESSAGES & BUBBLES
   ========================================================================== */

.message-row {
  display: flex;
  gap: 0.65rem;
  width: 100%;
  animation: slideUp 0.22s ease;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.bot {
  justify-content: flex-start;
}

.bubble {
  max-width: 88%;
  padding: 0.85rem 1.05rem;
  border-radius: 16px;
  font-size: 0.95rem; /* ~15.2px */
  line-height: 1.55;
  position: relative;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.message-row.user .bubble {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
}

.message-row.bot .bubble {
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.bot-identity {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.bot-badge-img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid #bfdbfe;
  background: #eff6ff;
  flex-shrink: 0;
}

.bot-badge-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--secondary);
}

.topic-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  color: #2563eb;
  background: #eff6ff;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid #bfdbfe;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble-meta {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.message-row.user .bubble-meta {
  color: rgba(255, 255, 255, 0.82);
  justify-content: flex-end;
}

/* Action Cards */
.action-card {
  margin-top: 0.75rem;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font-size: 0.88rem; /* ~14px */
  animation: slideUp 0.25s ease;
  width: 100%;
}

.action-card.checklist {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.action-card.flow {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.action-card.warning {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.action-card-title {
  font-weight: 700;
  margin-bottom: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  line-height: 1.35;
}

.action-card-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.action-card-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  line-height: 1.45;
}

.action-card.checklist li::before {
  content: "✓";
  font-weight: 800;
  color: #15803d;
  flex-shrink: 0;
}

.action-card.flow .flow-steps {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.action-card.flow .flow-step {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  line-height: 1.45;
}

/* Feedback Buttons */
.feedback-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px solid #f1f5f9;
  flex-wrap: wrap;
}

.feedback-btn {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  min-height: 36px;
  font-size: 0.8rem; /* ~13px */
  font-weight: 500;
  cursor: pointer;
  color: #475569;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.feedback-btn:hover {
  background: #f8fafc;
  color: var(--secondary);
}

.feedback-btn:active {
  transform: scale(0.96);
}

.feedback-btn.active-helpful {
  background: #ecfdf5 !important;
  color: #059669 !important;
  border-color: #6ee7b7 !important;
  font-weight: 600 !important;
}

.feedback-btn.active-improve {
  background: #fffbeb !important;
  color: #d97706 !important;
  border-color: #fcd34d !important;
  font-weight: 600 !important;
}

/* Typing Indicator */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 1rem;
  background: transparent;
  flex-shrink: 0;
}

.typing-indicator.active {
  display: flex;
}

.typing-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.typing-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.typing-dots {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.55rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  box-shadow: var(--shadow-sm);
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.typing-label {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 500;
}

.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  background: var(--primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.7s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Dynamic Follow-Up Chips Bar */
.dynamic-chips-container {
  display: flex;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: #ffffff;
  border-top: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  align-items: center;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}

.dynamic-chips-container::-webkit-scrollbar {
  display: none;
}

.dynamic-chip,
.dynamic-chip-btn {
  background: #ffffff !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 9999px !important;
  padding: 0.5rem 1rem !important;
  min-height: 40px !important;
  font-size: 0.86rem !important; /* ~13.8px */
  font-weight: 600 !important;
  color: #1e293b !important;
  cursor: pointer !important;
  flex-shrink: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 0.4rem !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
  touch-action: manipulation !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

.dynamic-chip:hover,
.dynamic-chip-btn:hover {
  background: #f8fafc !important;
  border-color: #93c5fd !important;
}

.dynamic-chip:active,
.dynamic-chip-btn:active {
  background: #eff6ff !important;
  border-color: var(--primary) !important;
  color: var(--primary) !important;
}

/* ==========================================================================
   MOBILE COMPOSER / INPUT BAR
   ========================================================================== */

.chat-input-bar {
  padding-top: 0.65rem;
  padding-left: max(0.85rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.85rem, env(safe-area-inset-right, 0px));
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
  background: #ffffff;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 20;
}

.input-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #f8fafc;
  border: 1.5px solid var(--border-strong);
  border-radius: 24px;
  padding: 0.25rem 0.35rem 0.25rem 1rem;
  transition: all 0.2s ease;
  min-height: 48px;
}

.input-form:focus-within {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px; /* 16px strictly prevents auto-zoom on mobile */
  color: var(--text-main);
  outline: none;
  min-height: 40px;
  line-height: 1.4;
}

.chat-input::placeholder {
  color: #94a3b8;
  font-size: 0.94rem;
}

.send-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
  touch-action: manipulation;
}

.send-btn:hover {
  background: var(--primary-hover);
}

.send-btn:active {
  transform: scale(0.92);
}

.input-disclaimer {
  font-size: 0.74rem; /* ~12px */
  color: #94a3b8;
  text-align: center;
  line-height: 1.2;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* ==========================================================================
   EXTRA SMALL SCREENS (<= 360px, e.g. iPhone SE 1st gen)
   ========================================================================== */

@media (max-width: 360px) {
  .chat-header {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }
  .agent-name {
    font-size: 0.95rem;
  }
  .clear-btn-text {
    display: none; /* Keep icon only */
  }
  .chip-btn {
    padding: 0.65rem 0.75rem;
    font-size: 0.88rem;
  }
}

/* ==========================================================================
   TABLETS & MEDIUM SCREENS (>= 768px)
   ========================================================================== */

@media (min-width: 768px) {
  body {
    background: var(--bg-app);
    justify-content: center;
    align-items: center;
    padding: 1.25rem;
  }

  .chat-app-wrapper {
    max-width: 780px;
    height: min(94vh, 900px);
    height: min(94dvh, 900px);
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }

  .chat-header {
    padding: 1rem 1.5rem;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
  }

  .chat-messages {
    padding: 1.5rem;
    gap: 1.25rem;
  }

  .welcome-card {
    padding: 1.5rem 1.25rem 2rem;
    max-width: 640px;
  }

  .starter-chips {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .bubble {
    max-width: 82%;
    padding: 1rem 1.25rem;
  }

  .chat-input-bar {
    padding: 1rem 1.5rem;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
  }
}

/* ==========================================================================
   DESKTOPS & LARGE DISPLAYS (>= 1024px)
   ========================================================================== */

@media (min-width: 1024px) {
  .chat-app-wrapper {
    max-width: 820px;
    height: min(92vh, 880px);
    height: min(92dvh, 880px);
  }

  .bubble {
    max-width: 78%;
  }

  .chat-messages::-webkit-scrollbar {
    width: 6px;
  }
  .chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 9999px;
  }
}

/* ==========================================================================
   LANDSCAPE MOBILE HEIGHT ADJUSTMENT (max-height <= 500px)
   ========================================================================== */

@media (max-height: 500px) and (orientation: landscape) {
  .chat-header {
    min-height: 48px;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
  }

  .agent-avatar {
    width: 32px;
    height: 32px;
  }

  .welcome-avatar-wrap {
    width: 44px;
    height: 44px;
    margin-bottom: 0.35rem;
  }

  .welcome-card {
    padding: 0.5rem 0.25rem 1rem;
  }

  .chat-input-bar {
    padding-top: 0.35rem;
    padding-bottom: max(0.35rem, env(safe-area-inset-bottom, 0px));
  }
}
