/* ============================================================================
   NEXUS AI FINANCIAL COPILOT — STYLESHEET
   Matches Nexus double-entry ledger aesthetics, supporting light & dark themes.
   ============================================================================ */

/* 1. Floating Launcher Button */
.nexus-copilot-trigger {
  position: fixed;
  bottom: 10px;
  right: 20px;
  z-index: 9990;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #1E6B36 0%, #155026 100%);
  color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 12px rgba(21, 80, 38, 0.35), 0 2px 4px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.nexus-copilot-trigger:hover {
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 6px 16px rgba(21, 80, 38, 0.45), 0 3px 6px rgba(0, 0, 0, 0.2);
  background: linear-gradient(135deg, #248141 0%, #1a6330 100%);
}

.nexus-copilot-trigger:active {
  transform: translateY(0) scale(0.98);
}

.nexus-copilot-trigger .copilot-sparkle-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  animation: copilot-pulse 3s infinite ease-in-out;
}

@keyframes copilot-pulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 0.95;
  }

  50% {
    transform: scale(1.15) rotate(5deg);
    opacity: 1;
  }
}

/* 2. Slide-out Copilot Drawer */
.nexus-copilot-drawer {
  position: fixed;
  top: 0;
  right: -480px;
  width: 460px;
  max-width: 100vw;
  height: 100vh;
  z-index: 9995;
  background: var(--paper-surface, #FFFFFF);
  color: var(--ink-900, #10161A);
  border-left: 1px solid var(--border-color, #D6DCD7);
  box-shadow: -12px 0 36px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  transition: right 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: 'Archivo', sans-serif;
}

[data-theme="dark"] .nexus-copilot-drawer {
  background: #182226;
  color: #E2EAE7;
  border-left-color: #2D3D45;
  box-shadow: -12px 0 42px rgba(0, 0, 0, 0.5);
}

.nexus-copilot-drawer.is-open {
  right: 0;
}

/* Backdrop for Mobile */
.nexus-copilot-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 22, 26, 0.4);
  backdrop-filter: blur(2px);
  z-index: 9992;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.nexus-copilot-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* 3. Drawer Header */
.copilot-header {
  padding: 16px 20px;
  background: var(--ink-800, #171F24);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

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

.copilot-header-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.copilot-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(30, 107, 54, 0.35);
  border: 1px solid #1E6B36;
  color: #48D072;
}

.copilot-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copilot-btn-icon {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.copilot-btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
}

/* 4. Active Screen Context Bar */
.copilot-context-bar {
  padding: 8px 16px;
  background: var(--rail-bg-raised, #CFE0D6);
  font-size: 11px;
  font-weight: 500;
  color: var(--rail-fg, #26332B);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color, #BCD0C3);
}

[data-theme="dark"] .copilot-context-bar {
  background: #202D33;
  color: #8BA196;
  border-bottom-color: #2A3C44;
}

.copilot-context-pill {
  display: flex;
  align-items: center;
  gap: 5px;
}

.copilot-context-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #1E6B36;
}

/* 5. Message Stream */
.copilot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.copilot-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}

.copilot-msg.user {
  align-self: flex-end;
  background: #1E6B36;
  color: #FFFFFF;
  padding: 10px 14px;
  border-radius: 14px 14px 2px 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.copilot-msg.assistant {
  align-self: flex-start;
  max-width: 95%;
  background: var(--paper-bg, #F7FAF8);
  color: var(--ink-900, #10161A);
  border: 1px solid var(--border-color, #E2E8E4);
  padding: 14px 16px;
  border-radius: 2px 14px 14px 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .copilot-msg.assistant {
  background: #1F2A30;
  color: #E2EAE7;
  border-color: #2F3E46;
}

/* Markdown formatting inside assistant bubble */
.copilot-msg.assistant p {
  margin: 0 0 10px 0;
}

.copilot-msg.assistant p:last-child {
  margin-bottom: 0;
}

.copilot-msg.assistant ul,
.copilot-msg.assistant ol {
  margin: 0 0 10px 18px;
  padding: 0;
}

.copilot-msg.assistant li {
  margin-bottom: 4px;
}

.copilot-msg.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 11.5px;
  border-radius: 4px;
  overflow: hidden;
}

.copilot-msg.assistant th,
.copilot-msg.assistant td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .copilot-msg.assistant th,
[data-theme="dark"] .copilot-msg.assistant td {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.copilot-msg.assistant th {
  background: rgba(0, 0, 0, 0.05);
  font-weight: 700;
}

[data-theme="dark"] .copilot-msg.assistant th {
  background: rgba(255, 255, 255, 0.06);
}

.copilot-msg.assistant td:last-child,
.copilot-msg.assistant th:last-child {
  text-align: right;
  font-family: 'IBM Plex Mono', monospace;
}

/* Expandable Workings & Calculation Audit Drawer */
.copilot-workings-accordion {
  margin-top: 12px;
  border-top: 1px dashed var(--border-color, #CCD6D0);
  padding-top: 8px;
}

.copilot-workings-toggle {
  font-size: 11px;
  font-weight: 600;
  color: #1E6B36;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

[data-theme="dark"] .copilot-workings-toggle {
  color: #58D68D;
}

.copilot-workings-content {
  display: none;
  background: rgba(0, 0, 0, 0.03);
  padding: 8px 10px;
  border-radius: 4px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  margin-top: 6px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .copilot-workings-content {
  background: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.08);
}

.copilot-workings-content.is-expanded {
  display: block;
}

/* 6. Quick Suggestion Chips */
.copilot-chips {
  padding: 8px 20px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  border-top: 1px solid var(--border-color, #E8EDE9);
}

[data-theme="dark"] .copilot-chips {
  border-top-color: #27343B;
}

.copilot-chip {
  white-space: nowrap;
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--paper-bg, #EEF3F0);
  color: var(--ink-800, #171F24);
  border: 1px solid var(--border-color, #D2DCD5);
  cursor: pointer;
  transition: all 0.15s ease;
}

[data-theme="dark"] .copilot-chip {
  background: #233037;
  color: #C0CFCA;
  border-color: #32444D;
}

.copilot-chip:hover {
  background: #1E6B36;
  color: #FFFFFF;
  border-color: #1E6B36;
}

/* 7. Input Area */
.copilot-footer {
  padding: 14px 20px 18px 20px;
  background: var(--paper-surface, #FFFFFF);
  border-top: 1px solid var(--border-color, #DDE3DF);
}

[data-theme="dark"] .copilot-footer {
  background: #182226;
  border-top-color: #27353C;
}

.copilot-input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--paper-bg, #F3F7F5);
  border: 1px solid var(--border-color, #CCD6D0);
  border-radius: 12px;
  padding: 8px 12px;
  transition: border-color 0.18s ease;
}

[data-theme="dark"] .copilot-input-box {
  background: #1E282E;
  border-color: #31424B;
}

.copilot-input-box:focus-within {
  border-color: #1E6B36;
  box-shadow: 0 0 0 2px rgba(30, 107, 54, 0.2);
}

.copilot-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: 'Archivo', sans-serif;
  font-size: 13px;
  line-height: 1.45;
  max-height: 100px;
  color: inherit;
}

.copilot-send-btn {
  background: #1E6B36;
  color: #FFFFFF;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.copilot-send-btn:hover:not(:disabled) {
  background: #258544;
}

.copilot-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Typing Indicator Animation */
.copilot-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
}

.copilot-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1E6B36;
  animation: typing-jump 1.4s infinite ease-in-out both;
}

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

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

@keyframes typing-jump {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.4;
  }

  40% {
    transform: scale(1.1);
    opacity: 1;
  }
}