/* Tooltip Component Styles */
.tooltip-container {
    position: relative;
    display: inline-block;
}

.tooltip {
    position: absolute;
    z-index: 1000;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    white-space: normal;
    max-width: 85vw; /* viewport width의 85%까지 확장 가능 */
    min-width: 150px; /* 기본 최소 너비 보장 */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    transform: translateY(5px);
    word-wrap: break-word; /* 긴 단어 줄바꿈 */
    overflow-wrap: break-word; /* 긴 단어 줄바꿈 (현대 브라우저) */
    text-align: left; /* 텍스트 왼쪽 정렬 */
    hyphens: auto; /* 자동 하이픈 처리 */
    -webkit-hyphens: auto;
    -ms-hyphens: auto;
}

.tooltip.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Tooltip Arrow */
.tooltip::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}

/* Tooltip Positions */
.tooltip.top {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-5px);
    margin-bottom: 8px;
}

.tooltip.top.show {
    transform: translateX(-50%) translateY(0);
}

.tooltip.top::before {
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0 6px;
    border-color: rgba(0, 0, 0, 0.9) transparent transparent transparent;
}

.tooltip.bottom {
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    margin-top: 8px;
}

.tooltip.bottom.show {
    transform: translateX(-50%) translateY(0);
}

.tooltip.bottom::before {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 6px 6px 6px;
    border-color: transparent transparent rgba(0, 0, 0, 0.9) transparent;
}

.tooltip.left {
    right: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(-5px);
    margin-right: 8px;
}

.tooltip.left.show {
    transform: translateY(-50%) translateX(0);
}

.tooltip.left::before {
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px 0 6px 6px;
    border-color: transparent transparent transparent rgba(0, 0, 0, 0.9);
}

.tooltip.right {
    left: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(5px);
    margin-left: 8px;
}

.tooltip.right.show {
    transform: translateY(-50%) translateX(0);
}

.tooltip.right::before {
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px 6px 6px 0;
    border-color: transparent rgba(0, 0, 0, 0.9) transparent transparent;
}

/* Trigger styles */
.tooltip-trigger {
    cursor: pointer;
    transition: color 0.2s ease;
}

.tooltip-trigger:hover {
    color: #3b82f6;
}

/* Desktop - 더 넓은 툴팁 */
@media (min-width: 1024px) {
    .tooltip {
        max-width: 600px; /* 데스크탑에서는 최대 600px */
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) {
    .tooltip {
        max-width: 90vw; /* 태블릿에서는 viewport의 90% */
        min-width: 250px; /* 태블릿 최소 너비 */
    }
}

/* Mobile - 최대한 활용 */
@media (max-width: 767px) {
    .tooltip {
        max-width: 95vw; /* 모바일에서는 viewport의 95%로 확장 */
        min-width: 200px; /* 최소 너비 보장 */
        font-size: 13px;
        padding: 10px 12px;
        /* 텍스트 최적화 */
        text-align: left;
        hyphens: auto; /* 자동 하이픈 처리 */
        -webkit-hyphens: auto;
        -ms-hyphens: auto;
    }
}

/* Very small devices */
@media (max-width: 360px) {
    .tooltip {
        max-width: 98vw; /* 아주 작은 화면에서는 98%까지 확장 */
        min-width: 180px; /* 최소 너비 보장 */
        font-size: 12px;
        padding: 8px 10px;
    }
}

/* 화면 오른쪽에서 잘리는 경우 조정 */
.tooltip.adjust-right {
    left: auto !important;
    right: 8px !important;
    transform: translateY(5px) !important;
}

.tooltip.adjust-right.show {
    transform: translateY(0) !important;
}

.tooltip.adjust-right.bottom {
    transform: translateY(5px) !important;
}

.tooltip.adjust-right.bottom.show {
    transform: translateY(0) !important;
}

/* 화면 왼쪽에서 잘리는 경우 조정 */  
.tooltip.adjust-left {
    left: 8px !important;
    right: auto !important;
    transform: translateY(5px) !important;
}

.tooltip.adjust-left.show {
    transform: translateY(0) !important;
}

.tooltip.adjust-left.bottom {
    transform: translateY(5px) !important;
}

.tooltip.adjust-left.bottom.show {
    transform: translateY(0) !important;
}

/* 모바일에서 더 정교한 위치 조정 */
@media (max-width: 767px) {
    .tooltip.bottom {
        left: clamp(4px, calc(50% - 50vw + 50%), calc(100vw - 4px - 100%));
    }
    
    .tooltip.adjust-right {
        right: 4px !important;
    }
    
    .tooltip.adjust-left {
        left: 4px !important;
    }
}