/* ============================================================
   PageSpeed Insight Checker — Frontend Styles
   Designed with a clean "data dashboard" aesthetic:
   dark navy/slate base, electric blue accents, crisp whites.
   ============================================================ */

/* ── CSS Custom Properties ── */
:root {
  --psic-bg:           #f8faff;
  --psic-surface:      #ffffff;
  --psic-surface2:     #f1f5fd;
  --psic-border:       #e2e8f4;
  --psic-text:         #0f172a;
  --psic-text-muted:   #64748b;
  --psic-accent:       #2563eb;
  --psic-accent-light: #dbeafe;
  --psic-accent-glow:  rgba(37, 99, 235, 0.25);
  --psic-good:         #16a34a;
  --psic-good-bg:      #dcfce7;
  --psic-avg:          #d97706;
  --psic-avg-bg:       #fef3c7;
  --psic-poor:         #dc2626;
  --psic-poor-bg:      #fee2e2;
  --psic-radius:       14px;
  --psic-radius-sm:    8px;
  --psic-shadow:       0 4px 24px rgba(15,23,42,0.08);
  --psic-shadow-lg:    0 8px 40px rgba(15,23,42,0.14);
  --psic-font:         'Sora', 'DM Sans', system-ui, sans-serif;
  --psic-mono:         'JetBrains Mono', 'Fira Code', monospace;
  --psic-transition:   0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode variables */
.psic-dark {
  --psic-bg:           #0b1120;
  --psic-surface:      #131e33;
  --psic-surface2:     #1a2744;
  --psic-border:       #243050;
  --psic-text:         #e2e8f0;
  --psic-text-muted:   #94a3b8;
  --psic-accent-light: #1e3a6e;
  --psic-accent-glow:  rgba(37, 99, 235, 0.35);
  --psic-shadow:       0 4px 24px rgba(0,0,0,0.35);
  --psic-shadow-lg:    0 8px 40px rgba(0,0,0,0.5);
}

/* Google Fonts import */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Wrapper ── */
.psic-wrapper {
  font-family: var(--psic-font);
  background: var(--psic-bg);
  color: var(--psic-text);
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  position: relative;
  transition: background var(--psic-transition), color var(--psic-transition);
  min-height: 300px;
}

/* ── Header ── */
.psic-header {
  text-align: center;
  margin-bottom: 36px;
}

.psic-header-icon {
  width: 56px;
  height: 56px;
  background: var(--psic-accent);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: #fff;
  box-shadow: 0 4px 20px var(--psic-accent-glow);
}

.psic-header-icon svg {
  width: 28px;
  height: 28px;
}

.psic-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
  color: var(--psic-text);
}

.psic-subtitle {
  font-size: 0.9375rem;
  color: var(--psic-text-muted);
  margin: 0;
}

/* ── Notice ── */
.psic-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--psic-radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 24px;
}

.psic-notice--error {
  background: var(--psic-poor-bg);
  color: var(--psic-poor);
  border: 1px solid rgba(220, 38, 38, 0.2);
}

/* ── Form ── */
.psic-form-container {
  margin-bottom: 32px;
}

.psic-input-group {
  display: flex;
  align-items: center;
  background: var(--psic-surface);
  border: 2px solid var(--psic-border);
  border-radius: var(--psic-radius);
  padding: 6px 6px 6px 16px;
  gap: 8px;
  transition: border-color var(--psic-transition), box-shadow var(--psic-transition);
  box-shadow: var(--psic-shadow);
}

.psic-input-group:focus-within {
  border-color: var(--psic-accent);
  box-shadow: 0 0 0 4px var(--psic-accent-glow);
}

.psic-input-icon {
  color: var(--psic-text-muted);
  flex-shrink: 0;
  display: flex;
}

.psic-url-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--psic-font);
  font-size: 0.9375rem;
  color: var(--psic-text);
  padding: 8px 0;
  min-width: 0;
}

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

