/**
 * Main Stylesheet for Performance Test Website
 * Mobile-first responsive design for iOS testing
 */

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: #333;
  background: #f5f5f5;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Typography */
h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: #1a1a1a;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
  color: #1a1a1a;
}

h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: #1a1a1a;
}

p {
  margin-bottom: 1rem;
}

/* Container */
.container {
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

/* Navigation Grid */
.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin: 20px 0;
}

.nav-button {
  display: inline-block;
  padding: 20px 30px;
  background: #007aff;
  color: white;
  text-decoration: none;
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
  font-size: 1.1rem;
  transition: background 0.2s, transform 0.1s;
  border: none;
  cursor: pointer;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-button:hover {
  background: #0051d5;
}

.nav-button:active {
  transform: scale(0.98);
}

.nav-button.secondary {
  background: #5ac8fa;
}

.nav-button.secondary:hover {
  background: #32b3e8;
}

.nav-button.danger {
  background: #ff3b30;
}

.nav-button.danger:hover {
  background: #d62b1f;
}

.nav-button.success {
  background: #34c759;
}

.nav-button.success:hover {
  background: #28a745;
}

/* Browser Info Display */
.browser-info {
  background: #f0f0f0;
  padding: 15px;
  border-radius: 6px;
  margin: 15px 0;
  font-size: 0.95rem;
  line-height: 1.8;
}

.browser-info strong {
  color: #007aff;
}

/* Metrics Card */
.metrics-card {
  background: white;
  border-radius: 8px;
  padding: 25px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin: 20px 0;
}

.metrics-card h2 {
  border-bottom: 2px solid #007aff;
  padding-bottom: 10px;
  margin-bottom: 15px;
}

/* Metrics Table */
.metrics-table {
  width: 100%;
  border-collapse: collapse;
  margin: 15px 0;
  font-size: 1rem;
}

.metrics-table tr {
  border-bottom: 1px solid #e0e0e0;
}

.metrics-table tr:last-child {
  border-bottom: none;
}

.metrics-table td {
  padding: 12px 10px;
}

.metrics-table td:first-child {
  font-weight: 500;
  color: #555;
  width: 45%;
}

.metrics-table td.metric-value {
  text-align: right;
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  width: 40%;
}

.metrics-table td.status {
  text-align: center;
  font-size: 1.3rem;
  width: 15%;
}

.metrics-table tr.total-row {
  background: #f8f8f8;
  border-top: 2px solid #007aff;
  border-bottom: 2px solid #007aff;
}

.metrics-table tr.total-row td {
  padding: 15px 10px;
}

/* Legend */
.legend {
  margin-top: 15px;
  padding: 10px;
  background: #f8f8f8;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #666;
  text-align: center;
}

/* Dashboard */
.dashboard {
  margin: 20px 0;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 10px;
}

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

.stat-card {
  background: #f8f8f8;
  padding: 20px;
  border-radius: 6px;
  border-left: 4px solid #007aff;
}

.stat-card h3 {
  font-size: 0.9rem;
  color: #666;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 2rem;
  font-weight: bold;
  color: #1a1a1a;
}

.stat-card .label {
  font-size: 0.85rem;
  color: #999;
  margin-top: 5px;
}

/* Comparison Table */
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 0.95rem;
}

.comparison-table thead {
  background: #007aff;
  color: white;
}

.comparison-table th {
  padding: 15px 10px;
  text-align: left;
  font-weight: 600;
}

.comparison-table th:nth-child(2),
.comparison-table th:nth-child(3),
.comparison-table th:nth-child(4) {
  text-align: right;
}

.comparison-table tbody tr {
  border-bottom: 1px solid #e0e0e0;
}

.comparison-table tbody tr:hover {
  background: #f8f8f8;
}

.comparison-table td {
  padding: 12px 10px;
}

.comparison-table td:nth-child(2),
.comparison-table td:nth-child(3),
.comparison-table td:nth-child(4) {
  text-align: right;
  font-family: 'Courier New', monospace;
}

.comparison-table .diff-positive {
  color: #ff3b30;
  font-weight: 600;
}

.comparison-table .diff-negative {
  color: #34c759;
  font-weight: 600;
}

.comparison-table .diff-neutral {
  color: #999;
}

/* Test Runs Table */
.test-runs-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 0.85rem;
}

.test-runs-table thead {
  background: #f0f0f0;
  position: sticky;
  top: 0;
}

.test-runs-table th {
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid #ddd;
}

