/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --border:     #2a2d3a;
  --text:       #e8eaf0;
  --text-muted: #7a7f99;
  --good:       #22c55e;
  --avg:        #f59e0b;
  --poor:       #ef4444;
  --blue:       #3b82f6;
  --radius:     10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ─── Header ────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; color: var(--text); }
.brand-sub { font-size: 13px; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 14px; }
.last-updated { font-size: 12px; color: var(--text-muted); }

.btn-refresh {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-refresh:hover { opacity: 0.85; }
.btn-refresh:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Main ──────────────────────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* ─── Controls bar (strategy + time range) ──────────────────────────── */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 28px;
}

.time-range {
  display: flex;
  align-items: center;
  gap: 8px;
}
.time-range-label {
  font-size: 12px;
  color: var(--text-muted);
}
.time-range-btns {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.tr-btn {
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.tr-btn:last-child { border-right: none; }
.tr-btn:hover { color: var(--text); background: var(--surface); }
.tr-btn.active { background: var(--surface); color: var(--text); }

/* ─── Tabs ──────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 20px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover { border-color: var(--blue); color: var(--text); }
.tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ─── Sections ──────────────────────────────────────────────────────── */
.section { margin-bottom: 36px; }
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.section-sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }

/* ─── Source Blocks ─────────────────────────────────────────────────── */
.source-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}

.source-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  gap: 12px;
  transition: background 0.15s;
}
.source-toggle:hover { background: color-mix(in srgb, var(--surface) 80%, white 20%); }

.source-toggle-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.source-name {
  font-size: 15px;
  font-weight: 600;
}

.source-meta {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.source-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.source-toggle[aria-expanded="false"] .source-chevron {
  transform: rotate(-90deg);
}

.source-body {
  padding: 20px 18px 8px;
  border-top: 1px solid var(--border);
}
.source-body.collapsed {
  display: none;
}

/* ─── Metric Cards (CWV) ────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.metric-card.good::before  { background: var(--good); }
.metric-card.avg::before   { background: var(--avg); }
.metric-card.poor::before  { background: var(--poor); }
.metric-card.na::before    { background: var(--border); }

.metric-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.metric-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.metric-unit  { font-size: 14px; font-weight: 400; color: var(--text-muted); }

.metric-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 4px;
  width: fit-content;
}
.good  .metric-badge { background: rgba(34,197,94,0.15);  color: var(--good); }
.avg   .metric-badge { background: rgba(245,158,11,0.15); color: var(--avg); }
.poor  .metric-badge { background: rgba(239,68,68,0.15);  color: var(--poor); }
.na    .metric-badge { background: var(--border);         color: var(--text-muted); }

.metric-threshold { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.metric-desc      { font-size: 11px; color: var(--text-muted); margin-top: 8px; line-height: 1.5; border-top: 1px solid var(--border); padding-top: 8px; }

/* ─── Delta chips ────────────────────────────────────────────────────── */
.delta-chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  width: fit-content;
  margin-top: 2px;
}
.delta-good { background: rgba(34,197,94,0.12);  color: var(--good); }
.delta-poor { background: rgba(239,68,68,0.12);  color: var(--poor); }
.delta-flat { background: var(--border);          color: var(--text-muted); }
.delta-none { background: transparent;            color: var(--text-muted); font-style: italic; }

/* ─── Score Cards (Lighthouse) ──────────────────────────────────────── */
.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 18px;
}

.score-ring {
  width: 60px; height: 60px;
  flex-shrink: 0;
}
.score-ring circle { fill: none; stroke-width: 6; stroke-linecap: round; }
.score-ring .track { stroke: var(--border); }
.score-ring .fill  { transition: stroke-dashoffset 0.6s ease; }

.score-info { flex: 1; min-width: 0; }
.score-label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.score-num   { font-size: 26px; font-weight: 700; line-height: 1; }
.score-num.good { color: var(--good); }
.score-num.avg  { color: var(--avg); }
.score-num.poor { color: var(--poor); }

/* ─── Skeleton loading ──────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  min-height: 100px;
  border-radius: var(--radius);
}
.score-card.skeleton { min-height: 80px; }

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

/* ─── Fetch overlay ─────────────────────────────────────────────────── */
.fetch-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.fetch-overlay.hidden { display: none; }

.fetch-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(600px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fetch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

.fetch-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
}
.fetch-close:hover { color: var(--text); }

.fetch-log {
  padding: 16px;
  font-family: 'SF Mono', 'Fira Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--good);
  overflow-y: auto;
  flex: 1;
  white-space: pre-wrap;
}

/* ─── Trend section ──────────────────────────────────────────────────── */
.trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.trend-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.trend-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.trend-card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.trend-chart-area {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
  margin: 2px 0;
}

.sparkline-svg {
  display: block;
  width: 100%;
  height: 72px;
}

.trend-no-data {
  position: relative;
}
.trend-no-data-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(15,17,23,0.5);
  letter-spacing: 0.5px;
}

.trend-card-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.trend-points {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.trend-unavailable {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--text-muted);
  padding: 20px 0;
  text-align: center;
}

/* ─── Login overlay ─────────────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.login-overlay.hidden { display: none; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px 36px;
  width: min(380px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.login-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.login-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 14px;
  font-size: 15px;
  color: var(--text);
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: var(--blue); }
.login-input::placeholder { color: var(--text-muted); opacity: 0.6; }

.login-error {
  font-size: 12px;
  color: var(--poor);
  padding: 6px 10px;
  background: rgba(239,68,68,0.1);
  border-radius: 5px;
}
.login-error.hidden { display: none; }

.login-btn {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.15s;
  font-family: var(--font);
}
.login-btn:hover    { opacity: 0.85; }
.login-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ─── Error state ───────────────────────────────────────────────────── */
.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--poor);
  font-size: 13px;
}
