/* PubRefsPop.css — references panel that can dock (pinned) beside the main
   column under the header, or float as a movable / resizable pop-up (unpinned).
   The card itself is the popup element (#pub-refs-pop) — no full-screen overlay,
   so when docked it can be an in-flow flex sibling of .coreInnerPage inside
   .corePage. Reuses .p2-card from popup_manager.css; colors come from fa.css. */

/* ── Trigger button (produced by FAD_Base::refsButton) ─────────────── */
.prp-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--border-color, #d9dee6);
    border-radius: 6px;
    background: #fff;
    color: var(--accent, #2563eb);
    font: inherit;
    font-size: 0.8rem;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    white-space: nowrap;
}
.prp-btn:hover {
    background: #eff6ff;
    border-color: var(--accent, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}
.prp-btn:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.prp-btn .fa-book-open { font-size: 0.85em; opacity: 0.85; }
.prp-btn .prp-btn-count { font-weight: 700; font-variant-numeric: tabular-nums; }
.prp-btn .prp-btn-against {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2em;
    padding: 0 0.3em;
    margin-left: 0.1rem;
    border-radius: 999px;
    background: #fee2e2;
    color: #991b1b;
    font-size: 0.72em;
    font-weight: 700;
}

/* ── Show / hide (popup_manager toggles .p2-open) ──────────────────── */
#pub-refs-pop.prp-card { display: none; --prp-top: 64px; }
#pub-refs-pop.prp-card.p2-open { display: flex; }   /* p2-card is a flex column */

/* ── Card (shared) ─────────────────────────────────────────────────── */
#pub-refs-pop.prp-card {
    min-width: 460px;
    min-height: 360px;
    max-width: 96vw;
    max-height: 96vh;
    border-radius: 0;
}

/* ── Pinned (docked) — fixed to the right, under the header; never scrolls.
     Space is reserved by padding .coreInnerPage (see body.prp-docked below). ─ */
/* z-index 99: under header */
#pub-refs-pop.prp--pinned {
    position: fixed;
    top: var(--prp-top, 64px);
    right: 0;
    bottom: 0;
    left: auto;
    width: 460px;
    height: auto;           /* top + bottom define the height */
    max-height: none;
    border-radius: 0;
    border-top: 1px solid var(--border-color, #e2e8f0);
    border-left: 1px solid var(--border-color, #e2e8f0);
    box-shadow: -4px 0 18px rgba(0, 0, 0, 0.08);
    resize: none;
    z-index: 99;

    animation: prp-slide-in 160ms ease-out;
}



/* ── Floating (pop-up) — fixed, out of flow (content reclaims full width) ─ */
/* z-index 101: over header */
#pub-refs-pop.prp--floating {
    position: fixed;
    top: 20px;
    right: 20px;
    height: 90vh;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 10px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.18);
    resize: both;           /* native bottom-right resize grip */
    overflow: hidden;
    animation: prp-pop-in 140ms ease-out;
    z-index: 101;
}
/* When dragged we anchor by left instead of right (JS sets inline left). */
#pub-refs-pop.prp--floating.prp--moved {
    right: auto;
}

@keyframes prp-slide-in {
    from { transform: translateX(28px); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}
@keyframes prp-pop-in {
    from { transform: translateY(8px) scale(0.99); opacity: 0; }
    to   { transform: translateY(0) scale(1);      opacity: 1; }
}

/* ── Frame parts never scroll — only the list does ─────────────────── */
.prp-header, .prp-tabs, .prp-types { flex: 0 0 auto; }
.prp-body {
    flex: 1 1 auto;
    min-height: 0;          /* allow the body to shrink so its list scrolls */
    overflow-y: auto;       /* scrollbar appears when there are many refs */
    overflow-x: hidden;
}

/* ── Header (doubles as the drag handle when floating) ─────────────── */
/* Controls (pin + ×) sit on a top row, title on the line beneath them. */
.prp-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    padding: 0.25rem 0.7rem 0.6rem;   /* tight top → buttons near the edge */
}
.prp-header-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.1rem;
    min-height: 1.4rem;
}
.prp-header .p2-header-title {
    flex: none;
    margin: 0;
    padding: 0 0.2rem;
    line-height: 1.25;
}
/* Title icon. Replaces style="color:#2563eb" (matches --primary-hover). */
.prp-title-icon { color: var(--primary-hover); }
.prp-card.prp--floating .prp-header {
    cursor: move;
    user-select: none;
}
.prp-card.prp--dragging { transition: none; }
.prp-card.prp--dragging .prp-body { pointer-events: none; }

/* Compact icon buttons, snug to the top */
.prp-header .p2-close { min-height: 1.4rem; min-width: 1.6rem; font-size: 1.25rem; padding: 0 0.25rem; }

