:root {
  --primary: #0066cc;
  --primary-dark: #004c99;
  --secondary: #6c757d;
  --success: #28a745;
  --warning: #ffc107;
  --danger: #dc3545;
  --dark: #1a1a2e;
  --light: #f8f9fa;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #f5f7fa;
  color: #333;
  line-height: 1.6;
}

.dashboard {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, var(--dark) 0%, #16213e 100%);
  color: white;
  padding: 24px 32px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 600;
}

.header .subtitle {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
  margin-top: 4px;
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.data-source {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.1);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
}

.cache-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}

.cache-info .cache-count {
  background: rgba(40, 167, 69, 0.3);
  padding: 4px 10px;
  border-radius: 12px;
}

.cache-info .cache-time {
  opacity: 0.8;
}

.btn-refresh {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-refresh:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: rotate(90deg);
}

.btn-refresh.loading {
  animation: spin 1s linear infinite;
  pointer-events: none;
  opacity: 0.6;
}

.source-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.source-indicator.live {
  background: var(--success);
  animation: pulse 2s infinite;
}

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

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  background: white;
  padding: 20px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

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

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

.filter-group select,
.filter-group input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 150px;
  background: white;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.btn-primary,
.btn-secondary {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

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

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

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

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-card.success {
  border-left: 4px solid var(--success);
}

.stat-icon {
  font-size: 2rem;
  opacity: 0.8;
}

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

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--dark);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--secondary);
}

.charts-section {
  display: grid;
  gap: 20px;
  margin-bottom: 20px;
}

.charts-section.two-col {
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}

.chart-container {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.chart-container.wide {
  grid-column: 1 / -1;
}

.chart-container h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--dark);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.chart-header-with-filters {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.chart-header-with-filters h3 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.chart-filters {
  display: flex;
  gap: 10px;
}

.chart-filters select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  background: white;
  cursor: pointer;
}

.chart-filters select:focus {
  outline: none;
  border-color: var(--primary);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
}

.checkbox-label:hover {
  border-color: var(--primary);
}

.checkbox-label input[type="checkbox"] {
  cursor: pointer;
}

.btn-reset-zoom {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-reset-zoom:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.zoom-hint {
  font-size: 0.75rem;
  color: var(--secondary);
  text-align: center;
  margin-bottom: 8px;
  opacity: 0.8;
}

.chart-container canvas {
  max-height: 300px;
}

.table-section {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.table-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--dark);
}

.record-count {
  font-size: 0.85rem;
  color: var(--secondary);
  background: var(--light);
  padding: 4px 12px;
  border-radius: 20px;
}

.table-wrapper {
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead {
  position: sticky;
  top: 0;
  background: var(--light);
  z-index: 10;
}

th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s, color 0.2s;
}

th.sortable:hover {
  background-color: rgba(0, 102, 204, 0.1);
  color: var(--primary);
}

th.sortable.active {
  color: var(--primary);
  background-color: rgba(0, 102, 204, 0.05);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background: rgba(0, 102, 204, 0.02);
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-badge.success {
  background: rgba(40, 167, 69, 0.1);
  color: var(--success);
}

.status-badge.error {
  background: rgba(220, 53, 69, 0.1);
  color: var(--danger);
}

.source-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
}

.source-tag.backend {
  background: rgba(0, 102, 204, 0.1);
  color: var(--primary);
}

.source-tag.frontend {
  background: rgba(108, 117, 125, 0.1);
  color: var(--secondary);
}

.footer {
  text-align: center;
  padding: 24px;
  color: var(--secondary);
  font-size: 0.85rem;
}

.btn-clear-cache {
  background: var(--danger);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 12px;
}

.btn-clear-cache:hover {
  background: #c82333;
  transform: translateY(-1px);
}

.btn-clear-cache:disabled {
  background: var(--secondary);
  cursor: not-allowed;
  transform: none;
}

.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  color: var(--secondary);
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.latency-value {
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 0.85rem;
}

.latency-value.high {
  color: var(--danger);
  font-weight: 600;
}

.latency-value.medium {
  color: var(--warning);
}

.latency-value.low {
  color: var(--success);
}

/* Zoom indicator */
.zoom-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(135deg, #e8f0fe 0%, #d2e3fc 100%);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 10px 20px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--primary-dark);
  font-weight: 500;
  animation: slideIn 0.2s ease-out;
}

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

.btn-reset-zoom-small {
  padding: 4px 12px;
  font-size: 0.75rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-reset-zoom-small:hover {
  background: var(--primary-dark);
}

.stats-grid.zoomed .stat-card {
  border-top: 2px solid var(--primary);
}

@media (max-width: 768px) {
  .header {
    flex-direction: column;
    text-align: center;
    gap: 16px;
  }

  .filters-bar {
    flex-direction: column;
  }

  .filter-group {
    width: 100%;
  }

  .filter-group select,
  .filter-group input {
    width: 100%;
  }

  .charts-section.two-col {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
