/* ============================================================
   RESULTS.CSS — Two-pane layout, document cards, fragments
   ============================================================ */

/* --- Results container (flex child of .search-page) --- */
body.in-results-mode #results-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* --- Two-pane grid --- */
.search-results-layout {
    display: grid;
    grid-template-columns: 480px 1fr;
    gap: 20px;
    padding: 8px 28px 16px;
    flex: 1;
    min-height: 0;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* --- Results list pane (left) --- */
.results-list-pane {
    overflow-y: auto;
    min-height: 0;
    padding-right: 12px;
    position: relative;
}
.results-list-pane {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}
.results-list-pane:hover {
    scrollbar-color: #cbd5e1 transparent;
}
.results-list-pane::-webkit-scrollbar { width: 6px; background: transparent; }
.results-list-pane::-webkit-scrollbar-track { background: transparent; }
.results-list-pane::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 3px;
}
.results-list-pane:hover::-webkit-scrollbar-thumb { background: #cbd5e1; }
.results-list-pane::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Dimming overlay for filter-change loading */
#results-list { position: relative; }
#results-list::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.55);
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}
#results-list.is-loading { pointer-events: none; }
#results-list.is-loading::after { opacity: 1; }

/* ============================================================
   DOCUMENT CARD
   ============================================================ */
.document-card {
    background: #fff;
    border-radius: 10px;
    padding: 16px 18px 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    border: 1px solid transparent;
}
.document-card:hover {
    background: #f8fafc;
    box-shadow: 0 1px 4px rgba(15,23,42,0.06);
}
.document-card.selected {
    background: #eff6ff;
    border-color: #bfdbfe;
}

