* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --gray: #484f58;
  --blue: #58a6ff;
  --purple: #bc8cff;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* Header */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-info {
  color: var(--text-secondary);
  font-size: 13px;
}

.env-toggle {
  display: flex;
  gap: 4px;
}

.env-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
}

.env-btn:hover {
  background: var(--border);
}

.env-btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* Main */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px;
}

/* Sections */
.section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Summary Cards */
.summary-cards {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.summary-card {
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  min-width: 120px;
  text-align: center;
}

.summary-card .count {
  font-size: 28px;
  display: block;
  margin-bottom: 2px;
}

.summary-card.healthy .count { color: var(--green); }
.summary-card.warning .count { color: var(--yellow); }
.summary-card.critical .count { color: var(--red); }
.summary-card.unknown .count { color: var(--gray); }

/* Infrastructure Grid */
.infra-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.infra-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  transition: border-color 0.2s;
}

.infra-card.status-healthy { border-left: 3px solid var(--green); }
.infra-card.status-warning { border-left: 3px solid var(--yellow); }
.infra-card.status-critical { border-left: 3px solid var(--red); }
.infra-card.status-unknown { border-left: 3px solid var(--gray); }

.card-header {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--gray);
}

.status-dot.healthy { background: var(--green); }
.status-dot.warning { background: var(--yellow); }
.status-dot.critical { background: var(--red); animation: pulse 1.5s infinite; }
.status-dot.unknown { background: var(--gray); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.card-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.card-body .metric {
  display: flex;
  justify-content: space-between;
}

.card-body .metric-value {
  color: var(--text-primary);
  font-weight: 500;
}

.sparkline-container {
  margin-top: 8px;
  height: 30px;
}

.sparkline {
  width: 100%;
  height: 30px;
}

/* Pipeline */
.pipeline {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
}

.pipeline-stage {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 16px;
  text-align: center;
  min-width: 120px;
}

.pipeline-stage .stage-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}

.pipeline-stage .stage-rate {
  font-size: 12px;
  color: var(--blue);
}

.pipeline-stage .stage-pending {
  font-size: 11px;
  color: var(--text-muted);
}

.pipeline-arrow {
  color: var(--text-muted);
  font-size: 16px;
  font-weight: bold;
}

.pipeline-latency {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.data-table th {
  background: var(--bg-secondary);
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Services Grid */
.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}

.service-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.service-item .svc-name {
  flex: 1;
  font-weight: 500;
}

.service-item .svc-time {
  color: var(--text-muted);
  font-size: 12px;
  min-width: 60px;
  text-align: right;
}

.service-item .svc-time.slow { color: var(--yellow); }
.service-item .svc-time.timeout { color: var(--red); font-weight: 600; }

/* Gateways Grid */
.gateways-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.gateway-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

/* Queues Grid */
.queues-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.queue-item {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  min-width: 140px;
}

.queue-item .queue-name {
  font-weight: 500;
  margin-bottom: 2px;
}

.queue-item .queue-count {
  font-size: 18px;
  font-weight: 700;
}

.queue-item.status-healthy .queue-count { color: var(--green); }
.queue-item.status-warning .queue-count { color: var(--yellow); }
.queue-item.status-critical .queue-count { color: var(--red); }

/* Alerts */
.alerts-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.alert-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
}

.alert-item:last-child {
  border-bottom: none;
}

.alert-time {
  color: var(--text-muted);
  font-size: 12px;
  min-width: 50px;
  flex-shrink: 0;
}

.alert-icon {
  flex-shrink: 0;
  font-size: 14px;
}

.alert-msg {
  color: var(--text-secondary);
}

.alert-item.critical .alert-msg { color: var(--red); }
.alert-item.warning .alert-msg { color: var(--yellow); }
.alert-item.info .alert-msg { color: var(--text-secondary); }

/* Status colors for container table */
.status-running { color: var(--green); }
.status-stopped { color: var(--red); }
.status-restarting { color: var(--yellow); }

.restart-count { color: var(--yellow); font-weight: 600; }
.restart-count.zero { color: var(--text-muted); font-weight: normal; }

/* Loading */
.loading {
  color: var(--text-muted);
  font-style: italic;
  padding: 16px;
  text-align: center;
}

/* Auth UI */
.btn-login {
  background: var(--blue);
  color: #fff;
  padding: 6px 16px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: opacity 0.2s;
}
.btn-login:hover { opacity: 0.85; }

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.user-name {
  font-size: 13px;
  color: var(--text-secondary);
}
.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); }

.role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
}
.role-admin { background: rgba(188, 140, 255, 0.2); color: var(--purple); }
.role-operator { background: rgba(63, 185, 80, 0.2); color: var(--green); }
.role-viewer { background: rgba(139, 148, 158, 0.2); color: var(--text-secondary); }

/* Action buttons */
.btn-action {
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: opacity 0.2s;
}
.btn-action:hover { opacity: 0.85; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 2px 8px; font-size: 11px; }

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
  max-width: 350px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast-info { border-left: 3px solid var(--blue); }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex;
  justify-content: center;
  align-items: center;
}
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
}
.modal-close:hover { color: var(--red); }
.modal-body { padding: 16px; }

.add-user-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.add-user-form input, .add-user-form select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
}
.add-user-form input { flex: 1; }

/* Connection banner */
.connection-banner {
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid var(--red);
  color: var(--red);
  padding: 10px 16px;
  border-radius: 6px;
  text-align: center;
  font-weight: 500;
  margin-bottom: 16px;
  animation: pulse-banner 2s infinite;
}
@keyframes pulse-banner {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Action column */
.action-col { text-align: center; white-space: nowrap; }
.action-col .btn-action { margin: 0 2px; }

/* Acknowledged alerts */
.alert-item.acknowledged { opacity: 0.5; }
.alert-item.acknowledged .alert-msg { text-decoration: line-through; }
.alert-acked { font-size: 11px; color: var(--green); margin-left: 8px; }

/* Logs viewer */
.modal-wide { width: 90%; max-width: 1100px; }
.logs-controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.logs-controls select,
.logs-controls input[type="text"] {
  background: var(--bg-primary); color: var(--text); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 4px; font-size: 12px;
}
.logs-controls input[type="text"] { width: 160px; }
.logs-auto-label { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.logs-viewer {
  background: #000; color: #d4d4d4; font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 12px; line-height: 1.5; padding: 12px; border-radius: 4px;
  max-height: 60vh; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
}

/* Responsive */
@media (max-width: 768px) {
  header {
    flex-direction: column;
    gap: 8px;
  }
  .summary-cards {
    flex-wrap: wrap;
  }
  .summary-card {
    min-width: 80px;
    flex: 1;
  }
  main {
    padding: 12px;
  }
  .user-name { display: none; }
  .modal { width: 95%; }
}
