/* ===== 개선된 아이템 조합 트리 시스템 스타일 ===== */

/* 기본 페이지 스타일 */
.page-header {
    text-align: center;
    margin: 1rem 0;
    padding: 1rem 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
}

.page-header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.page-header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* ===== 4레벨 아이템 선택 바 개선 ===== */
.level4-selection {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 0.8rem;
    margin: 0.8rem 0;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
}

.level4-selection h2 {
    text-align: center;
    margin-bottom: 0.6rem;
    color: #2d3748;
    font-weight: 600;
    font-size: 1.1rem;
}

.level4-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 0.8rem;
    max-width: none;
    margin: 0;
    width: 100%;
}

.level4-item {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 0.8rem 0.5rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    text-align: center;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.level4-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.level4-item:hover::before {
    opacity: 0.1;
}

.level4-item:hover {
    transform: translateY(-8px) scale(1.05);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 107, 107, 0.5);
}

.level4-item.selected {
    transform: translateY(-5px) scale(1.03);
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.4);
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

.level4-item.selected::before {
    background: linear-gradient(135deg, #667eea, #764ba2);
    opacity: 0.15;
}

.level4-item-image {
    width: 40px;
    height: 40px;
    margin: 0 auto 0.5rem auto;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.level4-item:hover .level4-item-image {
    transform: scale(1.1);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.level4-item-name {
    font-weight: 600;
    color: #2d3748;
    font-size: 0.7rem;
    line-height: 1.2;
    transition: color 0.3s ease;
}

.level4-item.selected .level4-item-name {
    color: #667eea;
    font-weight: 700;
}

/* ===== 트리 컨테이너 개선 ===== */
.tree-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    margin: 1rem 0;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    min-height: 550px;
}

.tree-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 1.2rem;
    text-align: center;
    position: relative;
}

.tree-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.2);
}

.tree-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

.tree-subtitle {
    font-size: 1rem;
    opacity: 0.9;
    font-weight: 400;
}

.tree-controls {
    position: absolute;
    top: 50%;
    right: 2rem;
    transform: translateY(-50%);
    display: flex;
    gap: 0.5rem;
}

.control-btn {
    width: 40px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

/* ===== SVG 트리 영역 개선 ===== */
.svg-tree-container {
    position: relative;
    width: 100%;
    height: 500px;
    overflow: hidden;
}

#treeSvg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#itemNodes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

/* ===== 아이템 노드 개선 ===== */
.item-node {
    position: absolute;
    pointer-events: auto;
    transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    opacity: 0;
    transform: scale(0.8) translateY(-20px);
    cursor: pointer;
}

.item-node.visible {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.item-node:hover {
    transform: scale(1.15) translateY(-8px);
    z-index: 100;
    filter: drop-shadow(0 12px 25px rgba(0,0,0,0.25));
}

/* 노드 레벨별 스타일 */
.item-node.level-4 {
    animation-delay: 0ms;
}

.item-node.level-3 {
    animation-delay: 200ms;
}

.item-node.level-2 {
    animation-delay: 400ms;
}

.item-node.level-1 {
    animation-delay: 600ms;
}

/* 노드 레시피 타입별 스타일 */
.item-node.recipe-final {
    filter: drop-shadow(0 8px 25px rgba(255, 107, 107, 0.4));
}

.item-node.recipe-basic {
    filter: drop-shadow(0 4px 15px rgba(102, 126, 234, 0.3));
}

.item-node.recipe-alternative {
    filter: drop-shadow(0 4px 15px rgba(165, 94, 234, 0.3));
}

/* ===== 연결선 애니메이션 개선 ===== */
.connection-line {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawLine 1.5s ease-out forwards;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

@keyframes drawLine {
    to {
        stroke-dashoffset: 0;
    }
}

/* ===== 고정 툴팁 개선 ===== */
.fixed-tooltip-container {
    position: sticky;
    top: 2rem;
    height: fit-content;
}

#fixedTooltip {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    opacity: 0;
    display: none;
}

#fixedTooltip.visible {
    opacity: 1;
    display: block;
}

.tooltip-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

#tooltipImage {
    width: 80px;
    height: 80px;
    border-radius: 15px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.tooltip-info {
    flex: 1;
}

#tooltipTitle {
    font-size: 1.3rem;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

#tooltipLevel {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 15px;
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tooltip-content {
    space-y: 1rem;
}

.tooltip-content > div {
    margin-bottom: 1rem;
}

.tooltip-content > div:last-child {
    margin-bottom: 0;
}

#tooltipEffect {
    background: rgba(72, 187, 120, 0.1);
    border: 1px solid rgba(72, 187, 120, 0.3);
    border-radius: 10px;
    padding: 1rem;
    color: #22543d;
    font-weight: 500;
    position: relative;
}

