/**
 * Styles for External Reference Validation Indicators
 * 
 * These styles create visual indicators for xref and tref elements
 * that show whether the external reference is still valid:
 * - Missing: Term no longer exists in external spec
 * - Changed: Definition content has been modified
 * - Error: Could not fetch external spec to validate
 * - Valid: Term exists and content matches (optional)
 */

/* ===== Base Indicator Styles ===== */

/**
 * Base styles for all validation indicators
 * Positioned inline next to the reference
 */
.external-ref-validation-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-left: 0.5em;
    font-size: 1.1em;
    vertical-align: middle;
    cursor: help;
    z-index: 10;
}

/**
 * The icon/emoji display
 * Made larger and more prominent with circular background
 */
.external-ref-validation-indicator .indicator-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8em;
    height: 1.8em;
    border-radius: 50%;
    line-height: 1;
    font-size: 1.2em;
    font-weight: bold;
    transition: all 0.2s ease-in-out;
}

/* ===== Status-specific Styles ===== */

/**
 * Missing term indicator - red/warning styling
 * Draws attention to broken references
 */
.external-ref-validation-indicator.external-ref-missing .indicator-icon {
    background-color: #db293b;
    color: #fff;
    box-shadow: 0 0 8px rgba(220, 53, 69, 0.6), inset 0 0 4px rgba(0, 0, 0, 0.2);
    animation: pulse-red 2s infinite;
}

/**
 * Changed definition indicator - orange/red styling
 * Indicates content drift that may need review
 */
.external-ref-validation-indicator.external-ref-changed .indicator-icon {
    background-color: #E03100;
    color: #fff;
    box-shadow: 0 0 10px rgba(255, 107, 53, 0.7), inset 0 0 4px rgba(0, 0, 0, 0.2);
    animation: pulse-orange 2s infinite;
}

/**
 * Error indicator - gray styling
 * Shows that validation could not be performed
 */
.external-ref-validation-indicator.external-ref-error .indicator-icon {
    background-color: #6c757d;
    color: #fff;
    box-shadow: 0 0 6px rgba(108, 117, 125, 0.5);
}

/**
 * Valid indicator - green/success styling
 * Confirms the reference is current (optional visibility)
 */
.external-ref-validation-indicator.external-ref-valid .indicator-icon {
    background-color: #218739;
    color: #fff;
    opacity: 1;
    box-shadow: 0 0 6px rgba(40, 167, 69, 0.4);
}

/**
 * Hover effect - make it even more prominent on hover
 */
.external-ref-validation-indicator:hover .indicator-icon {
    transform: scale(1.15);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
    animation-play-state: paused;
    opacity: 1;
}

/**
 * Pulse animations for attention-grabbing indicators
 */
@keyframes pulse-red {

    0%,
    100% {
        box-shadow: 0 0 8px rgba(220, 53, 69, 0.6), inset 0 0 4px rgba(0, 0, 0, 0.2);
    }

    50% {
        box-shadow: 0 0 15px rgba(220, 53, 69, 0.9), inset 0 0 4px rgba(0, 0, 0, 0.2);
    }
}

@keyframes pulse-orange {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(255, 107, 53, 0.7), inset 0 0 4px rgba(0, 0, 0, 0.2);
    }

    50% {
        box-shadow: 0 0 18px rgba(255, 107, 53, 1), inset 0 0 4px rgba(0, 0, 0, 0.2);
    }
}

/* ===== Details Popup ===== */

/**
 * Container for the details popup
 * Hidden by default, shown on hover
 */
.validation-details {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    min-width: 300px;
    max-width: 450px;
    padding: 12px;
    margin-top: 8px;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 0.85rem;
    text-align: left;
    line-height: 1.4;
    z-index: 1000;
    color: var(--bs-body-color, #212529);
}

/**
 * Arrow pointer for the popup
 */
.validation-details::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--bs-border-color, #dee2e6);
}

