/* Custom Tooltip Styles */
.custom-tooltip {
    background: rgba(32, 33, 36, 0.95);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    max-width: 250px;
    white-space: normal;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    letter-spacing: 0.2px;
    user-select: none;
}

.custom-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Arrow for tooltip */
.custom-tooltip::before {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 8px;
    height: 8px;
    background: inherit;
    box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    pointer-events: none;
}

/* Theme support */
body.theme .custom-tooltip {
    background: rgba(255, 255, 255, 0.95);
    color: #1a202c;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Ensure focusable elements have proper focus styles */
[data-tooltip]:focus,
[aria-label]:focus,
.achievement-bar:focus,
.position-heat-bar:focus,
.streak-segment:focus,
.sweet-spot-bar:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Make non-interactive elements focusable for tooltip accessibility */
.achievement-bar,
.position-heat-bar {
    cursor: pointer;
}

/* No pointer cursor for streak segments or sweet spots */
.streak-segment,
.sweet-spot-bar {
    cursor: default !important;
}

/* Note: tabindex should be set in HTML, not CSS */
.achievement-bar:not([tabindex]),
.position-heat-bar:not([tabindex]) {
    /* Elements should have tabindex="0" attribute in HTML for keyboard accessibility */
}

/* Tooltip positioning variations */
.custom-tooltip.position-top {
    margin-bottom: 8px;
}

.custom-tooltip.position-bottom {
    margin-top: 8px;
}

.custom-tooltip.position-bottom::before {
    top: -4px;
    bottom: auto;
    box-shadow: -2px -2px 2px rgba(0, 0, 0, 0.1);
}

.custom-tooltip.position-left {
    margin-right: 8px;
}

.custom-tooltip.position-left::before {
    right: -4px;
    left: auto;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}

.custom-tooltip.position-right {
    margin-left: 8px;
}

.custom-tooltip.position-right::before {
    left: -4px;
    right: auto;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}

/* Special styling for different tooltip types */
.custom-tooltip.achievement-tooltip {
    background: linear-gradient(135deg, #667eea 0%, #7c3aed 100%);
    font-weight: 600;
}

.custom-tooltip.warning-tooltip {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.custom-tooltip.success-tooltip {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.custom-tooltip.error-tooltip {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .custom-tooltip {
        font-size: 12px;
        padding: 5px 10px;
        max-width: 200px;
    }
    
    /* Disable tooltips on touch devices for better UX */
    @media (hover: none) {
        .custom-tooltip {
            display: none !important;
        }
    }
}

/* High contrast mode support */
@media (prefers-contrast) {
    .custom-tooltip {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
    
    body.theme .custom-tooltip {
        background: #fff;
        color: #000;
        border: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .custom-tooltip {
        transition: none;
    }
}

/* Z-index management to ensure tooltips appear above modals */
.add-race-dropdown.active ~ .custom-tooltip,
.quick-race-form:not([style*="display: none"]) ~ .custom-tooltip {
    z-index: 10001;
}

/* Special positioning for sidebar tooltips to avoid header overlap */
.sidebar-header .custom-tooltip,
.sidebar-header-buttons .custom-tooltip {
    z-index: 10002;
    transform: translateY(8px) translateX(-50%);
}

.sidebar-header .custom-tooltip.visible,
.sidebar-header-buttons .custom-tooltip.visible {
    transform: translateY(12px) translateX(-50%);
}

/* Ensure tooltips don't interfere with input fields */
.input-field:focus-within ~ .custom-tooltip {
    pointer-events: none;
    opacity: 0;
}

/* Animation for tooltip entrance */
@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.custom-tooltip.visible {
    animation: tooltipFadeIn 0.2s ease forwards;
}
