/**
 * Estilos CSS para el frontend de Custom Tooltips
 */

/* Contenedor principal de tooltips */
#custom-tooltip-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    z-index: 999999;
    pointer-events: none;
}

/* Estilos base para tooltips */
.custom-tooltip {
    position: absolute;
    z-index: 999999;
    padding: 10px 15px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    max-width: 300px;
    pointer-events: auto;
    cursor: default;
    
    /* Valores por defecto */
    background-color: #ffffff;
    color: #cccccc;
    
    /* Transiciones suaves */
    opacity: 1;
    transform: scale(1);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Tooltip oculto inicialmente */
.custom-tooltip.hidden {
    opacity: 0;
    transform: scale(0.8);
}

/* Tooltip visible */
.custom-tooltip.show {
    opacity: 1;
    transform: scale(1);
}

/* Contenido del tooltip */
.custom-tooltip-content {
    margin: 0;
    padding: 0;
}

/* Enlaces dentro del tooltip */
.custom-tooltip-content a {
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.custom-tooltip-content a:hover {
    text-decoration: none;
    opacity: 0.8;
}

.custom-tooltip-content p {
    margin: 0 0 10px 0;
}

.custom-tooltip-content p:last-child {
    margin-bottom: 0;
}

.custom-tooltip-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.custom-tooltip-content a {
    color: inherit;
    text-decoration: underline;
}

.custom-tooltip-content a:hover {
    text-decoration: none;
}

/* Flecha del tooltip */
.custom-tooltip-arrow {
    position: absolute;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    z-index: 1;
}

/* Posiciones de flecha según ubicación del tooltip */
.custom-tooltip[data-position="top"] .custom-tooltip-arrow {
    border-top-color: inherit;
    bottom: -12px;
    left: 50%;
    margin-left: -6px;
}

#custom-tooltip-container .custom-tooltip-arrow::after {
    content: "";
    position: absolute;
}

.custom-tooltip[data-position="bottom"] .custom-tooltip-arrow {
    border-bottom-color: inherit;
    top: -12px;
    left: 50%;
    margin-left: -6px;
}

.custom-tooltip[data-position="left"] .custom-tooltip-arrow {
    border-left-color: inherit;
    right: -12px;
    top: 50%;
    margin-top: -6px;
}

.custom-tooltip[data-position="right"] .custom-tooltip-arrow {
    border-right-color: inherit;
    left: -12px;
    top: 50%;
    margin-top: -6px;
}

.custom-tooltip[data-position="top-left"] .custom-tooltip-arrow,
.custom-tooltip[data-position="top-right"] .custom-tooltip-arrow {
    border-top-color: inherit;
    bottom: -12px;
}

.custom-tooltip[data-position="top-left"] .custom-tooltip-arrow {
    left: 20px;
}

.custom-tooltip[data-position="top-right"] .custom-tooltip-arrow {
    right: 20px;
}

.custom-tooltip[data-position="bottom-left"] .custom-tooltip-arrow,
.custom-tooltip[data-position="bottom-right"] .custom-tooltip-arrow {
    border-bottom-color: inherit;
    top: -12px;
}

.custom-tooltip[data-position="bottom-left"] .custom-tooltip-arrow {
    left: 20px;
}

.custom-tooltip[data-position="bottom-right"] .custom-tooltip-arrow {
    right: 20px;
}

/* Elementos que tienen tooltip activo */
[data-tooltip-active="true"] {
    position: relative;
}

/* Estilos para diferentes tipos de contenido */
.custom-tooltip-content h1,
.custom-tooltip-content h2,
.custom-tooltip-content h3,
.custom-tooltip-content h4,
.custom-tooltip-content h5,
.custom-tooltip-content h6 {
    margin: 0 0 10px 0;
    font-size: 1.1em;
    font-weight: bold;
}

.custom-tooltip-content ul,
.custom-tooltip-content ol {
    margin: 0 0 10px 20px;
    padding: 0;
}

.custom-tooltip-content li {
    margin-bottom: 5px;
}

.custom-tooltip-content blockquote {
    margin: 10px 0;
    padding: 10px 15px;
    border-left: 1px solid #cccccc;
    background: rgba(255, 255, 255, 0.1);
    font-style: italic;
}

.custom-tooltip-content code {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 4px;
    border-radius: 0;
    font-family: monospace;
    font-size: 0.9em;
}

.custom-tooltip-content pre {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 0;
    overflow-x: auto;
    font-family: monospace;
    font-size: 0.9em;
    white-space: pre-wrap;
}

/* Variaciones de tamaño */
.custom-tooltip.size-small {
    font-size: 12px;
    padding: 8px 12px;
    max-width: 200px;
}

.custom-tooltip.size-large {
    font-size: 16px;
    padding: 15px 20px;
    max-width: 400px;
}

/* Temas predefinidos */
.custom-tooltip.theme-dark {
    background-color: #2c3e50;
    color: #ffffff;
    border: 1px solid #34495e;
}

.custom-tooltip.theme-light {
    background-color: #ffffff;
    color: #000000;
    border: 1px solid #cccccc;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
}

.custom-tooltip.theme-success {
    background-color: #27ae60;
    color: #ffffff;
}

.custom-tooltip.theme-warning {
    background-color: #f39c12;
    color: #ffffff;
}

.custom-tooltip.theme-error {
    background-color: #e74c3c;
    color: #ffffff;
}

.custom-tooltip.theme-info {
    background-color: #3498db;
    color: #ffffff;
}

/* Animaciones adicionales */
@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes tooltipFadeOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-10px) scale(0.8);
    }
}

