/* ============================================
 * Debug Panel
 * ============================================
 * Comprehensive debug panel for game state visibility.
 * Features tabbed interface, collapsible sections, and JSON viewer.
 */

.debug-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-bg-panel);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  overflow: hidden;
}

/* Tab Navigation */
.debug-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: var(--space-2);
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.debug-tab {
  padding: var(--space-1) var(--space-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.debug-tab:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-tertiary);
}

.debug-tab.active {
  color: var(--color-accent-primary);
  background: var(--color-bg-panel);
  border-color: var(--color-border);
  border-bottom-color: var(--color-bg-panel);
  margin-bottom: -1px;
}

/* Tab Content */
.debug-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.debug-tab-content {
  display: none;
  padding: var(--space-3);
}

.debug-tab-content.active {
  display: block;
}

/* Sections */
.debug-section {
  margin-bottom: var(--space-4);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.debug-section:last-child {
  margin-bottom: 0;
}

/* Highlighted diagnostic section */
.debug-section--highlight {
  border-left: 3px solid var(--color-accent-primary);
}

/* Warning diagnostic section */
.debug-section--warning {
  border-left: 3px solid var(--color-accent-warning);
  background: var(--overlay-warning-subtle, rgba(251, 191, 36, 0.1));
}

/* Divider between sections */
.debug-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-4) 0;
}

/* Hint text for diagnostics */
.debug-hint {
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  font-style: italic;
  border-top: 1px solid var(--color-border-subtle);
}

/* Tag display for intents */
.debug-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
}

.debug-tag {
  display: inline-block;
  padding: 2px 6px;
  font-size: calc(var(--font-size-xs) * 0.9);
  border-radius: var(--radius-sm);
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
}

.debug-tag--success {
  background: var(--overlay-success-subtle, rgba(74, 222, 128, 0.2));
  color: var(--color-accent-success);
}

.debug-tag--muted {
  opacity: 0.6;
}

.debug-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  background: var(--color-bg-tertiary);
  border-bottom: 1px solid var(--color-border);
}

/* Collapsible sections */
.debug-section--collapsible .debug-section-title {
  cursor: pointer;
  user-select: none;
}

.debug-section--collapsible .debug-section-title:hover {
  background: rgba(97, 175, 239, 0.1);
}

.debug-chevron {
  display: inline-block;
  width: 12px;
  font-weight: bold;
  color: var(--color-text-muted);
  transition: transform 0.15s ease;
}

.debug-section--expanded .debug-chevron {
  transform: rotate(90deg);
}

/* Data rows */
.debug-data {
  padding: var(--space-2) var(--space-3);
}

.debug-data--collapsed {
  display: none;
}

.debug-section--expanded .debug-data--collapsed,
.debug-list-item--expanded + .debug-data--collapsed {
  display: block;
}

.debug-data--nested {
  margin-left: var(--space-4);
  padding: var(--space-2);
  background: var(--color-bg-panel);
  border-radius: var(--radius-sm);
  margin-top: var(--space-1);
  margin-bottom: var(--space-2);
}

.debug-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: var(--space-1) 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.debug-row:last-child {
  border-bottom: none;
}

.debug-label {
  color: var(--color-text-muted);
  flex-shrink: 0;
  margin-right: var(--space-2);
}

.debug-value {
  color: var(--color-text-primary);
  text-align: right;
  word-break: break-word;
}

/* Value status colors */
.debug-value--accent {
  color: var(--color-accent-primary);
}

.debug-value--info {
  color: #3b82f6;
}

.debug-value--success {
  color: #22c55e;
}

.debug-value--warning {
  color: #eab308;
}

.debug-value--danger {
  color: #ef4444;
}

/* Lists */
.debug-list {
  padding: var(--space-1) 0;
}

.debug-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.debug-list-item:last-child {
  border-bottom: none;
}

.debug-list-item--expandable {
  cursor: pointer;
}

.debug-list-item--expandable:hover {
  background: rgba(97, 175, 239, 0.05);
}