/* Doc header */
.doc-header-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}
.doc-title {
    font-size: 14px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.4;
    flex: 1;
    text-decoration: none;
}
.doc-title:hover { text-decoration: none; }
.doc-type-tag {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    flex-shrink: 0;
    margin-top: 2px;
}
.doc-type-tag.legal { background: #dcfce7; color: #166534; }
.doc-type-tag.sio { background: #dbeafe; color: #1e40af; }
.doc-type-tag.cie { background: #ffedd5; color: #9a3412; }

/* Doc meta */
.doc-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.doc-id {
    font-size: 12px;
    font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    color: #94a3b8;
    letter-spacing: -0.3px;
}
.doc-date {
    font-size: 12px;
    color: #94a3b8;
}
.status-pill {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}
.status-pill.in-force {
    background: #dcfce7;
    color: #166534;
}
.status-pill.repealed {
    background: #fee2e2;
    color: #991b1b;
}

/* Legacy badge compat (maps old trust-badge to new status-pill) */
.trust-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.trust-badge.in-force { background: #dcfce7; color: #166534; }
.trust-badge.repealed { background: #fee2e2; color: #991b1b; }
.trust-badge.consolidated { background: #dbeafe; color: #1e40af; }

/* ============================================================
   FRAGMENTS
   ============================================================ */
.doc-fragments {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.fragment {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 0 12px;
    padding: 10px 12px;
    margin: 0 -12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.1s;
    position: relative;
}
.fragment:hover { background: #f1f5f9; }
.fragment.active { background: #dbeafe; }

.fragment-locator {
    grid-column: 1;
    grid-row: 1;
    font-size: 13px;
    color: #2563eb;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Confidence indicator */
.confidence-indicator {
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: start;
    display: flex;
    align-items: center;
    gap: 5px;
    position: relative;
    cursor: help;
    padding: 12px 4px;
    margin: -8px -4px;
}
.confidence-bar {
    height: 4px;
    border-radius: 2px;
    background: #e2e8f0;
    transition: transform 0.15s;
}
.confidence-indicator:hover .confidence-bar { transform: scaleY(1.5); }
.confidence-bar.high { background: #2563eb; width: 24px; }
.confidence-bar.medium { background: #93c5fd; width: 18px; }
.confidence-bar.low { background: #cbd5e1; width: 12px; }

/* Confidence tooltip */
.confidence-tooltip {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: #fff;
    color: #475569;
    font-size: 12px;
    line-height: 1.5;
    padding: 10px 14px;
    border-radius: 8px;
    width: 220px;
    z-index: 50;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1), 0 1px 3px rgba(0,0,0,0.06);
    pointer-events: none;
}
.confidence-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    right: 8px;
    border: 6px solid transparent;
    border-bottom-color: #e2e8f0;
}
.confidence-tooltip::after {
    content: '';
    position: absolute;
    bottom: 100%;
    right: 9px;
    border: 5px solid transparent;
    border-bottom-color: #fff;
}
.confidence-indicator:hover .confidence-tooltip { display: block; }
.confidence-tooltip .tooltip-level {
    font-weight: 600;
    margin-bottom: 4px;
}
.confidence-tooltip .tooltip-level.high { color: #2563eb; }
.confidence-tooltip .tooltip-level.medium { color: #3b82f6; }
.confidence-tooltip .tooltip-level.low { color: #64748b; }

/* Legacy badge compat */
.confidence-badge {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    cursor: help;
}
.confidence-high { background: #dbeafe; color: #1e40af; }
.confidence-medium { background: #e0f2fe; color: #0369a1; }
.confidence-low { background: #f1f5f9; color: #64748b; }

/* Fragment snippet */
.fragment-snippet {
    grid-column: 1;
    grid-row: 2;
    font-size: 13px;
    color: #475569;
    line-height: 1.5;
    margin-top: 2px;
    max-height: 1.5em;
    overflow: hidden;
    transition: max-height 0.2s ease-out;
}
.fragment.active .fragment-snippet {
    max-height: 12em;
}

/* Fragment actions (animated reveal) */
.fragment-actions {
    grid-column: 1 / -1;
    grid-row: 3;
    display: flex;
    gap: 12px;
    align-items: center;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.2s ease-out, opacity 0.15s ease-out;
    padding: 0;
}
.fragment.active .fragment-actions {
    max-height: 28px;
    opacity: 1;
    padding-top: 6px;
    overflow: visible;
}
.fragment-action {
    font-size: 12px;
    color: #2563eb;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    margin: -2px -6px;
    border-radius: 4px;
    text-decoration: none;
    transition: background 0.1s;
}
.fragment-action:hover { background: #eff6ff; }

/* Legacy fragment-header (compat for old template) */
.fragment-header {
    display: contents;
}

/* Hits expand/collapse */
.hits-collapsed .fragment:nth-child(n+4) { display: none; }
.hits-toggle {
    font-size: 12px;
    color: #2563eb;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 12px;
    margin: 2px -12px 0;
    border-radius: 6px;
    text-align: left;
}
.hits-toggle:hover { background: #f1f5f9; }

/* Card footer */
.doc-card-footer {
    margin: 10px -18px -12px;
    padding: 10px 18px;
    border-top: 1px solid #e8edf2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.doc-open-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12.5px;
    font-weight: 500;
    color: #2563eb;
    text-decoration: none;
    transition: color 0.15s;
}
.doc-open-link:hover { color: #1d4ed8; }
.doc-open-link i { font-size: 11px; }
.doc-more-info {
    font-size: 11px;
    font-weight: 500;
    color: #2563eb;
    background: #eff6ff;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Legacy doc-footer (maps old template) */
.doc-footer {
    margin: 8px -18px -12px;
    padding: 8px 18px;
    border-top: 1px solid #f1f5f9;
    text-align: center;
}
.doc-link {
    font-size: 12px;
    color: #64748b;
    text-decoration: none;
    transition: color 0.15s;
}
.doc-link:hover { color: #2563eb; }
.doc-more-info {
    font-size: 11px;
    color: #94a3b8;
    margin-left: 6px;
}

/* Legacy doc-header (compat - old template still uses this wrapper) */
.doc-header { margin-bottom: 8px; }
.doc-title-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 4px;
}
.doc-source-badge {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    flex-shrink: 0;
}
.doc-source-badge.legal { background: #dcfce7; color: #166534; }
.doc-source-badge.sio { background: #dbeafe; color: #1e40af; }
.doc-source-badge.cie { background: #ffedd5; color: #9a3412; }
.doc-badges {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

/* Query term highlighting */
.highlight {
    background: #fef08a;
    padding: 0 2px;
    border-radius: 2px;
}
.highlight-synonym {
    background: #dcfce7;
    border-bottom: 1px dotted #22c55e;
}

/* Load more */
.load-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 20px;
    margin-top: 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    color: #2563eb;
    cursor: pointer;
    transition: all 0.15s;
}
.load-more-btn:hover {
    background: #f8fafc;
    border-color: #2563eb;
}
#load-more-container { margin-top: 8px; }

/* No results */
.no-results {
    text-align: center;
    padding: 40px;
    color: #64748b;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
    .search-results-layout { grid-template-columns: 1fr; }
    .preview-pane { display: none; }
    .results-list-pane { overflow: visible; padding-right: 0; }
    .document-card { cursor: default; }
    .fragment { cursor: default; }
    .fragment-actions { max-height: 40px; opacity: 1; margin-top: 6px; }
    .doc-footer { display: block; }
}
