/* ============================================================
   Ospaces — Published-site analytics dashboard
   Owner-facing modal opened from the Published-sites manager.
   Themable via the app's CSS variables (light + dark both work).
   ============================================================ */

/* modal shell — extends .modal (see style.css) */
.sa-modal {
  width: 600px;
  max-height: 78vh;
}

.sa-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sa-head-tt { display: flex; align-items: center; gap: 11px; min-width: 0; }
.sa-head-ic {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; background: var(--bg-callout);
}
.sa-title {
  font-family: var(--font-display); font-weight: 600; font-size: 16px; color: var(--text);
  letter-spacing: -0.2px;
}
.sa-sub {
  margin-top: 1px; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sa-close {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 7px;
  border: none; background: transparent; color: var(--text-light);
  font-size: 15px; cursor: pointer; line-height: 1;
  transition: background 0.12s, color 0.12s;
}
.sa-close:hover { background: var(--bg-hover); color: var(--text); }

.sa-body { overflow-y: auto; padding: 4px 18px 18px; }

/* loading / empty / error states */
.sa-loading {
  padding: 48px 20px; text-align: center; color: var(--text-light); font-size: 14px;
}
.sa-state {
  text-align: center; padding: 44px 24px 40px; color: var(--text-light);
}
.sa-state-ic { font-size: 38px; margin-bottom: 8px; }
.sa-state h3 {
  font-family: var(--font-display); font-size: 17px; font-weight: 600;
  color: var(--text); margin: 0 0 6px;
}
.sa-state p { font-size: 13.5px; line-height: 1.6; max-width: 380px; margin: 0 auto; }

/* stat tiles */
.sa-panel { padding-top: 14px; }
.sa-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 22px;
}
.sa-stat {
  border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--bg-callout); padding: 13px 14px; text-align: left;
}
.sa-stat-n {
  font-family: var(--font-display); font-size: 24px; font-weight: 600;
  color: var(--text); line-height: 1.05; font-variant-numeric: tabular-nums;
}
.sa-stat-l { margin-top: 4px; font-size: 11.5px; color: var(--text-light); }

/* sections */
.sa-section { margin-bottom: 22px; }
.sa-section:last-of-type { margin-bottom: 8px; }
.sa-h {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase;
  color: var(--text-faint); margin: 0 0 10px;
}

/* 14-day sparkline */
.sa-spark {
  border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--bg); padding: 12px 12px 8px;
}
.sa-spark svg { display: block; width: 100%; height: 52px; overflow: visible; }
.sa-spark-bar {
  fill: var(--accent);
  transition: opacity 0.12s;
}
.sa-spark-bar:hover { opacity: 0.7; }
.sa-spark-axis {
  display: flex; justify-content: space-between; margin-top: 6px;
  font-size: 10.5px; color: var(--text-faint); font-variant-numeric: tabular-nums;
}

/* per-page breakdown */
.sa-pages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sa-page-row {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) 90px 44px;
  align-items: center; gap: 9px;
}
.sa-page-ic { font-size: 15px; text-align: center; }
.sa-page-tt {
  font-size: 13px; color: var(--text); min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sa-page-bar {
  height: 7px; border-radius: 999px; background: var(--bg-callout); overflow: hidden;
}
.sa-page-fill {
  display: block; height: 100%; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 78%, transparent);
}
.sa-page-n {
  text-align: right; font-size: 12.5px; font-weight: 600; color: var(--text-light);
  font-variant-numeric: tabular-nums;
}

.sa-empty-inline {
  padding: 18px; text-align: center; font-size: 13px; color: var(--text-faint);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-card);
}

.sa-foot {
  font-size: 11.5px; color: var(--text-faint); line-height: 1.5;
  margin: 4px 0 0; padding-top: 12px; border-top: 1px solid var(--border);
}

/* per-site "Analytics" button in the sites manager (matches .sm-btn) */
.sm-btn[data-act="analytics"] .ic { width: 14px; height: 14px; }

/* self-contained fallback overlay (used only when #modal-layer is absent) */
.sa-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(10, 11, 26, 0.6);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding-top: 90px;
}
.sa-overlay .sa-modal {
  background: var(--bg-modal, var(--bg)); border-radius: 16px;
  box-shadow: var(--shadow-popover, 0 12px 40px rgba(0, 0, 0, 0.3));
  display: flex; flex-direction: column; overflow: hidden;
  max-width: calc(100vw - 40px);
}

@media (max-width: 560px) {
  .sa-stats { grid-template-columns: 1fr 1fr; }
  .sa-page-row { grid-template-columns: 20px minmax(0, 1fr) 56px 40px; }
}

/* ------------------------------------------------------------------
   Turnstile host (js/siteanalytics.js turnstileToken()).
   The widget is rendered with appearance:"interaction-only", so this
   box is EMPTY and invisible in the normal case — it only ever draws
   when Cloudflare decides this visitor must click something. It is
   removed from the DOM as soon as a token resolves (or times out),
   so it can't linger over a published page.
   ------------------------------------------------------------------ */
.sa-turnstile {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9000;
  /* Nothing to show until the widget draws itself. */
  line-height: 0;
}
.sa-turnstile:empty { display: none; }
.sa-turnstile iframe { border-radius: 8px; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22); }

@media (max-width: 400px) {
  .sa-turnstile { right: 8px; bottom: 8px; }
}
