/* ============================================================================
   MATCH VIEWER COMPONENT
   ============================================================================
   
   Display component for text reuse matches between documents.
   Shows expandable match cards with source/target sides, similarity scores,
   and text context. Includes selection controls and export functionality.
   
   ============================================================================ */

/* ============================================================================
   MAIN CONTAINER
   ============================================================================ */

.match-viewer {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding-bottom: calc(var(--footer-height) + 20px);  /* Space for fixed footer */
}

.match-viewer-header {
    text-align: center;
    margin-bottom: 20px;
}

.match-count {
    color: var(--color-text-secondary);
    font-size: 1.125rem;
}


/* ============================================================================
   MATCH LIST
   ============================================================================ */

.match-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.match-item {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}


/* ============================================================================
   MATCH HEADER (Expandable)
   ============================================================================ */

.match-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    cursor: pointer;
    background: #f8f9fa;
    border-bottom: 1px solid var(--color-gray-light);
    transition: background-color 0.15s ease;
}

.match-header:hover {
    background: var(--color-gray-light);
}

/* Match preview text */
.match-preview {
    flex: 1;
    color: var(--color-text-primary);
    font-size: 0.9375rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.match-preview.rtl {
    direction: rtl;
    text-align: start;
}

/* Source and target metadata containers */
.match-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    flex-shrink: 0;
}

.source-meta {
    background: var(--color-source-tint);
    border: 1px solid var(--color-source-border);
}

.target-meta {
    background: var(--color-target-tint);
    border: 1px solid var(--color-target-border);
}

/* Death year styling */
.match-meta .death-year {
    color: var(--color-text-secondary);
    font-size: 0.75rem;
}

/* Author styling */
.match-meta .author {
    font-weight: 600;
    color: var(--color-text-primary);
}

.match-meta .author.unknown {
    font-weight: 400;
    font-style: italic;
    color: var(--color-text-secondary);
}

/* Title styling */
.match-meta .title {
    color: var(--color-text-secondary);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Similarity badge */
.similarity {
    background: var(--color-primary);
    color: var(--color-white);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* Qur'anic badge — match contains verbatim Qur'an (quran_q >= 0.70). Emerald,
   distinct from the primary-coloured similarity chip. */
.quran-badge {
    background: #2f7d55;
    color: #fff;
    padding: 3px 9px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}
[data-theme="night-scholar"] .quran-badge {
    background: #3d9068;
}

/* Checkbox — desert accent when checked (was the browser-default blue) */
.match-header input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    accent-color: var(--color-primary);
}


/* ============================================================================
   MATCH BODY (Expanded Content)
   ============================================================================ */

.match-body {
    padding: 20px;
}

.match-side {
    margin-bottom: 20px;
    padding: 15px;
    border-radius: var(--radius-md);
    background: #f8f9fa;
}

.match-side.source {
    border-inline-end: 4px solid var(--color-source);
}

.match-side.target {
    border-inline-end: 4px solid var(--color-target);
}

.match-side-header {
    margin-bottom: 10px;
    font-size: 1rem;
    direction: rtl;
}

.match-side-header a {
    color: inherit;
    text-decoration: none;
    display: block;
    padding: 5px;
    border-radius: var(--radius-sm);
    transition: var(--transition-bg);
}

.match-side-header a:hover {
    background: var(--color-sand-light);
    text-decoration: underline;
}

.jump-icon {
    color: var(--color-primary);
    font-size: 0.875rem;
}

.year, .page-num {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}


/* ============================================================================
   MATCH TEXT DISPLAY
   ============================================================================ */

.match-text-container {
    font-size: 1.125rem;
    line-height: 2;
    padding: 10px;
}

.match-text-container .context {
    color: var(--color-text-secondary);
}

.match-text-container .match-text {
    color: #8b0000;  /* TODO: Add --color-match-text-red to variables */
    font-weight: 700;
    background: rgba(139, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 3px;
}

/* Standalone match text display */
.match-text {
    font-size: 1.1em;
    line-height: 1.8;
    padding: 1em;
    background: #f9f9f9;
    border-radius: var(--radius-sm);
    font-family: var(--font-primary);
}

.match-text.rtl {
    direction: rtl;
    text-align: start;
}

.context-before,
.context-after {
    color: var(--color-gray-note);
}

.highlighted-match {
    background-color: #fff3cd;  /* TODO: Add --color-match-highlight to variables */
    font-weight: 600;
    color: #000;
    padding: 2px 0;
    border-bottom: 2px solid #ffc107;  /* TODO: Add --color-match-border to variables */
}


/* ============================================================================
   MATCH ACTIONS (Compare Button)
   ============================================================================ */

.match-actions {
    display: flex;
    justify-content: center;
    padding: var(--space-4);
    border-top: 1px solid var(--color-gray-light);
    margin-top: var(--space-4);
}

.compare-button {
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    padding: var(--space-2) var(--space-5);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-primary);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    transition: var(--transition-all);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.compare-button:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.compare-button:active {
    transform: translateY(0);
}


/* ============================================================================
   LOAD MORE / PAGINATION
   ============================================================================ */

.load-more {
    text-align: center;
    margin-top: 30px;
}

.load-more button {
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    padding: 12px 30px;
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    font-family: var(--font-primary);
}

.load-more button:hover {
    background: var(--color-primary-dark);
}

.load-more button:disabled {
    background: var(--color-gray-medium);
    cursor: not-allowed;
}

.load-more button .loading-spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
    display: inline-block;
    vertical-align: middle;
    margin-inline-end: 4px;
}

.end-of-results {
    text-align: center;
    padding: 30px;
    color: var(--color-text-secondary);
    font-style: italic;
}

/* Prompt shown when no selective filter is active (the backend refuses
   unfiltered browsing of the billions-row match store) */
.needs-filter-prompt {
    text-align: center;
    padding: 48px 24px;
    margin: 24px auto;
    max-width: 480px;
    border: 1px dashed var(--color-border, #ccc);
    border-radius: 8px;
    color: var(--color-text-secondary);
}

.needs-filter-prompt h3 {
    color: var(--color-text-primary, inherit);
    margin-bottom: 12px;
}

.needs-filter-prompt p {
    margin-bottom: 20px;
    line-height: 1.7;
}


/* ============================================================================
   LOADING SPINNER
   ============================================================================ */

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-gray-light);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}