#tooltipEffect::before {
    content: '⚡';
    position: absolute;
    top: -8px;
    left: 12px;
    background: rgba(72, 187, 120, 0.2);
    padding: 0.2rem 0.5rem;
    border-radius: 5px;
    font-size: 0.8rem;
}

#tooltipDescription {
    color: #4a5568;
    line-height: 1.6;
    font-size: 0.95rem;
}

/* ===== 기본 메시지 개선 ===== */
#defaultMessage {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 500px;
    text-align: center;
    transition: all 0.4s ease;
}

#defaultMessage i {
    font-size: 4rem;
    color: #a0aec0;
    margin-bottom: 2rem;
    animation: pulse 2s infinite;
}

#defaultMessage p {
    font-size: 1.2rem;
    color: #718096;
    font-weight: 500;
    line-height: 1.6;
    max-width: 400px;
}

@keyframes pulse {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1);
    }
    50% { 
        opacity: 0.7; 
        transform: scale(1.05);
    }
}

/* ===== 로딩 애니메이션 개선 ===== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(102, 126, 234, 0.1);
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading p {
    color: #667eea;
    font-weight: 500;
    font-size: 1.1rem;
}

/* ===== 에러 메시지 개선 ===== */
.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    background: rgba(255, 107, 107, 0.05);
    border: 2px solid rgba(255, 107, 107, 0.2);
    border-radius: 20px;
    margin: 2rem;
}