.custom-tooltip.animate-in {
    animation: tooltipFadeIn 0.2s ease-out forwards;
}

.custom-tooltip.animate-out {
    animation: tooltipFadeOut 0.15s ease-in forwards;
}

/* Responsive */
@media screen and (max-width: 768px) {
    .custom-tooltip {
        max-width: 280px;
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .custom-tooltip.size-large {
        max-width: 320px;
        font-size: 14px;
    }
}

@media screen and (max-width: 480px) {
    .custom-tooltip {
        max-width: 250px;
        font-size: 12px;
        padding: 8px 10px;
    }
    
    .custom-tooltip.size-large {
        max-width: 280px;
        font-size: 13px;
    }
    
    /* En móviles, ajustar posición para evitar que se salga de pantalla */
    .custom-tooltip {
        left: 10px !important;
        right: 10px !important;
        max-width: calc(100vw - 20px) !important;
        width: auto !important;
    }
}

/* Accesibilidad */
@media (prefers-reduced-motion: reduce) {
    .custom-tooltip {
        transition: none;
    }
    
    .custom-tooltip.animate-in,
    .custom-tooltip.animate-out {
        animation: none;
    }
}

/* Alto contraste */
@media (prefers-contrast: high) {
    .custom-tooltip {
        border: 1px solid;
        box-shadow: none;
    }
    
    .custom-tooltip.theme-light {
        border-color: #000000;
    }
    
    .custom-tooltip.theme-dark {
        border-color: #cccccc;
    }
}

/* Modo oscuro del sistema */
@media (prefers-color-scheme: dark) {
    .custom-tooltip:not([class*="theme-"]) {
        background-color: #2c3e50;
        color: #ffffff;
        border: 1px solid #34495e;
    }
}

/* Estilos para elementos con tooltip en hover */
[data-has-tooltip] {
    cursor: help;
    position: relative;
}

[data-has-tooltip]:hover {
    text-decoration: underline;
    text-decoration-style: dotted;
}

/* Indicador visual para elementos con tooltip click */
[data-tooltip-trigger="click"] {
    cursor: pointer;
    position: relative;
}

[data-tooltip-trigger="click"]::after {
    content: "ⓘ";
    display: inline-block;
    margin-left: 4px;
    font-size: 0.8em;
    opacity: 0.6;
    font-weight: normal;
}

/* Ocultar indicador en elementos que ya tienen contenido visual */
[data-tooltip-trigger="click"] img::after,
[data-tooltip-trigger="click"] button::after,
[data-tooltip-trigger="click"] input::after {
    display: none;
}

/* Botón de cierre para tooltips con activación click */
.custom-tooltip-close {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    color: #000;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background-color 0.2s ease, transform 0.1s ease;
    font-family: Arial, sans-serif;
    font-weight: bold;
    padding: 0;
    margin: 0;
}

.custom-tooltip-close:hover {
    background: none;
    transform: scale(1.1);
}

.custom-tooltip-close:active {
    transform: scale(0.95);
}

.custom-tooltip-close:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 1px;
}

/* Ajustar padding del tooltip cuando tiene botón de cierre */
.custom-tooltip:has(.custom-tooltip-close) {
    padding-top: 30px;
}

/* Fallback para navegadores que no soportan :has() */
.custom-tooltip .custom-tooltip-close ~ .custom-tooltip-content {
    margin-top: 10px;
}

/* Estilos específicos para dispositivos móviles */
@media screen and (max-width: 768px) {
    .custom-tooltip-close {
        width: 24px;
        height: 24px;
        font-size: 16px;
        top: 8px;
        right: 8px;
    }
    
    .custom-tooltip:has(.custom-tooltip-close) {
        padding-top: 35px;
    }
    
    .custom-tooltip .custom-tooltip-close ~ .custom-tooltip-content {
        margin-top: 15px;
    }
}

/* Mejorar contraste en modo alto contraste */
@media (prefers-contrast: high) {
    .custom-tooltip-close {
        background: none;
        border: 1px solid #000;
    }
    
    .custom-tooltip-close:hover {
        background: none;
        color: #333;
    }
}

/* Modo oscuro del sistema */
@media (prefers-color-scheme: dark) {
    .custom-tooltip-close {
        background: none;
        color: #000;
    }
    
    .custom-tooltip-close:hover {
        background: none;
        color: #333;
    }
}
