/**
 * Sources Panel CSS
 *
 * Styles for the "View Sources" toggle and expandable source passages
 * in policy document conversations.
 */

/* Sources Section Container */
.sources-section {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
}

/* Sources Toggle Button */
.sources-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface-secondary, #f5f5f5);
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary, #666);
    cursor: pointer;
    transition: all 0.2s ease;
}

.sources-toggle:hover {
    background: var(--surface-tertiary, #eee);
    color: var(--text-primary, #333);
    border-color: var(--border-color-hover, rgba(0, 0, 0, 0.2));
}

.sources-toggle:focus-visible {
    outline: 2px solid var(--focus-ring-color, #0066cc);
    outline-offset: 2px;
}

.sources-toggle-icon {
    transition: transform 0.2s ease;
}

.sources-toggle[aria-expanded="true"] .sources-toggle-icon {
    transform: rotate(180deg);
}

.sources-toggle-text {
    font-family: inherit;
}

/* Sources Panel */
.sources-panel {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--surface-secondary, #f9f9f9);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
}

.sources-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Individual Source Item */
.source-item {
    padding: 0.75rem;
    background: var(--surface-primary, #fff);
    border-radius: 0.375rem;
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.source-item:hover {
    border-color: var(--border-color-hover, rgba(0, 0, 0, 0.15));
}

.source-item[data-expanded="true"] {
    border-color: var(--accent-color, #0066cc);
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.1);
}

/* Source Header */
.source-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.source-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

/* Tier Badges */
.source-tier {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-radius: 0.25rem;
}

.source-tier.tier-primary {
    background: var(--tier-primary-bg, #e6f4ea);
    color: var(--tier-primary-text, #1e7e34);
}

.source-tier.tier-secondary {
    background: var(--tier-secondary-bg, #fff3e0);
    color: var(--tier-secondary-text, #e65100);
}

.source-tier.tier-tertiary {
    background: var(--tier-tertiary-bg, #e3f2fd);
    color: var(--tier-tertiary-text, #1565c0);
}

/* Heading Path */
.source-path {
    font-size: 0.75rem;
    color: var(--text-secondary, #666);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Page Number */
.source-page {
    font-size: 0.75rem;
    color: var(--text-tertiary, #999);
    font-weight: 500;
}

/* Relevance Score */
.source-score {
    flex-shrink: 0;
}

.source-relevance {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--surface-tertiary, #f0f0f0);
    border-radius: 0.25rem;
    color: var(--text-secondary, #666);
}

/* Source Preview Text */
.source-preview {
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary, #333);
    margin-bottom: 0.5rem;
    /* Clamp to 3 lines */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Expand Button */
.source-expand-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--accent-color, #0066cc);
    background: transparent;
    border: 1px solid var(--accent-color, #0066cc);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.source-expand-btn:hover {
    background: var(--accent-color, #0066cc);
    color: #fff;
}

.source-expand-btn:focus-visible {
    outline: 2px solid var(--focus-ring-color, #0066cc);
    outline-offset: 2px;
}

.source-expand-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.expand-icon {
    transition: transform 0.2s ease;
}

/* Full Text Container */
.source-full-text {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
}

/* Context Text (before/after) */
.source-context {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-tertiary, #888);
    padding: 0.5rem;
    background: var(--surface-secondary, #f9f9f9);
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
}

.source-context.context-before {
    border-left: 3px solid var(--border-color, rgba(0, 0, 0, 0.15));
}

.source-context.context-after {
    border-right: 3px solid var(--border-color, rgba(0, 0, 0, 0.15));
    margin-top: 0.5rem;
    margin-bottom: 0;
}

/* Main Text (highlighted) */
.source-main-text {
    font-size: 0.9375rem;
    line-height: 1.7;
    color: var(--text-primary, #333);
    padding: 0.75rem;
    background: var(--highlight-bg, #fffde7);
    border-radius: 0.375rem;
    border: 1px solid var(--highlight-border, #fff59d);
}

/* Attribution */
.source-attribution {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border-color, rgba(0, 0, 0, 0.1));
    font-size: 0.75rem;
    color: var(--text-secondary, #666);
    font-style: italic;
}

/* Error State */
.source-error {
    padding: 0.75rem;
    background: var(--error-bg, #ffebee);
    color: var(--error-text, #c62828);
    border-radius: 0.25rem;
    font-size: 0.875rem;
    margin: 0;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .sources-toggle {
        background: var(--surface-secondary-dark, #2a2a2a);
        border-color: var(--border-color-dark, rgba(255, 255, 255, 0.1));
        color: var(--text-secondary-dark, #aaa);
    }

    .sources-toggle:hover {
        background: var(--surface-tertiary-dark, #333);
        color: var(--text-primary-dark, #eee);
    }

    .sources-panel {
        background: var(--surface-secondary-dark, #1a1a1a);
        border-color: var(--border-color-dark, rgba(255, 255, 255, 0.1));
    }

    .source-item {
        background: var(--surface-primary-dark, #222);
        border-color: var(--border-color-dark, rgba(255, 255, 255, 0.08));
    }

    .source-preview,
    .source-main-text {
        color: var(--text-primary-dark, #eee);
    }

    .source-context {
        color: var(--text-tertiary-dark, #777);
        background: var(--surface-tertiary-dark, #1a1a1a);
    }

    .source-main-text {
        background: var(--highlight-bg-dark, #3d3d00);
        border-color: var(--highlight-border-dark, #666600);
    }
}

/* Mobile Responsive */
@media (max-width: 640px) {
    .sources-section {
        margin-top: 0.75rem;
        padding-top: 0.5rem;
    }

    .sources-toggle {
        font-size: 0.8125rem;
        padding: 0.375rem 0.625rem;
    }

    .sources-panel {
        padding: 0.5rem;
    }

    .source-item {
        padding: 0.625rem;
    }

    .source-header {
        flex-direction: column;
        gap: 0.375rem;
    }

    .source-meta {
        width: 100%;
    }

    .source-path {
        max-width: 100%;
        white-space: normal;
    }

    .source-preview {
        font-size: 0.8125rem;
        -webkit-line-clamp: 4;
    }

    .source-main-text {
        font-size: 0.875rem;
        padding: 0.625rem;
    }
}

/* Animation for panel reveal */
.sources-panel:not([hidden]) {
    animation: sourcesReveal 0.2s ease-out;
}

@keyframes sourcesReveal {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Animation for source expansion */
.source-full-text:not([hidden]) {
    animation: sourceExpand 0.25s ease-out;
}

@keyframes sourceExpand {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}
