/* Web Vitals Performance Feedback Styles */
/* Visual feedback system for Core Web Vitals metrics */

/* Performance indicator styles */
.performance-indicator {
  position: fixed;
  top: 10px;
  right: 10px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #ccc;
  z-index: 1000;
  opacity: 0.7;
  transition: all 0.3s ease;
  pointer-events: none;
}

/* Overall performance status indicators */
html.performance-good .performance-indicator {
  background-color: #22c55e; /* Green for good performance */
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}

html.performance-needs-improvement .performance-indicator {
  background-color: #f59e0b; /* Orange for needs improvement */
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

html.performance-poor .performance-indicator {
  background-color: #ef4444; /* Red for poor performance */
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

/* LCP (Largest Contentful Paint) specific styles */
html.lcp-poor .main {
  animation: lcp-loading 2s ease-out;
}

@keyframes lcp-loading {
  0% {
    opacity: 0.8;
  }
  100% {
    opacity: 1;
  }
}

/* CLS (Cumulative Layout Shift) feedback */
html.cls-poor {
  --layout-shift-warning: 1;
}

html.cls-poor::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #ef4444, #f59e0b);
  z-index: 9999;
  animation: cls-warning 3s ease-out forwards;
}

@keyframes cls-warning {
  0% {
    opacity: 0.8;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
  }
}

/* FID (First Input Delay) feedback */
html.fid-poor .nav,
html.fid-poor button,
html.fid-poor a {
  position: relative;
}

html.fid-poor .nav::after,
html.fid-poor button::after,
html.fid-poor a::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(245, 158, 11, 0.1);
  animation: fid-pulse 2s infinite;
  pointer-events: none;
}

@keyframes fid-pulse {
  0%,
  100% {
    opacity: 0;
  }
  50% {
    opacity: 0.3;
  }
}

/* TTFB (Time to First Byte) feedback */
html.ttfb-poor body::before {
  content: 'サーバー応答が遅延しています';
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius, 8px);
  font-size: 0.875rem;
  z-index: 9999;
  animation: ttfb-notice 5s ease-out forwards;
}

@keyframes ttfb-notice {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  20% {
    opacity: 1;
    transform: translateY(0);
  }
  80% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* Performance debugging panel (only visible in development) */
.web-vitals-debug {
  position: fixed;
  bottom: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 1rem;
  border-radius: var(--border-radius, 8px);
  font-family: monospace;
  font-size: 12px;
  max-width: 300px;
  z-index: 10000;
  display: none;
}

/* Show debug panel when debug class is present */
html.web-vitals-debug .web-vitals-debug {
  display: block;
}

.web-vitals-debug h4 {
  margin: 0 0 0.5rem;
  font-size: 14px;
  color: #60a5fa;
}

.web-vitals-debug .metric {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
  padding: 0.25rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.web-vitals-debug .metric-name {
  font-weight: bold;
}

.web-vitals-debug .metric-value {
  color: #10b981;
}

.web-vitals-debug .metric-rating {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.web-vitals-debug .rating-good {
  background: #22c55e;
  color: white;
}

.web-vitals-debug .rating-needs-improvement {
  background: #f59e0b;
  color: white;
}

.web-vitals-debug .rating-poor {
  background: #ef4444;
  color: white;
}

/* Performance hints for users */
.performance-hint {
  position: fixed;
  bottom: 60px;
  right: 20px;
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-light, #e2e8f0);
  border-radius: var(--border-radius, 8px);
  padding: 0.75rem 1rem;
  max-width: 280px;
  font-size: 0.875rem;
  z-index: 1000;
  box-shadow: var(--shadow-soft, 0 4px 6px rgba(0, 0, 0, 0.1));
  display: none;
  animation: performance-hint-slide-up 0.3s ease-out;
}

@keyframes performance-hint-slide-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.performance-hint.show {
  display: block;
}

.performance-hint .hint-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 0.5rem;
  vertical-align: middle;
}

.performance-hint .hint-title {
  font-weight: 600;
  color: var(--text-color, #333);
  margin-bottom: 0.25rem;
}

.performance-hint .hint-text {
  color: var(--text-secondary, #666);
  line-height: 1.4;
}

.performance-hint .hint-dismiss {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: var(--text-secondary, #666);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.performance-hint .hint-dismiss:hover {
  color: var(--text-color, #333);
}

/* Skeleton loading states for poor performance */
html.lcp-poor .article-content img,
html.lcp-poor .article-content iframe {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .performance-indicator {
    border: 2px solid currentColor;
  }

  html.performance-good .performance-indicator {
    background-color: #0f7b0f;
  }

  html.performance-needs-improvement .performance-indicator {
    background-color: #b45309;
  }

  html.performance-poor .performance-indicator {
    background-color: #dc2626;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .performance-indicator,
  html.lcp-poor .main,
  html.cls-poor::before,
  html.fid-poor .nav::after,
  html.fid-poor button::after,
  html.fid-poor a::after,
  html.ttfb-poor body::before,
  .performance-hint,
  html.lcp-poor .article-content img,
  html.lcp-poor .article-content iframe {
    animation: none !important;
    transition: none !important;
  }

  .performance-indicator {
    opacity: 1;
  }
}
