/* 
   Tippy Tooltip Styling - Compatible with Read the Docs
   Works with both private repositories and public docs
   Coordinated with both tippy_preview.js and enhance_references.js
*/

/* Base tooltip styling */
.tippy-box {
    background-color: var(--pst-color-surface, white);
    color: var(--pst-color-text-base, #333);
    border: 1px solid var(--pst-color-border, #ccc);
    max-width: 800px !important; 
    font-size: 0.9rem;
    line-height: 1.4;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    z-index: 100000 !important; /* Make sure tooltips stay on top of other elements */
}

/* Support for standard reference links with tooltips */
a.reference.tippyAnchor, a.reference.internal {
    cursor: pointer;
}

/* Make sure the tippy tooltip content has good styling */
.tippy-content {
    padding: 12px;
    max-width: 800px;
    font-size: 0.9rem;
    overflow: auto;
    max-height: 600px !important;
}

/* Styled tooltip elements */
.tippy-preview {
    font-family: var(--pst-font-family-base, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif);
}

.tippy-preview-heading {
    font-weight: bold;
    padding-bottom: 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--pst-color-border, #eaecef);
    font-size: 1.1rem;
}

/* Enhanced full-page content preview styling */
.tippy-preview-full-content {
    max-height: 500px;
    overflow-y: auto;
    margin-top: 8px;
    padding: 5px 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.tippy-content-wrapper {
    width: 100%;
}

.tippy-box[data-theme="light-border"],
.tippy-content {
    max-height: none !important;
    overflow: visible !important;
}

/* Image styling */
.tippy-preview-full-content img {
    max-width: 100%;
    height: auto;
    margin: 8px 0;
    border: none;
    display: block;
}

/* Table styling */
.tippy-preview-full-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    font-size: 0.85rem;
}

.tippy-preview-full-content th,
.tippy-preview-full-content td {
    border: 1px solid #e1e4e8;
    padding: 6px 12px;
}

.tippy-preview-full-content th {
    background-color: #f6f8fa;
}

/* Make sure links inside tooltips are visible */
.tippy-preview-full-content a {
    color: #0366d6;
    text-decoration: underline;
}

/* Loading spinner for async content */
.loading-spinner {
    width: 24px;
    height: 24px;
    margin: 10px auto;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: var(--pst-color-primary, #2980b9);
    animation: spinner 0.8s linear infinite;
}

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

/* Error message styling */
.tippy-error-message {
    color: #e74c3c;
    font-size: 0.85rem;
    font-style: italic;
}

/* Section styling */
.tippy-section {
    margin-bottom: 15px;
}

/* RTD Theme compatibility */
.rst-content .tippy-preview-full-content .admonition,
.rst-content .tippy-preview-full-content .note,
.rst-content .tippy-preview-full-content .warning {
    padding: 12px;
    margin-bottom: 12px;
    background: #f8f8f8;
    border-left: 4px solid #2980b9;
}

/* ====== Fix for duplicate tooltips ====== */
/* Hide tooltips created by sphinx_tippy on elements we handle with our custom tooltips */
.custom-tippy-initialized + .tippy-box:not([data-theme="light-border"]) {
    display: none !important;
}

/* Ensure enhance_references tooltips have proper styling */
.enhance-references-tooltip {
    z-index: 100000 !important;
    opacity: 1 !important;
}

/* Style differences between the two tooltip systems */
.tippy-box[data-theme="light"] {
    background-color: #fff;
    border: 1px solid #e0e0e0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.tippy-box[data-theme="light-border"] {
    z-index: 100001 !important; /* Higher than other tooltips */
    opacity: 1 !important;
}

/* ====== CRITICAL: Prevent tooltips inside tooltips ====== */
/* Disable tooltips on elements inside tooltips */
.tippy-box a.reference,
.tippy-box .page-reference,
.tippy-box .section-reference,
.tippy-box .subsection-reference,
.tippy-box .tab-reference,
.tippy-box .table-reference,
.tippy-box .column-reference,
.tippy-box .item-reference,
.tippy-box .action-reference,
.tippy-box .code-reference,
.tippy-content a.reference,
.tippy-content .page-reference,
.tippy-content .section-reference,
.tippy-content .subsection-reference,
.tippy-content .tab-reference,
.tippy-content .table-reference,
.tippy-content .column-reference,
.tippy-content .item-reference,
.tippy-content .action-reference,
.tippy-content .code-reference {
    pointer-events: auto !important; /* Allow clicks but not tooltips */
    cursor: pointer;
}

/* Style for links marked as no-preview */
a.no-preview {
    text-decoration: inherit;
    color: inherit;
    cursor: pointer;
}

/* Hide the default browser tooltip */
.reference[title] {
    text-decoration: none;
}

/* Reference styles - ensure compatibility with custom reference types */
/* Page reference - blue-gray with document icon */
.page-reference {
    background-color: #e3f2fd;
    color: #0d47a1;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    position: relative;
    padding-left: 22px;
    text-decoration: none !important;
    border: 1px solid #bbdefb;
}

.page-reference::before {
    content: "📄";
    position: absolute;
    left: 5px;
    top: 1px;
}

/* Section reference - blue with list icon */
.section-reference {
    background-color: #e1f5fe;
    color: #01579b;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    position: relative;
    padding-left: 22px;
    text-decoration: none !important;
    border: 1px solid #b3e5fc;
}

.section-reference::before {
    content: "📋";
    position: absolute;
    left: 5px;
    top: 1px;
}

/* Subsection reference - pink with column icon */
.subsection-reference {
    background-color: #fce4ec;
    color: #c2185b;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    position: relative;
    padding-left: 22px;
    text-decoration: none !important;
    border: 1px solid #f8bbd0;
}

.subsection-reference::before {
    content: "📑";
    position: absolute;
    left: 5px;
    top: 1px;
}

/* Tab reference - gray with tab icon */
.tab-reference {
    background-color: #eeeeee;
    color: #424242;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    position: relative;
    padding-left: 22px;
    text-decoration: none !important;
    border: 1px solid #e0e0e0;
}

.tab-reference::before {
    content: "🔖";
    position: absolute;
    left: 5px;
    top: 1px;
}

/* Table reference - teal with grid icon */
.table-reference {
    background-color: #e0f2f1;
    color: #00695c;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    position: relative;
    padding-left: 22px;
    text-decoration: none !important;
    border: 1px solid #b2dfdb;
}

.table-reference::before {
    content: "🔲";
    position: absolute;
    left: 5px;
    top: 1px;
}

/* Column reference - light gray with column icon */
.column-reference {
    background-color: #f5f5f5;
    color: #616161;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    position: relative;
    padding-left: 22px;
    text-decoration: none !important;
    border: 1px solid #e0e0e0;
}

.column-reference::before {
    content: "📊";
    position: absolute;
    left: 5px;
    top: 1px;
}

/* Item reference - simple light gray background */
.item-reference {
    background-color: #f5f5f5;
    color: #212121;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    text-decoration: none !important;
    border: 1px solid #e0e0e0;
}

/* Action reference - bold red text with thin red border */
.action-reference {
    background-color: #ffffff;
    color: #f44336;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 0.85em;
    white-space: nowrap;
    text-transform: uppercase;
    text-decoration: none !important;
    border: 1px solid #f44336;
}

/* Code reference styling */
.code-reference {
    background-color: #f1f8e9;
    color: #33691e;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
    white-space: nowrap;
    text-decoration: none !important;
    border: 1px solid #dcedc8;
}