.error-container i {
    font-size: 3rem;
    color: #ff6b6b;
    margin-bottom: 1.5rem;
    animation: shake 2s infinite;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.error-container p {
    color: #ff6b6b;
    font-weight: 500;
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.retry-btn {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

.retry-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

/* ===== 상단 레이아웃: 아이템 선택 + 정보 ===== */
.top-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

/* ===== 하단 레이아웃: 트리 (전체 폭) ===== */
.bottom-layout {
    width: 100%;
}

.tree-section {
    min-height: 500px;
    width: 100%;
    height: calc(100vh - 350px);
}

.info-section {
    position: relative;
    height: fit-content;
}

/* ===== 추가 유틸리티 클래스 ===== */
.fade-in {
    animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slide-in-left {
    animation: slideInLeft 0.8s ease-out;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.bounce-in {
    animation: bounceIn 0.8s ease-out;
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===== 반응형 디자인 개선 ===== */
@media (max-width: 1200px) {
    .top-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .info-section {
        order: -1;
    }
    
    .tree-section {
        height: calc(100vh - 400px);
        min-height: 450px;
    }
    
    .level4-items {
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
        gap: 0.8rem;
    }
    
    .tree-controls {
        position: static;
        transform: none;
        margin-top: 1rem;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .level4-selection {
        padding: 1.5rem;
        margin: 1rem 0;
    }
    
    .level4-items {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.6rem;
    }
    
    .level4-item {
        padding: 0.6rem 0.4rem;
    }
    
    .level4-item-image {
        width: 35px;
        height: 35px;
        margin-bottom: 0.4rem;
    }
    
    .level4-item-name {
        font-size: 0.65rem;
    }
    
    .tree-container {
        margin: 1rem 0;
        border-radius: 15px;
    }
    
    .tree-header {
        padding: 1.5rem 1rem;
    }
    
    .tree-title {
        font-size: 1.4rem;
    }
    
    .svg-tree-container {
        height: 500px;
    }
    
    #fixedTooltip {
        padding: 1.5rem;
    }
    
    .tooltip-header {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    #tooltipImage {
        width: 60px;
        height: 60px;
    }
    
    #tooltipTitle {
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .page-header {
        margin: 1rem 0;
        padding: 1.5rem 1rem;
    }
    
    .page-header h1 {
        font-size: 2rem;
    }
    
    .level4-items {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .level4-item-image {
        width: 30px;
        height: 30px;
    }
    
    .svg-tree-container {
        height: 400px;
    }
    
    .main-layout {
        padding: 0 0.5rem;
    }
}

/* ===== 접근성 개선 ===== */
.level4-item:focus,
.item-node:focus,
.control-btn:focus {
    outline: 3px solid rgba(102, 126, 234, 0.6);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .item-node,
    .level4-item,
    .connection-line,
    .spinner {
        animation: none;
        transition: none;
    }
    
    .item-node:hover,
    .level4-item:hover {
        transform: none;
    }
}

/* ===== 다크 모드 지원 (추후 확장용) ===== */
@media (prefers-color-scheme: dark) {
    /* 다크 모드 스타일은 추후 구현 */
}

/* ===== 고해상도 디스플레이 최적화 ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .level4-item-image,
    #tooltipImage {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== 조합 트리 기능 스타일 ===== */

/* 조합 트리 버튼 */
.recipe-actions {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.recipe-tree-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    width: 100%;
    justify-content: center;
}

.recipe-tree-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    background: linear-gradient(135deg, #5a67d8, #6b46c1);
}

.recipe-tree-btn:active {
    transform: translateY(0);
}

.tree-icon {
    font-size: 1.2rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-5px);
    }
    60% {
        transform: translateY(-3px);
    }
}

/* 조합 트리 모달 */
.recipe-tree-modal {
    /* 스타일은 JavaScript에서 인라인으로 적용 */
}

.recipe-tree-content {
    /* 스타일은 JavaScript에서 인라인으로 적용 */
}

/* 로딩 스피너 (모달용) */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    text-align: center;
}

.loading-spinner .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(102, 126, 234, 0.1);
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.loading-spinner p {
    color: #667eea;
    font-weight: 500;
    margin: 0;
}

/* 조합 트리 노드 스타일 개선 */
.recipe-node {
    transition: all 0.3s ease;
    position: relative;
}

.recipe-node:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1) !important;
}

.recipe-node.level-0 {
    border-width: 3px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.recipe-node.level-1 {
    opacity: 0.95;
}

.recipe-node.level-2 {
    opacity: 0.9;
}

.recipe-node.level-3 {
    opacity: 0.85;
}

/* 에러 메시지 (모달용) */
.error-message {
    /* 스타일은 JavaScript에서 인라인으로 적용 */
}

.error-message h4 {
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.error-message p {
    margin-bottom: 20px;
    opacity: 0.8;
}

/* 반응형 조정 */
@media (max-width: 768px) {
    .recipe-tree-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
    }
    
    .tree-icon {
        font-size: 1rem;
    }
    
    .recipe-node {
        margin-left: 10px !important; /* JavaScript 인라인 스타일 오버라이드 */
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .loading-spinner {
        padding: 40px 20px;
    }
}

@media (max-width: 480px) {
    .recipe-tree-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .recipe-node {
        margin-left: 5px !important;
        padding: 10px;
        font-size: 0.85rem;
    }
}

/* ===== 삼각형 문제 해결을 위한 추가 CSS ===== */

/* 모든 삼각형 관련 스타일 제거/무효화 */
.tree-viewport *::before,
.tree-viewport *::after {
    display: none !important;
    content: none !important;
}

/* 트리 영역 내 삼각형 모양 요소 숨기기 */
.tree-viewport .triangle,
.tree-viewport [class*="triangle"],
.tree-viewport [style*="border-left"][style*="transparent"],
.tree-viewport [style*="border-right"][style*="transparent"] {
    display: none !important;
    visibility: hidden !important;
}

/* Bootstrap 드롭다운 삼각형 제거 */
.tree-viewport .dropdown-toggle::after,
.tree-viewport .dropup .dropdown-toggle::after,
.tree-viewport .dropend .dropdown-toggle::after,
.tree-viewport .dropstart .dropdown-toggle::before {
    display: none !important;
}

/* 강제로 삼각형 제거 (최종 보험) */
*[style*="border-left: 10px solid transparent"],
*[style*="border-right: 10px solid transparent"],
*[style*="border-bottom"] {
    display: none !important;
}

/* 트리 영역 클린업 */
.tree-container .triangle,
.tree-container [class*="triangle"] {
    display: none !important;
    visibility: hidden !important;
}

/* 트리 뷰포트 격리 */
.tree-viewport {
    isolation: isolate;
}

/* 안전한 기본 스타일 */
.tree-viewport * {
    box-sizing: border-box;
}

.tree-viewport *::before,
.tree-viewport *::after {
    box-sizing: border-box;
}

/* 추가 삼각형 제거 - 더 강력한 규칙 */
.tree-viewport {
    /* 모든 하위 요소의 의사 요소 완전 제거 */
}

.tree-viewport *::before,
.tree-viewport *::after {
    display: none !important;
    content: none !important;
    border: none !important;
    background: none !important;
}

/* SVG 내부 삼각형도 제거 */
.tree-viewport svg *[class*="triangle"],
.tree-viewport svg *[style*="triangle"] {
    display: none !important;
}

/* 특정 CSS 패턴으로 생성되는 삼각형 제거 */
.tree-viewport *[style*="border-left"][style*="transparent"],
.tree-viewport *[style*="border-right"][style*="transparent"],
.tree-viewport *[style*="border-top"][style*="transparent"],
.tree-viewport *[style*="border-bottom"][style*="transparent"] {
    display: none !important;
    visibility: hidden !important;
}
