/* =========================================================================
   CONFLUENCE AI ASSISTANT & MODAL INSPECTOR
   Floating Launcher, Slide-Over Drawer, Message Stream, Alerts, and Modals
   ========================================================================= */

/* Floating Launcher Trigger (Bottom-Right Floating Action Button) */
.floating-chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--color-primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-full);
  padding: 12px 20px;
  font-size: 0.88rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 100;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.floating-chat-trigger:hover {
  background: var(--color-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.beacon-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10B981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.4);
  animation: pulse-dot 2s infinite;
}

/* Slide-Over Drawer Backdrop */
.chat-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  z-index: 140;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.chat-drawer-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* Slide-Over Chat Drawer Container */
.chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 100%;
  background: var(--color-surface);
  box-shadow: -4px 0 25px rgba(15, 23, 42, 0.15);
  z-index: 150;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
  display: flex;
  flex-direction: column;
}

.chat-drawer.active {
  transform: translateX(0);
}

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

.drawer-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.drawer-close-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.drawer-close-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-muted);
}

/* Drawer Body & Stream */
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--color-background);
}

.drawer-welcome-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
}

.drawer-welcome-card h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 6px;
}

.drawer-welcome-card p {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}

.drawer-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.drawer-chip {
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 5px 10px;
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
  text-align: left;
}

.drawer-chip:hover {
  background: var(--color-primary-subtle);
  border-color: var(--color-primary-border);
  color: var(--color-primary-hover);
}

/* Messages */
.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
}

.avatar.user {
  background: #334155;
  color: #FFFFFF;
}

.avatar.assistant {
  background: var(--color-primary);
  color: #FFFFFF;
}

.avatar.assistant svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.message-bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.85rem;
  line-height: 1.55;
}

.message-row.user .message-bubble {
  background: var(--color-primary);
  color: #FFFFFF;
  border-bottom-right-radius: 2px;
}

.message-row.assistant .message-bubble {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 2px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Message Markdown Formats */
.message-bubble p {
  margin-bottom: 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble ul {
  margin-left: 18px;
  margin-bottom: 8px;
}

.message-bubble li {
  margin-bottom: 4px;
}

.message-bubble strong {
  color: var(--color-text);
  font-weight: 700;
}

.message-row.user .message-bubble strong {
  color: #FFFFFF;
}

/* Alert Banners inside messages */
.alert-banner {
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.82rem;
}

.alert-banner.critical {
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  color: var(--color-danger-text);
}

.alert-banner.warning {
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning-border);
  color: var(--color-warning-text);
}

.alert-banner svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-severity-tag {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-block;
  margin-bottom: 2px;
}

.alert-title {
  font-weight: 700;
  font-size: 0.86rem;
}

/* Grounding Context Footer Button */
.message-footer {
  padding-top: 8px;
  border-top: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--color-text-muted);
}

.inspect-btn {
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.inspect-btn:hover {
  background: var(--color-primary-subtle);
  color: var(--color-primary-hover);
  border-color: var(--color-primary-border);
}

/* Loading Row */
.loading-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.loading-bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Drawer Footer & Composer */
.drawer-footer {
  padding: 14px 18px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-input-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 4px 6px 4px 12px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.drawer-input-box:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(8, 145, 178, 0.15);
}

.drawer-input-box input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--color-text);
  background: transparent;
}

.drawer-input-box input::placeholder {
  color: var(--color-text-dim);
}

.drawer-send-btn {
  background: var(--color-primary);
  color: #FFFFFF;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.drawer-send-btn:hover {
  background: var(--color-primary-hover);
}

.drawer-stations-row {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.drawer-stations-row::-webkit-scrollbar {
  display: none;
}

.drawer-station-badge {
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  flex-shrink: 0;
}

.drawer-station-badge:hover {
  color: var(--color-primary);
  border-color: var(--color-primary-border);
  background: var(--color-primary-subtle);
}

/* -------------------------------------------------------------------------
   MODAL: GROUNDED TELEMETRY CONTEXT INSPECTOR
   ------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.35rem;
  cursor: pointer;
  color: var(--color-text-muted);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--color-background);
}

.modal-summary-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 0.78rem;
  color: var(--color-text-secondary);
}

.modal-summary-bar strong {
  color: var(--color-text);
}

.copy-raw-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.copy-raw-btn:hover {
  background: var(--color-surface-muted);
  color: var(--color-text);
}

.json-viewer {
  background: #0F172A;
  color: #38BDF8;
  padding: 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.45;
  overflow-x: auto;
  max-height: 50vh;
}

/* -------------------------------------------------------------------------
   RESPONSIVE DRAWER & MODAL RULES
   ------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .chat-drawer {
    width: 100%;
    max-width: 100%;
  }
  .floating-chat-trigger {
    bottom: 16px;
    right: 16px;
    padding: 10px 16px;
    font-size: 0.82rem;
  }
  .modal-overlay {
    padding: 12px;
  }
  .modal-card {
    max-height: 92vh;
  }
  .modal-summary-bar {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}
