/* Tooltip System CSS - Clean Professional Implementation */
:root {
    --tooltip-bg: #ffffff;
    --tooltip-text: #333333;
    --tooltip-border: #e5e7eb;
    --tooltip-border-radius: 6px;
    --tooltip-font-size: 13px;
    --tooltip-padding: 8px 12px;
    --tooltip-max-width: 250px;
    --tooltip-z-index: 999999;
    --tooltip-arrow-size: 5px;
    
    /* Icon styling */
    --tooltip-icon-size: 14px;
    --tooltip-icon-color: #6b7280;
    --tooltip-icon-border: #d1d5db;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --tooltip-bg: #ffffff;
        --tooltip-text: #333333;
        --tooltip-border: #e5e7eb;
    }
}

/* Tooltip Container - wraps both trigger and tooltip content */
.tooltip-container {
    position: relative;
    display: inline-block;
}

/* Tooltip Trigger - the clickable/hoverable element */
.tooltip-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tooltip-icon-size);
    height: var(--tooltip-icon-size);
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--tooltip-icon-border);
    color: var(--tooltip-icon-color);
    font-size: 9px;
    font-weight: 600;
    cursor: help;
    margin-left: 6px;
    flex-shrink: 0;
    transition: transform 0.15s ease;
    position: relative;
    vertical-align: middle;
    transform: translateY(0);
}

/* Make trigger clickable on touch devices */
@media (hover: none) and (pointer: coarse) {
    .tooltip-trigger {
        cursor: pointer;
    }
}

/* Subtle hover effect - no color changes */
.tooltip-trigger:hover {
    transform: scale(1.1) translateY(0);
}

/* Tooltip Content - the actual tooltip box */
.tooltip-content {
    position: absolute;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    border: 1px solid var(--tooltip-border);
    padding: var(--tooltip-padding);
    border-radius: var(--tooltip-border-radius);
    font-size: var(--tooltip-font-size);
    line-height: 1.4;
    max-width: var(--tooltip-max-width);
    min-width: 120px;
    
    /* Positioning - default to top-center */
    bottom: calc(100% + var(--tooltip-arrow-size) + 4px);
    left: 50%;
    transform: translateX(-50%);
    
    /* Visibility and animation */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    
    /* Z-index - single high value for all tooltips */
    z-index: var(--tooltip-z-index);
    
    /* Text styling */
    font-weight: 500;
    word-wrap: break-word;
    text-align: left;
    
    /* Add subtle shadow */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Tooltip Arrow */
.tooltip-content::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: var(--tooltip-arrow-size) solid transparent;
    border-top-color: var(--tooltip-bg);
}

/* Arrow border for better contrast */
.tooltip-content::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: calc(var(--tooltip-arrow-size) + 1px) solid transparent;
    border-top-color: var(--tooltip-border);
    z-index: -1;
}

/* Show tooltip on hover - disabled to prevent conflicts with JS toggle */
/* Tooltips are now controlled entirely by JavaScript for consistent behavior */

/* Alternative positioning classes */
.tooltip-bottom .tooltip-content {
    top: calc(100% + var(--tooltip-arrow-size) + 4px);
    bottom: auto;
}

.tooltip-bottom .tooltip-content::after {
    top: calc(-1 * var(--tooltip-arrow-size) * 2);
    border-top-color: transparent;
    border-bottom-color: var(--tooltip-bg);
}

.tooltip-bottom .tooltip-content::before {
    top: calc(-1 * (var(--tooltip-arrow-size) + 1px) * 2);
    border-top-color: transparent;
    border-bottom-color: var(--tooltip-border);
}

.tooltip-left .tooltip-content {
    right: calc(100% + var(--tooltip-arrow-size) + 4px);
    left: auto;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
}

.tooltip-left .tooltip-content::after {
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-left-color: var(--tooltip-bg);
    border-top-color: transparent;
}

.tooltip-left .tooltip-content::before {
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: calc(var(--tooltip-arrow-size) + 1px) solid transparent;
    border-left-color: var(--tooltip-border);
    z-index: -1;
}

.tooltip-right .tooltip-content {
    left: calc(100% + var(--tooltip-arrow-size) + 4px);
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
}

.tooltip-right .tooltip-content::after {
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-right-color: var(--tooltip-bg);
    border-top-color: transparent;
}

.tooltip-right .tooltip-content::before {
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: calc(var(--tooltip-arrow-size) + 1px) solid transparent;
    border-right-color: var(--tooltip-border);
    z-index: -1;
}

/* Edge detection classes - applied dynamically via JavaScript */
.tooltip-content.edge-left {
    left: 0 !important;
    transform: translateX(0) !important;
}

.tooltip-content.edge-right {
    left: auto !important;
    right: 0 !important;
    transform: translateX(0) !important;
}

