/* ============================================================
   Component: Streaming AI Copilot Chatbot — 360eDash
   Floating Action Button (FAB) + Collapsible Side Drawer
   Supports Light & Dark mode via CSS variables.
============================================================= */

:root {
  --aic-primary: #0f6a71;
  --aic-primary-hover: #0b4f54;
  --aic-primary-soft: #e4f1f1;
  --aic-accent: #fa891a;

  --aic-surface: #ffffff;
  --aic-surface-alt: #f8fafb;
  --aic-ink: #25343f;
  --aic-muted: #7c8b8d;
  --aic-border: #e2e8e9;

  --aic-success: #2f9e6e;
  --aic-success-soft: #e4f5ec;
  --aic-warning: #e3a21a;
  --aic-warning-soft: #fbf1de;
  --aic-danger: #d64545;
  --aic-danger-soft: #fbe8e8;
  --aic-info: #3e7cb1;
  --aic-info-soft: #e7f0f8;
}

html[data-theme="dark"] {
  --aic-primary: #21a7ae;
  --aic-primary-hover: #2ec0c8;
  --aic-primary-soft: rgba(33, 167, 174, 0.18);
  --aic-accent: #fb9832;

  --aic-surface: #18272c;
  --aic-surface-alt: #1f333a;
  --aic-ink: #e7eff0;
  --aic-muted: #9ab0b4;
  --aic-border: #2a3d42;

  --aic-success: #4fbd8a;
  --aic-success-soft: rgba(79, 189, 138, 0.16);
  --aic-warning: #e8b34a;
  --aic-warning-soft: rgba(232, 179, 74, 0.16);
  --aic-danger: #ef6b6b;
  --aic-danger-soft: rgba(239, 107, 107, 0.16);
  --aic-info: #69a8d6;
  --aic-info-soft: rgba(105, 168, 214, 0.16);
}

/* ---------- Floating Action Button (FAB) ---------- */
.ai-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1050;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--aic-primary);
  color: #ffffff;
  padding: 12px 20px;
  border-radius: 50px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 24px rgba(15, 106, 113, 0.35);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  outline: none;
}

.ai-chat-fab:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 28px rgba(15, 106, 113, 0.45);
  background: var(--aic-primary-hover);
}

.ai-chat-fab.is-hidden {
  display: none !important;
}

.ai-chat-fab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  font-size: 13px;
  animation: aicPulse 2.5s infinite;
}

@keyframes aicPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.ai-chat-fab-label {
  letter-spacing: 0.02em;
}

/* ---------- Collapsible Side Drawer ---------- */
.ai-chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 410px;
  max-width: 100vw;
  background: var(--aic-surface);
  border-left: 1px solid var(--aic-border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.15);
  z-index: 1060;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: inherit;
  color: var(--aic-ink);
}

.ai-chat-drawer.is-open {
  transform: translateX(0);
}

/* Header */
.ai-chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--aic-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--aic-surface);
}

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

.ai-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--aic-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.ai-chat-header-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--aic-ink);
  line-height: 1.2;
}

.ai-chat-header-status {
  font-size: 11.5px;
  color: var(--aic-success);
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}

.ai-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--aic-success);
}

.ai-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-chat-header-btn {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--aic-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.15s;
}

.ai-chat-header-btn:hover {
  background: var(--aic-surface-alt);
  color: var(--aic-ink);
}

/* Context Badge Bar */
.ai-chat-context-bar {
  padding: 6px 16px;
  background: var(--aic-surface-alt);
  border-bottom: 1px solid var(--aic-border);
  font-size: 11.5px;
  color: var(--aic-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-context-bar span {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Messages Body */
.ai-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Bubble Rows */
.ai-chat-msg {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: aicMsgIn 0.2s ease-out;
}

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

.ai-chat-msg.is-user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.ai-chat-msg.is-assistant {
  margin-right: auto;
}

.ai-chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  margin-top: 2px;
}

.ai-chat-msg.is-user .ai-chat-msg-avatar {
  background: var(--aic-muted);
  color: #ffffff;
}

.ai-chat-msg.is-assistant .ai-chat-msg-avatar {
  background: var(--aic-primary);
  color: #ffffff;
}

.ai-chat-msg-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.ai-chat-msg.is-user .ai-chat-msg-bubble {
  background: var(--aic-primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.ai-chat-msg.is-assistant .ai-chat-msg-bubble {
  background: var(--aic-surface-alt);
  color: var(--aic-ink);
  border: 1px solid var(--aic-border);
  border-bottom-left-radius: 4px;
}

/* Markdown formatting inside assistant bubbles */
.ai-chat-msg.is-assistant .ai-chat-msg-bubble p {
  margin: 0 0 8px 0;
}
.ai-chat-msg.is-assistant .ai-chat-msg-bubble p:last-child {
  margin-bottom: 0;
}
.ai-chat-msg.is-assistant .ai-chat-msg-bubble ul,
.ai-chat-msg.is-assistant .ai-chat-msg-bubble ol {
  margin: 6px 0 8px 18px;
  padding: 0;
}
.ai-chat-msg.is-assistant .ai-chat-msg-bubble li {
  margin-bottom: 4px;
}
.ai-chat-msg.is-assistant .ai-chat-msg-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
}
html[data-theme="dark"] .ai-chat-msg.is-assistant .ai-chat-msg-bubble code {
  background: rgba(255,255,255,0.1);
}
.ai-chat-msg.is-assistant .ai-chat-msg-bubble pre {
  background: rgba(0,0,0,0.05);
  padding: 8px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12px;
}

/* Assistant Markdown Headers */
.ai-chat-msg.is-assistant .ai-chat-msg-bubble h2,
.ai-chat-msg.is-assistant .ai-chat-msg-bubble h3,
.ai-chat-msg.is-assistant .ai-chat-msg-bubble h4,
.ai-chat-msg.is-assistant .ai-chat-msg-bubble h5 {
  margin: 12px 0 6px 0;
  font-weight: 700;
  color: inherit;
  line-height: 1.35;
}
.ai-chat-msg.is-assistant .ai-chat-msg-bubble h2 { font-size: 15px; }
.ai-chat-msg.is-assistant .ai-chat-msg-bubble h3 { font-size: 14px; }
.ai-chat-msg.is-assistant .ai-chat-msg-bubble h4 { font-size: 13px; }
.ai-chat-msg.is-assistant .ai-chat-msg-bubble h5 { font-size: 12px; }

/* Markdown Table */
.ai-chat-table-wrapper {
  overflow-x: auto;
  margin: 10px 0;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
html[data-theme="dark"] .ai-chat-table-wrapper {
  border-color: rgba(255, 255, 255, 0.12);
}
.ai-chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  text-align: left;
}
.ai-chat-table th {
  background: rgba(0, 0, 0, 0.04);
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  white-space: nowrap;
}
html[data-theme="dark"] .ai-chat-table th {
  background: rgba(255, 255, 255, 0.06);
  border-bottom-color: rgba(255, 255, 255, 0.12);
}
.ai-chat-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  vertical-align: top;
}
html[data-theme="dark"] .ai-chat-table td {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}
.ai-chat-table tr:last-child td {
  border-bottom: none;
}
.ai-chat-hr {
  border: none;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  margin: 12px 0;
}

/* Typewriter Cursor */
.ai-chat-cursor {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--aic-primary);
  margin-left: 3px;
  vertical-align: middle;
  animation: aicBlink 0.8s infinite;
}

@keyframes aicBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Typing Indicator (Thinking dots) */
.ai-chat-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  margin-bottom: 4px;
}