/* ============================================================================
   SELECTION CONTROLS
   ============================================================================ */

.selection-controls {
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
}

.selection-controls label {
    font-size: 1rem;
    cursor: pointer;
}

.selected-count {
    color: var(--color-primary);
    font-weight: 600;
}

.export-button {
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    padding: 8px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-primary);
    font-size: 1rem;
}

.export-button:hover:not(:disabled) {
    background: var(--color-primary-dark);
}

.export-button:disabled {
    background: var(--color-gray-medium);
    cursor: not-allowed;
    opacity: 0.6;
}


/* ============================================================================
   PAGINATION (replaces the old "load more")
   ============================================================================ */

.matches-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 20px 16px 28px;
    direction: rtl;
}

.matches-pagination .page-numbers {
    display: flex;
    align-items: center;
    gap: 4px;
}

.matches-pagination .page-nav-button,
.matches-pagination .page-number {
    min-width: 36px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--color-border-primary, #d4c4a8);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    color: var(--color-text-primary);
    font-family: var(--font-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.matches-pagination .page-nav-button:hover:not(:disabled),
.matches-pagination .page-number:hover:not(:disabled) {
    background: var(--color-sand-light, #f5f0e8);
    border-color: var(--color-primary);
}

.matches-pagination .page-number.current {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white);
    font-weight: 700;
    cursor: default;
}

.matches-pagination .page-nav-button:disabled,
.matches-pagination .page-number:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.matches-pagination .page-ellipsis {
    color: var(--color-text-muted);
    padding: 0 2px;
    user-select: none;
}

.matches-pagination .page-info {
    margin-inline-start: 8px;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    font-family: var(--font-primary);
}

/* "Jump to page" control */
.matches-pagination .page-jump {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-inline-start: 8px;
}

.matches-pagination .page-jump label {
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    font-family: var(--font-primary);
    white-space: nowrap;
}

.matches-pagination .page-jump-input {
    width: 58px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--color-border-primary, #d4c4a8);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    color: var(--color-text-primary);
    font-family: var(--font-primary);
    text-align: center;
    direction: ltr;
    -moz-appearance: textfield;
}

.matches-pagination .page-jump-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.12);
}

.matches-pagination .page-jump-go {
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: var(--color-white);
    font-family: var(--font-primary);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-all);
}

.matches-pagination .page-jump-go:hover:not(:disabled) {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

.matches-pagination .page-jump-go:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}


/* ============================================================================
   MATCH VIEWER FOOTER (Fixed at Bottom)
   ============================================================================ */

.match-viewer-footer {
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    width: 100%;
    height: var(--footer-height);
    z-index: var(--z-nav);
    background: var(--color-sand-footer);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    border-top: 2px solid var(--color-primary);
}

/* Scoped to the match-viewer footer. Left unscoped, `max-width: 1400px;
   margin: 0 auto` leaked onto the viz-page footers (network / sankey /
   heatmap), clamping their full-width even-spacing on wide monitors. */
.match-viewer-footer .footer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    max-width: var(--content-max-width);
    margin: 0 auto;
    height: 100%;
    gap: 1rem;
}

.footer-left,
.footer-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.footer-center {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* حفظ button — filled amber, identical to the document viewer's save button
   (.footer-nav-save .footer-button). Without this rule the shared
   SaveHistoryButtons `.footer-button` rendered as a bare browser button here,
   because `.footer-button` is scoped per module and the match viewer had no
   copy. */
.match-viewer-footer .footer-save-group .footer-button {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: var(--font-weight-medium);
    font-family: var(--font-primary);
    transition: var(--transition-bg);
}

.match-viewer-footer .footer-save-group .footer-button:hover {
    background: var(--color-primary-dark);
}

.select-all-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    font-family: var(--font-primary);
}

.select-all-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.selected-count.select-all-active {
    color: var(--color-primary);
    font-weight: 600;
}


/* ============================================================================
   FOOTER RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 768px) {
    .match-viewer-footer {
        height: auto;
        padding: 0.5rem 0;
    }

    .footer-controls {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
    }

    .footer-left,
    .footer-center,
    .footer-right {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .select-all-label {
        font-size: 0.875rem;
    }

    .export-button {
        padding: 6px 16px;
        font-size: 0.875rem;
    }
}