/* ===========================================================================
   Inspector de actividad y mensajes
   ========================================================================== */

.btn-debug-toggle {
  background-color: transparent;
  color: var(--text-muted);
}

.btn-debug-toggle.active {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: #bfdbfe;
  font-weight: 600;
}

.debug-panel {
  width: 440px;
  max-width: 45vw;
  height: 100%;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  max-height: 100%;
  background: var(--bg-surface);
  color: var(--text-main);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  flex-shrink: 0;
  box-shadow: var(--shadow-xl);
  animation: slideInRight 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.debug-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  min-height: 3.75rem;
  padding: 0.7rem 0.85rem 0.7rem 1rem;
  background: rgba(var(--bg-surface-rgb), var(--header-bg-alpha));
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(14px);
  user-select: none;
}

.debug-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.debug-badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  color: var(--primary);
  background: var(--primary-light);
}

.debug-badge-icon .ui-icon {
  width: 18px;
  height: 18px;
}

.debug-status-indicator {
  font-size: 0.68rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.debug-status-indicator.idle {
  background: var(--bg-surface-subtle);
  color: var(--text-muted);
}

.debug-status-indicator.streaming {
  background: rgba(234, 179, 8, 0.25);
  color: var(--warning);
  box-shadow: 0 0 8px rgba(234, 179, 8, 0.3);
  animation: pulse-glow 1.5s infinite;
}

.debug-status-indicator.done {
  background: rgba(34, 197, 94, 0.25);
  color: var(--success);
}

.debug-status-indicator.error {
  background: rgba(239, 68, 68, 0.25);
  color: var(--danger);
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(0.97); }
}

.debug-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.btn-debug-action {
  width: 32px;
  height: 32px;
  padding: 0;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  transition: all 0.15s ease;
  line-height: 1;
}

.btn-debug-action:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-debug-action.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-debug-action.btn-close-panel {
  font-weight: 700;
  padding: 0;
}


.debug-tabs {
  display: flex;
  gap: 0.3rem;
  padding: 0.55rem 0.75rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.debug-tab {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 500;
  min-height: 32px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.debug-tab.active {
  color: var(--primary);
  background: var(--primary-light);
  border-color: color-mix(in srgb, var(--primary) 28%, transparent);
  font-weight: 600;
}

.debug-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin: 0.65rem 0.75rem 0;
  padding: 0.6rem 0.7rem;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  user-select: none;
  flex-wrap: wrap;
}

.debug-control-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.debug-toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.debug-toggle-label {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.78rem;
}

.debug-status-pill {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.debug-status-pill.on {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.debug-status-pill.off {
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.debug-interceptor-modal {
  width: 92%;
  max-width: 800px;
  max-height: 88vh;
  border-radius: var(--radius-lg);
  border: 1px solid #334155;
  background: #0f172a;
  color: #f1f5f9;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
  overflow: hidden;
  z-index: 1000;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.debug-modal-send-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-debug-header-action {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 28px;
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-debug-header-send {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn-debug-header-send:hover {
  background: var(--primary-hover);
}

.btn-debug-header-stop {
  border: 1px solid rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
}

.btn-debug-header-stop:hover {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.25);
  color: #fde68a;
}

.modal-header-actions .modal-btn-action,
.modal-header-actions .modal-btn-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  font-size: 0.85rem;
  line-height: 1;
  transition: all 0.15s ease;
  box-sizing: border-box;
}

.modal-header-actions .modal-btn-action:hover,
.modal-header-actions .modal-btn-close:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

[data-theme="light"] .modal-header-actions .modal-btn-action,
[data-theme="light"] .modal-header-actions .modal-btn-close {
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #64748b;
}

[data-theme="light"] .modal-header-actions .modal-btn-action:hover,
[data-theme="light"] .modal-header-actions .modal-btn-close:hover {
  background: rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.18);
  color: #0f172a;
}

.debug-interceptor-modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.debug-modal-body {
  display: flex;
  flex-direction: column;
  padding: 1.15rem;
  gap: 1rem;
}

.debug-modal-info {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  font-size: 0.825rem;
  color: #bae6fd;
  line-height: 1.45;
}

.debug-editor-wrapper {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-md);
  border: 1px solid #334155;
  overflow: hidden;
  background: #090e1a;
}

.debug-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.75rem;
  background: #131d36;
  border-bottom: 1px solid #1e293b;
}

.debug-endpoint-badge {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.debug-editor-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-debug-editor-action {
  gap: 0.35rem;
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
}

.debug-payload-textarea {
  width: 100%;
  height: 340px;
  max-height: 50vh;
  padding: 0.85rem;
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #f1f5f9;
  background: #090e1a;
  border: none;
  resize: vertical;
  outline: none;
  tab-size: 2;
  box-sizing: border-box;
}

.debug-payload-textarea:focus {
  background: #070b14;
}

.debug-payload-textarea:focus-visible {
  outline: 1px solid var(--input-border-focus);
}

.debug-json-error {
  padding: 0.5rem 0.75rem;
  background: rgba(239, 68, 68, 0.15);
  border-top: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 0.78rem;
  font-family: monospace;
}

.debug-interceptor-modal.maximized {
  width: 98vw;
  max-width: 98vw;
  height: 96vh;
  max-height: 96vh;
  display: flex;
  flex-direction: column;
}

.debug-interceptor-modal.maximized .debug-modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.debug-interceptor-modal.maximized .debug-editor-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.debug-interceptor-modal.maximized .debug-payload-textarea {
  flex: 1;
  height: 100%;
  max-height: none;
}

.btn-secondary-action {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fbbf24;
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary-action:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: #f59e0b;
  color: #fde68a;
}

.debug-raw-toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #cbd5e1;
}

.raw-toggle-label {
  font-weight: 500;
  font-size: 0.78rem;
  color: #cbd5e1;
}

.raw-status-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #1e293b;
  color: #64748b;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.raw-status-badge.active {
  background: rgba(6, 182, 212, 0.2);
  color: #22d3ee;
  border-color: rgba(6, 182, 212, 0.4);
}

.switch.switch-sm {
  width: 32px;
  height: 18px;
}

.switch.switch-sm .slider {
  border-radius: 18px;
}

.switch.switch-sm .slider:before {
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
}

.switch.switch-sm input:checked + .slider:before {
  transform: translateX(14px);
}

.debug-log-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  background: var(--code-bg);
  scroll-behavior: smooth;
}

