/* Enhanced Message Viewer Styles */

.message-viewer-section {
  max-width: 100%;
}

/* Message Filters */
.message-filters {
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid var(--border-color);
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.filter-row:last-child {
  margin-bottom: 0;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-group input,
.filter-group select {
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--bg-card);
}

.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

/* Template Buttons */
.template-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.template-buttons .btn {
  font-size: 0.75rem;
  padding: 6px 10px;
}

/* Message Statistics Bar */
.message-stats {
  display: flex;
  gap: 20px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.875rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.message-stats span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.message-stats strong {
  font-size: 1.1rem;
  font-weight: 700;
}

/* Message Viewer Container */
.message-viewer-container {
  max-height: 600px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fafafa;
  padding: 8px;
}

/* Message Item */
.message-item {
  background: white;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  border-left: 4px solid;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
  animation: slideInMessage 0.3s ease;
}

.message-item:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

@keyframes slideInMessage {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Direction-based styling */
.message-item.client-to-server {
  border-left-color: #3b82f6;
  background: linear-gradient(to right, #dbeafe 0%, #ffffff 30px);
}

.message-item.server-to-client {
  border-left-color: #10b981;
  background: linear-gradient(to right, #d1fae5 0%, #ffffff 30px);
}

.message-item.broker-to-server {
  border-left-color: #f59e0b;
  background: linear-gradient(to right, #fef3c7 0%, #ffffff 30px);
}

.message-item.server-to-broker {
  border-left-color: #8b5cf6;
  background: linear-gradient(to right, #ede9fe 0%, #ffffff 30px);
}

/* Message Header */
.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

/* Direction Badge */
.direction-badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.direction-badge.client-to-server {
  background: #dbeafe;
  color: #1e40af;
}

.direction-badge.server-to-client {
  background: #d1fae5;
  color: #065f46;
}

.direction-badge.broker-to-server {
  background: #fef3c7;
  color: #92400e;
}

.direction-badge.server-to-broker {
  background: #ede9fe;
  color: #5b21b6;
}

/* Source Badge */
.source-badge {
  padding: 4px 10px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  background: #e5e7eb;
  color: #374151;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Message Time */
.message-time {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: 'Monaco', 'Courier New', monospace;
}

/* Icon Buttons */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 1rem;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--bg-secondary);
}

/* Message Topic Row */
.message-topic-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.message-topic-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.message-topic {
  flex: 1;
  min-width: 200px;
  background: #f3f4f6;
  padding: 6px 10px;
  border-radius: 6px;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 0.8rem;
  color: #1f2937;
  word-break: break-all;
}

/* Device Badge */
.device-badge {
  padding: 3px 8px;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: 'Monaco', 'Courier New', monospace;
}

/* QoS and Retain Badges */
.qos-badge {
  padding: 3px 8px;
  background: #e0e7ff;
  color: #4338ca;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 700;
}

.retain-badge {
  padding: 3px 8px;
  background: #fef3c7;
  color: #92400e;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 700;
}

/* Message Payload */
.message-payload {
  margin-bottom: 8px;
}

.message-payload pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 0;
}

.message-payload code {
  font-family: 'Monaco', 'Courier New', monospace;
}

/* JSON Syntax Highlighting */
.json-key {
  color: #93c5fd;
}

.json-string {
  color: #86efac;
}

.json-number {
  color: #fbbf24;
}

.json-boolean {
  color: #f472b6;
}

.json-null {
  color: #94a3b8;
}

/* Message Meta */
.message-meta {
  font-size: 0.7rem;
  color: var(--text-secondary);
  display: flex;
  gap: 8px;
  font-family: 'Monaco', 'Courier New', monospace;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: white;
  border-radius: 12px;
  max-width: 800px;
  max-height: 90vh;
  width: 90%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  animation: slideInModal 0.3s ease;
}

@keyframes slideInModal {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.btn-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-body pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.6;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .filter-row {
    grid-template-columns: 1fr;
  }

  .message-stats {
    flex-direction: column;
    gap: 8px;
  }

  .message-header {
    font-size: 0.85rem;
  }

  .message-topic {
    font-size: 0.75rem;
  }

  .message-payload pre {
    font-size: 0.75rem;
  }

  .modal-content {
    width: 95%;
    max-height: 95vh;
  }
}

/* Scrollbar Styling */
.message-viewer-container::-webkit-scrollbar {
  width: 10px;
}

.message-viewer-container::-webkit-scrollbar-track {
  background: #e5e7eb;
  border-radius: 5px;
}

.message-viewer-container::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 5px;
}

.message-viewer-container::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Loading Animation */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.loading-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

