/* ==========================================================================
   Prop Insight popup (NFL prop finder row modal)
   Shared by prop-finder.php today; every class is prefixed "pi-" so the
   hit-rate finder and game-props pages can adopt it later without collisions.
   Theme: site tokens from assets/css/style.css :root (--surface / --border /
   --accent / --green / --red / --amber, --radius, --font / --mono).
   ========================================================================== */

body.pi-scroll-lock { overflow: hidden; }

.pi-overlay { display: none; position: fixed; inset: 0; background: rgba(20, 23, 28, 0.55); z-index: 1100; align-items: flex-start; justify-content: center; padding: 28px 16px; overflow-y: auto; }   /* above the fixed site nav (z-index 1000) so the head is never clipped */
.pi-overlay.open { display: flex; }

.pi-modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); max-width: 920px; width: 100%; position: relative; box-shadow: var(--shadow-lg); font-family: var(--font); color: var(--text-primary); font-size: 0.86rem; line-height: 1.5; }
.pi-modal:focus { outline: none; }

.pi-close { position: absolute; top: 6px; right: 10px; background: none; border: 0; font-size: 1.7rem; line-height: 1; color: var(--text-secondary); cursor: pointer; z-index: 2; padding: 4px 8px; border-radius: var(--radius); }
.pi-close:hover, .pi-close:focus-visible { color: var(--text-primary); background: var(--surface-3); outline: 2px solid var(--accent); outline-offset: 1px; }

.pi-body { padding: 0 20px 18px; }   /* the overlay scrolls; the modal grows */

/* ─── Section chrome ─────────────────────────────────────────────────────── */
.pi-section { padding: 14px 0 6px; border-top: 1px solid var(--border); }
.pi-section:first-child { border-top: 0; }
.pi-h { font-family: var(--font-display); font-size: 0.98rem; font-weight: 700; margin: 0 0 10px; color: var(--text-primary); display: flex; align-items: baseline; gap: 8px; }
.pi-h .pi-h-key { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: var(--radius); background: var(--nav-bg); color: #fff; font-size: 0.68rem; font-weight: 700; text-align: center; line-height: 1.6; }
.pi-h3 { font-family: var(--font-display); font-size: 0.82rem; font-weight: 600; margin: 12px 0 6px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.03em; }
.pi-sub { font-size: 0.78rem; color: var(--text-secondary); margin: 0 0 8px; }
.pi-muted { color: var(--text-secondary); }
.pi-na { color: var(--text-muted); font-style: italic; }
.pi-note { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--amber); border-radius: var(--radius); padding: 8px 10px; font-size: 0.8rem; color: var(--text-secondary); margin: 8px 0; }
.pi-note.pi-note-info { border-left-color: var(--accent); }
.pi-note.pi-note-warn { border-left-color: var(--red); }