.psic-url-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.psic-analyze-btn {
  background: var(--psic-accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 24px;
  font-family: var(--psic-font);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform var(--psic-transition), box-shadow var(--psic-transition), background var(--psic-transition);
  white-space: nowrap;
  flex-shrink: 0;
  position: relative;
}

.psic-analyze-btn:hover:not(:disabled) {
  background: #1d4ed8;
  box-shadow: 0 4px 16px var(--psic-accent-glow);
  transform: translateY(-1px);
}

.psic-analyze-btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.psic-analyze-btn.is-loading .psic-btn-text {
  opacity: 0;
}

.psic-analyze-btn.is-loading .psic-btn-loader {
  display: block;
}

.psic-btn-loader {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: psic-spin 0.7s linear infinite;
}

/* ── Error message ── */
.psic-error-msg {
  color: var(--psic-poor);
  font-size: 0.875rem;
  font-weight: 500;
  margin-top: 10px;
  min-height: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Loading ── */
.psic-loading {
  display: none;
  text-align: center;
  padding: 60px 20px;
}

.psic-loading.is-visible {
  display: block;
}

.psic-loading-inner {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.psic-spinner {
  width: 56px;
  height: 56px;
  animation: psic-rotate 1.4s linear infinite;
}

.psic-spinner-track {
  stroke: var(--psic-border);
}

.psic-spinner-head {
  stroke: var(--psic-accent);
  stroke-dasharray: 80;
  stroke-dashoffset: 60;
  stroke-linecap: round;
  animation: psic-dash 1.4s ease-in-out infinite;
}

.psic-loading-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--psic-text);
  margin: 0;
}

.psic-loading-sub {
  font-size: 0.8125rem;
  color: var(--psic-text-muted);
  margin: 0;
}

/* ── Results ── */
.psic-results {
  display: none;
  animation: psic-fadeUp 0.4s ease both;
}

.psic-results.is-visible {
  display: block;
}

@keyframes psic-fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Result header ── */
.psic-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--psic-surface);
  border: 1px solid var(--psic-border);
  border-radius: var(--psic-radius);
  padding: 14px 20px;
  margin-bottom: 20px;
  box-shadow: var(--psic-shadow);
}

.psic-result-url-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--psic-text-muted);
  min-width: 0;
}

.psic-result-url {
  font-family: var(--psic-mono);
  font-size: 0.875rem;
  color: var(--psic-accent);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.psic-result-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Badges ── */
.psic-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}

.psic-badge--cache {
  background: var(--psic-accent-light);
  color: var(--psic-accent);
}

.psic-badge--mobile {
  background: var(--psic-good-bg);
  color: var(--psic-good);
}

.psic-badge--desktop {
  background: var(--psic-accent-light);
  color: var(--psic-accent);
}

/* ── Export button ── */
.psic-export-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1.5px solid var(--psic-border);
  border-radius: var(--psic-radius-sm);
  background: var(--psic-surface);
  color: var(--psic-text-muted);
  font-family: var(--psic-font);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--psic-transition);
}

.psic-export-btn:hover {
  border-color: var(--psic-accent);
  color: var(--psic-accent);
}

/* ── Tabs ── */
.psic-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--psic-surface2);
  border: 1px solid var(--psic-border);
  border-radius: var(--psic-radius);
  padding: 5px;
  margin-bottom: 24px;
  width: fit-content;
}

.psic-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--psic-text-muted);
  font-family: var(--psic-font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--psic-transition);
}

.psic-tab:hover:not(.psic-tab--active) {
  background: var(--psic-surface);
  color: var(--psic-text);
}

.psic-tab--active {
  background: var(--psic-surface);
  color: var(--psic-accent);
  font-weight: 600;
  box-shadow: var(--psic-shadow);
}

.psic-tab-loading {
  display: none;
  margin-left: 8px;
}

.psic-tab-loading.is-visible {
  display: flex;
  align-items: center;
}

.psic-tab-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--psic-border);
  border-top-color: var(--psic-accent);
  border-radius: 50%;
  animation: psic-spin 0.7s linear infinite;
}

/* ── Score Cards ── */
.psic-scores-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 640px) {
  .psic-scores-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 380px) {
  .psic-scores-grid {
    grid-template-columns: 1fr;
  }
}

.psic-score-card {
  background: var(--psic-surface);
  border: 1px solid var(--psic-border);
  border-radius: var(--psic-radius);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--psic-shadow);
  transition: transform var(--psic-transition), box-shadow var(--psic-transition);
  animation: psic-fadeUp 0.5s ease both;
}

.psic-score-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--psic-shadow-lg);
}

.psic-score-card:nth-child(1) { animation-delay: 0.05s; }
.psic-score-card:nth-child(2) { animation-delay: 0.10s; }
.psic-score-card:nth-child(3) { animation-delay: 0.15s; }
.psic-score-card:nth-child(4) { animation-delay: 0.20s; }

/* ── Gauge / SVG Circle ── */
.psic-gauge {
  position: relative;
  width: 80px;
  height: 80px;
}

.psic-gauge svg {
  transform: rotate(-90deg);
  width: 80px;
  height: 80px;
}

.psic-gauge-track {
  fill: none;
  stroke: var(--psic-border);
  stroke-width: 6;
}

.psic-gauge-fill {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 188;
  stroke-dashoffset: 188;
  transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.3s ease;
}

.psic-gauge-fill--good   { stroke: var(--psic-good); }
.psic-gauge-fill--avg    { stroke: var(--psic-avg); }
.psic-gauge-fill--poor   { stroke: var(--psic-poor); }

.psic-gauge-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  font-family: var(--psic-mono);
  letter-spacing: -0.02em;
}

