/* research.css — Collaborative Research Engine (Slice 2).
   Workspace dashboard + 3-layer tree coloring. */

/* ---- Dashboard ---- */
.research-page { max-width: 900px; }

.research-header {
    display: flex; flex-wrap: wrap; gap: 1rem;
    align-items: flex-start; justify-content: space-between;
    padding: 1.1rem 1.25rem; margin-bottom: 1rem;
    background: linear-gradient(135deg, rgba(74,124,89,0.10), rgba(74,124,89,0.02));
    border: 1px solid rgba(74,124,89,0.25); border-radius: 14px;
}
.research-eyebrow { font-size: .8rem; font-weight: 600; color: #4A7C59; letter-spacing: .02em; }
.research-title { margin: .15rem 0 .2rem; font-size: 1.55rem; line-height: 1.15; }
.research-sub { color: var(--text-muted, #667); font-size: .9rem; }
.research-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.lights-off-pill {
    display: inline-block; padding: 0 .4rem; border-radius: 999px;
    background: rgba(40,40,60,0.12); font-size: .75rem;
}

.btn-link {
    background: none; border: none; color: #4A7C59; cursor: pointer;
    padding: .35rem .5rem; font-weight: 600;
}
.btn-link:hover { text-decoration: underline; }

/* ---- Legend / layer toggles ---- */
.research-legend {
    display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
    margin-bottom: 1rem;
}
.research-legend-label { font-size: .85rem; color: var(--text-muted, #667); }
.layer-chip {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .25rem .6rem; border-radius: 999px; font-size: .82rem;
    border: 1px solid var(--border, #d8d8e0); cursor: pointer; user-select: none;
}
.layer-chip input { margin: 0; }
.layer-chip-theirs    { border-color: #4A7C59; color: #2f5a3e; }
.layer-chip-contested { border-color: #E0A100; color: #8a6500; }
.layer-chip-inherited { border-color: #9aa; color: #667; }

/* ---- Layer blocks ---- */
.research-layer-block {
    border: 1px solid var(--border, #e3e3ea); border-radius: 12px;
    margin-bottom: 1rem; overflow: hidden; background: var(--card-bg, #fff);
}
.research-block-theirs    { border-left: 4px solid #4A7C59; }
.research-block-contested { border-left: 4px solid #E0A100; }
.research-block-inherited { border-left: 4px solid #b9b9c4; }
.research-layer-head { padding: .8rem 1rem .2rem; }
.research-layer-head h2 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.research-layer-count {
    font-size: .8rem; font-weight: 600; color: #fff; background: #9aa;
    border-radius: 999px; padding: 0 .5rem; min-width: 1.4rem; text-align: center;
}
.research-block-theirs    .research-layer-count { background: #4A7C59; }
.research-block-contested .research-layer-count { background: #E0A100; }
.research-layer-blurb { margin: .2rem 0 .6rem; font-size: .82rem; color: var(--text-muted, #778); }
.research-layer-list { padding: 0 .5rem .6rem; }

.research-person-row {
    display: flex; align-items: center; gap: .6rem;
    padding: .45rem .6rem; border-radius: 8px;
}
.research-person-row:hover { background: rgba(0,0,0,0.03); }
.research-person-name { font-weight: 600; text-decoration: none; color: var(--text, #223); }
.research-person-name:hover { text-decoration: underline; }
.research-person-dates { font-size: .8rem; color: var(--text-muted, #889); }
.research-src-pill {
    font-size: .75rem; background: rgba(74,124,89,0.12); color: #2f5a3e;
    border-radius: 999px; padding: 0 .45rem;
}
.research-contested-why {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 50%;
    background: #E0A100; color: #fff; font-weight: 700; font-size: .8rem;
}
.research-empty-row { padding: .6rem; color: var(--text-muted, #889); font-size: .88rem; font-style: italic; }

/* ---- Add-source button + modal (Slice 1) ---- */
.research-add-src {
    background: none; border: 1px dashed var(--border, #ccd); color: var(--text-muted, #778);
    border-radius: 6px; font-size: .72rem; padding: .1rem .45rem; cursor: pointer; margin-left: auto;
}
.research-add-src:hover { border-color: #4A7C59; color: #2f5a3e; }
.src-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 2000;
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.src-modal {
    background: var(--card-bg, #fff); color: var(--text, #223); border-radius: 14px;
    padding: 1.25rem; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.src-modal h3 { margin: 0 0 .25rem; font-size: 1.15rem; }
.src-modal-hint { font-size: .82rem; color: var(--text-muted, #667); margin: 0 0 .9rem; }
.src-modal label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .6rem; color: var(--text, #334); }
.src-modal input[type=text], .src-modal select, .src-modal textarea {
    display: block; width: 100%; margin-top: .2rem; padding: .45rem .55rem; font: inherit;
    border: 1px solid var(--border, #d8d8e0); border-radius: 7px; background: var(--input-bg, #fff); color: var(--text, #223);
}
.src-modal .src-check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.src-modal .src-check input { width: auto; margin: 0; }
.src-modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* ---- Empty / start CTA ---- */
.research-empty { text-align: center; max-width: 520px; margin: 3rem auto; }
.research-empty-icon { font-size: 3rem; }
.research-empty h1 { margin: .5rem 0; }
.research-empty p { color: var(--text-muted, #667); margin-bottom: 1.25rem; }

/* ---- Tree layer coloring (class-flip, mirrors .show-bloodline) ----
   applyResearchMarkers paints .layer-theirs / .layer-contested / .layer-inherited
   onto .tree-node; .show-research-layers on the container turns the styling on. */
.tree-container.show-research-layers .tree-node.layer-theirs rect:nth-child(2) {
    stroke: #4A7C59; stroke-width: 2.5px; stroke-dasharray: 5 3;
}
.tree-container.show-research-layers .tree-node.layer-contested rect:nth-child(2) {
    stroke: #E0A100; stroke-width: 2.5px;
}
.tree-container.show-research-layers .tree-node.layer-inherited rect:nth-child(2) {
    opacity: .92;
}
/* contested marker glyph drawn by applyResearchMarkers */
.tree-research-contested { pointer-events: none; }

/* ---- Live-presence glow (Slice 4): "a light on in a house" ----
   live = someone researching this line now (pulsing green);
   embers = worked recently (steady amber); dark = no glow = an invitation. */
.tree-container.show-presence .tree-node.presence-live rect:nth-child(2) {
    stroke: #34c759; stroke-width: 3px;
    animation: presence-pulse 1.7s ease-in-out infinite;
}
@keyframes presence-pulse {
    0%, 100% { filter: drop-shadow(0 0 2px rgba(52,199,89,0.55)); }
    50%      { filter: drop-shadow(0 0 8px rgba(52,199,89,0.95)); }
}
.tree-container.show-presence .tree-node.presence-embers rect:nth-child(2) {
    stroke: #E0A100; stroke-width: 2.5px;
    filter: drop-shadow(0 0 4px rgba(224,161,0,0.5));
}
@media (prefers-reduced-motion: reduce) {
    .tree-container.show-presence .tree-node.presence-live rect:nth-child(2) { animation: none; filter: drop-shadow(0 0 5px rgba(52,199,89,0.85)); }
}

/* hide a layer when its toggle is off */
.tree-container.hide-layer-theirs    .tree-node.layer-theirs,
.tree-container.hide-layer-contested .tree-node.layer-contested,
.tree-container.hide-layer-inherited .tree-node.layer-inherited { opacity: .15; }

/* ---- Deep Research partner panel (Slice 3) ---- */
.research-partner {
    border: 1px solid rgba(74,124,89,0.3); border-radius: 12px;
    padding: .9rem 1rem; margin-bottom: 1rem;
    background: linear-gradient(135deg, rgba(74,124,89,0.06), rgba(74,124,89,0.01));
}
.rp-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.rp-head h2 { margin: 0; font-size: 1.05rem; }
.rp-opus {
    font-size: .65rem; font-weight: 700; letter-spacing: .04em; vertical-align: middle;
    background: #4A7C59; color: #fff; border-radius: 4px; padding: 1px 5px; margin-left: .25rem;
}
.rp-credits {
    font-size: .8rem; font-weight: 600; color: #2f5a3e; text-decoration: none;
    background: rgba(74,124,89,0.12); border-radius: 999px; padding: .15rem .6rem; white-space: nowrap;
}
.rp-credits:hover { text-decoration: underline; }
.rp-credits-low { background: rgba(224,161,0,0.18); color: #8a6500; }
.rp-blurb { margin: .35rem 0 .6rem; font-size: .82rem; color: var(--text-muted, #667); }
.rp-thread { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; }
.rp-thread:empty { display: none; }
.rp-msg { padding: .5rem .7rem; border-radius: 10px; font-size: .9rem; line-height: 1.45; max-width: 92%; }
.rp-msg-user { align-self: flex-end; background: #4A7C59; color: #fff; border-bottom-right-radius: 3px; }
.rp-msg-bot { align-self: flex-start; background: var(--card-bg, #fff); border: 1px solid var(--border, #e3e3ea); border-bottom-left-radius: 3px; }
.rp-msg-bot a { color: #4A7C59; }
.rp-typing { color: var(--text-muted, #889); font-style: italic; }
.rp-compose { display: flex; gap: .5rem; margin-top: .6rem; align-items: flex-end; }
.rp-compose textarea {
    flex: 1; resize: vertical; min-height: 2.4rem; padding: .5rem .6rem;
    border: 1px solid var(--border, #d8d8e0); border-radius: 8px; font: inherit;
    background: var(--input-bg, #fff); color: var(--text, #223);
}
.rp-compose .btn { white-space: nowrap; }

/* ---- Matchmaker Connections (Slice 5) ---- */
.research-connections {
    border: 1px solid rgba(224,161,0,0.35); border-radius: 12px;
    padding: .9rem 1rem; margin-bottom: 1rem;
    background: linear-gradient(135deg, rgba(224,161,0,0.07), rgba(224,161,0,0.01));
}
.research-connections h2 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.conn-count { font-size: .8rem; font-weight: 700; color: #fff; background: #E0A100; border-radius: 999px; padding: 0 .5rem; }
.conn-blurb { margin: .35rem 0 .7rem; font-size: .82rem; color: var(--text-muted, #667); }
.conn-card {
    display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between;
    padding: .6rem .7rem; border-radius: 9px; background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e3e3ea); margin-bottom: .5rem;
}
.conn-info { display: flex; align-items: center; gap: .55rem; }
.conn-glyph { font-size: 1.3rem; }
.conn-title { font-size: .92rem; }
.conn-sub { font-size: .78rem; color: var(--text-muted, #889); }
.conn-actions { display: flex; gap: .4rem; align-items: center; }
.conn-state { font-size: .82rem; color: var(--text-muted, #778); font-style: italic; }
.conn-connected { color: #2f5a3e; font-style: normal; font-weight: 600; }

/* ---- Reconciliation modal (Slice 6) ---- */
.recon-row { border-left: 3px solid #9aa; padding: .5rem .7rem; margin: .5rem 0; border-radius: 6px; background: rgba(0,0,0,0.02); }
.recon-merge { border-left-color: #4A7C59; }
.recon-source_wins { border-left-color: #3B7DD8; }
.recon-contested { border-left-color: #E0A100; }
.recon-field { font-weight: 700; font-size: .9rem; }
.recon-badge { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-radius: 4px; padding: 1px 5px; color: #fff; background: #9aa; }
.recon-badge-merge { background: #4A7C59; }
.recon-badge-source_wins { background: #3B7DD8; }
.recon-badge-contested { background: #E0A100; }
.recon-vals { font-size: .85rem; margin: .15rem 0; }
.recon-why { font-size: .8rem; color: var(--text-muted, #667); }

/* ---- Graft review (Slice 7, admin) ---- */
.graft-page { max-width: 760px; }
.graft-intro { color: var(--text-muted, #667); margin-bottom: 1.25rem; }
.graft-card { border: 1px solid var(--border, #e3e3ea); border-left: 4px solid #4A7C59; border-radius: 10px; padding: .9rem 1rem; margin-bottom: 1rem; background: var(--card-bg, #fff); }
.graft-head { display: flex; align-items: center; gap: .5rem; }
.graft-status { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-radius: 4px; padding: 1px 6px; background: #9aa; color: #fff; }
.graft-status-submitted { background: #4A7C59; }
.graft-status-needs_catchup { background: #E0A100; }
.graft-status-approved { background: #2f5a3e; }
.graft-status-rolled_back { background: #b06; }
.graft-counts { font-size: .85rem; color: var(--text-muted, #667); margin: .35rem 0; }
.graft-section { margin: .4rem 0; }
.graft-sec-title { font-size: .78rem; font-weight: 700; color: var(--text-muted, #778); text-transform: uppercase; letter-spacing: .03em; }
.graft-section ul { margin: .2rem 0 0; padding-left: 1.2rem; font-size: .88rem; }
.graft-actions { margin-top: .6rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.graft-result { margin-top: .4rem; }
.graft-done { color: #2f5a3e; font-weight: 600; font-size: .88rem; }
.graft-stale { color: #8a6500; font-size: .82rem; }

/* ---- Billing page (Slice 3) ---- */
.billing-page { max-width: 820px; }
.billing-title { margin-bottom: .25rem; }
.billing-intro { color: var(--text-muted, #667); margin-bottom: 1.25rem; }
.billing-balance-card {
    text-align: center; padding: 1.25rem; border-radius: 14px; margin-bottom: 1.5rem;
    background: linear-gradient(135deg, rgba(74,124,89,0.12), rgba(74,124,89,0.03));
    border: 1px solid rgba(74,124,89,0.25);
}
.billing-balance-num { font-size: 2.8rem; font-weight: 800; color: #2f5a3e; line-height: 1; }
.billing-balance-lbl { font-size: .95rem; color: var(--text, #334); margin-top: .25rem; }
.billing-balance-sub { font-size: .8rem; color: var(--text-muted, #778); margin-top: .15rem; }
.billing-plans { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.billing-plan {
    border: 1px solid var(--border, #e3e3ea); border-radius: 12px; padding: 1.1rem;
    background: var(--card-bg, #fff); display: flex; flex-direction: column;
}
.billing-plan-current { border-color: #4A7C59; box-shadow: 0 0 0 1px #4A7C59 inset; }
.billing-plan-name { font-weight: 700; font-size: 1.05rem; }
.billing-current-pill { font-size: .65rem; background: #4A7C59; color: #fff; border-radius: 4px; padding: 1px 5px; vertical-align: middle; }
.billing-plan-price { font-size: 1.8rem; font-weight: 800; margin: .3rem 0 .6rem; }
.billing-per { font-size: .9rem; font-weight: 500; color: var(--text-muted, #889); }
.billing-plan-features { list-style: none; padding: 0; margin: 0 0 1rem; flex: 1; }
.billing-plan-features li { padding: .25rem 0 .25rem 1.3rem; position: relative; font-size: .88rem; }
.billing-plan-features li::before { content: '✓'; position: absolute; left: 0; color: #4A7C59; font-weight: 700; }
.billing-plan-cta-current { color: #4A7C59; font-weight: 600; text-align: center; }
.billing-explainer { border-top: 1px solid var(--border, #e3e3ea); padding-top: 1rem; }
.billing-explainer h2 { font-size: 1.05rem; }
.billing-explainer li { margin: .3rem 0; font-size: .9rem; }

@media (max-width: 640px) {
    .research-header { flex-direction: column; }
    .research-actions { width: 100%; }
    .billing-plans { grid-template-columns: 1fr; }
}
