/**
 * PM Paper Tooltips - Styles
 * ===========================
 *
 * Advanced tooltip system for paper rendering with:
 * - Smart positioning
 * - Mobile-friendly design
 * - Theme-matched colors
 * - Smooth animations
 * - Interactive elements
 *
 * Copyright (c) 2025-2026 Andrew Keith Watts. All rights reserved.
 */

/* ========================================================================
   TOOLTIP CONTAINER
   ======================================================================== */

.pm-paper-tooltip {
    position: absolute;
    z-index: 100000;
    max-width: 500px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid rgba(139, 127, 255, 0.3);
    border-radius: 12px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.05),
        0 0 20px rgba(139, 127, 255, 0.2);
    color: #f8f9fa;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    pointer-events: none;
    animation: tooltipFadeIn 0.2s ease-out;
    backdrop-filter: blur(10px);
}

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

/* ========================================================================
   TOOLTIP HEADER
   ======================================================================== */

.tooltip-header {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(139, 127, 255, 0.2);
    background: rgba(139, 127, 255, 0.1);
    border-radius: 10px 10px 0 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip-variable,
.tooltip-param-name,
.tooltip-acronym {
    font-family: 'Courier New', 'Fira Code', monospace;
    color: #a394ff;
    font-size: 1.1em;
}

.tooltip-equation-number {
    color: #64ffda;
    font-size: 0.95em;
}

.tooltip-citation-key {
    color: #ffd700;
    font-size: 0.95em;
}

/* ========================================================================
   TOOLTIP BODY
   ======================================================================== */

.tooltip-body {
    padding: 12px 16px;
}

.tooltip-description {
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 8px;
    line-height: 1.5;
}

.tooltip-expansion {
    color: rgba(255, 255, 255, 0.9);
    font-style: italic;
    font-size: 0.95em;
}

/* ========================================================================
   VALUE DISPLAY
   ======================================================================== */

.tooltip-value-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 8px 0;
    padding: 8px 12px;
    background: rgba(100, 255, 218, 0.08);
    border-radius: 6px;
    border-left: 3px solid #64ffda;
}

.tooltip-value-row strong {
    color: #64ffda;
    font-size: 1.1em;
    font-family: 'Courier New', monospace;
}

.tooltip-value {
    color: #64ffda;
    font-weight: 600;
}

.tooltip-units {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9em;
    font-style: italic;
}

/* ========================================================================
   METADATA FIELDS
   ======================================================================== */

.tooltip-uncertainty,
.tooltip-source,
.tooltip-param-link {
    margin: 6px 0;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.9em;
}

.tooltip-uncertainty {
    background: rgba(255, 152, 0, 0.1);
    border-left: 3px solid #ff9800;
    color: #ffb74d;
}

.tooltip-source {
    background: rgba(158, 158, 158, 0.1);
    border-left: 3px solid #9e9e9e;
    color: #e0e0e0;
}

.tooltip-param-link {
    background: rgba(33, 150, 243, 0.1);
    border-left: 3px solid #2196f3;
    color: #90caf9;
}

.tooltip-label {
    font-weight: 600;
    margin-right: 6px;
    opacity: 0.7;
}

.tooltip-source code,
.tooltip-param-link code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', 'Fira Code', monospace;
    color: #a3e635;
    font-size: 0.95em;
}

/* ========================================================================
   STATUS BADGES
   ======================================================================== */