.tooltip-content.edge-top {
    top: calc(100% + var(--tooltip-arrow-size) + 4px) !important;
    bottom: auto !important;
}

.tooltip-content.edge-top::after {
    top: calc(-1 * var(--tooltip-arrow-size) * 2);
    border-top-color: transparent;
    border-bottom-color: var(--tooltip-bg);
}

.tooltip-content.edge-top::before {
    top: calc(-1 * (var(--tooltip-arrow-size) + 1px) * 2);
    border-top-color: transparent;
    border-bottom-color: var(--tooltip-border);
}

/* Arrow adjustments for edge-positioned tooltips */
.tooltip-content.edge-left::after,
.tooltip-content.edge-left::before {
    left: 10px;
    transform: translateX(0);
}

.tooltip-content.edge-right::after,
.tooltip-content.edge-right::before {
    right: 10px;
    left: auto;
    transform: translateX(0);
}

/* Constrain tooltip width when near edges */
.tooltip-content.constrain-width {
    max-width: calc(100vw - 30px) !important;
    width: max-content;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    :root {
        --tooltip-max-width: 200px;
        --tooltip-font-size: 12px;
        --tooltip-icon-size: 12px;
    }
}

@media (max-width: 480px) {
    :root {
        --tooltip-max-width: 180px;
        --tooltip-font-size: 11px;
        --tooltip-icon-size: 10px;
    }
}

/* Mobile touch support */
@media (hover: none) and (pointer: coarse) {
    /* On mobile devices, tooltips should be manually triggered */
    .tooltip-container:hover .tooltip-content {
        opacity: 0;
        visibility: hidden;
    }
    
    /* Mobile tooltips need larger touch targets */
    .tooltip-trigger {
        min-width: 24px;
        min-height: 24px;
        touch-action: manipulation;
    }
    
    /* Ensure tooltips are readable on mobile */
    .tooltip-content {
        font-size: 14px;
        padding: 10px 14px;
        max-width: calc(100vw - 40px);
    }
}

/* Prevent tooltip content from being selectable on mobile */
.tooltip-content {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* Context-specific adjustments */

/* Navbar tooltips */
.navbar .tooltip-trigger {
    margin-left: 0;
    margin-right: 6px;
}

/* Navbar dropdown label alignment */
.navbar .detail-label {
    display: flex;
    align-items: center;
    gap: 4px;
}

.navbar .detail-label .tooltip-container {
    flex-shrink: 0;
}

/* Feature list tooltips (smaller) */
.feature-list .tooltip-trigger {
    --tooltip-icon-size: 10px;
    font-size: 7px;
    margin-left: 3px;
}

/* File input container layout and tooltips */
.file-input-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.file-input-container .tooltip-trigger {
    --tooltip-icon-color: rgba(255, 255, 255, 0.8);
    --tooltip-icon-border: rgba(255, 255, 255, 0.5);
    margin-left: 0;
    align-self: flex-start;
    margin-top: 4px;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .tooltip-trigger,
    .tooltip-content {
        transition: none;
    }
    
    .tooltip-trigger:hover {
        transform: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --tooltip-bg: #000000;
        --tooltip-text: #ffffff;
        --tooltip-icon-border: #000000;
    }
    
    .tooltip-trigger {
        border-width: 2px;
    }
}

/* Focus styles for keyboard navigation */
.tooltip-trigger:focus {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

.tooltip-trigger:focus + .tooltip-content,
.tooltip-container:focus-within .tooltip-content {
    opacity: 1;
    visibility: visible;
}

/* Button-specific tooltip alignment */
button .tooltip-trigger,
.action-button .tooltip-trigger,
.upgrade-btn .tooltip-trigger,
.current-plan-button .tooltip-trigger,
.billing-portal-btn .tooltip-trigger,
#submitButton .tooltip-trigger {
    vertical-align: baseline;
    transform: translateY(-1px);
}

button .tooltip-trigger:hover,
.action-button .tooltip-trigger:hover,
.upgrade-btn .tooltip-trigger:hover,
.current-plan-button .tooltip-trigger:hover,
.billing-portal-btn .tooltip-trigger:hover,
#submitButton .tooltip-trigger:hover {
    transform: scale(1.1) translateY(-1px);
}

/* Heading tooltips (subscription page, etc.) */
h1 .tooltip-trigger,
h2 .tooltip-trigger,
h3 .tooltip-trigger,
h4 .tooltip-trigger,
h5 .tooltip-trigger,
h6 .tooltip-trigger {
    vertical-align: baseline;
    transform: translateY(-2px);
    margin-left: 8px;
}

h1 .tooltip-trigger:hover,
h2 .tooltip-trigger:hover,
h3 .tooltip-trigger:hover,
h4 .tooltip-trigger:hover,
h5 .tooltip-trigger:hover,
h6 .tooltip-trigger:hover {
    transform: scale(1.1) translateY(-2px);
}
