/* ═════════════════════════════════════════════════════════════════════
   Cloudflare Site Manager — Dashboard
   ═════════════════════════════════════════════════════════════════════ */

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

:root {
  --bg-body:     #0d1117;
  --bg-card:     #161b22;
  --bg-card-hover: #1c2333;
  --bg-input:    #0d1117;
  --bg-header:   #0d1117;

  --border:      #30363d;
  --border-card: #21262d;

  --text:        #e6edf3;
  --text-dim:    #8b949e;
  --text-muted:  #6e7681;

  --accent:      #3b82f6;
  --accent-bg:   rgba(59, 130, 246, 0.12);

  --green:       #3fb950;
  --green-bg:    rgba(63, 185, 80, 0.12);
  --red:         #f85149;
  --red-bg:      rgba(248, 81, 73, 0.12);
  --yellow:      #d29922;
  --yellow-bg:   rgba(210, 153, 34, 0.12);
  --blue:        #58a6ff;
  --blue-bg:     rgba(88, 166, 255, 0.12);
  --purple:      #a371f7;
  --purple-bg:   rgba(163, 113, 247, 0.12);

  --shadow: 0 1px 3px rgba(0,0,0,.3);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --fast: 150ms;
  --normal: 250ms;
}

:root[data-theme="light"] {
  --bg-body:     #f6f8fa;
  --bg-card:     #ffffff;
  --bg-card-hover: #f0f4f8;
  --bg-input:    #f6f8fa;
  --bg-header:   #ffffff;

  --border:      #d0d7de;
  --border-card: #d8dee4;

  --text:        #1f2328;
  --text-dim:    #656d76;
  --text-muted:  #8b949e;

  --shadow: 0 1px 3px rgba(31,35,40,.08);

  --accent-bg: rgba(59, 130, 246, 0.1);
  --green-bg:  rgba(38, 166, 65, 0.1);
  --red-bg:    rgba(207, 34, 46, 0.1);
  --yellow-bg: rgba(191, 135, 0, 0.1);
  --blue-bg:   rgba(9, 105, 218, 0.1);
  --purple-bg: rgba(130, 80, 223, 0.1);
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-body);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--normal) var(--ease), color var(--normal) var(--ease);
}