/* Pin toggle button */
.prp-pin { font-size: 0.8rem; }
.prp-pin i { transition: transform 120ms; }
.prp-pin[aria-pressed="true"] {
    color: var(--primary-color, #2563eb);
    background: rgba(37, 99, 235, 0.12);
}
.prp-pin[aria-pressed="true"] i { transform: rotate(-30deg); }

/* ── For / Against tabs ────────────────────────────────────────────── */
.prp-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    background: var(--table-header-bg, #f8fafc);
    flex: 0 0 auto;
}
.prp-tab {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 0.75rem;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text-muted, #6b7280);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 120ms, border-color 120ms, background 120ms;
}
.prp-tab:hover { background: rgba(37, 99, 235, 0.06); }
.prp-tab.is-active {
    color: var(--primary-color, #2563eb);
    border-bottom-color: var(--primary-color, #2563eb);
    background: var(--bg-card, #fff);
}
.prp-tab[data-stance="against"].is-active {
    color: #b91c1c;
    border-bottom-color: #b91c1c;
}
.prp-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35em;
    height: 1.35em;
    padding: 0 0.3em;
    font-size: 0.74rem;
    line-height: 1;
    border-radius: 999px;
    background: var(--border-color, #e2e8f0);
    color: var(--text-main, #1e293b);
}
.prp-tab.is-active .prp-tab-count { background: var(--primary-color, #2563eb); color: #fff; }
.prp-tab[data-stance="against"].is-active .prp-tab-count { background: #b91c1c; }
.prp-tabs.prp-tabs--single { display: none; }

/* ── Study-type filter — segmented control ─────────────────────────── */
.prp-types {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0;
    margin: 0.6rem 0.9rem;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 8px;
    background: var(--table-header-bg, #f1f5f9);
    overflow-x: auto;
    flex: 0 0 auto;
    scrollbar-width: thin;
}
.prp-type-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.32rem 0.7rem;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    background: transparent;
    border: none;
    border-right: 1px solid var(--border-color, #e2e8f0);
    cursor: pointer;
    white-space: nowrap;
    transition: background 120ms, color 120ms;
}
.prp-type-chip:last-child { border-right: none; }
.prp-type-chip:hover { background: rgba(37, 99, 235, 0.08); color: var(--text-main, #1e293b); }
.prp-type-chip.is-active {
    background: var(--primary-color, #2563eb);
    color: #fff;
}
.prp-type-count {
    font-size: 0.72rem;
    opacity: 0.8;
    font-variant-numeric: tabular-nums;
}

/* ── Body / list ───────────────────────────────────────────────────── */
.prp-body { padding: 0; }
.prp-list { display: flex; flex-direction: column; }

/* ── Reference card ────────────────────────────────────────────────── */
.prp-ref {
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border-color, #eef2f7);
}
.prp-ref:hover { background: rgba(37, 99, 235, 0.035); }

.prp-ref-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.3rem;
}
.prp-ref-year {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-main, #1e293b);
    font-variant-numeric: tabular-nums;
}
.prp-ref-type {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.08rem 0.4rem;
    border-radius: 4px;
    background: #e2e8f0;
    color: #1e293b;
    text-transform: capitalize;
}
.prp-ref-type[data-t="rct"],
.prp-ref-type[data-t="clinical trial"]      { background: #dcfce7; color: #166534; }
.prp-ref-type[data-t="meta-analysis"],
.prp-ref-type[data-t="systematic review"]   { background: #dbeafe; color: #1e40af; }
.prp-ref-type[data-t="review"]              { background: #ede9fe; color: #5b21b6; }
.prp-ref-type[data-t="animal"],
.prp-ref-type[data-t="in vivo"]             { background: #fef3c7; color: #92400e; }
.prp-ref-type[data-t="in-vitro"]            { background: #fae8ff; color: #86198f; }
.prp-ref-type[data-t="observational"]       { background: #ffedd5; color: #9a3412; }
.prp-ref-journal {
    font-size: 0.76rem;
    color: var(--text-muted, #6b7280);
    font-style: italic;
}

.prp-ref-title {
    font-size: 0.84rem;
    line-height: 1.35;
    color: var(--text-main, #1e293b);
    margin-bottom: 0.4rem;
}

.prp-ref-note {
    font-size: 0.76rem;
    line-height: 1.35;
    color: #b91c1c;
    background: #fef2f2;
    border-left: 3px solid #fecaca;
    padding: 0.3rem 0.5rem;
    border-radius: 0 4px 4px 0;
    margin-bottom: 0.4rem;
}
.prp-ref-strength {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.prp-ref-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.prp-ref-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.73rem;
    font-weight: 600;
    text-decoration: none;
    padding: 0.16rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border-color, #e2e8f0);
    color: var(--primary-color, #2563eb);
    background: var(--bg-card, #fff);
    transition: background 120ms, border-color 120ms;
}
.prp-ref-link:hover { background: rgba(37, 99, 235, 0.08); border-color: var(--primary-color, #2563eb); }
.prp-ref-link--pmid { color: #0f766e; }
.prp-ref-link--pmc  { color: #7c3aed; }
.prp-ref-link--doi  { color: #2563eb; }
.prp-ref-link i { font-size: 0.9em; opacity: 0.8; }

.prp-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted, #6b7280);
    font-style: italic;
    font-size: 0.86rem;
}

/* ── Trigger button (rendered inside data cards by FAD_Base::refsButton) ── */
.prp-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.55rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary-color, #2563eb);
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 120ms, border-color 120ms, box-shadow 120ms;
}
.prp-btn:hover {
    background: rgba(37, 99, 235, 0.08);
    border-color: var(--primary-color, #2563eb);
}
.prp-btn i { opacity: 0.8; }
.prp-btn-count { font-variant-numeric: tabular-nums; }
.prp-btn-against {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.3em;
    height: 1.3em;
    padding: 0 0.28em;
    margin-left: 0.15rem;
    font-size: 0.68rem;
    border-radius: 999px;
    background: #fee2e2;
    color: #991b1b;
}

/* ── Mobile: full-width fixed drawer for both states (no side-by-side) ── */
@media (max-width: 560px) {
    #pub-refs-pop.prp-card { min-width: 0; }
    #pub-refs-pop.prp--pinned,
    #pub-refs-pop.prp--floating {
        position: fixed;
        top: var(--prp-top, 64px);
        left: 0; right: 0; bottom: 0;
        width: auto;
        height: auto;
        max-width: 100vw;
        flex: none;
        resize: none;
    }
    /* No room to sit side-by-side on a phone — don't reserve space. */
    body.prp-docked .coreInnerPage { padding-right: 0; }
}