.ai-chat-typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--aic-primary);
  border-radius: 50%;
  display: inline-block;
  animation: aicBounce 1.3s infinite ease-in-out both;
}

.ai-chat-typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.ai-chat-typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes aicBounce {
  0%, 80%, 100% {
    transform: scale(0.3);
    opacity: 0.35;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Action Consent Card */
.ai-chat-consent-card {
  margin-top: 10px;
  background: var(--aic-surface);
  border: 1px solid var(--aic-warning);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(227, 162, 26, 0.12);
}

.ai-chat-consent-head {
  background: var(--aic-warning-soft);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(227, 162, 26, 0.3);
}

.ai-chat-consent-title {
  font-size: 12px;
  font-weight: 700;
  color: #925d00;
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
}

.ai-chat-consent-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12.5px;
}

.ai-chat-consent-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.ai-chat-consent-row .lbl {
  color: var(--aic-muted);
  flex-shrink: 0;
}

.ai-chat-consent-row .val {
  font-weight: 600;
  color: var(--aic-ink);
  text-align: right;
}

.ai-chat-consent-desc {
  background: var(--aic-surface-alt);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--aic-ink);
  line-height: 1.4;
  margin-top: 4px;
}

.ai-chat-consent-actions {
  padding: 10px 14px;
  background: var(--aic-surface-alt);
  border-top: 1px solid var(--aic-border);
  display: flex;
  gap: 8px;
}

.ai-btn-approve {
  flex: 1;
  background: var(--aic-success);
  color: #ffffff;
  border: none;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s;
}

.ai-btn-approve:hover {
  opacity: 0.9;
}

.ai-btn-dismiss {
  background: transparent;
  border: 1px solid var(--aic-border);
  color: var(--aic-muted);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.ai-btn-dismiss:hover {
  background: var(--aic-surface);
  color: var(--aic-ink);
}

.ai-chat-consent-status {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.ai-chat-consent-status.is-approved {
  background: var(--aic-success-soft);
  color: var(--aic-success);
}

.ai-chat-consent-status.is-dismissed {
  background: var(--aic-surface-alt);
  color: var(--aic-muted);
}

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

.ai-chat-chip-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--aic-muted);
  text-transform: uppercase;
}

.ai-chat-chip {
  background: var(--aic-surface);
  border: 1px solid var(--aic-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--aic-ink);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-chat-chip:hover {
  border-color: var(--aic-primary);
  color: var(--aic-primary);
  background: var(--aic-primary-soft);
  transform: translateX(2px);
}

/* Footer & Input */
.ai-chat-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--aic-border);
  background: var(--aic-surface);
}

.ai-chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.ai-chat-textarea {
  flex: 1;
  background: var(--aic-surface-alt);
  border: 1px solid var(--aic-border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--aic-ink);
  outline: none;
  resize: none;
  font-family: inherit;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.15s;
}

.ai-chat-textarea:focus {
  border-color: var(--aic-primary);
}

.ai-chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--aic-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: all 0.15s;
}

.ai-chat-send-btn:hover:not(:disabled) {
  background: var(--aic-primary-hover);
}

.ai-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-chat-disclaimer {
  font-size: 10.5px;
  color: var(--aic-muted);
  text-align: center;
  margin-top: 8px;
  line-height: 1.4;
}

/* Responsive */
@media (max-width: 640px) {
  .ai-chat-drawer {
    width: 100vw;
  }
  .ai-chat-fab {
    bottom: 16px;
    right: 16px;
    padding: 10px 16px;
    font-size: 13px;
  }
}