.psic-gauge-text--good { color: var(--psic-good); }
.psic-gauge-text--avg  { color: var(--psic-avg); }
.psic-gauge-text--poor { color: var(--psic-poor); }

.psic-score-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--psic-text-muted);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Section ── */
.psic-section {
  margin-bottom: 28px;
}

.psic-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--psic-text);
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}

/* ── Vitals Grid ── */
.psic-vitals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (max-width: 640px) {
  .psic-vitals-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 380px) {
  .psic-vitals-grid {
    grid-template-columns: 1fr;
  }
}

.psic-vital-card {
  background: var(--psic-surface);
  border: 1px solid var(--psic-border);
  border-radius: var(--psic-radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--psic-shadow);
  animation: psic-fadeUp 0.5s ease both;
  transition: border-color var(--psic-transition);
  border-left: 3px solid var(--psic-border);
}

.psic-vital-card--good { border-left-color: var(--psic-good); }
.psic-vital-card--avg  { border-left-color: var(--psic-avg); }
.psic-vital-card--poor { border-left-color: var(--psic-poor); }

.psic-vital-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--psic-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.psic-vital-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--psic-mono);
  color: var(--psic-text);
  letter-spacing: -0.02em;
}

.psic-vital-label {
  font-size: 0.8125rem;
  color: var(--psic-text-muted);
}

/* ── Opportunities ── */
.psic-opportunities {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.psic-opportunity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--psic-surface);
  border: 1px solid var(--psic-border);
  border-radius: var(--psic-radius-sm);
  padding: 14px 16px;
  box-shadow: var(--psic-shadow);
  animation: psic-fadeUp 0.5s ease both;
}

.psic-opportunity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}

.psic-opportunity-dot--good { background: var(--psic-good); }
.psic-opportunity-dot--avg  { background: var(--psic-avg); }
.psic-opportunity-dot--poor { background: var(--psic-poor); }

.psic-opportunity-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--psic-text);
  margin-bottom: 2px;
}

.psic-opportunity-value {
  font-size: 0.8125rem;
  color: var(--psic-text-muted);
  font-family: var(--psic-mono);
}

/* ── History Section ── */
.psic-history-section {
  border-top: 1px solid var(--psic-border);
  padding-top: 28px;
  margin-top: 8px;
}

.psic-history-empty {
  text-align: center;
  color: var(--psic-text-muted);
  font-size: 0.875rem;
  padding: 32px 20px;
  background: var(--psic-surface);
  border: 1px dashed var(--psic-border);
  border-radius: var(--psic-radius);
}

.psic-history-table-wrap {
  overflow-x: auto;
  border-radius: var(--psic-radius);
  border: 1px solid var(--psic-border);
  box-shadow: var(--psic-shadow);
}

.psic-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: var(--psic-surface);
}

.psic-history-table th {
  background: var(--psic-surface2);
  color: var(--psic-text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--psic-border);
}

.psic-history-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--psic-border);
  color: var(--psic-text);
  vertical-align: middle;
}

.psic-history-table tr:last-child td {
  border-bottom: none;
}

.psic-history-table tr:hover td {
  background: var(--psic-surface2);
}

.psic-history-url {
  font-family: var(--psic-mono);
  font-size: 0.8125rem;
  color: var(--psic-accent);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  cursor: pointer;
}

.psic-history-url:hover {
  text-decoration: underline;
}

.psic-score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 24px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--psic-mono);
}

.psic-score-pill--good { background: var(--psic-good-bg); color: var(--psic-good); }
.psic-score-pill--avg  { background: var(--psic-avg-bg);  color: var(--psic-avg); }
.psic-score-pill--poor { background: var(--psic-poor-bg); color: var(--psic-poor); }

.psic-history-date {
  color: var(--psic-text-muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

/* ── Dark Mode Toggle ── */
.psic-dark-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--psic-border);
  background: var(--psic-surface);
  color: var(--psic-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--psic-shadow-lg);
  transition: all var(--psic-transition);
  z-index: 9999;
}

.psic-dark-toggle:hover {
  border-color: var(--psic-accent);
  color: var(--psic-accent);
  transform: scale(1.1);
}

.psic-dark .psic-icon-sun { display: none; }
.psic-icon-moon { display: none; }
.psic-dark .psic-icon-moon { display: block; }

/* ── Animations ── */
@keyframes psic-spin {
  to { transform: rotate(360deg); }
}

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

@keyframes psic-dash {
  0%   { stroke-dashoffset: 60; }
  50%  { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -60; }
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .psic-wrapper {
    padding: 20px 14px 72px;
  }

  .psic-title {
    font-size: 1.375rem;
  }

  .psic-input-group {
    flex-wrap: wrap;
    padding: 10px;
  }

  .psic-analyze-btn {
    width: 100%;
    justify-content: center;
  }

  .psic-result-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
