/* ==========================================================================
   SpeedPulse Modern Network Diagnostics Design System
   Sleek, High-Contrast, Accessible, Responsive CSS
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;

  /* Light Theme */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-surface-subtle: #f1f5f9;
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --color-primary: #0284c7;
  --color-primary-hover: #0369a1;
  --color-primary-subtle: #e0f2fe;

  --color-download: #0284c7;
  --color-upload: #9333ea;
  --color-latency: #d97706;
  --color-success: #16a34a;
  --color-danger: #dc2626;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

/* Dark Theme */
html.dark {
  --bg-primary: #0b0f19;
  --bg-surface: #111827;
  --bg-surface-elevated: #1f2937;
  --bg-surface-subtle: #1e293b;
  --border-subtle: #1f293d;
  --border-strong: #334155;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --color-primary: #38bdf8;
  --color-primary-hover: #0ea5e9;
  --color-primary-subtle: #0c4a6e;

  --color-download: #38bdf8;
  --color-upload: #c084fc;
  --color-latency: #fbbf24;
  --color-success: #34d399;
  --color-danger: #f87171;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
}

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

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

/* Container */
.container {
  width: 100%;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.25rem;
}

.brand-icon {
  width: 2rem;
  height: 2rem;
  color: var(--color-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

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

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
}

.btn-danger {
  background-color: var(--color-danger);
  color: #ffffff;
}

.btn-secondary {
  background-color: var(--bg-surface-subtle);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--border-subtle);
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

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

.btn-large {
  padding: 0.875rem 2.25rem;
  font-size: 1.125rem;
  border-radius: var(--radius-full);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Cards & Surface */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

/* Test Area */
.test-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 0 1.5rem 0;
  text-align: center;
}

.gauge-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 320px;
  height: 320px;
  margin: 0 auto;
}

.gauge-canvas {
  width: 100%;
  height: 100%;
}

.test-controls {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Progress bar */
.progress-container {
  width: 100%;
  max-width: 480px;
  height: 6px;
  background-color: var(--bg-surface-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 1.25rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-download), var(--color-upload));
  transition: width 0.15s linear;
}

/* Metric Cards Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.metric-card {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  position: relative;
}

.metric-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.metric-value-wrapper {
  margin-top: 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
}

.metric-value {
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1.1;
  font-family: var(--font-sans);
}

.metric-unit {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-sub {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
}

.badge-ready { background: var(--bg-surface-subtle); color: var(--text-muted); }
.badge-testing-download { background: rgba(2, 132, 199, 0.15); color: var(--color-download); }
.badge-testing-upload { background: rgba(147, 51, 234, 0.15); color: var(--color-upload); }
.badge-completed { background: rgba(22, 163, 74, 0.15); color: var(--color-success); }
.badge-failed { background: rgba(220, 38, 38, 0.15); color: var(--color-danger); }
.badge-active { background: rgba(56, 189, 248, 0.2); color: var(--color-primary); }

/* Diagnostics & Quality Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 2rem;
}

@media (max-width: 840px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.section-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.diag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.diag-table th, .diag-table td {
  padding: 0.625rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.diag-table th {
  color: var(--text-muted);
  font-weight: 500;
  width: 40%;
}

.diag-table td {
  font-weight: 600;
  color: var(--text-primary);
}

/* Rating items */
.ratings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.rating-box {
  padding: 1rem;
  background-color: var(--bg-surface-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.rating-box-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
}

.rating-box-val {
  font-size: 1.125rem;
  font-weight: 700;
  margin-top: 0.25rem;
  color: var(--color-primary);
}

/* History Table */
.history-section {
  margin-top: 2.5rem;
}

.history-table-container {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.history-table th, .history-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.history-table th {
  background-color: var(--bg-surface-subtle);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Toast Notification */
.notification-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background-color: var(--text-primary);
  color: var(--bg-surface);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.notification-show {
  opacity: 1;
  transform: translateY(0);
}

/* Footer */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  padding: 2rem 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* Accessibility: Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print Styles for PDF Export */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .site-header, .site-footer, .test-controls, .header-actions, .history-section, .btn {
    display: none !important;
  }
  .card {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    break-inside: avoid;
  }
  .gauge-wrapper {
    display: none !important;
  }
  .metrics-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