.debug-list-name {
  flex: 1;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.debug-list-value {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  text-align: right;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Simple lists */
.debug-simple-list {
  list-style: none;
  margin: 0;
  padding: var(--space-2) var(--space-3);
}

.debug-simple-list li {
  padding: var(--space-1) 0;
  color: var(--color-text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.debug-simple-list li:last-child {
  border-bottom: none;
}

/* Subsections */
.debug-subsection {
  margin-top: var(--space-2);
}

.debug-subsection h4 {
  margin: 0 0 var(--space-1) 0;
  padding: 0 var(--space-3);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
}

/* Badges */
.debug-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--color-bg-tertiary);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* Status badges */
.debug-badge--pending {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.debug-badge--active {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
}

.debug-badge--completed,
.debug-badge--success {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.debug-badge--failed,
.debug-badge--error {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

/* Content type badges */
.debug-badge--dm_response,
.debug-badge--dm {
  background: rgba(139, 92, 246, 0.2);
  color: #8b5cf6;
}

.debug-badge--player,
.debug-badge--player_action {
  background: rgba(97, 175, 239, 0.2);
  color: var(--color-accent-primary);
}

.debug-badge--system {
  background: rgba(156, 163, 175, 0.2);
  color: #9ca3af;
}

/* Importance badges */
.debug-badge--importance-high {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.debug-badge--importance-medium {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.debug-badge--importance-low {
  background: rgba(156, 163, 175, 0.2);
  color: #9ca3af;
}

/* Tension badges */
.debug-badge--tension-high {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.debug-badge--tension-medium {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.debug-badge--tension-low {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

/* Condition badges */
.debug-conditions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
}

.debug-condition-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-md);
  font-size: 10px;
  font-weight: var(--font-weight-medium);
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* JSON viewer */
.debug-json {
  margin-top: var(--space-2);
  padding: var(--space-2);
  background: var(--color-bg-panel);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  overflow-x: auto;
}

.debug-json pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.4;
  color: var(--color-text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Empty state */
.debug-empty {
  padding: var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  font-style: italic;
}

/* Footer */
.debug-footer {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  flex-shrink: 0;
}

.debug-btn {
  flex: 1;
  padding: var(--space-2);
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.debug-btn:hover {
  border-color: var(--color-accent-primary);
  color: var(--color-text-primary);
}

.debug-btn--refresh:hover {
  border-color: #3b82f6;
  color: #3b82f6;
}

.debug-btn--copy:hover {
  border-color: #22c55e;
  color: #22c55e;
}

.debug-btn.copied {
  background: rgba(34, 197, 94, 0.2);
  border-color: #22c55e;
  color: #22c55e;
}

/* Scrollbar styling for debug panel */
.debug-content::-webkit-scrollbar {
  width: 6px;
}

.debug-content::-webkit-scrollbar-track {
  background: var(--color-bg-secondary);
}

.debug-content::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

.debug-content::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* ============================================
 * Tool Execution Traces
 * ============================================
 * Real-time tool execution visibility for admin debug panel
 */

.debug-tool-traces {
  max-height: 400px;
  overflow-y: auto;
}

.tool-trace-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.tool-trace-row:hover {
  background: var(--color-bg-tertiary);
}

.tool-trace-row:last-child {
  border-bottom: none;
}

/* Flash animation for new traces */
.tool-trace-row.tool-trace--new {
  background: rgba(34, 197, 94, 0.15);
  animation: trace-flash 0.3s ease-out;
}

@keyframes trace-flash {
  from {
    background: rgba(97, 175, 239, 0.3);
  }
  to {
    background: rgba(34, 197, 94, 0.15);
  }
}

/* Status variants */
.tool-trace-row.tool-trace--executed {
  border-left: 2px solid #22c55e;
}

.tool-trace-row.tool-trace--failed {
  border-left: 2px solid #ef4444;
}

/* Selection traces (UI-driven) - blue left border */
.tool-trace-row.tool-trace--selection {
  border-left: 2px solid #3b82f6;
}

.tool-trace-row.tool-trace--selection.tool-trace--executed {
  border-left: 2px solid #3b82f6;
}

.tool-trace-name--selection {
  color: #3b82f6;
}

.selection-value-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  font-weight: var(--font-weight-medium);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Context builders display */
.debug-context-builders {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-2) 0;
}

.debug-context-builder-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-family: var(--font-mono);
  background: rgba(139, 92, 246, 0.15);
  color: #8b5cf6;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.debug-empty-inline {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: var(--font-size-xs);
}

.tool-trace-name {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-semibold);
  color: var(--color-accent-primary);
  flex-shrink: 0;
}

.execution-time-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--color-bg-tertiary);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

/* Trigger source badges */
.trigger-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: var(--font-weight-medium);
}

.trigger-badge--ai {
  background: rgba(139, 92, 246, 0.2);
  color: #8b5cf6;
}

.trigger-badge--player {
  background: rgba(97, 175, 239, 0.2);
  color: var(--color-accent-primary);
}

.trigger-badge--system {
  background: rgba(156, 163, 175, 0.2);
  color: #9ca3af;
}

/* Expanded trace details */
.tool-trace-row .debug-data--nested {
  width: 100%;
  margin-top: var(--space-2);
}

.tool-trace-row .debug-data--nested pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 10px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--color-bg-panel);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
}

/* Chevron rotation on expand */
.tool-trace-row .debug-chevron {
  transition: transform 0.15s ease;
}

.tool-trace-row.debug-list-item--expanded .debug-chevron {
  transform: rotate(90deg);
}

/* Badge for danger status */
.debug-badge--danger {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}
