:root {
  --bg-dark: #0b0f19;
  --bg-panel: #111827;
  --bg-card: #1f2937;
  --bg-hover: #374151;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3b82f6;

  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-purple: #8b5cf6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;

  --inbound-color: #10b981;
  --inbound-bg: rgba(16, 185, 129, 0.12);
  --outbound-color: #3b82f6;
  --outbound-bg: rgba(59, 130, 246, 0.12);

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Fira Code', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header Navbar */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.logo-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #ffffff;
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.server-status {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.status-connected {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
  border-color: rgba(16, 185, 129, 0.3);
}

.status-connecting {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
  border-color: rgba(245, 158, 11, 0.3);
}

.status-disconnected {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  border-color: rgba(239, 68, 68, 0.3);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
  box-shadow: 0 0 8px currentColor;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.2); }
  100% { opacity: 1; transform: scale(1); }
}

.broker-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  background-color: var(--bg-card);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-family: var(--font-mono);
}

/* App Layout */
.app-container {
  padding: 1.5rem 2rem;
  max-width: 1700px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Stats Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-card {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.15);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.icon-total { background: rgba(139, 92, 246, 0.15); color: var(--accent-purple); }
.icon-inbound { background: rgba(16, 185, 129, 0.15); color: var(--accent-green); }
.icon-outbound { background: rgba(59, 130, 246, 0.15); color: var(--accent-blue); }
.icon-senders { background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); }
.icon-targets { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); }

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
}

.text-inbound { color: var(--accent-green); }
.text-outbound { color: var(--accent-blue); }

/* Main Panels Layout */
.main-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 1.5rem;
  flex: 1;
}

@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.panel-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.02);
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge-tag {
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent-blue);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

.header-title-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.1);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.blink-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent-red);
  border-radius: 50%;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

.panel-actions {
  display: flex;
  gap: 0.5rem;
}

/* Command Dispatch Form */
.command-form {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.label-with-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.quick-presets {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.preset-title {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.btn-preset {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--accent-cyan);
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-preset:hover {
  background: var(--accent-cyan);
  color: #000;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.checkbox-group {
  justify-content: flex-end;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem !important;
}

input[type="text"], select, textarea {
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  resize: vertical;
}

input[type="text"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary.active {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-green);
  border-color: rgba(16, 185, 129, 0.4);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

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

.btn-danger-outline {
  background: transparent;
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.15);
}

.alert {
  margin: 0 1.5rem 1.5rem 1.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

.alert.success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.alert.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.hidden {
  display: none !important;
}

/* Logs Filter Bar */
.filter-bar {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.search-input-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-input-wrapper input {
  padding-left: 2.5rem;
  width: 100%;
}

.filter-dropdowns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-select, .filter-input {
  font-size: 0.8rem;
  padding: 0.4rem 0.65rem;
  flex: 1;
  min-width: 130px;
}

/* Logs Table */
.logs-table-wrapper {
  flex: 1;
  overflow-y: auto;
  max-height: 650px;
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.825rem;
}

.logs-table th {
  background-color: var(--bg-panel);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logs-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

.logs-table tbody tr {
  transition: background-color 0.15s;
  cursor: pointer;
}

.logs-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

/* New row animation */
@keyframes highlightRow {
  0% { background-color: rgba(59, 130, 246, 0.25); }
  100% { background-color: transparent; }
}

.new-row-anim {
  animation: highlightRow 2s ease-out;
}

/* Badges */
.badge-dir {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-in {
  background: var(--inbound-bg);
  color: var(--inbound-color);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-out {
  background: var(--outbound-bg);
  color: var(--outbound-color);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-sender, .badge-target {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  display: inline-block;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-sender { color: var(--accent-cyan); }
.badge-target { color: var(--accent-amber); }

.topic-cell {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  word-break: break-all;
}

.payload-preview {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-primary);
  max-width: 350px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.time-cell {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
  gap: 0.5rem;
}

.empty-state i {
  font-size: 2.5rem;
}

/* Footer & Pagination */
.logs-footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-panel);
}

.footer-info {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-num {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 650px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.825rem;
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.modal-payload-box label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 0.5rem;
}

.modal-payload-box pre {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-cyan);
  max-height: 250px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

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