/* ═══════════════════════════════════════════════════════
   Dash Chat Panel — SSE Edition v2
   Scoped with .dc-* prefix. Does not affect the main site.
   Design: Linear/Vercel-inspired floating panel.
   ═══════════════════════════════════════════════════════ */

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Trigger button ── */
.dc-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: #0284C7;
  color: #fff;
  border: none;
  border-radius: 9999px;
  font-family: var(--sans, 'DM Sans', -apple-system, sans-serif);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.3);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s, opacity 0.2s;
}
.dc-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(2, 132, 199, 0.4);
}
.dc-trigger:active {
  transform: translateY(0) scale(0.98);
}
.dc-trigger-avatar {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  vertical-align: middle;
}
.dc-hidden { display: none !important; }

/* ── Panel ── */
.dc-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 420px;
  height: 600px;
  max-height: calc(100vh - 48px);
  display: none;
  flex-direction: column;
  background: #FFFFFF;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.03),
    0 4px 12px rgba(0, 0, 0, 0.06),
    0 16px 40px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  font-family: var(--sans, 'DM Sans', -apple-system, sans-serif);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}
.dc-panel.dc-open {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}
/* Force the transition to play on open */
.dc-panel.dc-animating {
  display: flex;
}

/* ── Accent line at top ── */
.dc-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #4F46E5, #818CF8, #4F46E5);
  z-index: 1;
}

/* ── Header ── */
.dc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  position: relative;
}
.dc-header-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
}
.dc-header-info {
  flex: 1;
  min-width: 0;
}
.dc-header-title {
  font-size: 15px;
  font-weight: 600;
  color: #1E293B;
  display: flex;
  align-items: center;
  gap: 6px;
}
.dc-header-scope {
  font-size: 11px;
  color: #94A3B8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.dc-close-btn {
  background: none;
  border: none;
  color: #94A3B8;
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  border-radius: 8px;
  transition: all 0.12s ease;
}
.dc-close-btn:hover {
  background: #F1F5F9;
  color: #475569;
}

/* ── Status dot ── */
.dc-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  transition: background 0.2s ease;
}
.dc-status-connected {
  background: #10B981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}
.dc-status-thinking {
  background: #F59E0B;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
  animation: dc-pulse 1.2s ease-in-out infinite;
}
.dc-status-disconnected { background: #CBD5E1; }

@keyframes dc-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 2px rgba(245,158,11,0.2); }
  50% { opacity: 0.5; box-shadow: 0 0 0 4px rgba(245,158,11,0.1); }
}

/* ── Messages area ── */
.dc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.dc-messages::-webkit-scrollbar { width: 4px; }
.dc-messages::-webkit-scrollbar-track { background: transparent; }
.dc-messages::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 2px;
  transition: background 0.2s;
}
.dc-messages:hover::-webkit-scrollbar-thumb { background: #CBD5E1; }

/* ── Message bubbles ── */
.dc-msg {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  color: #334155;
  word-wrap: break-word;
  animation: dc-msg-in 0.15s ease-out;
}
@keyframes dc-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.dc-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #4F46E5 0%, #5B52F0 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 4px rgba(79, 70, 229, 0.15);
}
.dc-msg-assistant {
  align-self: flex-start;
  background: #F8FAFC;
  border: 1px solid #EEF2FF;
  border-bottom-left-radius: 4px;
}
.dc-msg-error {
  align-self: center;
  background: #FEF2F2;
  color: #DC2626;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid #FECACA;
}
.dc-msg-info {
  align-self: center;
  color: #94A3B8;
  font-size: 12px;
  padding: 4px 0;
}

/* ── Sender label ── */
.dc-msg-sender {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent, #4F46E5);
  margin-bottom: 4px;
}
.dc-msg-avatar {
  width: 16px;
  height: 16px;
  border-radius: 3px;
}

/* ── Thinking indicator ── */
.dc-thinking {
  display: flex;
  gap: 5px;
  padding: 12px 16px;
  align-self: flex-start;
}
.dc-thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #A5B4FC;
  animation: dc-bounce 1.4s ease-in-out infinite;
}
.dc-thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.dc-thinking-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes dc-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-8px); opacity: 1; }
}

/* ── Tool status pill ── */
.dc-tool-status {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #4F46E5;
  padding: 4px 12px;
  background: #EEF2FF;
  border-radius: 20px;
  margin-left: 4px;
  animation: dc-msg-in 0.15s ease-out;
}
.dc-tool-spinner {
  width: 10px;
  height: 10px;
  border: 1.5px solid #C7D2FE;
  border-top-color: #4F46E5;
  border-radius: 50%;
  animation: dc-spin 0.8s linear infinite;
}
@keyframes dc-spin {
  to { transform: rotate(360deg); }
}

/* ── Stopped label ── */
.dc-stopped-label {
  display: block;
  font-size: 11px;
  color: #94A3B8;
  font-style: italic;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #E2E8F0;
}

/* ── Input area ── */
.dc-input-area {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 14px 14px;
  background: #fff;
}