.test-runs-table tbody tr {
  border-bottom: 1px solid #e0e0e0;
}

.test-runs-table tbody tr:hover {
  background: #f8f8f8;
}

.test-runs-table td {
  padding: 10px 8px;
}

.test-runs-table .browser-safari {
  color: #007aff;
  font-weight: 600;
}

.test-runs-table .browser-chrome {
  color: #34c759;
  font-weight: 600;
}

/* Charts */
.chart-container {
  margin: 30px 0;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chart-title {
  font-size: 1.2rem;
  margin-bottom: 15px;
  color: #1a1a1a;
}

.bar-chart {
  margin: 20px 0;
}

.bar-group {
  margin-bottom: 20px;
}

.bar-label {
  font-size: 0.9rem;
  margin-bottom: 5px;
  font-weight: 500;
}

.bar-wrapper {
  display: flex;
  gap: 10px;
  align-items: center;
}

.bar {
  height: 30px;
  background: #007aff;
  border-radius: 4px;
  transition: width 0.3s ease;
  position: relative;
  min-width: 2px;
}

.bar.safari {
  background: #007aff;
}

.bar.chrome {
  background: #34c759;
}

.bar-value {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Alerts */
.alert {
  padding: 15px 20px;
  border-radius: 6px;
  margin: 15px 0;
}

.alert-info {
  background: #e3f2fd;
  border-left: 4px solid #007aff;
  color: #014361;
}

.alert-warning {
  background: #fff3cd;
  border-left: 4px solid #ff9500;
  color: #664d03;
}

.alert-success {
  background: #d4edda;
  border-left: 4px solid #34c759;
  color: #155724;
}

/* Loading State */
.loading {
  text-align: center;
  padding: 40px;
  color: #999;
}

.loading:after {
  content: '...';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* Utilities */
.text-center {
  text-align: center;
}

.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 20px; }
.mt-3 { margin-top: 30px; }
.mb-1 { margin-bottom: 10px; }
.mb-2 { margin-bottom: 20px; }
.mb-3 { margin-bottom: 30px; }

.text-muted {
  color: #999;
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .container {
    padding: 20px;
  }

  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.35rem;
  }

  .nav-grid {
    grid-template-columns: 1fr;
  }

  .nav-button {
    font-size: 1rem;
    padding: 18px 25px;
  }

  .metrics-table {
    font-size: 0.9rem;
  }

  .metrics-table td {
    padding: 10px 5px;
  }

  .comparison-table,
  .test-runs-table {
    font-size: 0.8rem;
  }

  .comparison-table th,
  .comparison-table td,
  .test-runs-table th,
  .test-runs-table td {
    padding: 8px 5px;
  }

  .stat-card .value {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.2rem;
  }

  .nav-button {
    min-height: 60px;
    font-size: 0.95rem;
  }

  .metrics-card {
    padding: 15px;
  }

  .comparison-table,
  .test-runs-table {
    font-size: 0.75rem;
  }
}

/* =======================
   DEBUG PANEL STYLES
   ======================= */

/* Debug Panel Container */
.debug-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 650px;
  max-width: 90vw;
  max-height: 85vh;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Debug Header */
.debug-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.debug-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.close-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.2s;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Debug Tabs */
.debug-tabs {
  display: flex;
  background: #f8f9fa;
  border-bottom: 2px solid #e0e0e0;
}

.tab-btn {
  flex: 1;
  padding: 12px 16px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  color: #666;
  transition: all 0.2s;
  position: relative;
}

.tab-btn:hover {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
}

.tab-btn.active {
  background: white;
  color: #667eea;
  border-bottom: 3px solid #667eea;
}

/* Debug Content */
.debug-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: white;
}

.tab-content {
  display: none;
}

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

/* Optimization Badges */
.optimization-badge {
  display: flex;
  align-items: flex-start;
  padding: 12px 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  border-left: 4px solid;
  transition: transform 0.2s, box-shadow 0.2s;
}

