/* ============================================
   NARA CHATBOT WIDGET
   Floating sales assistant — landing page + dashboard.
   Matches landing page design tokens.
   ============================================ */

/* ---- Variables ---- */
:root {
  --nara-primary:      #1A7A4A;
  --nara-primary-dark: #145C38;
  --nara-primary-bg:   #E8F5EE;
  --nara-white:        #ffffff;
  --nara-gray-50:      #f9f9f9;
  --nara-gray-100:     #f1f1f1;
  --nara-gray-200:     #e4e4e4;
  --nara-text:         #111111;
  --nara-text-mid:     #444444;
  --nara-text-light:   #888888;
  --nara-radius:       16px;
  --nara-shadow:       0 12px 40px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
  --nara-z:            9990;
}

/* ---- Root widget container ---- */
#nara-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--nara-z);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ============================================
   TOGGLE BUTTON
   ============================================ */

.nara-toggle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--nara-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(26, 122, 74, 0.45);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
  position: relative;
  color: #fff;
  outline: none;
}

.nara-toggle:hover {
  background: var(--nara-primary-dark);
  transform: scale(1.07);
  box-shadow: 0 6px 24px rgba(26, 122, 74, 0.55);
}

.nara-toggle:focus-visible {
  outline: 3px solid var(--nara-primary);
  outline-offset: 3px;
}

/* Chat / close icon swap */
.nara-toggle-icon--close { display: none; }

.nara-toggle--active .nara-toggle-icon--chat  { display: none; }
.nara-toggle--active .nara-toggle-icon--close { display: block; }

/* Notification badge */
.nara-toggle-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: #E53E3E;
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  transition: opacity 0.2s;
}

.nara-toggle--active .nara-toggle-badge { opacity: 0; pointer-events: none; }

/* Pulse ring — attracts attention on first load */
@keyframes nara-pulse {
  0%   { transform: scale(1);    opacity: 0.7; }
  70%  { transform: scale(1.55); opacity: 0;   }
  100% { transform: scale(1.55); opacity: 0;   }
}

.nara-toggle::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--nara-primary);
  animation: nara-pulse 2.2s ease-out 1.5s 2;
  z-index: -1;
}

/* ============================================
   CHAT PANEL
   ============================================ */

.nara-panel {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  width: 370px;
  max-height: 540px;
  background: var(--nara-white);
  border-radius: var(--nara-radius);
  box-shadow: var(--nara-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  border: 1px solid var(--nara-gray-200);
}

.nara-panel--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ---- Header ---- */
.nara-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--nara-primary);
  color: #fff;
  flex-shrink: 0;
}

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

.nara-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.35);
}

.nara-header-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.nara-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.82);
}

.nara-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5af08a;
  flex-shrink: 0;
}

.nara-close-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.nara-close-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

/* ---- Messages area ---- */
.nara-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.nara-messages::-webkit-scrollbar { width: 4px; }
.nara-messages::-webkit-scrollbar-track { background: transparent; }
.nara-messages::-webkit-scrollbar-thumb { background: var(--nara-gray-200); border-radius: 4px; }

/* ---- Individual messages ---- */
.nara-msg {
  display: flex;
  max-width: 88%;
  animation: nara-msg-in 0.18s ease;
}

@keyframes nara-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.nara-msg--bot  { align-self: flex-start; }
.nara-msg--user { align-self: flex-end; }

.nara-msg-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
}

.nara-msg--bot .nara-msg-bubble {
  background: var(--nara-gray-100);
  color: var(--nara-text);
  border-bottom-left-radius: 4px;
}

.nara-msg--user .nara-msg-bubble {
  background: var(--nara-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Rich text inside bot bubbles */
.nara-msg--bot .nara-msg-bubble p {
  margin: 0 0 6px;
}
.nara-msg--bot .nara-msg-bubble p:last-child {
  margin-bottom: 0;
}
.nara-msg--bot .nara-msg-bubble strong {
  color: var(--nara-primary-dark);
  font-weight: 700;
}
.nara-msg--bot .nara-msg-bubble ul {
  margin: 6px 0;
  padding-left: 18px;
}
.nara-msg--bot .nara-msg-bubble li {
  margin-bottom: 3px;
}
.nara-msg--bot .nara-msg-bubble a {
  color: var(--nara-primary);
  text-decoration: underline;
  font-weight: 600;
  word-break: break-all;
}
.nara-msg--bot .nara-msg-bubble a:hover {
  color: var(--nara-primary-dark);
}

/* Typing indicator */
.nara-msg-bubble--typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  min-width: 52px;
}

.nara-msg-bubble--typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--nara-text-light);
  display: inline-block;
  animation: nara-bounce 1.1s ease-in-out infinite;
}
.nara-msg-bubble--typing span:nth-child(2) { animation-delay: 0.18s; }
.nara-msg-bubble--typing span:nth-child(3) { animation-delay: 0.36s; }

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

/* ---- Suggestion chips ---- */
.nara-suggestions {
  padding: 6px 14px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.nara-chip {
  background: var(--nara-primary-bg);
  border: 1px solid rgba(26, 122, 74, 0.25);
  color: var(--nara-primary-dark);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.nara-chip:hover {
  background: #d4eddf;
  border-color: var(--nara-primary);
  transform: translateY(-1px);
}

/* ---- Input area ---- */
.nara-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--nara-gray-200);
  background: var(--nara-white);
  flex-shrink: 0;
}

.nara-input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--nara-gray-200);
  border-radius: 10px;
  font-size: 0.875rem;
  color: var(--nara-text);
  background: var(--nara-gray-50);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  min-width: 0;
}

.nara-input::placeholder { color: var(--nara-text-light); }

.nara-input:focus {
  border-color: var(--nara-primary);
  background: #fff;
}

.nara-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--nara-primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.nara-send-btn:hover:not(:disabled) {
  background: var(--nara-primary-dark);
  transform: scale(1.06);
}

.nara-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ---- Footer note ---- */
.nara-footer-note {
  text-align: center;
  font-size: 0.7rem;
  color: var(--nara-text-light);
  padding: 5px 0 8px;
  flex-shrink: 0;
}

.nara-footer-note a {
  color: var(--nara-text-light);
  text-decoration: underline;
}

/* ============================================
   MOBILE
   Full-width panel slides up from above the
   landing-bubbles bottom nav (~64px).
   ============================================ */

@media (max-width: 767px) {
  #nara-widget {
    bottom: 80px; /* 64px bottom nav + 16px gap */
    right: 16px;
  }

  .nara-panel {
    position: fixed;
    bottom: 64px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    /* Use svh so the panel never extends behind the browser chrome */
    max-height: calc(100svh - 148px);
    max-height: calc(100vh - 148px); /* fallback for older browsers */
    border-radius: var(--nara-radius) var(--nara-radius) 0 0;
    transform: translateY(20px);
  }

  .nara-panel--open {
    transform: translateY(0);
  }

  /* Allow chips to wrap so nothing overflows the panel edge */
  .nara-chip {
    white-space: normal;
    word-break: break-word;
    flex: 1 1 calc(50% - 6px);
    max-width: calc(50% - 3px);
    text-align: center;
  }

  /* Keep input row contents fully visible */
  .nara-input-wrap {
    padding: 10px 12px;
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  /* Prevent iOS Safari from zooming in when the input is focused */
  .nara-input {
    font-size: 16px;
  }
}
