/**
 * Unified Notes Styles - Handles both endnotes and footnotes
 * Replaces inline-endnotes.css with improved design and accessibility
 */

/* Note reference badges (clickable elements) */
.note-ref,
.footnote-ref,
.endnote-ref,
sup[data-ref],
span[data-note] {
    display: inline;
    color: var(--color-primary, #f39c12);
    font-weight: 600;
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    text-decoration: none;
    font-size: 0.85em;
    vertical-align: super;
    line-height: 1;
    border: 1px solid transparent;
    position: relative;
}

.note-ref:hover,
.footnote-ref:hover,
.endnote-ref:hover,
sup[data-ref]:hover,
span[data-note]:hover {
    background: var(--color-primary, #f39c12);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(243, 156, 18, 0.3);
}

.note-ref.active,
.footnote-ref.active,
.endnote-ref.active,
sup[data-ref].active,
span[data-note].active {
    background: var(--color-primary, #f39c12);
    color: white;
    box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.4);
}

.note-ref:focus,
.footnote-ref:focus,
.endnote-ref:focus,
sup[data-ref]:focus,
span[data-note]:focus {
    outline: 2px solid var(--color-primary, #f39c12);
    outline-offset: 2px;
    border-color: var(--color-primary, #f39c12);
}

/* Converted text references get special styling */
.converted-ref {
    background: rgba(243, 156, 18, 0.1);
    border: 1px solid rgba(243, 156, 18, 0.3);
}

/* Tooltip container */
.note-tooltip {
    position: absolute;
    z-index: 10000;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
    max-width: 400px;
    min-width: 300px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(0.95);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.note-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Tooltip header */
.note-tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--color-primary, #f39c12), var(--color-secondary, #e74c3c));
    color: white;
    font-weight: 600;
}

.note-tooltip-number {
    font-size: 0.95rem;
    font-weight: 700;
}

.note-tooltip-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    transition: all 0.2s ease;
    font-family: Arial, sans-serif;
}

.note-tooltip-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.note-tooltip-close:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Tooltip content */
.note-tooltip-content {
    padding: 16px;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary, #333);
    max-height: 250px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--color-primary, #f39c12) transparent;
}

.note-tooltip-content::-webkit-scrollbar {
    width: 6px;
}

.note-tooltip-content::-webkit-scrollbar-track {
    background: transparent;
}

.note-tooltip-content::-webkit-scrollbar-thumb {
    background: var(--color-primary, #f39c12);
    border-radius: 3px;
}

.note-tooltip-content::-webkit-scrollbar-thumb:hover {
    background: var(--color-secondary, #e74c3c);
}

/* Dark theme support */
[data-theme="dark"] .note-tooltip {
    background: var(--bg-primary, #1a1a2e);
    border-color: var(--border-color, #333);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .note-tooltip-content {
    color: var(--text-primary, #e0e0e0);
}

[data-theme="dark"] .note-ref,
[data-theme="dark"] .footnote-ref,
[data-theme="dark"] .endnote-ref,
[data-theme="dark"] sup[data-ref],
[data-theme="dark"] span[data-note] {
    color: var(--color-primary, #f39c12);
}

[data-theme="dark"] .note-ref:hover,
[data-theme="dark"] .footnote-ref:hover,
[data-theme="dark"] .endnote-ref:hover,
[data-theme="dark"] sup[data-ref]:hover,
[data-theme="dark"] span[data-note]:hover {
    background: var(--color-primary, #f39c12);
    color: white;
}

[data-theme="dark"] .converted-ref {
    background: rgba(243, 156, 18, 0.15);
    border-color: rgba(243, 156, 18, 0.4);
}

/* Sepia theme */
[data-theme="sepia"] .note-ref,
[data-theme="sepia"] .footnote-ref,
[data-theme="sepia"] .endnote-ref,
[data-theme="sepia"] sup[data-ref],
[data-theme="sepia"] span[data-note] {
    color: var(--color-primary, #8b4513);
}

[data-theme="sepia"] .note-ref:hover,
[data-theme="sepia"] .footnote-ref:hover,
[data-theme="sepia"] .endnote-ref:hover,
[data-theme="sepia"] sup[data-ref]:hover,
[data-theme="sepia"] span[data-note]:hover {
    background: var(--color-primary, #8b4513);
    color: white;
}

[data-theme="sepia"] .note-tooltip {
    background: #faf7f0;
    border-color: #d4c4a8;
}

[data-theme="sepia"] .note-tooltip-content {
    color: #3c2e26;
}

[data-theme="sepia"] .converted-ref {
    background: rgba(139, 69, 19, 0.1);
    border-color: rgba(139, 69, 19, 0.3);
}

/* High contrast theme */
[data-theme="high-contrast"] .note-ref,
[data-theme="high-contrast"] .footnote-ref,
[data-theme="high-contrast"] .endnote-ref,
[data-theme="high-contrast"] sup[data-ref],
[data-theme="high-contrast"] span[data-note] {
    color: #ffff00;
    background: transparent;
    border: 2px solid #ffff00;
    font-weight: 900;
}

[data-theme="high-contrast"] .note-ref:hover,
[data-theme="high-contrast"] .footnote-ref:hover,
[data-theme="high-contrast"] .endnote-ref:hover,
[data-theme="high-contrast"] sup[data-ref]:hover,
[data-theme="high-contrast"] span[data-note]:hover,
[data-theme="high-contrast"] .note-ref:focus,
[data-theme="high-contrast"] .footnote-ref:focus,
[data-theme="high-contrast"] .endnote-ref:focus,
[data-theme="high-contrast"] sup[data-ref]:focus,
[data-theme="high-contrast"] span[data-note]:focus {
    background: #ffff00;
    color: #000000;
}

[data-theme="high-contrast"] .note-tooltip {
    background: #000000;
    border: 3px solid #ffff00;
}

[data-theme="high-contrast"] .note-tooltip-content {
    color: #ffffff;
}

/* RTL adjustments */
[dir="rtl"] .note-tooltip-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .note-ref,
[dir="rtl"] .footnote-ref,
[dir="rtl"] .endnote-ref,
[dir="rtl"] sup[data-ref],
[dir="rtl"] span[data-note] {
    margin-left: 2px;
    margin-right: 0;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .note-tooltip {
        max-width: calc(100vw - 20px);
        min-width: 280px;
        left: 10px !important;
        right: 10px;
        width: auto !important;
    }

    .note-tooltip-content {
        font-size: 0.9rem;
        padding: 14px;
        max-height: 200px;
    }

    .note-tooltip-header {
        padding: 10px 14px;
    }

    .note-ref,
    .footnote-ref,
    .endnote-ref,
    sup[data-ref],
    span[data-note] {
        padding: 2px 5px;
        font-size: 0.9em;
        min-width: 20px;
        text-align: center;
    }
}

/* Tablet adjustments */
@media (max-width: 1024px) and (min-width: 769px) {
    .note-tooltip {
        max-width: 350px;
        min-width: 280px;
    }
}

/* Print styles - hide tooltips, style refs for print */
@media print {
    .note-tooltip {
        display: none !important;
    }

    .note-ref,
    .footnote-ref,
    .endnote-ref,
    sup[data-ref],
    span[data-note] {
        color: inherit !important;
        background: none !important;
        border: none !important;
        box-shadow: none !important;
        font-weight: bold;
    }

    .note-ref::after,
    .footnote-ref::after,
    .endnote-ref::after,
    sup[data-ref]::after,
    span[data-note]::after {
        content: " (انظر الحواشي)";
        font-size: 0.7em;
        font-style: italic;
    }
}

/* Animation for tooltip appearance */
@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.note-tooltip.visible {
    animation: tooltipFadeIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Loading state for notes */
.notes-loading .note-ref,
.notes-loading .footnote-ref,
.notes-loading .endnote-ref,
.notes-loading sup[data-ref],
.notes-loading span[data-note] {
    opacity: 0.6;
    cursor: wait;
}

/* Error state */
.notes-error .note-ref,
.notes-error .footnote-ref,
.notes-error .endnote-ref,
.notes-error sup[data-ref],
.notes-error span[data-note] {
    color: #e74c3c;
    cursor: not-allowed;
}

/* Accessibility improvements */
.note-ref:focus-visible,
.footnote-ref:focus-visible,
.endnote-ref:focus-visible,
sup[data-ref]:focus-visible,
span[data-note]:focus-visible {
    outline: 3px solid var(--color-primary, #f39c12);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .note-ref,
    .footnote-ref,
    .endnote-ref,
    sup[data-ref],
    span[data-note],
    .note-tooltip {
        transition: none;
        animation: none;
    }
    
    .note-ref:hover,
    .footnote-ref:hover,
    .endnote-ref:hover,
    sup[data-ref]:hover,
    span[data-note]:hover {
        transform: none;
    }
}