.optimization-badge:hover {
  transform: translateX(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.optimization-badge.detected {
  background: #e8f5e9;
  border-left-color: #4caf50;
}

.optimization-badge.not-detected {
  background: #fff3e0;
  border-left-color: #ff9800;
}

.optimization-badge.chrome-only {
  background: #e3f2fd;
  border-left-color: #2196f3;
}

.badge-icon {
  font-size: 1.3rem;
  margin-right: 12px;
  min-width: 24px;
}

.badge-content {
  flex: 1;
}

.badge-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
  color: #333;
}

.badge-description {
  font-size: 0.85rem;
  color: #666;
  line-height: 1.4;
}

/* Waterfall Chart */
.waterfall-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 6px;
  font-size: 0.85rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-color {
  width: 20px;
  height: 12px;
  border-radius: 2px;
}

.legend-color.dns {
  background: #2196f3;
}

.legend-color.tcp {
  background: #4caf50;
}

.legend-color.tls {
  background: #ff9800;
}

.legend-color.request {
  background: #9c27b0;
}

.legend-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.legend-badge.cached {
  background: #757575;
  color: white;
}

.legend-badge.early {
  background: #f44336;
  color: white;
}

/* Waterfall Rows */
.waterfall-chart {
  background: #fafafa;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.waterfall-row {
  display: grid;
  grid-template-columns: 180px 1fr 120px;
  gap: 12px;
  padding: 8px;
  border-bottom: 1px solid #eee;
  align-items: center;
  font-size: 0.85rem;
}

.waterfall-row:last-child {
  border-bottom: none;
}

.waterfall-row.early-request {
  background: #fff3e0;
  border-radius: 4px;
}

.resource-name {
  font-size: 0.85rem;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.resource-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 20px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  background: #e0e0e0;
  color: #666;
}

.resource-type-icon.script {
  background: #fff3e0;
  color: #f57c00;
}

.resource-type-icon.link {
  background: #e3f2fd;
  color: #1976d2;
}

.resource-type-icon.img {
  background: #e8f5e9;
  color: #388e3c;
}

/* Resource Timeline */
.resource-timeline {
  position: relative;
  height: 28px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: visible;
}

.timeline-segment {
  position: absolute;
  height: 100%;
  border-radius: 2px;
  transition: opacity 0.2s;
}

.timeline-segment:hover {
  opacity: 0.8;
}

.timeline-segment.dns {
  background: #2196f3;
}

.timeline-segment.tcp {
  background: #4caf50;
}

.timeline-segment.tls {
  background: #ff9800;
}

.timeline-segment.request {
  background: #9c27b0;
}

.timeline-segment.cached {
  background: #bdbdbd;
}

/* Resource Duration and Badges */
.resource-duration {
  font-size: 0.85rem;
  color: #666;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.resource-badge {
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.resource-badge.cached {
  background: #757575;
  color: white;
}

.resource-badge.early {
  background: #f44336;
  color: white;
}

.resource-badge.protocol {
  background: #2196f3;
  color: white;
}

/* Waterfall Scale */
.waterfall-scale {
  position: relative;
  height: 24px;
  margin-top: 8px;
  border-top: 1px solid #e0e0e0;
  font-size: 0.75rem;
  color: #999;
}

.waterfall-scale span {
  position: absolute;
  transform: translateX(-50%);
  top: 4px;
}

/* Debug Logs */
.debug-log {
  font-family: 'Monaco', 'Menlo', 'Consolas', 'Courier New', monospace;
  font-size: 0.8rem;
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 16px;
  border-radius: 6px;
  max-height: 500px;
  overflow-y: auto;
  line-height: 1.6;
}

.debug-log-entry {
  margin-bottom: 4px;
  word-wrap: break-word;
}

.debug-log-entry.info {
  color: #4fc3f7;
}

.debug-log-entry.warn {
  color: #ffb74d;
}

.debug-log-entry.error {
  color: #ef5350;
}

.debug-log-entry.success {
  color: #66bb6a;
  font-weight: 600;
}

/* Debug Actions */
.debug-actions {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  background: #f8f9fa;
  border-top: 1px solid #e0e0e0;
}

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

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: white;
  color: #667eea;
  border: 2px solid #667eea;
}

.btn-secondary:hover {
  background: #f0f3ff;
}

/* Debug Indicator (floating badge on pages) */
#debug-indicator {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
  z-index: 9999;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .debug-panel {
    width: 95vw;
    right: 2.5vw;
    top: 10px;
    max-height: 90vh;
  }

  .waterfall-row {
    grid-template-columns: 120px 1fr 80px;
    gap: 8px;
    font-size: 0.75rem;
  }

  .resource-name {
    font-size: 0.75rem;
  }

  .debug-actions {
    flex-direction: column;
  }
}

/* Print Styles */
@media print {
  body {
    background: white;
  }

  .container {
    box-shadow: none;
  }

  .nav-button {
    display: none;
  }

  .metrics-card,
  .chart-container {
    break-inside: avoid;
  }
}