.tooltip-status {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tooltip-status.status-established {
    background: rgba(76, 175, 80, 0.2);
    color: #81c784;
    border: 1px solid rgba(76, 175, 80, 0.4);
}

.tooltip-status.status-predicted {
    background: rgba(33, 150, 243, 0.2);
    color: #64b5f6;
    border: 1px solid rgba(33, 150, 243, 0.4);
}

.tooltip-status.status-derived {
    background: rgba(156, 39, 176, 0.2);
    color: #ba68c8;
    border: 1px solid rgba(156, 39, 176, 0.4);
}

/* ========================================================================
   EQUATION PREVIEW
   ======================================================================== */

.tooltip-equation-preview {
    padding: 12px;
    margin: 8px 0;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    border: 1px solid rgba(139, 127, 255, 0.2);
    text-align: center;
    font-size: 1.1em;
}

/* ========================================================================
   LINKS & ACTIONS
   ======================================================================== */

.tooltip-link {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.tooltip-link a {
    color: #8b7fff;
    text-decoration: none;
    font-size: 0.9em;
    transition: color 0.2s ease;
}

.tooltip-link a:hover {
    color: #a394ff;
    text-decoration: underline;
}

.tooltip-action {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
}

.tooltip-action small {
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.85em;
    font-style: italic;
}

/* ========================================================================
   TOOLTIP VARIANTS (by type)
   ======================================================================== */

.pm-tooltip-variable {
    border-color: rgba(100, 255, 218, 0.4);
}

.pm-tooltip-variable .tooltip-header {
    background: rgba(100, 255, 218, 0.1);
    border-bottom-color: rgba(100, 255, 218, 0.2);
}

.pm-tooltip-parameter {
    border-color: rgba(139, 127, 255, 0.4);
}

.pm-tooltip-formula-ref {
    border-color: rgba(255, 215, 0, 0.4);
}

.pm-tooltip-formula-ref .tooltip-header {
    background: rgba(255, 215, 0, 0.1);
    border-bottom-color: rgba(255, 215, 0, 0.2);
}

.pm-tooltip-citation {
    border-color: rgba(255, 193, 7, 0.4);
}

.pm-tooltip-citation .tooltip-header {
    background: rgba(255, 193, 7, 0.1);
    border-bottom-color: rgba(255, 193, 7, 0.2);
}

.pm-tooltip-acronym {
    border-color: rgba(76, 175, 80, 0.4);
}

.pm-tooltip-acronym .tooltip-header {
    background: rgba(76, 175, 80, 0.1);
    border-bottom-color: rgba(76, 175, 80, 0.2);
}

/* ========================================================================
   INTERACTIVE ELEMENTS - COPY BUTTONS
   ======================================================================== */

.copy-equation-btn {
    background: rgba(139, 127, 255, 0.15);
    border: 1px solid rgba(139, 127, 255, 0.3);
    color: #a394ff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-weight: 500;
}

.copy-equation-btn:hover {
    background: rgba(139, 127, 255, 0.25);
    border-color: rgba(139, 127, 255, 0.5);
    transform: translateY(-1px);
}

.copy-equation-btn:active {
    transform: translateY(0);
}

.copy-equation-btn.copied {
    background: rgba(76, 175, 80, 0.2);
    border-color: rgba(76, 175, 80, 0.4);
    color: #81c784;
}

/* Small copy button for equation wrappers */
.equation-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    font-size: 0.8em;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.equation-wrapper:hover .equation-copy-btn {
    opacity: 1;
}

/* ========================================================================
   INTERACTIVE ELEMENTS - LATEX TOGGLE
   ======================================================================== */

.latex-toggle-btn {
    background: rgba(74, 222, 128, 0.15);
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: #4ade80;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-weight: 500;
    margin-left: 8px;
}

.latex-toggle-btn:hover {
    background: rgba(74, 222, 128, 0.25);
    border-color: rgba(74, 222, 128, 0.5);
    transform: translateY(-1px);
}

.latex-toggle-btn:active {
    transform: translateY(0);
}

/* Show/hide plaintext section based on toggle state */
.pm-formula-card .pm-formula-plaintext-section {
    display: none;
}

.pm-formula-card.show-plaintext .pm-formula-plaintext-section {
    display: block;
}

.pm-formula-card.show-plaintext .pm-formula-latex {
    display: none;
}

/* ========================================================================
   MOBILE RESPONSIVE
   ======================================================================== */

@media (max-width: 768px) {
    .pm-paper-tooltip {
        max-width: 90vw;
        font-size: 13px;
        /* On mobile, center tooltips */
        position: fixed !important;
        left: 5vw !important;
        right: 5vw !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        width: 90vw !important;
        pointer-events: auto; /* Allow taps to close */
    }

    .tooltip-header {
        padding: 10px 12px;
    }

    .tooltip-body {
        padding: 10px 12px;
    }

    .copy-equation-btn,
    .latex-toggle-btn {
        font-size: 0.8em;
        padding: 5px 10px;
    }

    /* Always show copy button on mobile */
    .equation-copy-btn {
        opacity: 1;
    }
}

/* Touch devices - ensure tooltips are visible and interactive */
@media (hover: none) and (pointer: coarse) {
    .pm-paper-tooltip {
        pointer-events: auto;
    }

    /* Make tappable elements more obvious */
    [data-pm-value],
    .equation-ref,
    .acronym,
    .citation {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(139, 127, 255, 0.3);
        padding: 2px 4px;
        margin: -2px -4px;
        border-radius: 3px;
    }

    [data-pm-value]:active,
    .equation-ref:active,
    .acronym:active {
        background: rgba(139, 127, 255, 0.15);
    }
}

/* ========================================================================
   PRINT STYLES
   ======================================================================== */

@media print {
    .pm-paper-tooltip {
        display: none !important;
    }

    .copy-equation-btn,
    .latex-toggle-btn,
    .equation-copy-btn {
        display: none !important;
    }
}

/* ========================================================================
   ACCESSIBILITY
   ======================================================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .pm-paper-tooltip {
        border-width: 3px;
        box-shadow: 0 0 0 2px #fff;
    }

    .tooltip-header {
        border-bottom-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .pm-paper-tooltip {
        animation: none;
    }

    .copy-equation-btn,
    .latex-toggle-btn {
        transition: none;
    }
}

/* Focus styles for keyboard navigation */
.copy-equation-btn:focus,
.latex-toggle-btn:focus {
    outline: 2px solid #8b7fff;
    outline-offset: 2px;
}

/* ========================================================================
   DARK MODE ADJUSTMENTS
   ======================================================================== */

@media (prefers-color-scheme: dark) {
    /* Already optimized for dark mode, but ensure consistency */
    .pm-paper-tooltip {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    }
}

/* Light mode (if site ever supports it) */
@media (prefers-color-scheme: light) {
    .pm-paper-tooltip {
        background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
        color: #1a1a2e;
        border-color: rgba(139, 127, 255, 0.4);
        box-shadow:
            0 10px 40px rgba(0, 0, 0, 0.15),
            0 0 0 1px rgba(0, 0, 0, 0.05);
    }

    .tooltip-header {
        background: rgba(139, 127, 255, 0.08);
        border-bottom-color: rgba(139, 127, 255, 0.2);
    }

    .tooltip-description,
    .tooltip-expansion {
        color: rgba(0, 0, 0, 0.85);
    }

    .tooltip-variable,
    .tooltip-param-name,
    .tooltip-acronym {
        color: #6b5cff;
    }

    .tooltip-value-row {
        background: rgba(100, 255, 218, 0.1);
    }

    .tooltip-value-row strong {
        color: #00a896;
    }
}

/* ========================================================================
   LOADING STATES
   ======================================================================== */

.tooltip-loading {
    padding: 16px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
}

.tooltip-loading::after {
    content: '...';
    animation: tooltipLoading 1.5s infinite;
}

@keyframes tooltipLoading {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.tooltip-error {
    padding: 16px;
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid rgba(244, 67, 54, 0.3);
    border-radius: 8px;
    color: #f87171;
}