/* ── Header ─────────────────────────────────────────────────────────── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: var(--bg-header);
  border-bottom: 1px solid var(--border);
}
.header-brand { display: flex; align-items: center; gap: 12px; }
.header-brand svg { width: 36px; height: 36px; color: var(--accent); }
.header-brand h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.header-brand .accent { color: var(--accent); }
.header-subtitle { font-size: 0.75rem; color: var(--text-dim); }
.header-subtitle a { color: var(--text-dim); text-decoration: none; }
.header-subtitle a:hover { color: var(--accent); }
.header-actions { display: flex; gap: 6px; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font-size: 0.82rem; font-weight: 500;
  cursor: pointer; transition: all var(--fast) var(--ease); font-family: inherit; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--bg-card-hover); }
.btn:active { transform: scale(0.97); }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { opacity: 0.9; }

[data-theme="dark"] .sun-icon { display: block; } [data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon { display: none; } [data-theme="light"] .moon-icon { display: block; }

/* ── Main Layout ────────────────────────────────────────────────────── */
.main { max-width: 1200px; margin: 0 auto; padding: 24px 28px; }
.loading-state { text-align: center; padding: 60px 0; color: var(--text-dim); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-progress {
  margin: 24px auto 0;
  max-width: 320px;
  text-align: left;
}
.loading-step {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; font-size: 0.82rem; color: var(--text-muted);
  transition: color 0.3s;
}
.loading-step.done { color: var(--green); }
.loading-step.active { color: var(--text); }
.loading-step .step-icon {
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
  background: var(--bg-input); color: var(--text-muted);
  transition: all 0.3s;
}
.loading-step.done .step-icon { background: var(--green-bg); color: var(--green); }
.loading-step.active .step-icon {
  background: var(--accent-bg); color: var(--accent);
  animation: pulse-step 1s ease-in-out infinite;
}
@keyframes pulse-step {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ── KPI Cards ──────────────────────────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
@media (max-width: 800px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 450px) { .kpi-row { grid-template-columns: 1fr; } }

.kpi-card {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 14px;
  transition: background var(--normal);
}
.kpi-icon {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1.3rem;
}
.kpi-icon.green  { background: var(--green-bg);  color: var(--green); }
.kpi-icon.red    { background: var(--red-bg);    color: var(--red); }
.kpi-icon.yellow { background: var(--yellow-bg); color: var(--yellow); }
.kpi-icon.blue   { background: var(--blue-bg);   color: var(--blue); }
.kpi-icon.purple { background: var(--purple-bg); color: var(--purple); }

.kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }
.kpi-pct { font-size: 0.78rem; color: var(--text-dim); margin-top: 4px; }

/* ── Grid 2-col ─────────────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
@media (max-width: 750px) { .dash-grid { grid-template-columns: 1fr; } }

/* ── Panel ──────────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.panel h2 {
  font-size: 0.85rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-dim); margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.panel h2 .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ── Donut Chart (SVG) ──────────────────────────────────────────────── */
.chart-donut-wrap { display: flex; align-items: center; gap: 24px; }
.chart-donut-wrap svg { flex-shrink: 0; }
.chart-legend { font-size: 0.8rem; }
.chart-legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.chart-legend-val { margin-left: auto; font-weight: 600; }

/* ── Bar Chart (SVG) ────────────────────────────────────────────────── */
.chart-bar-wrap { width: 100%; }
.chart-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.chart-bar-label { width: 80px; font-size: 0.78rem; color: var(--text-dim); text-align: right; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-bar-track { flex: 1; height: 22px; background: var(--bg-input); border-radius: 4px; overflow: hidden; position: relative; }
.chart-bar-fill { height: 100%; border-radius: 4px; transition: width 0.6s var(--ease); display: flex; align-items: center; padding-left: 8px; font-size: 0.73rem; font-weight: 600; color: #fff; min-width: fit-content; }
.chart-bar-val { width: 36px; font-size: 0.78rem; font-weight: 600; flex-shrink: 0; }

/* ── Alert List ─────────────────────────────────────────────────────── */
.alert-list { max-height: 260px; overflow-y: auto; }
.alert-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.83rem;
}
.alert-item:last-child { border-bottom: none; }
.alert-severity { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; }
.alert-severity.critical { background: var(--red); box-shadow: 0 0 6px var(--red); }
.alert-severity.warning { background: var(--yellow); }
.alert-domain { font-weight: 600; }
.alert-error { color: var(--red); font-size: 0.78rem; margin-top: 1px; }
.alert-empty { text-align: center; padding: 30px; color: var(--text-muted); font-size: 0.85rem; }

/* ── Improvement Cards ──────────────────────────────────────────────── */
.improvement-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.improvement-item:last-child { border-bottom: none; }
.improvement-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 2px; }
.improvement-text { flex: 1; }
.improvement-title { font-weight: 600; font-size: 0.85rem; }
.improvement-desc { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }
.improvement-badge {
  font-size: 0.73rem; padding: 2px 10px; border-radius: 20px; font-weight: 600; flex-shrink: 0;
}
.improvement-badge.high { background: var(--red-bg); color: var(--red); }
.improvement-badge.medium { background: var(--yellow-bg); color: var(--yellow); }
.improvement-badge.low { background: var(--blue-bg); color: var(--blue); }
.improvement-empty { text-align: center; padding: 30px; color: var(--green); font-size: 0.85rem; }

/* ── Last updated ───────────────────────────────────────────────────── */
.last-updated { text-align: right; font-size: 0.73rem; color: var(--text-muted); margin-top: 16px; }
