/* ─────────────────────────────────────────────────────────────────────────
   CSPTracker Component Primitives — focus ring, modals, keyframes,
   prose rules, and a11y-first base styles.

   Loaded after tokens.css but BEFORE styles.css so page-specific
   overrides in styles.css and tdp-polish.css still win when intentional.

   Patterns adapted from open-design (Apache-2.0), re-skinned for the
   dark navy palette.
   ───────────────────────────────────────────────────────────────────────── */


/* ── A11y: keyboard-only focus ring ───────────────────────────────────── */
*:focus-visible {
    outline: var(--ring-width) solid var(--ring-color);
    outline-offset: var(--ring-offset);
    border-radius: var(--radius-xs);
}
*:focus:not(:focus-visible) {
    outline: none;
}

/* Inputs get a soft halo via box-shadow instead of the outline (more
   visually integrated with field styling). Components in styles.css can
   still override per-input with a stronger ring. */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring-soft);
    border-color: var(--ring-color);
}


/* ── Animations ───────────────────────────────────────────────────────── */
@keyframes cspFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes cspPopIn {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

@keyframes cspSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes cspPulse {
    0%, 100% { opacity: 1;    transform: scale(1); }
    50%      { opacity: 0.55; transform: scale(0.92); }
}


/* ── Modal pattern (drop-in for any <div class="csp-modal-backdrop">) ─ */
.csp-modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: cspFadeIn var(--motion-fast) var(--ease-out);
}

.csp-modal {
    background: var(--card-bg-elevated);
    border: 1px solid var(--border-color-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: min(560px, 92vw);
    max-height: 86vh;
    overflow: auto;
    padding: var(--space-5);
    animation: cspPopIn var(--motion-base) var(--ease-pop);
}

.csp-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.csp-modal-title {
    font-family: var(--font-display);
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.csp-modal-close {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-md);
    transition: background var(--motion-fast) var(--ease-out),
                color      var(--motion-fast) var(--ease-out);
}
.csp-modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}


/* ── Prose / markdown rendering (used by AI advisor responses) ───────── */
.csp-prose {
    color: var(--text-secondary);
    line-height: var(--lh-normal);
    font-size: var(--fs-base);
}
.csp-prose > * + * {
    margin-top: var(--space-3);
}
.csp-prose h1,
.csp-prose h2,
.csp-prose h3,
.csp-prose h4 {
    color: var(--text-primary);
    font-family: var(--font-display);
    font-weight: 700;
    line-height: var(--lh-tight);
    letter-spacing: var(--tracking-tight);
    margin-top: var(--space-5);
    margin-bottom: var(--space-2);
}
.csp-prose h1 { font-size: var(--fs-xl); }
.csp-prose h2 { font-size: var(--fs-lg); }
.csp-prose h3 { font-size: var(--fs-md); }
.csp-prose h4 { font-size: var(--fs-base); text-transform: uppercase; letter-spacing: var(--tracking-wide); color: var(--text-muted); }

.csp-prose p { margin: 0; }
.csp-prose ul,
.csp-prose ol {
    padding-left: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}
.csp-prose code {
    font-family: var(--font-mono);
    font-size: 0.92em;
    background: var(--bg-tertiary);
    padding: 0.1em 0.4em;
    border-radius: var(--radius-xs);
    color: var(--accent-hot);
}
.csp-prose pre {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    overflow-x: auto;
    line-height: var(--lh-snug);
}
.csp-prose pre code {
    background: transparent;
    padding: 0;
    color: var(--text-secondary);
}
.csp-prose hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: var(--space-5) 0;
}
.csp-prose a {
    color: var(--accent-hot);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color var(--motion-fast) var(--ease-out);
}
.csp-prose a:hover { color: var(--accent-color); }


/* ── Admin-gated UI ───────────────────────────────────────────────────── */
/* .bot-settings-panel is the collapsible Settings dropdown on each strategy
   page. Hidden by default; revealed only when the bootstrapUserIdentity
   script in _base.html confirms the current user is an admin. */
