/* ============ SCANNING / LOADING SCREEN ============
 * Full-screen overlay served by scan-result.php (markup in
 * partials/scan-loader.php) while a scan is queued or underway. It polls the
 * backend and reloads the page once the scan resolves.
 *
 * One state on screen at a time — no step list. Every visual keys off the
 * [data-state] attribute on .scan-loader:
 *   "pending" — Completed = 0, waiting for a worker  → amber accents
 *   "running" — Completed = 2, scan underway         → pink accents (default)
 *   "done"    — parting frame set by JS just before the reload → green
 * Relies on the theme tokens defined in css/styles.css. */
.scan-loader {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
  background:
    radial-gradient(720px 540px at 50% 30%, rgba(253, 29, 96, 0.16), transparent 72%),
    radial-gradient(780px 560px at 50% 104%, rgba(255, 168, 7, 0.10), transparent 72%),
    var(--bg-color);
  opacity: 0; visibility: hidden;
  transition: opacity 380ms ease;
}
.scan-loader.active { opacity: 1; visibility: visible; }
/* While queued, cool the backdrop toward the amber end of the palette. */
.scan-loader[data-state="pending"] {
  background:
    radial-gradient(720px 540px at 50% 30%, rgba(255, 168, 7, 0.13), transparent 72%),
    radial-gradient(780px 560px at 50% 104%, rgba(253, 29, 96, 0.09), transparent 72%),
    var(--bg-color);
}
.scan-loader[data-state="done"] {
  background:
    radial-gradient(720px 540px at 50% 30%, rgba(77, 216, 156, 0.12), transparent 72%),
    radial-gradient(780px 560px at 50% 104%, rgba(255, 168, 7, 0.08), transparent 72%),
    var(--bg-color);
}

.loader-inner { width: 100%; max-width: 560px; text-align: center; }
.scan-loader.active .loader-inner {
  animation: loader-rise 560ms cubic-bezier(.2,.7,.2,1) both;
}
@keyframes loader-rise {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* logo + spinning ring */
.loader-logo {
  position: relative;
  width: 216px; height: 216px;
  margin: 0 auto 38px;
}
.loader-logo::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 5px solid var(--divider-color);
}
.loader-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg,
    rgba(253, 29, 96, 0) 0deg,
    rgba(253, 29, 96, 0) 210deg,
    var(--accent-color) 318deg,
    var(--accent-secondary-color) 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 5px));
  animation: loader-spin 1.05s linear infinite;
}
/* Queued: the ring idles — amber, and a slower, calmer sweep. */
.scan-loader[data-state="pending"] .loader-ring {
  background: conic-gradient(from 0deg,
    rgba(255, 168, 7, 0) 0deg,
    rgba(255, 168, 7, 0) 210deg,
    var(--accent-secondary-color) 318deg,
    var(--brand-bright) 360deg);
  animation-duration: 2.2s;
}
.scan-loader[data-state="done"] .loader-ring {
  background: conic-gradient(from 0deg,
    rgba(77, 216, 156, 0) 0deg,
    rgba(77, 216, 156, 0) 210deg,
    #36CFC0 318deg,
    var(--success) 360deg);
}
@keyframes loader-spin { to { transform: rotate(360deg); } }
.loader-logo img {
  position: absolute; inset: 43px;
  width: 130px; height: auto;
  animation: loader-pulse 2.2s ease-in-out infinite;
}
@keyframes loader-pulse {
  0%, 100% { transform: scale(1);    filter: drop-shadow(0 0 14px rgba(255, 138, 40, 0.35)); }
  50%      { transform: scale(1.07); filter: drop-shadow(0 0 30px rgba(255, 138, 40, 0.6)); }
}

/* live status pill — Queued / Scanning / Complete */
.loader-status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--divider-color);
  background: var(--surface-2);
  font-size: 12.5px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 20px;
  transition: color 320ms ease, border-color 320ms ease, background 320ms ease;
}
.loader-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-subtle);
  transition: background 320ms ease, box-shadow 320ms ease;
}
.scan-loader[data-state="pending"] .loader-status {
  color: var(--brand-bright);
  border-color: rgba(255, 168, 7, 0.32);
  background: var(--brand-dim);
}
.scan-loader[data-state="pending"] .loader-status-dot {
  background: var(--accent-secondary-color);
  box-shadow: 0 0 10px rgba(255, 168, 7, 0.8);
  animation: loader-dot-pulse 1.7s ease-in-out infinite;
}
.scan-loader[data-state="running"] .loader-status {
  color: var(--danger-bright);
  border-color: rgba(253, 29, 96, 0.36);
  background: var(--danger-bg);
}
.scan-loader[data-state="running"] .loader-status-dot {
  background: var(--accent-color);
  box-shadow: 0 0 10px rgba(253, 29, 96, 0.85);
  animation: loader-dot-pulse 1.1s ease-in-out infinite;
}
.scan-loader[data-state="done"] .loader-status {
  color: var(--success);
  border-color: rgba(77, 216, 156, 0.36);
  background: var(--success-bg);
}
.scan-loader[data-state="done"] .loader-status-dot {
  background: var(--success);
  box-shadow: 0 0 10px rgba(77, 216, 156, 0.8);
}
@keyframes loader-dot-pulse {
  0%, 100% { opacity: 1;    transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.8); }
}