.debug-entry {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  word-break: break-word;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid transparent;
  box-shadow: var(--shadow-xs);
  animation: fadeIn 0.15s ease-out;
}

.debug-entry.debug-entry-network {
  border-left-color: #38bdf8;
  background: rgba(56, 189, 248, 0.04);
}

.debug-entry.debug-entry-thinking {
  border-left-color: #eab308;
  background: rgba(234, 179, 8, 0.05);
}

.debug-entry.debug-entry-tool {
  border-left-color: #a855f7;
  background: rgba(168, 85, 247, 0.05);
}

.debug-entry.debug-entry-stats {
  border-left-color: #22c55e;
  background: rgba(34, 197, 94, 0.04);
}

.debug-entry.debug-entry-error {
  border-left-color: #ef4444;
  background: rgba(239, 68, 68, 0.07);
}

.debug-entry.debug-entry-warning {
  border-left-color: #f59e0b;
  background: rgba(245, 158, 11, 0.07);
}

.debug-entry.debug-entry-system {
  border-left-color: #64748b;
  background: rgba(100, 116, 139, 0.04);
}

.debug-entry-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.7rem;
  margin-bottom: 0.15rem;
}

.debug-time {
  color: #64748b;
  font-size: 0.68rem;
}

.debug-tag {
  font-weight: 700;
  font-size: 0.65rem;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.debug-tag.network {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
}

.debug-tag.thinking {
  background: rgba(234, 179, 8, 0.22);
  color: #fde047;
}

.debug-tag.tool {
  background: rgba(168, 85, 247, 0.22);
  color: #d8b4fe;
}

.debug-tag.stats {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}

.debug-tag.error {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.debug-tag.warning {
  background: rgba(245, 158, 11, 0.25);
  color: #fde68a;
}

.debug-tag.system {
  background: rgba(100, 116, 139, 0.25);
  color: #cbd5e1;
}

.debug-msg {
  color: var(--code-text);
  white-space: pre-wrap;
  font-family: var(--font-mono);
}

.debug-entry-thinking .debug-msg {
  color: #fef08a;
  font-style: italic;
  line-height: 1.5;
}

.debug-entry-error .debug-msg {
  color: #fca5a5;
}

.debug-entry-warning .debug-msg {
  color: #fde68a;
}

.debug-entry.debug-entry-raw {
  border-left-color: #06b6d4;
  background: rgba(6, 182, 212, 0.05);
}

.debug-entry.debug-entry-raw.raw-outgoing {
  border-left-color: #3b82f6;
  background: rgba(59, 130, 246, 0.06);
}

.debug-tag.raw {
  background: rgba(6, 182, 212, 0.2);
  color: #22d3ee;
}

.debug-entry.debug-entry-raw.raw-outgoing .debug-tag.raw {
  background: rgba(59, 130, 246, 0.22);
  color: #60a5fa;
}

.debug-entry-raw .debug-msg {
  color: #a5f3fc;
  word-break: break-all;
  font-size: 0.72rem;
  line-height: 1.4;
}

.debug-entry-raw.raw-outgoing .debug-msg {
  color: #bfdbfe;
}

.debug-entry-tool .debug-msg {
  color: #e9d5ff;
}

.btn-debug-action:focus-visible,
.debug-tab:focus-visible,
.debug-toggle-wrapper .switch:focus-within {
  outline: none;
  box-shadow: var(--input-focus-ring);
}

/* Responsividad en pantallas pequeñas */
@media (max-width: 900px) {
  .debug-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    width: 92vw;
    max-width: 92vw;
    z-index: 1000;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
  }
}

@media (max-width: 768px) {
  .debug-interceptor-modal {
    width: 100vw;
    width: 100dvw;
    max-width: 100vw;
    max-width: 100dvw;
    left: 0;
    right: 0;
    margin-left: 0;
    margin-right: 0;
    border-left: none;
    border-right: none;
    border-radius: 0;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }

  .debug-interceptor-modal .modal-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .debug-modal-send-actions {
    order: 3;
    width: 100%;
  }

  .btn-debug-header-action {
    flex: 1 1 0;
    justify-content: center;
  }
}
