.citation-link {
    color: #0369a1;
    text-decoration: underline;
    cursor: pointer;
    font-weight: 600;
    transition: color 0.2s ease;
}

.citation-link:hover {
    color: #075985;
    text-decoration: underline;
}

/* Hover preview for [1], [2] citations */
.citation {
    position: relative;
    cursor: pointer;
    color: #2563eb;
    font-weight: 500;
    text-decoration: underline;
    text-decoration-style: dotted;
    transition: color 0.2s ease;
}

.citation:hover,
.citation:focus {
    color: #1d4ed8;
    outline: none;
}

.citation::after {
    content: attr(data-url);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: #111827;
    color: #fff;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 100;
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    word-break: break-all;
}

.citation::before {
    content: '';
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #111827;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 101;
}

.citation:hover::after,
.citation:focus::after,
.citation:hover::before,
.citation:focus::before {
    opacity: 1;
}

/* Citation excerpt modal */
.citation-excerpt-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

.citation-excerpt-modal-overlay.open {
    display: flex;
}

.citation-excerpt-modal {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 36rem;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.citation-excerpt-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--neutral-200);
    flex-shrink: 0;
}

.citation-excerpt-modal-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--neutral-900);
}

.citation-excerpt-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--neutral-500);
    cursor: pointer;
    padding: 0.25rem;
}

.citation-excerpt-modal-close:hover {
    color: var(--neutral-900);
}

.citation-excerpt-modal-body {
    flex: 1;
    overflow: auto;
    padding: 1rem 1.25rem;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--neutral-800);
}

.citation-excerpt-modal-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--neutral-200);
    flex-shrink: 0;
}

.citation-excerpt-modal-link {
    color: var(--color-primary);
    font-weight: 500;
    text-decoration: none;
}

.citation-excerpt-modal-link:hover {
    text-decoration: underline;
}

/* Inline excerpt under message */
.citation-excerpt-inline {
    display: none;
    width: 100%;
    margin-top: 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--neutral-200);
    background: var(--neutral-50);
    overflow: hidden;
}

.citation-excerpt-inline.open {
    display: block;
}

.citation-excerpt-inline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--neutral-200);
    background: #fff;
}

.citation-excerpt-inline-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--neutral-800);
}

.citation-excerpt-inline-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--neutral-500);
    cursor: pointer;
    padding: 0.15rem;
}

.citation-excerpt-inline-close:hover {
    color: var(--neutral-900);
}

.citation-excerpt-inline-body {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--neutral-800);
    max-height: 16rem;
    overflow-y: auto;
}

.citation-excerpt-inline-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--neutral-200);
    background: #fff;
}

.citation-excerpt-inline-toggle-frame {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.citation-excerpt-inline-toggle-frame:hover {
    text-decoration: underline;
}

.citation-excerpt-inline-toggle-frame[aria-pressed="true"] {
    color: var(--neutral-600);
}

.citation-excerpt-inline-link {
    color: var(--color-primary);
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
}

.citation-excerpt-inline-link:hover {
    text-decoration: underline;
}

.citation-excerpt-inline-iframe {
    display: block;
    width: 100%;
    height: 360px;
    min-height: 200px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--neutral-100);
}

/* Inline citation body with iframe */
.citation-inline {
    display: inline;
}

.citation-inline-trigger {
    display: inline;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
    font: inherit;
    color: var(--color-primary);
    text-decoration: underline;
    cursor: pointer;
    text-underline-offset: 2px;
}

.citation-inline-trigger:hover {
    color: var(--color-primary-hover);
}

.citation-inline-body {
    display: block;
    margin: var(--space-2) 0 var(--space-4);
    padding: var(--space-2);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-sm);
    background: var(--neutral-50);
}

.citation-inline-iframe {
    display: block;
    width: 100%;
    height: 320px;
    min-height: 200px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--neutral-100);
}

/* Sources collapse styling */
.message.sources-collapse {
    margin-top: 0.5rem;
}

.sources-collapse details {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 0;
    margin: 0.5rem 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

.sources-collapse details:hover {
    border-color: #94a3b8;
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.15);
}

.sources-collapse details[open] {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border-color: #3b82f6;
}

.sources-collapse summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 600;
    color: #334155;
    list-style: none;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.sources-collapse summary::-webkit-details-marker {
    display: none;
}

.sources-collapse summary::before {
    content: "▶";
    font-size: 0.8em;
    transition: transform 0.2s ease;
    color: #64748b;
}

.sources-collapse details[open] summary::before {
    transform: rotate(90deg);
    color: #3b82f6;
}

.sources-content {
    padding: 0.5rem 1rem 1rem;
    line-height: 1.8;
    font-size: 0.875rem;
    color: #475569;
}

.sources-content a {
    color: #0369a1;
    text-decoration: none;
    font-weight: 500;
}

.sources-content a:hover {
    text-decoration: underline;
    color: #075985;
}

.sources-collapse details > *:not(summary) {
    padding: 0 1rem 1rem;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    color: #475569;
    font-size: 0.9em;
    line-height: 1.5;
}

.sources-collapse details[open] > *:not(summary) {
    animation: sourcesExpand 0.3s ease;
}

@keyframes sourcesExpand {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

