/* ============ DEBUG PANEL ============ */

/* Error badge — bottom-right corner, always visible */
#ds-err-badge {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 99000;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20,23,31,.9);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 20px;
  padding: 5px 10px 5px 8px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  color: #5c6474;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  transition: background 150ms, border-color 150ms, color 150ms;
  user-select: none;
  backdrop-filter: blur(6px);
}
#ds-err-badge:hover {
  background: rgba(27,31,42,.95);
  border-color: rgba(255,255,255,.18);
  color: #9aa3b2;
}
/* Error state */
#ds-err-badge:not([data-clean]) {
  background: #1b1218;
  border-color: rgba(248,113,113,.35);
  color: #f87171;
}
#ds-err-badge:not([data-clean]):hover {
  background: #261820;
  border-color: rgba(248,113,113,.6);
}
#ds-err-badge .ds-badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5c6474;
  flex-shrink: 0;
  transition: background 150ms;
}
#ds-err-badge:not([data-clean]) .ds-badge-dot {
  background: #f87171;
  animation: ds-pulse 2s ease-in-out infinite;
}
@keyframes ds-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* Panel overlay */
#ds-debug-panel {
  position: fixed;
  inset: 0;
  z-index: 99100;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 16px;
  pointer-events: none;
}
#ds-debug-panel.hidden { display: none; }

/* Panel card */
#ds-debug-panel .dp-card {
  pointer-events: all;
  width: 540px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  background: #0d0f14;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(0,0,0,.7), 0 1px 2px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  color: #eef0f4;
}

/* Header */
.dp-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.dp-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #9aa3b2;
  flex: 1;
}
.dp-shortcut {
  font-size: 10px;
  color: #5c6474;
  background: rgba(255,255,255,.05);
  border-radius: 4px;
  padding: 2px 6px;
}
.dp-close {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: none;
  border: none;
  color: #5c6474;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: background 120ms, color 120ms;
}
.dp-close:hover { background: rgba(255,255,255,.08); color: #eef0f4; }

/* Tabs */
.dp-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.dp-tab {
  padding: 8px 16px;
  font-size: 11.5px;
  font-weight: 600;
  color: #5c6474;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 120ms, border-color 120ms;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}
.dp-tab:hover { color: #9aa3b2; }
.dp-tab.active { color: #eef0f4; border-bottom-color: #6366f1; }

/* Body */
.dp-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.dp-pane { display: none; padding: 12px 0; }
.dp-pane.active { display: block; }

/* Toolbar inside a pane (clear, copy buttons) */
.dp-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,.05);
  margin-bottom: 8px;
}
.dp-action {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 5px;
  cursor: pointer;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  color: #9aa3b2;
  transition: background 120ms, color 120ms;
}
.dp-action:hover { background: rgba(255,255,255,.1); color: #eef0f4; }
.dp-action.danger:hover { background: rgba(248,113,113,.15); color: #f87171; border-color: rgba(248,113,113,.3); }

/* Error entries */
.dp-err-list { display: flex; flex-direction: column; gap: 1px; }
.dp-err-entry {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.dp-err-entry:last-child { border-bottom: none; }
.dp-err-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.dp-err-type {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 1px 5px;
  border-radius: 3px;
}
.dp-err-type.error    { background: rgba(248,113,113,.15); color: #f87171; }
.dp-err-type.unhandled{ background: rgba(251,146,60,.15);  color: #fb923c; }
.dp-err-type.info     { background: rgba(99,102,241,.15);  color: #818cf8; }
.dp-err-ts {
  font-size: 10px;
  color: #5c6474;
  flex: 1;
}
.dp-err-page {
  font-size: 10px;
  color: #5c6474;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dp-err-msg {
  font-size: 12px;
  color: #fca5a5;
  line-height: 1.4;
  word-break: break-word;
  margin-bottom: 4px;
}
.dp-err-stack {
  font-size: 10.5px;
  color: #5c6474;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
  background: rgba(255,255,255,.03);
  border-radius: 4px;
  padding: 6px 8px;
  margin-top: 4px;
}
.dp-empty {
  padding: 24px 16px;
  color: #5c6474;
  text-align: center;
  font-size: 12px;
}
.dp-empty-icon { font-size: 22px; margin-bottom: 6px; }

/* State pane — JSON tree */
.dp-state-block {
  margin: 0 16px 10px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 6px;
  overflow: hidden;
}
.dp-state-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6366f1;
  padding: 6px 10px;
  background: rgba(99,102,241,.07);
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.dp-state-json {
  font-size: 11px;
  color: #9aa3b2;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 220px;
  overflow-y: auto;
  line-height: 1.55;
}

/* Session pane */
.dp-kv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.dp-kv-table td {
  padding: 6px 16px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  vertical-align: top;
}
.dp-kv-table td:first-child {
  color: #5c6474;
  width: 130px;
  white-space: nowrap;
}
.dp-kv-table td:last-child {
  color: #eef0f4;
  word-break: break-all;
}
.dp-kv-ok  { color: #34d399 !important; }
.dp-kv-err { color: #f87171 !important; }

@media (max-width: 700px) {
  #ds-err-badge { display: none !important; }
}