.bot-settings-panel {
    display: none;
}
body.is-admin .bot-settings-panel {
    display: block;
}


/* ── Reduced motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    @keyframes cspFadeIn  { from, to { opacity: 1; } }
    @keyframes cspPopIn   { from, to { opacity: 1; transform: none; } }
    @keyframes cspSlideUp { from, to { opacity: 1; transform: none; } }
    @keyframes cspPulse   { from, to { opacity: 1; transform: none; } }
}

/* ── Site footer ──────────────────────────────────────────────────────────
   Used on every page that extends _base.html or _console_base.html.
   Also inlined (with matching CSS vars) on standalone pages:
   login.html, signup.html, agents.html.
   ─────────────────────────────────────────────────────────────────────── */
.site-footer {
    margin-top: auto;
    padding: 20px 24px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    /* .dashboard-container is a flex column with per-section `order`
       overrides — without an explicit high order the footer (default 0)
       can render ABOVE reordered sections. Always last. */
    order: 99;
}

.site-footer-inner {
    max-width: 1240px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.site-footer-copy {
    font-size: 12px;
    color: var(--text-dim, #62666d);
    font-family: 'Space Grotesk', 'Inter', -apple-system, sans-serif;
}

.site-footer-links {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.site-footer-links a {
    font-size: 12px;
    color: var(--text-dim, #62666d);
    text-decoration: none;
    font-family: 'Space Grotesk', 'Inter', -apple-system, sans-serif;
    transition: color 0.15s;
}

.site-footer-links a:hover {
    color: var(--text, #e2e4e7);
}

.site-footer-disclaimer {
    max-width: 1240px;
    margin: 12px auto 0;
    font-size: 11px;
    line-height: 1.55;
    color: var(--text-dim, #62666d);
    font-family: 'Space Grotesk', 'Inter', -apple-system, sans-serif;
}

.site-footer-disclaimer a {
    color: var(--text-dim, #62666d);
}

.site-footer-disclaimer a:hover {
    color: var(--text, #e2e4e7);
}

/* Legal page prose — used by terms.html / privacy.html / risk.html / support.html */
.legal-page {
    max-width: 780px;
    margin: 40px auto;
    padding: 0 24px 60px;
}

.legal-page h1 {
    font-size: 26px;
    font-weight: 650;
    color: var(--text, #e2e4e7);
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.legal-page .legal-meta {
    font-size: 13px;
    color: var(--text-dim, #62666d);
    margin-bottom: 36px;
}

.legal-page h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text, #e2e4e7);
    letter-spacing: -0.01em;
    margin-top: 36px;
    margin-bottom: 10px;
}

.legal-page p,
.legal-page li {
    font-size: 14px;
    line-height: 1.75;
    color: var(--text-secondary, #a0a5af);
}

.legal-page ul,
.legal-page ol {
    padding-left: 22px;
    margin-bottom: 14px;
}

.legal-page li {
    margin-bottom: 4px;
}

.legal-page a {
    color: var(--primary-color, #5e6ad2);
    text-decoration: none;
}

.legal-page a:hover {
    text-decoration: underline;
}

.legal-page .legal-notice {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 3px solid var(--primary-color, #5e6ad2);
    border-radius: 8px;
    padding: 16px 18px;
    margin: 24px 0;
}

.legal-page .legal-notice p {
    margin: 0;
    font-size: 13px;
}

/* Support FAQ */
.faq-item {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 18px 0;
}

.faq-item:last-child {
    border-bottom: none;
}

.faq-item h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text, #e2e4e7);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

.faq-item p {
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-secondary, #a0a5af);
    margin: 0;
}

.support-contact-box {
    background: rgba(94, 106, 210, 0.07);
    border: 1px solid rgba(94, 106, 210, 0.22);
    border-radius: 10px;
    padding: 20px 22px;
    margin: 28px 0;
}

.support-contact-box p {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary, #a0a5af);
}

.support-contact-box a {
    color: #6f9bff;
}