/* ── Mode toggle (inside input area) ── */
.dc-mode-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 2px 6px;
}
.dc-mode-label {
  font-size: 10px;
  color: #94A3B8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}
.dc-mode-btn {
  padding: 3px 10px;
  border: 1px solid transparent;
  border-radius: 20px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  color: #94A3B8;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}
.dc-mode-btn:hover {
  color: #64748B;
  background: #F1F5F9;
}
.dc-mode-btn.dc-mode-active {
  background: #EEF2FF;
  color: #4F46E5;
  border-color: #C7D2FE;
  font-weight: 600;
}

/* ── Input row ── */
.dc-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.dc-input-wrap {
  flex: 1;
  min-width: 0;
}
.dc-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 13.5px;
  color: #334155;
  resize: none;
  outline: none;
  background: #FAFBFC;
  line-height: 1.4;
  max-height: 120px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.dc-input:hover {
  border-color: #CBD5E1;
}
.dc-input:focus {
  border-color: #4F46E5;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.08);
}
.dc-input::placeholder { color: #94A3B8; }

.dc-send-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4F46E5 0%, #6366F1 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
  box-shadow: 0 1px 4px rgba(79, 70, 229, 0.2);
}
.dc-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.dc-send-btn:active {
  transform: scale(0.95);
}
.dc-send-btn:disabled {
  background: #E2E8F0;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

/* ── Stop mode ── */
.dc-send-btn.dc-stop-mode {
  background: linear-gradient(135deg, #EF4444 0%, #F87171 100%);
  box-shadow: 0 1px 4px rgba(239, 68, 68, 0.2);
}
.dc-send-btn.dc-stop-mode:hover {
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}
.dc-stop-icon {
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 2px;
}

/* ── Footer ── */
.dc-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
  background: #FAFBFC;
}
.dc-footer-left {
  display: flex;
  gap: 4px;
}
.dc-footer-btn {
  background: none;
  border: none;
  color: #94A3B8;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  transition: all 0.12s ease;
}
.dc-footer-btn:hover { color: #475569; background: #F1F5F9; }
.dc-footer-version { font-size: 10px; color: #CBD5E1; }

/* ── Markdown content inside assistant messages ── */
.dc-msg-assistant h1,
.dc-msg-assistant h2,
.dc-msg-assistant h3 {
  font-size: 13.5px;
  font-weight: 700;
  margin: 8px 0 4px;
  color: #1E293B;
}
.dc-msg-assistant p { margin: 4px 0; }
.dc-msg-assistant ul, .dc-msg-assistant ol {
  margin: 4px 0;
  padding-left: 20px;
}
.dc-msg-assistant li { margin: 2px 0; }
.dc-msg-assistant code {
  background: #EEF2FF;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 12px;
  color: #4F46E5;
}
.dc-msg-assistant pre {
  background: #1E293B;
  color: #E2E8F0;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.5;
}
.dc-msg-assistant pre code {
  background: none;
  padding: 0;
  color: inherit;
}
.dc-msg-assistant strong { color: #1E293B; }
.dc-msg-assistant a {
  color: #4F46E5;
  text-decoration: none;
}
.dc-msg-assistant a:hover { text-decoration: underline; }

/* ── Tables ── */
.dc-table-wrap {
  overflow-x: auto;
  margin: 8px 0;
  border-radius: 8px;
  border: 1px solid #E2E8F0;
}
.dc-table {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
}
.dc-table th {
  background: #4F46E5;
  color: #fff;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  font-size: 11px;
}
.dc-table th:first-child { border-radius: 7px 0 0 0; }
.dc-table th:last-child { border-radius: 0 7px 0 0; }
.dc-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #F1F5F9;
}
.dc-table tr:nth-child(even) td { background: #FAFBFC; }
.dc-table tr:last-child td { border-bottom: none; }

/* ── Streaming cursor ── */
.dc-streaming-cursor::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 14px;
  background: #4F46E5;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: dc-blink 0.7s step-end infinite;
}
@keyframes dc-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── History separator ── */
.dc-history-sep {
  text-align: center;
  color: #CBD5E1;
  font-size: 11px;
  padding: 4px 0;
}

/* ── Starter suggestions ── */
.dc-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
  animation: dc-msg-in 0.2s ease-out;
}
.dc-starter-btn {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 20px;
  font-family: inherit;
  font-size: 12px;
  color: #475569;
  cursor: pointer;
  transition: all 0.12s ease;
  line-height: 1.3;
  text-align: left;
}
.dc-starter-btn:hover {
  background: #EEF2FF;
  border-color: #C7D2FE;
  color: #4F46E5;
}

/* ── New session indicator ── */
.dc-new-session {
  text-align: center;
  color: #94A3B8;
  font-size: 11px;
  padding: 8px 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.dc-new-session::before,
.dc-new-session::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #E2E8F0;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .dc-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    bottom: 8px;
    right: 8px;
    border-radius: 12px;
  }
}
