/* ============================================
   "Ask EnergySense" AI assistant (ai_assistant.js)
   Floating button + chat panel, same palette as style.css
   ============================================ */

/* Lift the toasts so they do not cover the assistant button. */
.toast-container:not(.toast-container-alert) {
  bottom: 96px;
}

.ai-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9000;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--status-green));
  color: #001018;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0, 204, 255, 0.35);
  transition: transform var(--transition), box-shadow var(--transition);
}

.ai-fab:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 10px 30px rgba(0, 204, 255, 0.5);
}

.ai-fab svg {
  width: 28px;
  height: 28px;
}

.ai-fab.is-open {
  transform: rotate(90deg);
}

.ai-panel {
  position: fixed;
  right: 24px;
  bottom: 94px;
  z-index: 9000;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--card-background);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5), var(--shadow-glow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.ai-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.ai-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(90deg, rgba(0, 204, 255, 0.12), rgba(0, 230, 118, 0.06));
}

.ai-panel-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-panel-icon svg {
  width: 18px;
  height: 18px;
}

.ai-panel-title {
  flex: 1;
  min-width: 0;
}

.ai-panel-title strong {
  display: block;
  font-size: 0.95rem;
}

.ai-panel-title span {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.ai-icon-button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
}

.ai-icon-button:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.ai-icon-button svg {
  width: 18px;
  height: 18px;
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-message {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.6;
  word-wrap: break-word;
  unicode-bidi: plaintext;
}

.ai-message-user {
  align-self: flex-end;
  background: var(--accent);
  color: #001018;
  border-bottom-right-radius: 4px;
}

.ai-message-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.ai-message-assistant ul {
  margin: 4px 0;
  padding-inline-start: 18px;
}

.ai-message-assistant p + p,
.ai-message-assistant p + ul,
.ai-message-assistant ul + p {
  margin-top: 6px;
}

.ai-message-meta {
  display: block;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.8;
}

.ai-message-error {
  border-color: rgba(255, 77, 77, 0.4);
  color: #ffb3b3;
}

.ai-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: ai-typing-bounce 1s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-typing-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 10px;
}

.ai-suggestion {
  border: 1px solid var(--border-accent);
  background: var(--accent-dim);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.76rem;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

.ai-suggestion:hover {
  background: rgba(0, 204, 255, 0.28);
}

.ai-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border-color);
}

.ai-input {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 110px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #334155;
  background: var(--primary-dark);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  unicode-bidi: plaintext;
}

.ai-input:focus {
  border-color: var(--accent);
}

.ai-send {
  width: 42px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #001018;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-send svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 600px) {
  /* Smaller on phones so it covers less of the cards underneath. */
  .ai-fab {
    right: 16px;
    bottom: 16px;
    width: 48px;
    height: 48px;
  }

  .ai-fab svg {
    width: 22px;
    height: 22px;
  }

  .toast-container:not(.toast-container-alert) {
    bottom: 76px;
  }

  .ai-panel {
    right: 16px;
    bottom: 84px;
    height: calc(100vh - 110px);
  }
}
