/**
 * AI Chat Assistant Styles
 *
 * Theme-token compliant, responsive, supports light/dark modes.
 * Prefix: nd-chat-
 *
 * @package NightDesk
 */

/* ==========================================================================
   1. Chat Launcher Button
   ========================================================================== */

.nd-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--nd-accent);
  color: var(--nd-accent-ink);
  border: none;
  box-shadow: 0 4px 16px var(--nd-shadow);
  cursor: pointer;
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, background 0.2s ease;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.nd-chat-launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px var(--nd-shadow);
}

.nd-chat-launcher:active {
  transform: scale(0.96);
}

.nd-chat-launcher:focus-visible {
  outline: 2px solid var(--nd-accent);
  outline-offset: 3px;
}

.nd-chat-launcher-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
  stroke: currentColor;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nd-chat-launcher .nd-chat-icon-close {
  display: none;
}

.nd-chat-launcher.is-open .nd-chat-icon-chat {
  display: none;
}

.nd-chat-launcher.is-open .nd-chat-icon-close {
  display: block;
}

.nd-chat-launcher-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--nd-accent);
  border: 2px solid var(--nd-bg-raised);
  display: none;
}

.nd-chat-launcher.has-unread .nd-chat-launcher-badge {
  display: block;
  animation: ndChatPulse 2s infinite;
}

@keyframes ndChatPulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--nd-accent) 70%, transparent);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 6px transparent;
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 transparent;
  }
}

/* ==========================================================================
   2. Chat Panel Container
   ========================================================================== */

.nd-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 116px);
  background: var(--nd-bg-raised);
  border: 1px solid var(--nd-border);
  border-radius: 16px;
  box-shadow: 0 12px 36px var(--nd-shadow);
  z-index: 9991;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s ease;
}

.nd-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ==========================================================================
   3. Panel Header & Disclaimer
   ========================================================================== */

.nd-chat-head {
  padding: 14px 16px 10px;
  background: var(--nd-bg-raised);
  border-bottom: 1px solid var(--nd-border);
  flex-shrink: 0;
}

.nd-chat-head-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nd-chat-identity {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nd-chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--nd-accent);
  color: var(--nd-accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.nd-chat-avatar svg {
  width: 14px;
  height: 14px;
}

.nd-chat-title-wrap {
  display: flex;
  flex-direction: column;
}

.nd-chat-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--nd-text);
  line-height: 1.2;
  margin: 0;
}

.nd-chat-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--nd-muted);
  line-height: 1;
  margin-top: 2px;
}

.nd-chat-close-btn {
  background: transparent;
  border: none;
  color: var(--nd-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background 0.15s ease;
}

.nd-chat-close-btn:hover {
  color: var(--nd-text);
  background: var(--nd-bg);
}

.nd-chat-disclaimer {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--nd-muted);
  background: var(--nd-bg);
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--nd-border);
}

/* ==========================================================================
   4. Panel Body & Message List
   ========================================================================== */

.nd-chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.nd-chat-body::-webkit-scrollbar {
  display: none;
}

/* Message Bubble */
.nd-chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
  animation: ndChatFadeIn 0.2s ease;
}

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

.nd-chat-msg--assistant {
  align-self: flex-start;
  background: var(--nd-bg);
  color: var(--nd-text);
  border: 1px solid var(--nd-border);
  border-radius: 14px 14px 14px 3px;
}

.nd-chat-msg--user {
  align-self: flex-end;
  background: var(--nd-accent);
  color: var(--nd-accent-ink);
  border-radius: 14px 14px 3px 14px;
}

/* Suggested Chips */
.nd-chat-chips-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.nd-chat-chip-btn {
  background: var(--nd-bg);
  border: 1px solid var(--nd-border);
  color: var(--nd-text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  line-height: 1.3;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.nd-chat-chip-btn:hover {
  background: var(--nd-bg-raised);
  border-color: var(--nd-muted);
  transform: translateY(-1px);
}

.nd-chat-chip-btn:active {
  transform: translateY(0);
}

/* Article Recommendation Cards */
.nd-chat-articles-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}

.nd-chat-article-card {
  display: block;
  background: var(--nd-bg-raised);
  border: 1px solid var(--nd-border);
  border-radius: 10px;
  padding: 10px 12px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.nd-chat-article-card:hover {
  border-color: var(--nd-accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--nd-shadow);
}

.nd-chat-article-cat {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--nd-muted);
  margin-bottom: 2px;
}

.nd-chat-article-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--nd-text);
  line-height: 1.3;
  margin: 0;
}

.nd-chat-article-excerpt {
  font-size: 11.5px;
  color: var(--nd-muted);
  line-height: 1.35;
  margin: 4px 0 0;
}

/* Typing indicator */
.nd-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
  background: var(--nd-bg);
  border: 1px solid var(--nd-border);
  border-radius: 14px 14px 14px 3px;
}

.nd-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--nd-muted);
  animation: ndChatBounce 1.4s infinite ease-in-out both;
}

.nd-chat-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.nd-chat-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

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

/* Quiet "Still thinking..." notice after 6 seconds */
.nd-chat-thinking {
  font-size: 11.5px;
  color: var(--nd-muted);
  font-style: italic;
  padding: 2px 8px;
  margin-top: -6px;
  align-self: flex-start;
  animation: ndChatFadeIn 0.3s ease;
}

/* Retry Button */
.nd-chat-retry-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  background: transparent;
  color: var(--nd-text);
  border: 1px solid var(--nd-border);
  cursor: pointer;
  transition: background 0.15s ease;
}

.nd-chat-retry-btn:hover {
  background: var(--nd-bg-raised);
}

/* ==========================================================================
   5. Panel Footer & Input
   ========================================================================== */

.nd-chat-foot {
  padding: 12px 14px;
  background: var(--nd-bg-raised);
  border-top: 1px solid var(--nd-border);
  flex-shrink: 0;
}

.nd-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: relative;
}

.nd-chat-input {
  flex: 1 1 auto;
  min-height: 38px;
  max-height: 96px;
  padding: 8px 12px;
  font-size: 13.5px;
  line-height: 1.4;
  background: var(--nd-bg);
  border: 1px solid var(--nd-border);
  color: var(--nd-text);
  border-radius: 8px;
  resize: none;
  font-family: inherit;
  transition: border-color 0.15s ease;
  scrollbar-width: none;
}

.nd-chat-input:focus {
  outline: none;
  border-color: var(--nd-accent);
}

.nd-chat-input::placeholder {
  color: var(--nd-muted);
}

.nd-chat-send-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--nd-accent);
  color: var(--nd-accent-ink);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
  padding: 0;
}

.nd-chat-send-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.nd-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nd-chat-send-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: currentColor;
}

/* ==========================================================================
   6. Mobile Fullscreen Mode (< 640px)
   ========================================================================== */

@media (max-width: 639px) {
  .nd-chat-launcher {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .nd-chat-launcher.is-open {
    display: none;
  }

  .nd-chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: none;
    bottom: 0;
    right: 0;
    z-index: 99999;
  }

  .nd-chat-head {
    padding: 16px 16px 12px;
  }

  .nd-chat-close-btn {
    padding: 8px;
  }
}
