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

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #4d2c8e;
  --primary-hover: #3d1f73;
  --primary-light: #ede9fe;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --info: #2563eb;
  --info-bg: #dbeafe;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.connection-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 2s infinite;
}

.connection-status.connected .dot {
  background: var(--success);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

nav {
  display: flex;
  gap: 4px;
}

.nav-btn {
  background: none;
  border: none;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.15s;
}

.nav-btn:hover { background: var(--surface-muted); }
.nav-btn.active { background: var(--primary-light); color: var(--primary); }

main {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

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

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Dashboard Row */
.dashboard-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  overflow: hidden;
}

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

.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
}

/* Live Feed */
.live-feed {
  max-height: 500px;
  overflow-y: auto;
  padding: 8px;
}

.feed-item {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 4px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: background 0.15s;
  border-left: 3px solid transparent;
  animation: slideIn 0.3s ease;
}

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

.feed-item:hover { background: var(--surface-muted); }

.feed-item .badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  min-width: 32px;
  text-align: center;
}

.feed-item .feed-info {
  flex: 1;
  min-width: 0;
}

.feed-item .feed-desc {
  font-weight: 500;
  font-size: 13px;
}

.feed-item .feed-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.feed-item .feed-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Bar Chart */
.bar-chart {
  padding: 20px;
  max-height: 500px;
  overflow-y: auto;
}

.bar-item {
  margin-bottom: 8px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 2px;
}

.bar-track {
  height: 20px;
  background: var(--surface-muted);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.5s ease;
  min-width: 2px;
}

/* Tables */
.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: var(--surface-muted);
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr { cursor: pointer; transition: background 0.1s; }
.data-table tbody tr:hover { background: var(--surface-muted); }

/* Filters */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}

.filter-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Buttons */
.btn-sm {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-sm:hover { background: var(--primary-hover); }
.btn-sm.btn-secondary { background: var(--surface-muted); color: var(--text); border: 1px solid var(--border); }
.btn-sm.btn-secondary:hover { background: var(--border); }
.btn-sm.btn-danger { background: var(--danger); }
.btn-sm.btn-danger:hover { background: #b91c1c; }

.btn-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
}

/* Pagination */
.pagination {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

/* Search Bar */
.search-bar {
  padding: 16px 20px;
  display: flex;
  gap: 8px;
}

/* Empty State */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Badges */
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
}

/* Sig icons */
.sig-valid { color: var(--success); font-weight: 700; }
.sig-invalid { color: var(--danger); font-weight: 700; }
.sig-none { color: var(--text-muted); }

/* Forms */
.form-row {
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-row .filter-input {
  padding: 8px 12px;
}

.form-actions {
  padding: 12px 20px;
  display: flex;
  gap: 8px;
}

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

.modal {
  background: var(--surface);
  border-radius: 10px;
  width: 90%;
  max-width: 800px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 { font-size: 16px; }

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

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-item {
  background: var(--surface-muted);
  padding: 10px 14px;
  border-radius: 6px;
}

.detail-item .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-item .value {
  font-size: 14px;
  font-weight: 500;
  margin-top: 2px;
  word-break: break-all;
}

.raw-payload {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 8px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
}

.raw-payload-toggle {
  cursor: pointer;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  margin-top: 12px;
}

/* Tracking Timeline */
.timeline {
  position: relative;
  padding-left: 28px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding: 12px 0 12px 20px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 16px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
}

.timeline-item.current::before {
  background: var(--success);
  width: 14px;
  height: 14px;
  left: -25px;
}

.timeline-item .tl-time {
  font-size: 12px;
  color: var(--text-muted);
}

.timeline-item .tl-code {
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.timeline-item .tl-desc {
  font-size: 13px;
  color: var(--text);
  margin-top: 2px;
}

.timeline-item .tl-location {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Responsive */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
