/* P3 paid-access gate — fail-closed shell veil + compact Russian stub.
 *
 * Loaded by every paid shell together with access-guard.js. Two jobs:
 *   1. keep the shell invisible until data-p3-gate="allowed" (the critical
 *      subset is also inlined in each document's <head>, so nothing flashes
 *      before this file arrives);
 *   2. style the in-place stub in the noir/cyan P3 language.
 *
 * Containment is structural, not inherited: every body child except the gate
 * stub is removed from layout with display:none. `visibility:hidden` alone is
 * only *inherited*, so an existing descendant with its own
 * `visibility:visible` (e.g. .chart-popup-modal.visible, .signals-panel.open)
 * would still paint through it.
 *
 * No gradients-as-decoration, no left accent rails, no icon topper: the card is
 * a single status panel with one cyan action.
 */

html:not([data-p3-gate="allowed"]),
html:not([data-p3-gate="allowed"]) body {
  background: #05070d !important;
}

html:not([data-p3-gate="allowed"]) body {
  visibility: hidden !important;
  overflow: hidden !important;
}

html:not([data-p3-gate="allowed"]) body > *:not(#p3-paid-gate) {
  display: none !important;
  visibility: hidden !important;
}

html:not([data-p3-gate="allowed"]) #p3-paid-gate {
  visibility: visible !important;
}

html[data-p3-gate="allowed"] #p3-paid-gate {
  display: none !important;
}

/* The paid markup is server-held, so an allow is followed by a real payload
 * request. Until that answer is mounted the stub stays (truthfully) on screen,
 * and the document is still empty behind it. */
html[data-p3-gate="allowed"]:not([data-p3-shell="mounted"]) #p3-paid-gate {
  display: flex !important;
  visibility: visible !important;
}

/* Returning signed-in boot: the entry HTML is intentionally neutral. While the
 * first server-authorized shell answer is in flight, show one quiet workspace
 * line instead of the plans/access card. This is presentation only; the gate
 * still decides from the server answer and a deny immediately restores the
 * truthful Free/guest/unknown card below. */
#p3-paid-gate .p3-paid-gate__quiet {
  display: none;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: var(--p3-gate-muted);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0.01em;
}

#p3-paid-gate .p3-paid-gate__quiet::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--p3-gate-accent);
  animation: p3-gate-quiet-pulse 1.2s ease-in-out infinite;
}

html[data-p3-gate="checking"][data-p3-returning="1"] #p3-paid-gate .p3-paid-gate__card {
  display: none !important;
}

html[data-p3-gate="checking"][data-p3-returning="1"] #p3-paid-gate .p3-paid-gate__quiet {
  display: flex;
}

@keyframes p3-gate-quiet-pulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  #p3-paid-gate .p3-paid-gate__quiet::before { animation: none; }
}

#p3-paid-shell[data-p3-shell] {
  display: contents;
}

#p3-paid-gate {
  --p3-gate-bg: #05070d;
  --p3-gate-surface: #0a0f17;
  --p3-gate-line: rgba(120, 176, 214, 0.18);
  --p3-gate-ink: #e7eef7;
  --p3-gate-muted: #8b9cb2;
  --p3-gate-accent: #22d3ee;
  --p3-gate-accent-ink: #041019;
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(1100px 520px at 50% -20%, rgba(34, 211, 238, 0.07), transparent 60%),
    var(--p3-gate-bg);
  color: var(--p3-gate-ink);
  font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
}

#p3-paid-gate *,
#p3-paid-gate *::before,
#p3-paid-gate *::after {
  box-sizing: border-box;
}

#p3-paid-gate .p3-paid-gate__card {
  width: 100%;
  max-width: 404px;
  padding: 26px 24px 20px;
  background: var(--p3-gate-surface);
  border: 1px solid var(--p3-gate-line);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(34, 211, 238, 0.04) inset;
}

#p3-paid-gate .p3-paid-gate__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--p3-gate-muted);
}

#p3-paid-gate .p3-paid-gate__mark {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--p3-gate-accent);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.7);
}

#p3-paid-gate .p3-paid-gate__title {
  margin: 0 0 10px;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#p3-paid-gate .p3-paid-gate__lead {
  margin: 0 0 14px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--p3-gate-muted);
  text-wrap: pretty;
}

#p3-paid-gate .p3-paid-gate__status {
  margin: 0 0 18px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(139, 156, 178, 0.85);
}

#p3-paid-gate .p3-paid-gate__status[hidden] {
  display: none;
}

#p3-paid-gate .p3-paid-gate__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#p3-paid-gate .p3-paid-gate__cta,
#p3-paid-gate .p3-paid-gate__retry {
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

#p3-paid-gate .p3-paid-gate__cta {
  background: var(--p3-gate-accent);
  color: var(--p3-gate-accent-ink);
  border: 1px solid var(--p3-gate-accent);
}

#p3-paid-gate .p3-paid-gate__cta:hover {
  background: #67e8f9;
  border-color: #67e8f9;
}

