/* ═══════════════════════════════════════════════════
   Debug Panel — Developer Tool Aesthetic
   Terminal-meets-IDE: clean hierarchy, activity timeline,
   utilitarian precision with refined details
   ═══════════════════════════════════════════════════ */

/* ── Element Picker Overlay ── */
.debug-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  cursor: crosshair;
  background: rgba(0, 0, 0, 0.02);
}

/* ── Highlight Box ── */
.debug-highlight-box {
  position: absolute;
  z-index: 100000;
  pointer-events: none;
  border: 2px solid #7367f0;
  border-radius: 4px;
  background: rgba(115, 103, 240, 0.06);
  box-shadow: 0 0 0 1px rgba(115, 103, 240, 0.15), 0 0 20px rgba(115, 103, 240, 0.1);
  transition: all 0.08s ease-out;
  display: none;
}

/* ── Highlight Label ── */
.debug-highlight-label {
  position: absolute;
  z-index: 100001;
  pointer-events: none;
  background: #7367f0;
  color: #fff;
  font-size: 10px;
  font-family: var(--bs-font-monospace);
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  display: none;
  letter-spacing: 0.2px;
  box-shadow: 0 2px 8px rgba(115, 103, 240, 0.3);
}

/* ── Context Menu ── */
.debug-context-menu {
  position: fixed;
  z-index: 100002;
  background: var(--bs-body-bg, #fff);
  border: 1px solid var(--bs-border-color, #e0e0e0);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);
  padding: 4px;
  min-width: 180px;
  animation: debugMenuIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-bs-theme='dark'] .debug-context-menu {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.2);
}

@keyframes debugMenuIn {
  from { opacity: 0; transform: scale(0.92) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.debug-context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--bs-body-color, #333);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.debug-context-menu-item:hover {
  background: rgba(115, 103, 240, 0.08);
  color: #7367f0;
}

.debug-context-menu-item i {
  font-size: 17px;
  color: #7367f0;
}

.debug-context-menu-separator {
  height: 1px;
  background: var(--bs-border-color, #e0e0e0);
  margin: 4px 8px;
}

/* ══════════════════════════════════════════
   Context Card — Selected Element Preview
   ══════════════════════════════════════════ */
.debug-context-card {
  margin: 0 14px 2px;
  padding: 0;
  background: var(--bs-tertiary-bg, #f8f8fb);
  border: 1px solid var(--bs-border-color, #e4e4e8);
  border-radius: 10px;
  font-size: 12px;
  overflow: hidden;
  animation: debugMenuIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.debug-context-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 6px;
}

.debug-context-card-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: #7367f0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.debug-context-card-title::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7367f0;
  flex-shrink: 0;
}

.btn-close-sm {
  font-size: 7px;
  padding: 2px;
  opacity: 0.4;
  transition: opacity 0.15s;
}

.btn-close-sm:hover {
  opacity: 1;
}

.debug-context-card-body {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px 10px;
}

.debug-context-selector {
  font-size: 11px;
  font-family: var(--bs-font-monospace);
  word-break: break-all;
  color: var(--bs-body-color);
  flex: 1;
  line-height: 1.5;
  background: rgba(115, 103, 240, 0.05);
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid rgba(115, 103, 240, 0.1);
}

.debug-context-thumb {
  width: 52px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--bs-border-color, #ddd);
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}


/* ══════════════════════════════════════════
   Activity Timeline — Steps Log
   A vertical timeline of completed actions
   ══════════════════════════════════════════ */
.debug-steps-log {
  display: none;
  flex-direction: column;
  gap: 0;
  margin-bottom: 6px;
  font-size: 12px;
  font-family: var(--bs-font-monospace);
  background: var(--bs-tertiary-bg, #f8f8fb);
  border: 1px solid var(--bs-border-color, #e4e4e8);
  border-radius: 10px;
  padding: 10px 12px;
  max-height: 160px;
  overflow-y: auto;
  position: relative;
}

.debug-steps-log.visible {
  display: flex;
}

/* Scrollbar inside steps log */
.debug-steps-log::-webkit-scrollbar {
  width: 4px;
}
.debug-steps-log::-webkit-scrollbar-track {
  background: transparent;
}
.debug-steps-log::-webkit-scrollbar-thumb {
  background: var(--bs-border-color);
  border-radius: 2px;
}

/* Individual step item with timeline dot */
.debug-step-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 4px 0;
  color: var(--bs-body-color, #444);
  line-height: 1.5;
  position: relative;
  padding-inline-start: 20px;
  font-size: 11px;
}

/* Timeline connector line */
.debug-step-item::before {
  content: '';
  position: absolute;
  inset-inline-start: 5px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--bs-border-color, #e0e0e0);
}

.debug-step-item:first-child::before {
  top: 50%;
}

.debug-step-item:last-child::before {
  bottom: 50%;
}

.debug-step-item:only-child::before {
  display: none;
}

/* Timeline dot */
.debug-step-item::after {
  content: '';
  position: absolute;
  inset-inline-start: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bs-border-color, #ccc);
  border: 1.5px solid var(--bs-body-bg, #fff);
  z-index: 1;
}

/* Color-coded dots based on tool type */
.debug-step-item[data-tool="read"]::after { background: #7367f0; }
.debug-step-item[data-tool="edit"]::after { background: #ff9f43; }
.debug-step-item[data-tool="write"]::after { background: #28c76f; }
.debug-step-item[data-tool="grep"]::after,
.debug-step-item[data-tool="search"]::after { background: #00cfe8; }
.debug-step-item[data-tool="glob"]::after,
.debug-step-item[data-tool="find"]::after { background: #00cfe8; }
.debug-step-item[data-tool="bash"]::after { background: #ea5455; }
.debug-step-item[data-tool="think"]::after { background: #b8b2f0; }

.debug-step-item i {
  display: none; /* hide icon, using dot instead */
}

.debug-step-item > span:first-of-type {
  font-weight: 500;
  flex-shrink: 0;
}

.debug-step-item .debug-step-detail {
  color: var(--bs-secondary-color, #8a8a9a);
  font-size: 10px;
  opacity: 0.8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

/* Steps log header (toggle) */
.debug-steps-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--bs-secondary-color, #8a8a9a);
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: start;
  font-family: var(--bs-font-monospace);
  transition: color 0.15s;
}

.debug-steps-toggle:hover {
  color: var(--bs-body-color);
}

.debug-steps-toggle i {
  font-size: 12px;
  transition: transform 0.2s;
}

.debug-steps-toggle.is-collapsed i {
  transform: rotate(-90deg);
}

[dir="rtl"] .debug-steps-toggle.is-collapsed i {
  transform: rotate(90deg);
}

.debug-steps-toggle .debug-steps-count {
  background: rgba(115, 103, 240, 0.1);
  color: #7367f0;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  margin-inline-start: auto;
}


/* ══════════════════════════════════════════
   Active Step — Current Operation Indicator
   Animated spinner with pulsing glow
   ══════════════════════════════════════════ */
.debug-active-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--bs-body-color);
  font-family: var(--bs-font-monospace);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 0;
}

.debug-step-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(115, 103, 240, 0.15);
  border-top-color: #7367f0;
  border-radius: 50%;
  animation: debugSpin 0.7s linear infinite;
  flex-shrink: 0;
}

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

.debug-step-label {
  font-weight: 600;
  flex-shrink: 0;
  color: #7367f0;
}

.debug-active-step .debug-step-detail {
  color: var(--bs-secondary-color, #8a8a9a);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-inline-start: 0;
}

/* Tool-specific icon colors in active step */
.debug-active-step .ti.tabler-file-text { color: #7367f0; }
.debug-active-step .ti.tabler-edit { color: #ff9f43; }
.debug-active-step .ti.tabler-file-plus { color: #28c76f; }
.debug-active-step .ti.tabler-search,
.debug-active-step .ti.tabler-folders { color: #00cfe8; }
.debug-active-step .ti.tabler-terminal-2 { color: #ea5455; }
.debug-active-step .ti.tabler-brain { color: #b8b2f0; }


/* ══════════════════════════════════════════
   Reload Notice — File Modification Alert
   With animated progress bar
   ══════════════════════════════════════════ */
.debug-reload-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 500;
  color: #b47d00;
  background: rgba(255, 193, 7, 0.08);
  border: 1px solid rgba(255, 193, 7, 0.2);
  border-radius: 8px;
  animation: debugMenuIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

[data-bs-theme='dark'] .debug-reload-notice {
  color: #ffc857;
  background: rgba(255, 193, 7, 0.06);
  border-color: rgba(255, 193, 7, 0.15);
}

/* Progress bar along bottom */
.debug-reload-notice::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, #ff9f43, #ffc107);
  animation: reloadProgress 5s linear forwards;
  border-radius: 0 0 8px 8px;
}

@keyframes reloadProgress {
  from { width: 100%; }
  to { width: 0%; }
}

.debug-reload-notice i {
  animation: debugSpin 1s linear infinite;
  color: #ff9f43;
}

.debug-reload-countdown {
  font-weight: 700;
  font-family: var(--bs-font-monospace);
}


/* ══════════════════════════════════════════
   Code Blocks & Response Content
   ══════════════════════════════════════════ */
.debug-response-content {
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}

.debug-response-content p {
  margin-bottom: 8px;
}

.debug-response-content p:last-child {
  margin-bottom: 0;
}

.debug-response-content ul,
.debug-response-content ol {
  padding-inline-start: 18px;
  margin-bottom: 8px;
}

.debug-response-content li {
  margin-bottom: 3px;
}

.debug-response-content strong {
  font-weight: 600;
  color: var(--bs-heading-color, var(--bs-body-color));
}

.debug-code-block {
  background: #1e1e2e;
  color: #cdd6f4;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 10px 0;
  overflow-x: auto;
  font-size: 12px;
  font-family: var(--bs-font-monospace);
  white-space: pre;
  line-height: 1.5;
  position: relative;
}

/* Language label on code blocks */
.debug-code-block::before {
  content: attr(data-lang);
  position: absolute;
  top: 6px;
  inset-inline-end: 10px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(205, 214, 244, 0.35);
  font-weight: 500;
}

.debug-code-block::-webkit-scrollbar {
  height: 4px;
}
.debug-code-block::-webkit-scrollbar-track {
  background: transparent;
}
.debug-code-block::-webkit-scrollbar-thumb {
  background: rgba(205, 214, 244, 0.15);
  border-radius: 2px;
}

.debug-inline-code {
  background: rgba(115, 103, 240, 0.08);
  color: #7367f0;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--bs-font-monospace);
  font-weight: 500;
}

[data-bs-theme='dark'] .debug-inline-code {
  background: rgba(115, 103, 240, 0.15);
  color: #b8b2f0;
}


/* ══════════════════════════════════════════
   Message Enhancements
   Bot messages: clean, borderless, wide
   User messages: accent-tinted
   ══════════════════════════════════════════ */

/* Bot message content stretches wider for tool output */
.bot-message .message-content {
  max-width: 88%;
}

/* Bot message bubble refinements */
.bot-message .message-bubble {
  border-radius: 2px 12px 12px 12px;
  padding: 12px 16px;
}

[dir="rtl"] .bot-message .message-bubble {
  border-radius: 12px 2px 12px 12px;
}

/* Streaming text refinements */
.streaming-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
}


/* ══════════════════════════════════════════
   RTL Support
   ══════════════════════════════════════════ */
[dir="rtl"] .debug-context-card-body {
  flex-direction: row-reverse;
}

[dir="rtl"] .debug-context-menu-item {
  flex-direction: row-reverse;
  text-align: right;
}

[dir="rtl"] .debug-highlight-label {
  direction: ltr;
}

[dir="rtl"] .debug-step-item {
  padding-inline-start: 20px;
  padding-inline-end: 0;
}
