/* ==============================================
   AI Navigator Chat — eSided
   Slide-out panel with expand mode.
   All classes prefixed esided-chat- to avoid conflicts.
   ============================================== */

/* ---- FAB trigger button ---- */
.esided-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-blue, #0091d2);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  z-index: 9998;
  transition: transform .2s, box-shadow .2s;
}
.esided-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
}

/* ---- Overlay (mobile) ---- */
.esided-chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 9999;
}
.esided-chat-overlay.esided-chat-open { display: block; }

/* ---- Panel ---- */
.esided-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #fff;
  box-shadow: -4px 0 24px rgba(0,0,0,.15);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform .3s cubic-bezier(.4,0,.2,1), visibility .3s, width .3s cubic-bezier(.4,0,.2,1);
}
.esided-chat-panel.esided-chat-open {
  transform: translateX(0);
  visibility: visible;
}
.esided-chat-panel.esided-chat-expanded {
  width: 100vw;
  box-shadow: none;
}
.esided-chat-panel.esided-chat-expanded .esided-chat-header,
.esided-chat-panel.esided-chat-expanded .esided-chat-messages,
.esided-chat-panel.esided-chat-expanded .esided-chat-email-bar,
.esided-chat-panel.esided-chat-expanded .esided-chat-input-area,
.esided-chat-panel.esided-chat-expanded .esided-chat-turn-counter,
.esided-chat-panel.esided-chat-expanded .esided-chat-ended {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

/* ---- Header ---- */
.esided-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-shrink: 0;
}
.esided-chat-header-title {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: #111;
  flex: 1;
}
.esided-chat-header-actions {
  display: flex;
  gap: 4px;
}
.esided-chat-header-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #6b7280;
  padding: 6px;
  border-radius: 6px;
  font-size: 16px;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.esided-chat-header-btn:hover {
  background: #e5e7eb;
  color: #111;
}

/* ---- Messages area ---- */
.esided-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- Message bubbles ---- */
.esided-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
}
.esided-chat-panel.esided-chat-expanded .esided-chat-msg {
  max-width: 640px;
}
.esided-chat-msg-user {
  align-self: flex-end;
  background: var(--primary-blue, #0091d2);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.esided-chat-msg-assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}

/* ---- Rendered markdown inside assistant bubbles ---- */
.esided-chat-msg-assistant p {
  margin: 0 0 8px 0;
}
.esided-chat-msg-assistant p:last-child {
  margin-bottom: 0;
}
.esided-chat-msg-assistant h1,
.esided-chat-msg-assistant h2,
.esided-chat-msg-assistant h3,
.esided-chat-msg-assistant h4,
.esided-chat-msg-assistant h5,
.esided-chat-msg-assistant h6 {
  font-size: 14px;
  font-weight: 700;
  margin: 10px 0 4px 0;
  line-height: 1.3;
}
.esided-chat-msg-assistant h1:first-child,
.esided-chat-msg-assistant h2:first-child,
.esided-chat-msg-assistant h3:first-child {
  margin-top: 0;
}
.esided-chat-msg-assistant ul,
.esided-chat-msg-assistant ol {
  margin: 4px 0 8px 0;
  padding-left: 20px;
}
.esided-chat-msg-assistant li {
  margin-bottom: 2px;
}
.esided-chat-msg-assistant li:last-child {
  margin-bottom: 0;
}
.esided-chat-msg-assistant code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
}
.esided-chat-msg-assistant pre {
  background: rgba(0, 0, 0, 0.06);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
  max-width: 100%;
}
.esided-chat-msg-assistant pre code {
  background: none;
  padding: 0;
  font-size: 12px;
}
.esided-chat-msg-assistant strong {
  font-weight: 600;
}
.esided-chat-msg-assistant a {
  color: var(--primary-blue, #0091d2);
  text-decoration: underline;
}
.esided-chat-msg-assistant blockquote {
  border-left: 3px solid rgba(0, 0, 0, 0.15);
  margin: 6px 0;
  padding: 2px 0 2px 10px;
  color: #4b5563;
}
.esided-chat-msg-assistant hr {
  border: none;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  margin: 8px 0;
}

/* ---- Presets ---- */
.esided-chat-presets {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
}
.esided-chat-preset-btn {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  text-align: left;
  transition: background .15s, border-color .15s;
  line-height: 1.4;
}
.esided-chat-preset-btn:hover {
  background: #e6f5fb;
  border-color: #7dcfee;
}

/* ---- Loading bubble (injected into messages area dynamically) ---- */
.esided-chat-loading {
  align-self: flex-start;
  padding: 10px 14px;
  background: #f3f4f6;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  max-width: 85%;
}

.esided-chat-loading-dots {
  display: flex;
  gap: 5px;
  margin-bottom: 6px;
}
.esided-chat-loading-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: esided-chat-bounce .6s infinite alternate;
}
.esided-chat-loading-dots span:nth-child(2) { animation-delay: .15s; }
.esided-chat-loading-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes esided-chat-bounce {
  to { opacity: .3; transform: translateY(-3px); }
}

.esided-chat-loading-tip {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
}

/* ---- Email capture bar ---- */
.esided-chat-email-bar {
  display: none;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #e6f5fb;
  flex-shrink: 0;
}
.esided-chat-email-bar.esided-chat-visible { display: block; }

.esided-chat-email-bar p {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: #374151;
  margin: 0 0 8px 0;
  line-height: 1.4;
}
.esided-chat-email-form {
  display: flex;
  gap: 8px;
}
.esided-chat-email-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  outline: none;
}
.esided-chat-email-input:focus {
  border-color: var(--primary-blue, #0091d2);
  box-shadow: 0 0 0 2px rgba(0,145,210,.15);
}
.esided-chat-email-submit {
  padding: 8px 16px;
  background: var(--primary-blue, #0091d2);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.esided-chat-email-submit:hover { background: var(--primary-dark, #007bb5); }
.esided-chat-email-submit:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.esided-chat-email-status {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  margin-top: 6px;
}
.esided-chat-email-status.esided-chat-success { color: #16a34a; }
.esided-chat-email-status.esided-chat-error { color: #dc2626; }

/* ---- Input area ---- */
.esided-chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}
.esided-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  outline: none;
  resize: none;
  min-height: 80px;
  max-height: 160px;
}
.esided-chat-input:focus {
  border-color: var(--primary-blue, #0091d2);
  box-shadow: 0 0 0 2px rgba(0,145,210,.15);
}
.esided-chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-blue, #0091d2);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background .15s;
  flex-shrink: 0;
  align-self: flex-end;
}
.esided-chat-send-btn:hover { background: var(--primary-dark, #007bb5); }
.esided-chat-send-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ---- Turn counter ---- */
.esided-chat-turn-counter {
  text-align: center;
  padding: 4px 0 0;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: #9ca3af;
}

/* ---- Session ended ---- */
.esided-chat-ended {
  display: none;
  padding: 16px;
  text-align: center;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-shrink: 0;
}
.esided-chat-ended.esided-chat-visible { display: block; }
.esided-chat-ended p {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: #6b7280;
  margin: 0 0 10px 0;
}
.esided-chat-ended-cta {
  display: inline-block;
  padding: 8px 20px;
  background: var(--primary-blue, #0091d2);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.esided-chat-ended-cta:hover { background: var(--primary-dark, #007bb5); }

/* ---- Mobile ---- */
@media (max-width: 480px) {
  .esided-chat-panel {
    width: 100vw;
  }
  .esided-chat-fab {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}