.loader-title {
  font-size: 36px; font-weight: 800;
  color: var(--text); letter-spacing: -0.025em;
  margin-bottom: 12px;
}
.loader-url {
  font-family: var(--mono); font-size: 16.5px;
  color: var(--accent-color);
  /* Prefer natural break points (/, -), only split mid-word as a last resort. */
  overflow-wrap: anywhere; line-height: 1.5;
  margin-bottom: 34px;
  /* Clamp huge URLs so the loader card keeps its shape. */
  display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.scan-loader[data-state="pending"] .loader-url { color: var(--brand-bright); }
.scan-loader[data-state="done"] .loader-url { color: var(--success); }

/* progress bar — indeterminate sweep while the scan is unresolved */
.loader-progress {
  position: relative;
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--divider-color);
  border-radius: 6px;
  overflow: hidden;
}
.loader-progress::after {
  content: "";
  position: absolute; top: 0; bottom: 0; left: -45%;
  width: 42%;
  border-radius: 6px;
  background: var(--accent-gradient);
  background-size: 200% auto;
  box-shadow: 0 0 18px rgba(253, 29, 96, 0.5);
  animation: loader-sweep 1.25s cubic-bezier(.65,.04,.34,1) infinite;
}
/* Queued: the sweep idles too — amber and unhurried. */
.scan-loader[data-state="pending"] .loader-progress::after {
  background: linear-gradient(to right, var(--accent-secondary-color), var(--brand-bright));
  box-shadow: 0 0 18px rgba(255, 168, 7, 0.45);
  animation-duration: 2.4s;
}
.loader-progress.done::after { display: none; }
@keyframes loader-sweep {
  0%   { left: -45%; }
  100% { left: 100%; }
}
/* solid fill, revealed once the scan completes */
.loader-progress-bar {
  position: relative; z-index: 1;
  height: 100%; width: 0;
  border-radius: 6px;
  background: var(--accent-gradient);
  background-size: 200% auto;
  box-shadow: 0 0 18px rgba(253, 29, 96, 0.5);
  transition: width 540ms cubic-bezier(.32,.72,.3,1);
}
.scan-loader[data-state="done"] .loader-progress-bar {
  background: var(--success-gradient);
  box-shadow: 0 0 18px rgba(77, 216, 156, 0.5);
}

/* one-line phase readout under the bar — the poll script swaps its text as
 * the scan progresses (and cycles activity messages while running) */
.loader-phase {
  margin: 20px auto 0;
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 440px;
  min-height: 24px;   /* keep the layout still while messages swap */
  transition: opacity 260ms ease;
}
.loader-phase.swap { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  /* The dot animations come from state-scoped rules, so these selectors must
   * match their specificity — bare class selectors would lose the cascade. */
  .loader-ring, .loader-logo img,
  .loader-progress::after,
  .scan-loader[data-state] .loader-status-dot,
  .scan-loader.active .loader-inner { animation: none; }
}

/* Short viewports: shrink the logo so everything stays on screen. */
@media (max-height: 760px) {
  .loader-logo { width: 168px; height: 168px; margin-bottom: 28px; }
  .loader-logo img { inset: 34px; width: 100px; }
}

/* ============ SCAN ERROR SCREEN ============
 * Shown in place of the loader when scan-status.php reports the scan failed
 * (scheduled_scan.Completed = 3). Mirrors the loader overlay's look. */
.scan-error {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
  background:
    radial-gradient(720px 540px at 50% 30%, rgba(253, 29, 96, 0.16), transparent 72%),
    radial-gradient(780px 560px at 50% 104%, rgba(255, 168, 7, 0.10), transparent 72%),
    var(--bg-color);
  opacity: 0; visibility: hidden;
  transition: opacity 380ms ease;
}
.scan-error.active { opacity: 1; visibility: visible; }
.scan-error.active .loader-inner {
  animation: loader-rise 560ms cubic-bezier(.2,.7,.2,1) both;
}

.scan-error-icon {
  width: 132px; height: 132px;
  margin: 0 auto 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--accent-color);
  background: rgba(253, 29, 96, 0.10);
  border: 1px solid rgba(253, 29, 96, 0.30);
}

.scan-error-text {
  font-size: 17px; color: var(--text-muted);
  line-height: 1.6;
  margin: 0 auto 40px;
  max-width: 420px;
}

@media (prefers-reduced-motion: reduce) {
  .scan-error.active .loader-inner { animation: none; }
}