/* ─── Header (A) ────────────────────────────────────────────────────────── */
.pi-head { display: flex; align-items: center; gap: 14px; padding: 16px 56px 16px 20px;   /* right gutter reserves room for the absolutely-positioned close button */ border-bottom: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.pi-headshot { width: 56px; height: 56px; border-radius: var(--radius); object-fit: cover; background: var(--surface-3); flex: 0 0 auto; }
.pi-name { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; line-height: 1.2; margin: 0; }
.pi-name-sub { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.pi-market-line { margin-left: auto; text-align: right; }
.pi-market-line .pi-market { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }
.pi-market-line .pi-line { font-family: var(--mono); font-size: 1.35rem; font-weight: 600; color: var(--text-primary); line-height: 1.1; }
.pi-market-line .pi-book { font-size: 0.72rem; color: var(--text-secondary); }

/* ─── Tables ────────────────────────────────────────────────────────────── */
.pi-scroll { overflow-x: auto; }
.pi-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin: 0 0 10px; }
.pi-table th { text-align: left; font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 5px 16px 5px 0; border-bottom: 1px solid var(--border); white-space: nowrap; font-weight: 600; }
.pi-table td { padding: 5px 16px 5px 0; border-bottom: 1px solid var(--border); color: var(--text-primary); white-space: nowrap; vertical-align: top; }
.pi-table th:last-child, .pi-table td:last-child { padding-right: 0; }
.pi-table td.pi-num + td:not(.pi-num), .pi-table th.pi-num + th:not(.pi-num) { padding-left: 6px; }
.pi-table td.pi-num, .pi-table th.pi-num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pi-table tr.pi-best-over td.pi-over-px, .pi-table tr.pi-best-under td.pi-under-px { color: var(--green); font-weight: 700; }
.pi-table td.pi-best { background: var(--green-soft); color: var(--green); font-weight: 700; }
.pi-table th.pi-group, .pi-table td.pi-group { background: var(--surface-3); color: var(--text-primary); font-family: var(--font-display); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 8px; font-weight: 700; white-space: normal; }
.pi-table td.pi-wrap { white-space: normal; }
.pi-table tr.pi-row-partial td { color: var(--text-muted); }

/* ─── Chips / stat grid ─────────────────────────────────────────────────── */
.pi-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.pi-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; min-width: 88px; text-align: center; }
.pi-chip .pi-chip-l { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.pi-chip .pi-chip-v { font-family: var(--mono); font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.pi-chip .pi-chip-s { font-size: 0.68rem; color: var(--text-secondary); font-family: var(--mono); }
.pi-chip.pi-chip-good .pi-chip-v { color: var(--green); }
.pi-chip.pi-chip-bad .pi-chip-v { color: var(--red); }
.pi-chip.pi-chip-mid .pi-chip-v { color: var(--amber); }
.pi-chip.pi-chip-primary { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }

.pi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 18px; margin-bottom: 8px; }
.pi-kv { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dotted var(--border); padding: 3px 0; font-size: 0.8rem; }
.pi-kv .pi-k { color: var(--text-secondary); }
.pi-kv .pi-v { font-family: var(--mono); text-align: right; }

/* ─── Badges ────────────────────────────────────────────────────────────── */
.pi-badge { display: inline-block; padding: 2px 9px; border-radius: 3px; font-size: 0.72rem; font-weight: 700; line-height: 1.5; vertical-align: middle; }
.pi-badge.pi-over { background: var(--green-soft); color: var(--green); }
.pi-badge.pi-under { background: var(--red-soft); color: var(--red); }
.pi-badge.pi-none, .pi-badge.pi-neutral { background: var(--surface-3); color: var(--text-secondary); }
.pi-badge.pi-push { background: var(--amber-soft); color: var(--amber); }
.pi-badge.pi-conf-high { background: var(--green-soft); color: var(--green); }
.pi-badge.pi-conf-medium { background: var(--amber-soft); color: var(--amber); }
.pi-badge.pi-conf-low { background: var(--red-soft); color: var(--red); }
.pi-badge.pi-tag { background: var(--nav-bg); color: #fff; }

.pi-arrow { display: inline-block; width: 1.4em; text-align: center; font-weight: 700; }
.pi-arrow.pi-over { color: var(--green); }
.pi-arrow.pi-under { color: var(--red); }
.pi-arrow.pi-neutral { color: var(--text-muted); }

/* ─── Decision (B) ──────────────────────────────────────────────────────── */
.pi-decision { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 18px; }
.pi-reasons { margin: 0; padding-left: 1.1rem; font-size: 0.8rem; }
.pi-reasons li { margin: 2px 0; }
.pi-reasons.pi-reasons-over li::marker { color: var(--green); }
.pi-reasons.pi-reasons-under li::marker { color: var(--red); }

/* ─── Performance (C) ───────────────────────────────────────────────────── */
.pi-chart-wrap { position: relative; height: 220px; margin: 4px 0 10px; }
.pi-chart-wrap canvas { max-width: 100%; }
.pi-toggle { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-secondary); margin: 6px 0 10px; }
.pi-toggle input { margin: 0; }
.pi-res { display: inline-block; padding: 1px 7px; border-radius: var(--radius); font-size: 0.66rem; font-weight: 700; }
.pi-res.pi-over { background: var(--green-soft); color: var(--green); }
.pi-res.pi-under { background: var(--red-soft); color: var(--red); }
.pi-res.pi-push { background: var(--amber-soft); color: var(--amber); }
.pi-res.pi-partial { background: var(--surface-3); color: var(--text-secondary); }

/* ─── Footer (E) ────────────────────────────────────────────────────────── */
.pi-footer { font-size: 0.74rem; color: var(--text-secondary); }
.pi-footer .pi-disclaimer { margin-top: 6px; font-weight: 600; color: var(--text-secondary); }

/* ─── States ────────────────────────────────────────────────────────────── */
.pi-state { padding: 40px 20px; text-align: center; color: var(--text-secondary); font-size: 0.9rem; }
.pi-state.pi-error { color: var(--red); }
.pi-spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: pi-spin 0.8s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes pi-spin { to { transform: rotate(360deg); } }

/* ─── Row / button wiring on the finder table ───────────────────────────── */
.pf-row-insight { cursor: pointer; }
.pf-insight-btn { background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 0.3rem 0.7rem; font-size: 0.76rem; font-weight: 600; color: var(--text-secondary); cursor: pointer; font-family: inherit; margin-right: 0.35rem; }
.pf-insight-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── Mobile: full-screen sheet ─────────────────────────────────────────── */
@media (max-width: 767px) {
    .pi-overlay { padding: 0; align-items: stretch; }
    .pi-modal { max-width: none; width: 100%; min-height: 100vh; min-height: 100dvh; border: 0; border-radius: 0; box-shadow: none; }
    .pi-body { padding: 0 14px 24px; }
    .pi-head { padding: 14px 44px 12px 14px; border-radius: 0; }
    .pi-market-line { margin-left: 0; text-align: left; flex-basis: 100%; }
    .pi-decision, .pi-grid { grid-template-columns: 1fr; }
    .pi-chart-wrap { height: 190px; }
}

@media (prefers-reduced-motion: reduce) {
    .pi-spinner { animation: none; }
}