.validation-details::after {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid var(--bs-body-bg, #fff);
}

/**
 * Show details on click (when the active class is applied via JavaScript)
 */
.external-ref-validation-indicator.has-details.active .validation-details {
    display: block;
}

/**
 * Header section of the popup
 */
.validation-details-header {
    font-weight: 600;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

/**
 * Similarity score display
 */
.validation-similarity {
    font-size: 0.75rem;
    margin-bottom: 8px;
    padding: 4px 8px;
    background: rgba(255, 193, 7, 0.1);
    border-radius: 4px;
    text-align: center;
    font-weight: 500;
}

/* Missing indicator header - red theme */
.external-ref-missing .validation-details-header {
    color: var(--bs-danger, #dc3545);
}

/* Changed indicator header - orange theme */
.external-ref-changed .validation-details-header {
    color: var(--bs-warning, #ffc107);
}

/**
 * Content sections within the popup
 */
.validation-details-section {
    margin-bottom: 10px;
}

.validation-details-section:last-of-type {
    margin-bottom: 8px;
}

.validation-details-section strong {
    display: block;
    margin-bottom: 4px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

/**
 * Content comparison boxes
 */
.validation-content-old,
.validation-content-new {
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    max-height: 100px;
    overflow-y: auto;
    word-break: break-word;
}

/* Old content - strikethrough styling */
.validation-content-old {
    background: rgba(220, 53, 69, 0.1);
    border-left: 3px solid var(--bs-danger, #dc3545);
    text-decoration: line-through;
    opacity: 0.8;
}

/* New content - highlight styling */
.validation-content-new {
    background: rgba(25, 135, 84, 0.1);
    border-left: 3px solid var(--bs-success, #198754);
}

/**
 * Footer section with action hint
 */
.validation-details-footer {
    padding-top: 8px;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    font-size: 0.75rem;
    opacity: 0.8;
}

/* ===== Responsive Adjustments ===== */

@media (max-width: 576px) {
    .validation-details {
        min-width: 250px;
        max-width: 90vw;
        left: 0;
        transform: none;
        font-size: 0.8rem;
    }

    .validation-details::before,
    .validation-details::after {
        left: 15px;
        transform: none;
    }
}

/* ===== Dark Mode Support ===== */

[data-bs-theme="dark"] .validation-details {
    background: var(--bs-dark, #212529);
    border-color: var(--bs-gray-700, #495057);
}

[data-bs-theme="dark"] .validation-details::after {
    border-bottom-color: var(--bs-dark, #212529);
}

[data-bs-theme="dark"] .validation-content-old {
    background: rgba(220, 53, 69, 0.2);
}

[data-bs-theme="dark"] .validation-content-new {
    background: rgba(25, 135, 84, 0.2);
}

/* ===== Indicator Animation ===== */

/**
 * Subtle pulse animation for attention-drawing indicators
 */
@keyframes validation-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

.external-ref-missing .indicator-icon,
.external-ref-changed .indicator-icon {
    animation: validation-pulse 2s ease-in-out infinite;
}

/* ===== Integration with Term Styling ===== */

/**
 * Ensure indicators work well within dt elements (for trefs)
 */
dt.term-external .external-ref-validation-indicator {
    margin-left: 0.5em;
}

/**
 * Ensure indicators work well within inline text (for xrefs)
 */
a.x-term-reference+.external-ref-validation-indicator {
    margin-right: 0.25em;
}

/* ===== Print Styles ===== */

@media print {

    /* Hide interactive elements but show status text */
    .validation-details {
        display: none !important;
    }

    /* Show a simpler indicator for print */
    .external-ref-missing::after {
        content: ' [MISSING]';
        color: #dc3545;
        font-size: 0.7em;
    }

    .external-ref-changed::after {
        content: ' [CHANGED]';
        color: #ffc107;
        font-size: 0.7em;
    }
}

/* ===== External Reference Changes Report ===== */

/**
 * Container for the changes report in the settings panel
 */
.external-ref-changes-report {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 6px;
    background: var(--bs-body-bg, #fff);
}

/**
 * Table styling for the changes report
 */
.external-ref-changes-table {
    margin-bottom: 0;
    font-size: 0.8rem;
}

.external-ref-changes-table th {
    position: sticky;
    top: 0;
    background: var(--bs-secondary-bg, #e9ecef);
    border-bottom: 2px solid var(--bs-border-color, #dee2e6);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.5rem 0.4rem;
}

.external-ref-changes-table td {
    padding: 0.4rem;
    vertical-align: middle;
}

/**
 * Column widths
 */
.external-ref-changes-table .col-status {
    width: 40px;
    text-align: center;
}

.external-ref-changes-table .col-term {
    min-width: 80px;
    max-width: 120px;
}

.external-ref-changes-table .col-spec {
    min-width: 60px;
    max-width: 100px;
}

.external-ref-changes-table .col-similarity {
    width: 50px;
    text-align: center;
}

.external-ref-changes-table .col-action {
    width: 40px;
    text-align: center;
}

/**
 * Status icons in the table
 */
.status-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5em;
    height: 1.5em;
    font-size: 1rem;
}

/**
 * Term name styling
 */
.term-name {
    display: block;
    font-weight: 500;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
}

/**
 * Spec badge styling
 */
.spec-badge {
    display: inline-block;
    padding: 0.15em 0.4em;
    font-size: 0.7rem;
    background: var(--bs-secondary-bg, #e9ecef);
    border-radius: 4px;
    word-break: break-word;
}

/**
 * Similarity value styling
 */
.similarity-value {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--bs-warning, #ffc107);
}

.similarity-na {
    color: var(--bs-secondary, #6c757d);
    font-size: 0.8rem;
}

/**
 * Go to reference button
 */
.go-to-ref-btn {
    padding: 0.15rem 0.35rem;
    font-size: 0.75rem;
    line-height: 1;
}

/**
 * Row highlighting based on status
 */
.external-ref-changes-table tr.result-changed {
    background-color: rgba(255, 193, 7, 0.08);
}

.external-ref-changes-table tr.result-missing {
    background-color: rgba(220, 53, 69, 0.08);
}

.external-ref-changes-table tr.result-error {
    background-color: rgba(108, 117, 125, 0.08);
}

.external-ref-changes-table tr:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/**
 * Highlight animation when scrolling to a reference
 */
@keyframes highlight-flash {

    0%,
    100% {
        background-color: transparent;
    }

    50% {
        background-color: rgba(255, 193, 7, 0.3);
    }
}

.highlight-ref {
    animation: highlight-flash 0.5s ease-in-out 3;
    outline: 2px solid var(--bs-warning, #ffc107);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ===== Dark Mode Support for Report ===== */

[data-bs-theme="dark"] .external-ref-changes-report {
    border-color: var(--bs-gray-700, #495057);
}

[data-bs-theme="dark"] .external-ref-changes-table th {
    background: var(--bs-gray-800, #343a40);
}

[data-bs-theme="dark"] .spec-badge {
    background: var(--bs-gray-700, #495057);
}

[data-bs-theme="dark"] .external-ref-changes-table tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

[data-bs-theme="dark"] .external-ref-changes-table tr.result-changed {
    background-color: rgba(255, 193, 7, 0.15);
}

[data-bs-theme="dark"] .external-ref-changes-table tr.result-missing {
    background-color: rgba(220, 53, 69, 0.15);
}

[data-bs-theme="dark"] .external-ref-changes-table tr.result-error {
    background-color: rgba(108, 117, 125, 0.15);
}

[data-bs-theme="dark"] .highlight-ref {
    background-color: rgba(255, 193, 7, 0.4);
}