/* =====================================================================
   Metrix — Dark theme stylesheet
   ===================================================================== */

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

/* Ensure the HTML hidden attribute always wins over CSS display rules */
[hidden] { display: none !important; }

:root {
  --bg:          #0f1117;
  --card:        #1a1d27;
  --card-hover:  #1f2333;
  --border:      #2a2d3e;
  --accent:      #00d4aa;
  --accent-dim:  rgba(0, 212, 170, 0.15);
  --text:        #e2e8f0;
  --text-muted:  #8892a4;
  --green:       #00d4aa;
  --orange:      #f59e0b;
  --red:         #ef4444;
  --radius:      12px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
}

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  background: rgba(26, 29, 39, 0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  height: 64px;
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: #000;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  flex-shrink: 0;
}

.logo-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.logo-tagline {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1;
}

/* ── Main layout ── */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

/* ── Hero ── */
.hero {
  text-align: center;
}

.hero-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #e2e8f0 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.hero-sub {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 32px;
}

/* ── Test Form ── */
.test-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.form-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 760px;
  flex-wrap: wrap;
}

.url-input {
  flex: 1 1 320px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  padding: 12px 16px;
  outline: none;
  transition: border-color 0.2s;
}

.url-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.url-input::placeholder { color: var(--text-muted); }

.select-wrapper {
  position: relative;
}

.location-select {
  appearance: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  padding: 12px 36px 12px 14px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
  min-width: 160px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238892a4' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.location-select:focus { border-color: var(--accent); }

.run-btn {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 12px 28px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
}

.run-btn:hover { opacity: 0.88; }
.run-btn:active { transform: scale(0.98); }
.run-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.form-error {
  color: var(--red);
  font-size: 0.875rem;
  margin-top: 4px;
}

.profile-hint {
  color: var(--text-muted);
  font-size: 0.825rem;
  margin-top: 4px;
}

/* ── Loading ── */
.loading-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 60px 0;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text { color: var(--text-muted); }

/* ── Results ── */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.results-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.results-title { font-size: 1.5rem; font-weight: 700; }

.results-url {
  color: var(--accent);
  font-size: 0.875rem;
  word-break: break-all;
}

/* ── Score ring ── */
.score-row {
  display: flex;
  align-items: center;
  gap: 40px;
  flex-wrap: wrap;
}

.score-card {
  position: relative;
  width: 140px;
  height: 140px;
  flex-shrink: 0;
}

.score-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}

.score-ring-arc {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  transition: stroke-dashoffset 1s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.4s;
}

.score-label-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.score-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.score-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green  { background: var(--green); }
.dot-orange { background: var(--orange); }
.dot-red    { background: var(--red); }

/* ── Section heading ── */
.section-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

/* ── Metrics grid ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: background 0.2s;
}

.metric-card:hover { background: var(--card-hover); }

.metric-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 4px;
}

.metric-score {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  display: inline-block;
}

.score-good    { background: rgba(0,212,170,0.15); color: var(--green); }
.score-avg     { background: rgba(245,158,11,0.15); color: var(--orange); }
.score-poor    { background: rgba(239,68,68,0.15);  color: var(--red); }

/* ── Waterfall ── */
/* Full-width breakout: escapes the .main max-width so waterfall uses the viewport */
.waterfall-breakout {
  width: 100vw;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 24px;
  box-sizing: border-box;
}

/* PerfCascade uses a light theme internally — give it a white canvas */
.waterfall-container {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  min-height: 120px;
  width: 100%;
  color: #111;
}

/* PerfCascade SVG sizing */
.waterfall-container svg {
  width: 100% !important;
  min-width: 800px;
  height: auto !important;
  display: block;
}

/* ── Screenshot ── */
.screenshot-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  line-height: 0;
}

.screenshot-img {
  width: 100%;
  height: auto;
  display: block;
}

/* ── Redirect chain ── */
.redirect-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.redirect-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--orange);
  background: rgba(245, 158, 11, 0.15);
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-right: 4px;
}

.redirect-hop {
  color: var(--text-muted);
  word-break: break-all;
}

.redirect-arrow {
  color: var(--orange);
  font-weight: bold;
  flex-shrink: 0;
}

.redirect-final {
  color: var(--text);
  font-weight: 600;
  word-break: break-all;
}

/* ── History ── */
.history-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.history-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: background 0.2s;
}

.history-item:hover { background: var(--card-hover); }

.history-score {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
  border: 2px solid;
}

.history-score.good   { border-color: var(--green);  color: var(--green); }
.history-score.avg    { border-color: var(--orange); color: var(--orange); }
.history-score.poor   { border-color: var(--red);    color: var(--red); }

.history-meta {
  flex: 1;
  min-width: 0;
}

.history-url {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-view-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}

.history-view-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .hero-title { font-size: 1.8rem; }
  .form-row { flex-direction: column; }
  .url-input,
  .location-select,
  .run-btn { width: 100%; }
  .score-row { flex-direction: column; align-items: flex-start; }
}
