/* ============================================================
   THE OAK DEVELOPMENT — AI Chatbot Widget
   Self-contained styles, namespaced under #oak-chatbot-root
   ============================================================ */

#oak-chatbot-root {
  --oak-black: #141414;
  --oak-text: #1A1A1A;
  --oak-text-2: #6B6B6B;
  --oak-bg: #FFFFFF;
  --oak-bg-alt: #F5F3EF;
  --oak-accent: #8B7355;
  --oak-accent-h: #A08660;
  --oak-border: #E2DDD8;
  --oak-font: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --oak-r: 16px;
  --oak-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);

  position: fixed;
  z-index: 999999;
  font-family: var(--oak-font);
  -webkit-font-smoothing: antialiased;
}

#oak-chatbot-root * {
  box-sizing: border-box;
}

/* ── Floating Action Button ── */
.oak-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--oak-black);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  transition: background 0.3s var(--oak-ease), transform 0.3s var(--oak-ease), box-shadow 0.3s var(--oak-ease);
  animation: oak-fab-in 0.5s var(--oak-ease) both;
}

.oak-fab:hover {
  background: var(--oak-accent);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(139, 115, 85, 0.35);
}

.oak-fab svg {
  width: 26px;
  height: 26px;
}

@keyframes oak-fab-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

/* ── Preview bubble ── */
.oak-preview-bubble {
  position: fixed;
  bottom: 92px;
  right: 24px;
  max-width: 240px;
  background: var(--oak-bg);
  color: var(--oak-text);
  border: 1px solid var(--oak-border);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.35s var(--oak-ease), transform 0.35s var(--oak-ease);
  pointer-events: none;
}

.oak-preview-bubble.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.oak-preview-bubble button.oak-preview-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--oak-bg);
  border: 1px solid var(--oak-border);
  color: var(--oak-text-2);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Chat window ── */
.oak-chat-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: 88vh;
  background: var(--oak-bg);
  border-radius: var(--oak-r);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.24);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.28s var(--oak-ease), transform 0.28s var(--oak-ease);
}

.oak-chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ── */
.oak-chat-header {
  background: var(--oak-black);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.oak-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.oak-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.oak-chat-header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.oak-chat-header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.oak-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34C759;
  display: inline-block;
  flex-shrink: 0;
}

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

.oak-chat-close svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.oak-chat-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* ── Messages area ── */
.oak-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--oak-bg-alt);
}

.oak-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: oak-msg-in 0.25s var(--oak-ease) both;
}

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

.oak-msg.oak-bot {
  align-self: flex-start;
  background: #fff;
  color: var(--oak-text);
  border: 1px solid var(--oak-border);
  border-bottom-left-radius: 4px;
}

.oak-msg.oak-user {
  align-self: flex-end;
  background: var(--oak-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── Typing indicator ── */
.oak-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--oak-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.oak-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--oak-text-2);
  animation: oak-bounce 1.2s infinite ease-in-out;
}

.oak-typing span:nth-child(2) { animation-delay: 0.15s; }
.oak-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes oak-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Quick reply chips ── */
.oak-chips {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 100%;
}

.oak-chip {
  background: #fff;
  border: 1px solid var(--oak-accent);
  color: var(--oak-accent);
  border-radius: 980px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  font-family: var(--oak-font);
}

.oak-chip:hover {
  background: var(--oak-accent);
  color: #fff;
}

/* ── Input area ── */
.oak-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--oak-border);
  background: #fff;
  flex-shrink: 0;
}

.oak-chat-input {
  flex: 1;
  border: 1px solid var(--oak-border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: var(--oak-font);
  color: var(--oak-text);
  resize: none;
  max-height: 100px;
  outline: none;
  transition: border-color 0.2s;
}

.oak-chat-input:focus {
  border-color: var(--oak-accent);
}

.oak-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--oak-black);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.oak-chat-send:hover {
  background: var(--oak-accent);
}

.oak-chat-send:disabled {
  background: var(--oak-border);
  cursor: not-allowed;
}

.oak-chat-send svg {
  width: 16px;
  height: 16px;
}

/* ── Footer ── */
.oak-chat-footer {
  text-align: center;
  padding: 6px 0 8px;
  font-size: 11px;
  color: var(--oak-text-2);
  background: #fff;
  flex-shrink: 0;
}

.oak-chat-footer a {
  color: var(--oak-text-2);
  text-decoration: underline;
}

.oak-chat-footer a:hover {
  color: var(--oak-accent);
}

/* ── Mobile: full-screen sheet ── */
@media (max-width: 640px) {
  .oak-chat-window {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    transform: translateY(24px);
  }

  .oak-chat-window.open {
    transform: translateY(0);
  }

  .oak-chat-header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }

  /* 16px input prevents iOS Safari from auto-zooming on focus,
     which was pushing the close/send buttons off-screen */
  .oak-chat-input {
    font-size: 16px;
  }

  .oak-chat-footer {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  /* hide the floating button while the chat is open */
  #oak-chatbot-root.oak-open .oak-fab,
  #oak-chatbot-root.oak-open .oak-preview-bubble {
    display: none;
  }

  .oak-fab {
    bottom: 16px;
    right: 16px;
  }

  .oak-preview-bubble {
    right: 16px;
    bottom: 82px;
    max-width: 200px;
  }
}
