/* ════════════════════════════════════════════════════════════════════════
   POCR.AI — Provenance Panel (Phase 5a)
   ────────────────────────────────────────────────────────────────────────
   Renders below the output row via the #provenanceContainer div in
   index.html. Mounted by provenance.js.

   Highlight style: Option 2 — underline + grey shade
   Multi-source sentences get numbered suffixes (1,2,3) matching the
   numbered badges on active source cards.
   ════════════════════════════════════════════════════════════════════════ */

/* Only show the panel when it has content */
#provenanceContainer:empty { display: none; }

/* ── Panel sizing — match output box width ────────────────────────
   The .output-row above uses grid-template-columns: 1fr 80px (output
   box + 80px action-controls + 10px gap). The panel sits as a sibling
   below, so we mirror the same grid and place the panel in column 1
   only. The 80px column is left empty so the panel right-edge aligns
   exactly with the output box right-edge.
   ──────────────────────────────────────────────────────────────────── */
#provenanceContainer:not(:empty) {
    display: grid;
    grid-template-columns: 1fr 80px;
    gap: 10px;
    width: 100%;
    margin-top: 8px;
    margin-bottom: 8px;
}
#provenanceContainer > .prov-panel {
    grid-column: 1 / 2;
}

/* ── Panel sizing — span full output-row width ─────────────────────
   Panel right edge aligns with the RESET button's right edge (full
   output-row width), giving source cards that are wider than the
   RESULTS FORMAT tiles below.
   ──────────────────────────────────────────────────────────────────── */
.prov-panel {
    display: block;
    width: 100%;
    border: 2px solid #000;
    background: #fff;
    font-family: 'Montserrat', sans-serif;
    box-sizing: border-box;
}

/* ── Header ─────────────────────────────────────────────────────────
   Point 4: remove black fill, render SOURCES as plain black bold text.
   ──────────────────────────────────────────────────────────────────── */
.prov-hdr {
    background: #fff;
    color: #000;
    padding: 8px 14px;
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.15em;
    display: flex; align-items: center; gap: 14px;
    border-bottom: 2px solid #000;
}
.prov-hdr .prov-title { flex: 0 0 auto; color: #000; }
.prov-hdr .summary-pills {
    display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap;
}
.prov-hdr .sp {
    background: #000;
    color: #fff;
    border: 1px solid #000;
    padding: 1px 6px; font-size: 9px;
    text-transform: uppercase; letter-spacing: 0.05em;
}

/* ── Hint / clear bar ──────────────────────────────────────────────── */
.prov-hint {
    padding: 6px 14px;
    background: #f5f5f5;
    border-bottom: 1px solid #ddd;
    font-size: 10px; color: #555;
    text-transform: uppercase; letter-spacing: 0.05em;
    display: flex; align-items: center; justify-content: space-between;
}
.prov-hint-text { flex: 1; }
.prov-clear-btn {
    border: 1px solid #000; background: #fff;
    padding: 1px 8px;
    font-size: 9px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.05em;
    cursor: pointer;
    font-family: 'Montserrat', sans-serif;
    visibility: hidden;
}
.prov-clear-btn.visible { visibility: visible; }
.prov-clear-btn:hover { background: #000; color: #fff; }

/* ── Source list grid — fixed 2 rows × 4 cols ─────────────────────
   No expand/collapse. Always 8 slots; empty slots padded by JS to
   keep the grid balanced when fewer than 8 chunks were retrieved.
   ──────────────────────────────────────────────────────────────────── */
.prov-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(2, 1fr);
    gap: 0;
}

.prov-item {
    padding: 10px 12px;
    border-right: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    transition: background 0.08s;
    user-select: none;
    min-height: 110px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}
.prov-item:nth-child(4n) { border-right: none; }
.prov-item:nth-child(n+5) { border-bottom: none; }  /* row 2 has no bottom border */

.prov-item:not(.prov-item-empty):hover { background: #f5f5f5; }
.prov-item.active:not(.prov-item-empty) {
    background: #f0f0f0;
    box-shadow: inset 0 0 0 2px #000;
}

/* Empty slot — visible grid cell, no content, no interaction */
.prov-item-empty {
    cursor: default;
    background: #fafafa;
}

.prov-top {
    display: flex; align-items: baseline; gap: 6px;
    margin-bottom: 4px;
}
.prov-cardnum {
    font-size: 11px;
    font-weight: 700;
    color: #000;
    flex: 0 0 auto;
}
.prov-label {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em;
    flex: 1 1 auto;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.prov-sub {
    font-size: 9px; color: #888;
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-bottom: 6px;
}
.prov-snippet {
    font-size: 10px; color: #555;
    line-height: 1.35;
    flex: 1 1 auto;
    margin-bottom: 6px;
    /* always-visible 1-2 line snippet */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.prov-score-bar {
    height: 3px; background: #eee;
    width: 100%; position: relative;
    flex: 0 0 auto;
}
.prov-score-fill {
    position: absolute; left: 0; top: 0; bottom: 0;
    background: #000;
}

/* ── Highlights in output body ─────────────────────────────────────
   Two-tier hybrid system:
   - HARD layer (.prov-hl) — backend cosine match (citations.py ≥ 0.55).
     Persistent spans wrapped at SSE 'done' by app.js applyCitations.
     Active state = darker grey #dcdcdc.
   - SOFT layer (.prov-hl-soft) — frontend Jaccard match (provenance.js
     ≥ 0.35). Wrapped on card click, unwrapped on clear. Lighter grey
     #ececec signals lower confidence (semantic, not exact match).
   No underline either layer — grey-only per 2026-05 UX direction.
   ──────────────────────────────────────────────────────────────────── */
.prov-hl {
    transition: background 0.12s;
    cursor: default;
}
.prov-hl.on {
    background: #dcdcdc;
    padding: 1px 2px;
}

.prov-hl-soft {
    transition: background 0.12s;
    cursor: default;
}
.prov-hl-soft.on {
    background: #ececec;
    padding: 1px 2px;
}

/* Numeric suffix — always visible at end of cited paragraphs in the
   output body. Format: "(1)" or "(1, 4)" for multi-source. Set by
   applyCitations on the 'done' SSE event. */
.prov-num-suffix {
    display: inline;
    font-size: 10px;
    font-weight: 700;
    color: #000;
    margin-left: 4px;
    font-family: 'Montserrat', sans-serif;
    user-select: none;
}

/* ── Empty state (zero retrievals) ─────────────────────────────── */
.prov-empty {
    padding: 18px;
    text-align: center;
    font-size: 10px; color: #999;
    text-transform: uppercase; letter-spacing: 0.1em;
}