#p3-paid-gate .p3-paid-gate__retry {
  background: transparent;
  color: var(--p3-gate-ink);
  border: 1px solid rgba(120, 176, 214, 0.3);
}

#p3-paid-gate .p3-paid-gate__retry:hover {
  border-color: rgba(34, 211, 238, 0.6);
  color: var(--p3-gate-accent);
}

#p3-paid-gate .p3-paid-gate__retry[hidden] {
  display: none;
}

#p3-paid-gate .p3-paid-gate__cta:focus-visible,
#p3-paid-gate .p3-paid-gate__retry:focus-visible,
#p3-paid-gate .p3-paid-gate__foot a:focus-visible {
  outline: 2px solid var(--p3-gate-accent);
  outline-offset: 2px;
}

#p3-paid-gate .p3-paid-gate__foot {
  margin: 18px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(139, 156, 178, 0.7);
}

#p3-paid-gate .p3-paid-gate__foot a {
  color: rgba(139, 156, 178, 0.95);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Legacy access-code entry: one compact bottom link that reveals the existing
   five-character code path. It is deliberately quieter than the account CTA. */
#p3-paid-gate .p3-paid-gate__legacy-line {
  margin: 8px 0 0;
}

#p3-paid-gate .p3-paid-gate__legacy {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(139, 156, 178, 0.9);
  font: inherit;
  font-size: 11.5px;
  line-height: 1.4;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

#p3-paid-gate .p3-paid-gate__legacy:hover {
  color: var(--p3-gate-ink);
}

#p3-paid-gate .p3-paid-gate__legacy-form {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(120, 176, 214, 0.14);
}

#p3-paid-gate .p3-paid-gate__legacy-form[hidden] {
  display: none;
}

#p3-paid-gate .p3-paid-gate__legacy-label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--p3-gate-muted);
}

#p3-paid-gate .p3-paid-gate__legacy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

#p3-paid-gate .p3-paid-gate__legacy-input {
  width: 110px;
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid rgba(120, 176, 214, 0.3);
  border-radius: 8px;
  background: rgba(5, 7, 13, 0.6);
  color: var(--p3-gate-ink);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

#p3-paid-gate .p3-paid-gate__legacy-input:focus-visible {
  outline: 2px solid var(--p3-gate-accent);
  outline-offset: 1px;
  border-color: transparent;
}

#p3-paid-gate .p3-paid-gate__legacy-submit {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(120, 176, 214, 0.3);
  border-radius: 8px;
  background: transparent;
  color: var(--p3-gate-ink);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

#p3-paid-gate .p3-paid-gate__legacy-submit:hover {
  border-color: rgba(34, 211, 238, 0.6);
  color: var(--p3-gate-accent);
}

#p3-paid-gate .p3-paid-gate__legacy-submit:disabled {
  opacity: 0.55;
  cursor: default;
}

#p3-paid-gate .p3-paid-gate__legacy-hint,
#p3-paid-gate .p3-paid-gate__legacy-status {
  margin: 6px 0 0;
  font-size: 10.5px;
  line-height: 1.45;
  color: rgba(139, 156, 178, 0.75);
}

#p3-paid-gate .p3-paid-gate__legacy-status:empty {
  display: none;
}

#p3-paid-gate .p3-paid-gate__legacy-status[data-tone="error"] {
  color: #f2a6a6;
}

#p3-paid-gate .p3-paid-gate__legacy-status[data-tone="ok"] {
  color: var(--p3-gate-accent);
}

#p3-paid-gate .p3-paid-gate__legacy-back {
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(139, 156, 178, 0.85);
  font: inherit;
  font-size: 10.5px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

#p3-paid-gate .p3-paid-gate__legacy-back:hover {
  color: var(--p3-gate-ink);
}

#p3-paid-gate .p3-paid-gate__legacy:focus-visible,
#p3-paid-gate .p3-paid-gate__legacy-submit:focus-visible,
#p3-paid-gate .p3-paid-gate__legacy-back:focus-visible {
  outline: 2px solid var(--p3-gate-accent);
  outline-offset: 2px;
}

#p3-paid-gate[data-p3-gate-view="checking"] .p3-paid-gate__mark {
  animation: p3-gate-pulse 1.1s ease-in-out infinite;
}

@keyframes p3-gate-pulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

@media (max-width: 420px) {
  #p3-paid-gate {
    padding: 16px 12px;
    align-items: flex-start;
    padding-top: 12vh;
  }
  #p3-paid-gate .p3-paid-gate__card {
    padding: 22px 18px 18px;
    border-radius: 14px;
  }
  #p3-paid-gate .p3-paid-gate__title {
    font-size: 18px;
  }
  #p3-paid-gate .p3-paid-gate__actions > * {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  #p3-paid-gate .p3-paid-gate__mark {
    animation: none;
  }
  #p3-paid-gate .p3-paid-gate__cta,
  #p3-paid-gate .p3-paid-gate__retry {
    transition: none;
  }
}
